use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class ResourceTypesResourceTest method createShouldIgnoreUUIDInJson.
/*
* A UUID is supplied on create, but it is ignored
*/
@Test
public void createShouldIgnoreUUIDInJson() throws EntitlementException {
//given
CreateRequest mockCreateRequest = mock(CreateRequest.class);
JsonValue content = mock(JsonValue.class);
given(mockCreateRequest.getContent()).willReturn(content);
given(mockCreateRequest.getNewResourceId()).willReturn(null);
String jsonWithUuid = "{" + " \"actions\": {" + " \"ACTION\": true," + " \"CREATE\": true," + " \"DELETE\": true," + " \"PATCH\": true," + " \"QUERY\": true," + " \"READ\": true," + " \"UPDATE\": true" + " }," + " \"description\": \"An example resource type\"," + " \"uuid\": \"123.456.789\"," + " \"name\": \"myResourceType\"," + " \"patterns\": [" + " \"http://example.com:80/*\"" + " ]" + "}" + ";";
// Json has unnecessary UUID
given(content.toString()).willReturn(jsonWithUuid);
doCallRealMethod().when(resourceTypeService).saveResourceType(any(Subject.class), anyString(), any(ResourceType.class));
//when
Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.createInstance(mockServerContext, mockCreateRequest);
//then
assertThat(promise).succeeded();
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class ResourceTypesResourceTest method queryShouldHandleQueryException.
@Test
public void queryShouldHandleQueryException() throws Exception {
//given
setupExistingResourceTypeFromJson(jsonResourceType);
QueryRequest queryRequest = mock(QueryRequest.class);
QueryResponseHandler queryHandler = makeQueryResponseHandler();
Throwable t = new QueryException(QueryException.QueryErrorCode.FILTER_BOOLEAN_LITERAL_FALSE);
when(resourceTypeService.getResourceTypesData(any(Subject.class), anyString())).thenThrow(t);
//when
Promise<QueryResponse, ResourceException> promise = resourceTypesResource.queryCollection(mockServerContext, queryRequest, queryHandler);
//then
assertThat(promise).failedWithResourceException().withCode(ResourceException.BAD_REQUEST);
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class ResourceTypesResourceTest method shouldCreateResourceType.
@Test
public void shouldCreateResourceType() throws EntitlementException {
//given
CreateRequest mockCreateRequest = mock(CreateRequest.class);
JsonValue content = mock(JsonValue.class);
given(mockCreateRequest.getContent()).willReturn(content);
given(content.toString()).willReturn(jsonResourceType);
doCallRealMethod().when(resourceTypeService).saveResourceType(any(Subject.class), anyString(), any(ResourceType.class));
//when
Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.createInstance(mockServerContext, mockCreateRequest);
//then
assertThat(promise).succeeded().withContent().stringAt("name").isEqualTo("myResourceType");
}
use of org.forgerock.json.resource.ResourceException 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.ResourceException 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);
}
Aggregations