Search in sources :

Example 6 with CreateRequest

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();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceType(org.forgerock.openam.entitlement.ResourceType) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 7 with CreateRequest

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");
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceType(org.forgerock.openam.entitlement.ResourceType) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 8 with CreateRequest

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);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 9 with CreateRequest

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);
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 10 with CreateRequest

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);
}
Also used : CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Aggregations

CreateRequest (org.forgerock.json.resource.CreateRequest)70 Test (org.testng.annotations.Test)62 ResourceResponse (org.forgerock.json.resource.ResourceResponse)42 JsonValue (org.forgerock.json.JsonValue)39 ResourceException (org.forgerock.json.resource.ResourceException)38 Context (org.forgerock.services.context.Context)27 DeleteRequest (org.forgerock.json.resource.DeleteRequest)19 ReadRequest (org.forgerock.json.resource.ReadRequest)18 RootContext (org.forgerock.services.context.RootContext)18 UriRouterContext (org.forgerock.http.routing.UriRouterContext)17 ActionRequest (org.forgerock.json.resource.ActionRequest)17 PatchRequest (org.forgerock.json.resource.PatchRequest)17 QueryRequest (org.forgerock.json.resource.QueryRequest)17 UpdateRequest (org.forgerock.json.resource.UpdateRequest)17 Request (org.forgerock.http.protocol.Request)16 AttributesContext (org.forgerock.services.context.AttributesContext)16 Subject (javax.security.auth.Subject)13 RealmContext (org.forgerock.openam.rest.RealmContext)11 EntitlementException (com.sun.identity.entitlement.EntitlementException)9 ResourceType (org.forgerock.openam.entitlement.ResourceType)9