diff --git a/solr/core/src/test/org/apache/solr/handler/admin/api/ClusterPropsAPITest.java b/solr/core/src/test/org/apache/solr/handler/admin/api/ClusterPropsAPITest.java index 9ae628e71eb..f690dbc1498 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/api/ClusterPropsAPITest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/api/ClusterPropsAPITest.java @@ -18,6 +18,8 @@ package org.apache.solr.handler.admin.api; import static org.apache.solr.common.util.Utils.getObjectByPath; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.not; import java.net.URL; import java.util.List; @@ -86,11 +88,14 @@ public void tearDown() throws Exception { @Test public void testClusterPropertyOpsAllGood() throws Exception { try (HttpSolrClient client = new HttpSolrClient.Builder(baseUrl.toString()).build()) { - // List Properties, confirm there aren't any + // List Properties, confirm the test property does not exist + // This ignores eventually existing other properties Object o = Utils.executeGET(client.getHttpClient(), baseUrlV2ClusterProps, Utils.JSONCONSUMER); assertNotNull(o); - assertEquals(0, ((List) getObjectByPath(o, true, "clusterProperties")).size()); + @SuppressWarnings("unchecked") + List initProperties = (List) getObjectByPath(o, true, "clusterProperties"); + assertThat(initProperties, not(hasItem(testClusterProperty))); // Create a single cluster property String path = baseUrlV2ClusterProps + "/" + testClusterProperty; @@ -100,13 +105,12 @@ public void testClusterPropertyOpsAllGood() throws Exception { o = Utils.executeHttpMethod(client.getHttpClient(), path, Utils.JSONCONSUMER, httpPut); assertNotNull(o); - // List Properties, this time there should be 1 + // List Properties, this time there should be the just added property o = Utils.executeGET(client.getHttpClient(), baseUrlV2ClusterProps, Utils.JSONCONSUMER); assertNotNull(o); - assertEquals(1, ((List) getObjectByPath(o, true, "clusterProperties")).size()); - assertEquals( - testClusterProperty, - (String) ((List) getObjectByPath(o, true, "clusterProperties")).get(0)); + @SuppressWarnings("unchecked") + List updatedProperties = (List) getObjectByPath(o, true, "clusterProperties"); + assertThat(updatedProperties, hasItem(testClusterProperty)); // Fetch Cluster Property // Same path as used in the Create step above @@ -122,10 +126,12 @@ public void testClusterPropertyOpsAllGood() throws Exception { o = Utils.executeHttpMethod(client.getHttpClient(), path, Utils.JSONCONSUMER, httpDelete); assertNotNull(o); - // List Properties, should be back to 0 + // List Properties, the test property should be gone o = Utils.executeGET(client.getHttpClient(), baseUrlV2ClusterProps, Utils.JSONCONSUMER); assertNotNull(o); - assertEquals(0, ((List) getObjectByPath(o, true, "clusterProperties")).size()); + @SuppressWarnings("unchecked") + List clearedProperties = (List) getObjectByPath(o, true, "clusterProperties"); + assertThat(clearedProperties, not(hasItem(testClusterProperty))); } }