diff --git a/src/test/java/org/opensearch/security/resources/CreatedByTests.java b/src/test/java/org/opensearch/security/resources/CreatedByTests.java index 6b183ccbc7..346a949444 100644 --- a/src/test/java/org/opensearch/security/resources/CreatedByTests.java +++ b/src/test/java/org/opensearch/security/resources/CreatedByTests.java @@ -19,17 +19,18 @@ import org.opensearch.core.common.io.stream.StreamOutput; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; -import org.opensearch.test.OpenSearchTestCase; +import org.opensearch.security.test.SingleClusterTest; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class CreatedByTests extends OpenSearchTestCase { +public class CreatedByTests extends SingleClusterTest { private static final String CREATOR_TYPE = "user"; diff --git a/src/test/java/org/opensearch/security/resources/RecipientTypeRegistryTests.java b/src/test/java/org/opensearch/security/resources/RecipientTypeRegistryTests.java index 394bae608e..725b430752 100644 --- a/src/test/java/org/opensearch/security/resources/RecipientTypeRegistryTests.java +++ b/src/test/java/org/opensearch/security/resources/RecipientTypeRegistryTests.java @@ -10,12 +10,12 @@ import org.hamcrest.MatcherAssert; -import org.opensearch.test.OpenSearchTestCase; +import org.opensearch.security.test.SingleClusterTest; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.assertThrows; -public class RecipientTypeRegistryTests extends OpenSearchTestCase { +public class RecipientTypeRegistryTests extends SingleClusterTest { public void testFromValue() { RecipientTypeRegistry.registerRecipientType("ble1", new RecipientType("ble1")); @@ -23,8 +23,8 @@ public void testFromValue() { // Valid Value RecipientType type = RecipientTypeRegistry.fromValue("ble1"); - assertNotNull(type); - assertEquals("ble1", type.getType()); + MatcherAssert.assertThat(type, notNullValue()); + MatcherAssert.assertThat(type.getType(), is(equalTo("ble1"))); // Invalid Value IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> RecipientTypeRegistry.fromValue("bleble")); diff --git a/src/test/java/org/opensearch/security/resources/ShareWithTests.java b/src/test/java/org/opensearch/security/resources/ShareWithTests.java index 43b2b6f502..7c5396d493 100644 --- a/src/test/java/org/opensearch/security/resources/ShareWithTests.java +++ b/src/test/java/org/opensearch/security/resources/ShareWithTests.java @@ -21,18 +21,17 @@ import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.core.common.io.stream.StreamOutput; +import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.security.spi.resources.ResourceAccessScope; -import org.opensearch.test.OpenSearchTestCase; +import org.opensearch.security.test.SingleClusterTest; import org.mockito.Mockito; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; @@ -40,7 +39,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class ShareWithTests extends OpenSearchTestCase { +public class ShareWithTests extends SingleClusterTest { @Before public void setupResourceRecipientTypes() { @@ -55,16 +54,16 @@ public void testFromXContentWhenCurrentTokenIsNotStartObject() throws IOExceptio ShareWith shareWith = ShareWith.fromXContent(parser); - assertNotNull(shareWith); + MatcherAssert.assertThat(shareWith, notNullValue()); Set sharedWithScopes = shareWith.getSharedWithScopes(); - assertNotNull(sharedWithScopes); + MatcherAssert.assertThat(sharedWithScopes, notNullValue()); MatcherAssert.assertThat(1, equalTo(sharedWithScopes.size())); SharedWithScope scope = sharedWithScopes.iterator().next(); MatcherAssert.assertThat("read_only", equalTo(scope.getScope())); SharedWithScope.ScopeRecipients scopeRecipients = scope.getSharedWithPerScope(); - assertNotNull(scopeRecipients); + MatcherAssert.assertThat(scopeRecipients, notNullValue()); Map> recipients = scopeRecipients.getRecipients(); MatcherAssert.assertThat(recipients.get(RecipientTypeRegistry.fromValue(DefaultRecipientType.USERS.getName())).size(), is(1)); MatcherAssert.assertThat(recipients.get(RecipientTypeRegistry.fromValue(DefaultRecipientType.USERS.getName())), contains("user1")); @@ -77,11 +76,11 @@ public void testFromXContentWhenCurrentTokenIsNotStartObject() throws IOExceptio public void testFromXContentWithEmptyInput() throws IOException { String emptyJson = "{}"; - XContentParser parser = XContentType.JSON.xContent().createParser(xContentRegistry(), null, emptyJson); + XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, null, emptyJson); ShareWith result = ShareWith.fromXContent(parser); - assertNotNull(result); + MatcherAssert.assertThat(result, notNullValue()); MatcherAssert.assertThat(result.getSharedWithScopes(), is(empty())); } @@ -108,7 +107,7 @@ public void testFromXContentWithStartObject() throws IOException { ShareWith shareWith = ShareWith.fromXContent(parser); - assertNotNull(shareWith); + MatcherAssert.assertThat(shareWith, notNullValue()); Set scopes = shareWith.getSharedWithScopes(); MatcherAssert.assertThat(scopes.size(), equalTo(2)); @@ -152,7 +151,7 @@ public void testFromXContentWithUnexpectedEndOfInput() throws IOException { ShareWith result = ShareWith.fromXContent(mockParser); - assertNotNull(result); + MatcherAssert.assertThat(result, notNullValue()); MatcherAssert.assertThat(result.getSharedWithScopes(), is(empty())); }