use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldCreatePoliciesInStore.
@Test
public void shouldCreatePoliciesInStore() throws Exception {
// Given
String id = "uniqueId";
long lastModified = 12345l;
JsonValue json = new JsonValue("");
CreateRequest request = mockCreateRequest(id, json);
Privilege policy = mockPrivilege(id, lastModified);
JsonValue result = new JsonValue("result");
given(mockParser.parsePolicy(id, json)).willReturn(policy);
given(mockParser.printPolicy(policy)).willReturn(result);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.createInstance(mockServerContext, request);
// Then
verify(mockStore).create(policy);
assertThat(promise).succeeded().withId().isNotNull();
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldRejectMismatchedPolicyName.
@Test
public void shouldRejectMismatchedPolicyName() throws Exception {
// Given
String policyName = "policyName";
String differentPolicyName = "Different!";
JsonValue json = JsonValue.json(JsonValue.object(JsonValue.field("name", policyName)));
CreateRequest request = mockCreateRequest(differentPolicyName, json);
Privilege policy = mockPrivilege(policyName, 123l);
given(mockParser.parsePolicy(differentPolicyName, json)).willReturn(policy);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.createInstance(mockServerContext, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PolicyResourceTest method mockPrivilege.
private Privilege mockPrivilege(String name, long lastModified) throws EntitlementException {
Privilege mock = new StubPrivilege();
mock.setName(name);
mock.setLastModifiedDate(lastModified);
return mock;
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldParseResourceAttributes.
@Test
public void shouldParseResourceAttributes() throws Exception {
// Given
List<String> values = Arrays.asList("one", "two", "three");
JsonValue content = buildJson(field("resourceAttributes", Arrays.asList(object(field("type", "Static"), field("propertyName", "test"), field("propertyValues", values)))));
// Given
Privilege result = parser.parsePolicy(POLICY_NAME, content);
// Then
assertThat(result.getResourceAttributes()).hasSize(1);
ResourceAttribute attr = result.getResourceAttributes().iterator().next();
assertThat(attr).isInstanceOf(StaticAttributes.class);
assertThat(attr.getPropertyName()).isEqualTo("test");
assertThat(attr.getPropertyValues()).containsOnly(values.toArray());
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldNotPrintPolicyAttributes.
@Test
public void shouldNotPrintPolicyAttributes() throws Exception {
// Given
Privilege policy = new StubPrivilege();
policy.setEntitlement(new Entitlement());
policy.getEntitlement().setAttributes(Collections.singletonMap("one", CollectionUtils.asSet("two")));
// When
JsonValue result = parser.printPolicy(policy);
// Then
// Attributes should not appear on the policy entitlement
assertThat(result.get("attributes").asMapOfList(String.class)).isNullOrEmpty();
}
Aggregations