use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class PolicyV1FilterTest method resourceTypeAssociationOnUpdate.
/**
* Verifies that the appropriate resource type is associated with the policy being updated.
*/
@Test
public void resourceTypeAssociationOnUpdate() throws Exception {
// Given
given(contextHelper.getRealm(context)).willReturn("/abc");
given(contextHelper.getSubject(context)).willReturn(subject);
UpdateRequest updateRequest = mock(UpdateRequest.class);
JsonValue jsonValue = json(object(field("applicationName", "testApp")));
given(updateRequest.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.filterUpdate(context, updateRequest, 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();
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class ResourceTypesResourceTest method createShouldFailIfCallerSubjectNotPresent.
@Test
public void createShouldFailIfCallerSubjectNotPresent() {
//given
CreateRequest mockCreateRequest = mock(CreateRequest.class);
// subject is null, which will represent a broken SSOTokenContext
callerSubject = null;
//when
Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.createInstance(mockServerContext, mockCreateRequest);
//then
assertResourcePromiseFailedWithCodes(promise, ResourceException.INTERNAL_ERROR, EntitlementException.INTERNAL_ERROR);
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldReportBadCreateRequests.
@Test
public void shouldReportBadCreateRequests() throws Exception {
// Given
String id = "uniqueId";
JsonValue json = new JsonValue("");
CreateRequest request = mockCreateRequest(id, json);
given(mockParser.parsePolicy(id, json)).willThrow(new EntitlementException(EntitlementException.INVALID_JSON, "Mock error message"));
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.createInstance(mockServerContext, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldDeletePoliciesFromStore.
@Test
public void shouldDeletePoliciesFromStore() throws Exception {
// Given
String id = "uniqueId";
DeleteRequest request = mock(DeleteRequest.class);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.deleteInstance(mockServerContext, id, request);
// Then
verify(mockStore).delete(id);
assertThat(promise).succeeded().withId().isNotNull();
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class ClientResourceTest method shouldCreateIdentity.
@Test
public void shouldCreateIdentity() throws SSOException, IdRepoException, ResourceException {
// Given
Map<String, ArrayList<String>> client = new HashMap<>();
//must contain userpassword, realm, client_id, "com.forgerock.openam.oauth2provider.clientType"
client.put("client_id", new ArrayList(Arrays.asList("client")));
client.put("userpassword", new ArrayList(Arrays.asList("password")));
client.put("realm", new ArrayList(Arrays.asList("/")));
client.put("com.forgerock.openam.oauth2provider.clientType", new ArrayList(Arrays.asList("Public")));
when(mockSubSchema.getAttributeSchema(eq("client"))).thenReturn(mock(AttributeSchema.class));
when(mockSubSchema.getAttributeSchema(eq("userpassword"))).thenReturn(mock(AttributeSchema.class));
when(mockSubSchema.getAttributeSchema(eq("realm"))).thenReturn(mock(AttributeSchema.class));
when(mockSubSchema.getAttributeSchema(eq("com.forgerock.openam.oauth2provider.clientType"))).thenReturn(mock(AttributeSchema.class));
CreateRequest request = mock(CreateRequest.class);
JsonValue val = mock(JsonValue.class);
when(request.getContent()).thenReturn(val);
when(val.getObject()).thenReturn(client);
Map<String, String> responseVal = new HashMap<String, String>();
responseVal.put("success", "true");
JsonValue response = new JsonValue(responseVal);
ResourceResponse expectedResource = newResourceResponse("results", "1", response);
// When
Promise<ResourceResponse, ResourceException> createInstancePromise = resource.createInstance(null, request);
// Then
assertThat(createInstancePromise).succeeded().withObject().isEqualToIgnoringGivenFields(expectedResource, ResourceResponse.FIELD_REVISION, ResourceResponse.FIELD_CONTENT);
ResourceResponse resourceResponse = createInstancePromise.getOrThrowUninterruptibly();
assertEquals(resourceResponse.getContent().toString(), response.toString());
}
Aggregations