use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class ScriptResourceTest method shouldFailIfNoScriptIsSuppliedOnCreate.
@Test(expectedExceptions = BadRequestException.class)
public void shouldFailIfNoScriptIsSuppliedOnCreate() throws ResourceException {
// given
JsonValue requestJson = json(object(field(SCRIPT_NAME, "MyJavaScript"), field(SCRIPT_LANGUAGE, "JAVASCRIPT"), field(SCRIPT_CONTEXT, "POLICY_CONDITION")));
CreateRequest createRequest = mock(CreateRequest.class);
when(createRequest.getContent()).thenReturn(requestJson);
// when
scriptResource.createInstance(context, createRequest).getOrThrowUninterruptibly();
// then - exception
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class ScriptResourceTest method shouldFailIfNoLanguageIsSuppliedOnCreate.
@Test(expectedExceptions = BadRequestException.class)
public void shouldFailIfNoLanguageIsSuppliedOnCreate() throws ResourceException {
// given
JsonValue requestJson = json(object(field(SCRIPT_NAME, "MyJavaScript"), field(SCRIPT_TEXT, encodeScript), field(SCRIPT_CONTEXT, "POLICY_CONDITION")));
CreateRequest createRequest = mock(CreateRequest.class);
when(createRequest.getContent()).thenReturn(requestJson);
// when
scriptResource.createInstance(context, createRequest).getOrThrowUninterruptibly();
// then - exception
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldAcceptConsistentPolicyNamesFromURLandJSON.
@Test
public void shouldAcceptConsistentPolicyNamesFromURLandJSON() throws Exception {
// Given
String policyName = "policyName";
// Policy name can be specified in *both* URL and JSON so long as it is equal
JsonValue json = JsonValue.json(JsonValue.object(JsonValue.field("name", policyName)));
CreateRequest request = mockCreateRequest(policyName, json);
Privilege policy = mockPrivilege(policyName, 123l);
given(mockParser.parsePolicy(policyName, json)).willReturn(policy);
// When
policyResource.createInstance(mockServerContext, request);
// Then
verify(mockParser).parsePolicy(policyName, json);
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class PolicyV1FilterTest method createFailsWhenMissingApplication.
/**
* Verifies that the application name missing from the request is handled appropriately.
*/
@Test
public void createFailsWhenMissingApplication() {
// Given
CreateRequest createRequest = mock(CreateRequest.class);
JsonValue jsonValue = json(object());
given(createRequest.getContent()).willReturn(jsonValue);
// When
Promise<ResourceResponse, ResourceException> promise = filter.filterCreate(context, createRequest, requestHandler);
// Then
assertThat(promise).failedWithResourceException().withCode(ResourceException.BAD_REQUEST);
// Request should not be forwarded.
verifyNoMoreInteractions(requestHandler);
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class PolicyV1FilterTest method resourceTypeAssociationOnCreate.
/**
* Verifies that the appropriate resource type is associated with the policy being created.
*/
@Test
public void resourceTypeAssociationOnCreate() throws Exception {
// Given
given(contextHelper.getRealm(context)).willReturn("/abc");
given(contextHelper.getSubject(context)).willReturn(subject);
CreateRequest createRequest = mock(CreateRequest.class);
JsonValue jsonValue = json(object(field("applicationName", "testApp")));
given(createRequest.getContent()).willReturn(jsonValue);
given(applicationServiceFactory.create(subject, "/abc")).willReturn(applicationService);
Application application = mock(Application.class);
given(applicationService.getApplication("testApp")).willReturn(application);
Set<String> resourceTypeUUIDs = new HashSet<>(CollectionUtils.asSet("abc-def-hij"));
given(application.getResourceTypeUuids()).willReturn(resourceTypeUUIDs);
// When
Promise<ResourceResponse, ResourceException> promise = filter.filterCreate(context, createRequest, requestHandler);
// Then
assertThat(promise).succeeded();
verify(applicationServiceFactory).create(subject, "/abc");
verify(applicationService).getApplication("testApp");
assertThat(jsonValue.get("resourceTypeUuid").asString()).isEqualTo("abc-def-hij");
assertThat(promise.get().getContent().contains("resourceTypeUuid")).isFalse();
}
Aggregations