use of org.forgerock.json.resource.CreateRequest 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.CreateRequest 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.CreateRequest 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.CreateRequest 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.CreateRequest in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldAcceptPolicyNameFromUrl.
@Test
public void shouldAcceptPolicyNameFromUrl() throws Exception {
// Given
String policyName = "policyName";
JsonValue json = new JsonValue("");
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);
}
Aggregations