Skip to content

Commit

Permalink
Adds test for recipient registry
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Dec 31, 2024
1 parent f1d3011 commit 00ba7a7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void registerRecipientType(String key, RecipientType recipientType
public static RecipientType fromValue(String value) {
RecipientType type = REGISTRY.get(value);
if (type == null) {
throw new IllegalArgumentException("Unknown RecipientType: " + value);
throw new IllegalArgumentException("Unknown RecipientType: " + value + ". Must be 1 of these: " + REGISTRY.values());
}
return type;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.accesscontrol.resources;

import org.opensearch.test.OpenSearchTestCase;
import org.hamcrest.MatcherAssert;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

public class RecipientTypeRegistryTests extends OpenSearchTestCase {

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());

// Invalid Value
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> RecipientTypeRegistry.fromValue("bleble"));
MatcherAssert.assertThat("Unknown RecipientType: bleble. Must be 1 of these: [ble1, ble2]", is(equalTo(exception.getMessage())));
}
}

0 comments on commit 00ba7a7

Please sign in to comment.