3030import org .apache .solr .client .solrj .SolrClient ;
3131import org .apache .solr .client .solrj .SolrRequest ;
3232import org .apache .solr .client .solrj .SolrServerException ;
33- import org .apache .solr .client .solrj .impl .CloudSolrClient ;
3433import org .apache .solr .client .solrj .response .LukeResponse ;
3534import org .apache .solr .client .solrj .response .QueryResponse ;
3635import org .apache .solr .client .solrj .response .SolrPingResponse ;
@@ -48,9 +47,6 @@ class CollectionServiceTest {
4847 @ Mock
4948 private SolrClient solrClient ;
5049
51- @ Mock
52- private CloudSolrClient cloudSolrClient ;
53-
5450 @ Mock
5551 private QueryResponse queryResponse ;
5652
@@ -75,32 +71,17 @@ void constructor_ShouldInitializeWithSolrClient() {
7571 assertNotNull (collectionService );
7672 }
7773
78- @ Test
79- void listCollections_WithCloudSolrClient_ShouldReturnCollections () throws Exception {
80- // Given - This test verifies the service can be constructed with
81- // CloudSolrClient
82- CollectionService cloudService = new CollectionService (cloudSolrClient , objectMapper );
83-
84- // Note: This test cannot fully exercise listCollections() because it requires
85- // mocking static methods in CollectionAdminRequest which requires PowerMock or
86- // Mockito inline. The actual behavior is tested in integration tests.
87-
88- // When/Then - Verify service construction
89- assertNotNull (cloudService , "Should be able to construct service with CloudSolrClient" );
90- }
91-
9274 @ Test
9375 void listCollections_WhenExceptionOccurs_ShouldReturnEmptyList () throws Exception {
94- // Note: This test cannot fully exercise listCollections() with mock SolrClient
95- // because it requires mocking CoreAdminRequest processing. The actual error
96- // handling behavior is tested in integration tests.
76+ // Given - mock throws exception
77+ when (solrClient .request (any (), any ())).thenThrow (new SolrServerException ("Connection error" ));
9778
98- // Given/When - Using regular SolrClient (non-cloud) which will attempt
99- // CoreAdmin
100- // The mock doesn't have a real CoreAdmin implementation
79+ // When
80+ List <String > result = collectionService .listCollections ();
10181
102- // Then - Verify service is constructed
103- assertNotNull (collectionService , "Service should be constructed successfully" );
82+ // Then
83+ assertNotNull (result );
84+ assertTrue (result .isEmpty ());
10485 }
10586
10687 // Collection name extraction tests
@@ -697,16 +678,13 @@ void isHandlerStatsEmpty() throws Exception {
697678
698679 // List collections tests
699680 @ Test
700- void listCollections_CloudClient_Success () throws Exception {
701- CloudSolrClient cloudClient = mock (CloudSolrClient .class );
702-
681+ void listCollections_Success () throws Exception {
703682 NamedList <Object > response = new NamedList <>();
704683 response .add ("collections" , Arrays .asList ("collection1" , "collection2" ));
705684
706- when (cloudClient .request (any (), any ())).thenReturn (response );
685+ when (solrClient .request (any (), any ())).thenReturn (response );
707686
708- CollectionService service = new CollectionService (cloudClient , objectMapper );
709- List <String > result = service .listCollections ();
687+ List <String > result = collectionService .listCollections ();
710688
711689 assertNotNull (result );
712690 assertEquals (2 , result .size ());
@@ -715,64 +693,33 @@ void listCollections_CloudClient_Success() throws Exception {
715693 }
716694
717695 @ Test
718- void listCollections_CloudClient_NullCollections () throws Exception {
719- CloudSolrClient cloudClient = mock (CloudSolrClient .class );
720-
696+ void listCollections_NullCollections () throws Exception {
721697 NamedList <Object > response = new NamedList <>();
722698 response .add ("collections" , null );
723699
724- when (cloudClient .request (any (), any ())).thenReturn (response );
700+ when (solrClient .request (any (), any ())).thenReturn (response );
725701
726- CollectionService service = new CollectionService (cloudClient , objectMapper );
727- List <String > result = service .listCollections ();
702+ List <String > result = collectionService .listCollections ();
728703
729704 assertNotNull (result );
730705 assertTrue (result .isEmpty ());
731706 }
732707
733708 @ Test
734- void listCollections_CloudClient_Error () throws Exception {
735- CloudSolrClient cloudClient = mock (CloudSolrClient .class );
736- when (cloudClient .request (any (), any ())).thenThrow (new SolrServerException ("Connection error" ));
709+ void listCollections_Error () throws Exception {
710+ when (solrClient .request (any (), any ())).thenThrow (new SolrServerException ("Connection error" ));
737711
738- CollectionService service = new CollectionService (cloudClient , objectMapper );
739- List <String > result = service .listCollections ();
712+ List <String > result = collectionService .listCollections ();
740713
741714 assertNotNull (result );
742715 assertTrue (result .isEmpty ());
743716 }
744717
745718 @ Test
746- void listCollections_NonCloudClient_Success () throws Exception {
747- // Create a NamedList to represent the core status response
748- NamedList <Object > response = new NamedList <>();
749- NamedList <Object > status = new NamedList <>();
750-
751- NamedList <Object > core1Status = new NamedList <>();
752- NamedList <Object > core2Status = new NamedList <>();
753-
754- status .add ("core1" , core1Status );
755- status .add ("core2" , core2Status );
756- response .add ("status" , status );
757-
758- // Mock the solrClient request to return the response
759- when (solrClient .request (any (), any ())).thenReturn (response );
760-
761- CollectionService service = new CollectionService (solrClient , objectMapper );
762- List <String > result = service .listCollections ();
763-
764- assertNotNull (result );
765- assertEquals (2 , result .size ());
766- assertTrue (result .contains ("core1" ));
767- assertTrue (result .contains ("core2" ));
768- }
769-
770- @ Test
771- void listCollections_NonCloudClient_Error () throws Exception {
719+ void listCollections_IOError () throws Exception {
772720 when (solrClient .request (any (), any ())).thenThrow (new IOException ("IO error" ));
773721
774- CollectionService service = new CollectionService (solrClient , objectMapper );
775- List <String > result = service .listCollections ();
722+ List <String > result = collectionService .listCollections ();
776723
777724 assertNotNull (result );
778725 assertTrue (result .isEmpty ());
@@ -897,38 +844,22 @@ private NamedList<Object> createCompleteHandlerData() {
897844
898845 // createCollection tests
899846 @ Test
900- void createCollection_success_cloudClient () throws Exception {
901- CloudSolrClient cloudClient = mock (CloudSolrClient .class );
902- when (cloudClient .request (any (), any ())).thenReturn (new NamedList <>());
903-
904- CollectionService service = new CollectionService (cloudClient , objectMapper );
905- CollectionCreationResult result = service .createCollection ("new_collection" , "_default" , 1 , 1 );
906-
907- assertNotNull (result );
908- assertTrue (result .success ());
909- assertEquals ("new_collection" , result .name ());
910- assertNotNull (result .createdAt ());
911- }
912-
913- @ Test
914- void createCollection_success_standaloneClient () throws Exception {
847+ void createCollection_success () throws Exception {
915848 when (solrClient .request (any (), isNull ())).thenReturn (new NamedList <>());
916849
917- CollectionCreationResult result = collectionService .createCollection ("new_core " , null , null , null );
850+ CollectionCreationResult result = collectionService .createCollection ("new_collection " , "_default" , 1 , 1 );
918851
919852 assertNotNull (result );
920853 assertTrue (result .success ());
921- assertEquals ("new_core " , result .name ());
854+ assertEquals ("new_collection " , result .name ());
922855 assertNotNull (result .createdAt ());
923856 }
924857
925858 @ Test
926859 void createCollection_defaultsApplied () throws Exception {
927- CloudSolrClient cloudClient = mock (CloudSolrClient .class );
928- when (cloudClient .request (any (), any ())).thenReturn (new NamedList <>());
860+ when (solrClient .request (any (), isNull ())).thenReturn (new NamedList <>());
929861
930- CollectionService service = new CollectionService (cloudClient , objectMapper );
931- CollectionCreationResult result = service .createCollection ("defaults_collection" , null , null , null );
862+ CollectionCreationResult result = collectionService .createCollection ("defaults_collection" , null , null , null );
932863
933864 assertTrue (result .success ());
934865 assertEquals ("defaults_collection" , result .name ());
0 commit comments