Skip to content

Commit

Permalink
Fixes checkstyle errors
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Jan 10, 2025
1 parent 512c1a8 commit 85c4556
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@

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.notNullValue;
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"));
RecipientTypeRegistry.registerRecipientType("ble2", new RecipientType("ble2"));

// 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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,29 @@
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.notNullValue;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
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() {
Expand All @@ -55,16 +58,16 @@ public void testFromXContentWhenCurrentTokenIsNotStartObject() throws IOExceptio

ShareWith shareWith = ShareWith.fromXContent(parser);

assertNotNull(shareWith);
MatcherAssert.assertThat(shareWith, notNullValue());
Set<SharedWithScope> 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<RecipientType, Set<String>> 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"));
Expand All @@ -77,11 +80,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()));
}

Expand All @@ -108,7 +111,7 @@ public void testFromXContentWithStartObject() throws IOException {

ShareWith shareWith = ShareWith.fromXContent(parser);

assertNotNull(shareWith);
MatcherAssert.assertThat(shareWith, notNullValue());
Set<SharedWithScope> scopes = shareWith.getSharedWithScopes();
MatcherAssert.assertThat(scopes.size(), equalTo(2));

Expand Down Expand Up @@ -152,7 +155,7 @@ public void testFromXContentWithUnexpectedEndOfInput() throws IOException {

ShareWith result = ShareWith.fromXContent(mockParser);

assertNotNull(result);
MatcherAssert.assertThat(result, notNullValue());
MatcherAssert.assertThat(result.getSharedWithScopes(), is(empty()));
}

Expand Down

0 comments on commit 85c4556

Please sign in to comment.