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 PolicyResourceDelegateTest method shouldCreatePolicies.
@Test
public void shouldCreatePolicies() throws ResourceException {
//Given
//Given
Context context = mock(Context.class);
Set<JsonValue> policies = new HashSet<JsonValue>();
JsonValue policyOne = json(object(field("name", "POLICY_ONE")));
JsonValue policyTwo = json(object(field("name", "POLICY_TWO")));
policies.add(policyOne);
policies.add(policyTwo);
List<ResourceResponse> createdPolicies = new ArrayList<ResourceResponse>();
ResourceResponse createdPolicyOne = newResourceResponse("ID_1", "REVISION_1", json(object()));
ResourceResponse createdPolicyTwo = newResourceResponse("ID_2", "REVISION_2", json(object()));
createdPolicies.add(createdPolicyOne);
createdPolicies.add(createdPolicyTwo);
Promise<ResourceResponse, ResourceException> createPolicyOnePromise = Promises.newResultPromise(createdPolicyOne);
Promise<ResourceResponse, ResourceException> createPolicyTwoPromise = Promises.newResultPromise(createdPolicyTwo);
given(policyResource.handleCreate(eq(context), Matchers.<CreateRequest>anyObject())).willReturn(createPolicyOnePromise).willReturn(createPolicyTwoPromise);
//When
List<ResourceResponse> returnedPolicies = delegate.createPolicies(context, policies).getOrThrowUninterruptibly();
//Then
verify(policyResource, never()).handleDelete(eq(context), Matchers.<DeleteRequest>anyObject());
assertThat(returnedPolicies).isEqualTo(createdPolicies);
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class PolicyResourceDelegateTest method shouldHandleFailureToCreatePoliciesByDeletingCreatedPolicies.
@Test(expectedExceptions = ResourceException.class)
public void shouldHandleFailureToCreatePoliciesByDeletingCreatedPolicies() throws ResourceException {
//Given
//Given
Context context = mock(Context.class);
Set<JsonValue> policies = new HashSet<JsonValue>();
JsonValue policyOne = json(object(field("name", "POLICY_ONE")));
JsonValue policyTwo = json(object(field("name", "POLICY_TWO")));
policies.add(policyOne);
policies.add(policyTwo);
ResourceResponse createdPolicyOne = newResourceResponse("ID_1", "REVISION_1", json(object()));
ResourceException exception = mock(ResourceException.class);
Promise<ResourceResponse, ResourceException> createPolicyOnePromise = Promises.newResultPromise(createdPolicyOne);
Promise<ResourceResponse, ResourceException> createPolicyTwoPromise = Promises.newExceptionPromise(exception);
Promise<ResourceResponse, ResourceException> deletePolicyOnePromise = Promises.newResultPromise(createdPolicyOne);
given(policyResource.handleCreate(eq(context), Matchers.<CreateRequest>anyObject())).willReturn(createPolicyOnePromise).willReturn(createPolicyTwoPromise);
given(policyResource.handleDelete(eq(context), Matchers.<DeleteRequest>anyObject())).willReturn(deletePolicyOnePromise);
//When
try {
delegate.createPolicies(context, policies).getOrThrowUninterruptibly();
} catch (ResourceException e) {
//Then
ArgumentCaptor<DeleteRequest> requestCaptor = ArgumentCaptor.forClass(DeleteRequest.class);
verify(policyResource).handleDelete(eq(context), requestCaptor.capture());
assertThat(requestCaptor.getValue().getResourcePathObject().leaf()).isEqualTo("ID_1");
throw e;
}
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class UmaEnabledFilterTest method testFilterCreate.
@Test(dataProvider = "factories")
public void testFilterCreate(UmaProviderSettingsFactory factory, boolean expectFailure) throws Exception {
// Given
UmaEnabledFilter filter = new UmaEnabledFilter(factory);
CreateRequest request = Requests.newCreateRequest("test", json(object()));
// When
Promise<ResourceResponse, ResourceException> promise = filter.filterCreate(context, request, requestHandler);
// Then
checkResult(expectFailure, promise);
if (expectFailure) {
verifyNoMoreInteractions(requestHandler);
} else {
verify(requestHandler).handleCreate(context, request);
}
}
Aggregations