Search in sources :

Example 16 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class ApplicationsResourceTest method shouldThrowInternalIfApplicationClassCannotBeInstantiated.

@Test(expectedExceptions = InternalServerErrorException.class)
public void shouldThrowInternalIfApplicationClassCannotBeInstantiated() throws ResourceException {
    //given
    SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSSOTokenContext);
    realmContext.setSubRealm("/", "/");
    CreateRequest mockCreateRequest = mock(CreateRequest.class);
    Subject subject = new Subject();
    given(mockSSOTokenContext.getCallerSubject()).willReturn(subject);
    applicationsResource = new ApplicationsResource(debug, applicationManagerWrapper, applicationTypeManagerWrapper, queryAttributes, resourceErrorHandler) {

        @Override
        protected ApplicationWrapper createApplicationWrapper(JsonValue jsonValue, Subject mySubject) throws EntitlementException {
            throw new EntitlementException(6);
        }
    };
    //when
    Promise<ResourceResponse, ResourceException> result = applicationsResource.createInstance(realmContext, mockCreateRequest);
    //then
    result.getOrThrowUninterruptibly();
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ApplicationWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationWrapper) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 17 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class ApplicationsResourceTest method shouldReturnNullIfSubjectNullOnCreate.

@Test(expectedExceptions = BadRequestException.class)
public void shouldReturnNullIfSubjectNullOnCreate() throws ResourceException {
    //given
    SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSSOTokenContext);
    realmContext.setSubRealm("REALM", "REALM");
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    CreateRequest mockCreateRequest = mock(CreateRequest.class);
    given(mockSSOTokenContext.getCallerSubject()).willReturn(null);
    //when
    Promise<ResourceResponse, ResourceException> result = applicationsResource.createInstance(mockServerContext, mockCreateRequest);
    //then
    result.getOrThrowUninterruptibly();
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Context(org.forgerock.services.context.Context) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 18 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class ApplicationsResourceTest method shouldCreateApplication.

@Test
public void shouldCreateApplication() throws ExecutionException, ResourceException {
    //given
    SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSSOTokenContext);
    realmContext.setSubRealm("/", "/");
    CreateRequest mockCreateRequest = mock(CreateRequest.class);
    Subject mockSubject = new Subject();
    Application mockApplication = mock(Application.class);
    applicationsResource = new ApplicationsResource(debug, applicationManagerWrapper, applicationTypeManagerWrapper, queryAttributes, resourceErrorHandler) {

        @Override
        protected ApplicationWrapper createApplicationWrapper(JsonValue jsonValue, Subject mySubject) throws EntitlementException {
            return applicationWrapper;
        }

        @Override
        protected ApplicationWrapper createApplicationWrapper(Application application, ApplicationTypeManagerWrapper type) {
            return applicationWrapper;
        }
    };
    given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
    given(applicationWrapper.getApplication()).willReturn(mockApplication);
    given(mockApplication.getName()).willReturn("newApplication");
    //when
    Promise<ResourceResponse, ResourceException> result = applicationsResource.createInstance(realmContext, mockCreateRequest);
    //then
    assertThat(result.getOrThrowUninterruptibly()).isNotNull();
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) ApplicationTypeManagerWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeManagerWrapper) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) Subject(javax.security.auth.Subject) EntitlementException(com.sun.identity.entitlement.EntitlementException) ApplicationWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationWrapper) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) Application(com.sun.identity.entitlement.Application) Test(org.testng.annotations.Test)

Example 19 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class ApplicationsResourceTest method shouldThrowBadRequestIfApplicationWrapperCannotBeCreated.

@Test(expectedExceptions = BadRequestException.class)
public void shouldThrowBadRequestIfApplicationWrapperCannotBeCreated() throws ResourceException {
    //given
    SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSSOTokenContext);
    realmContext.setSubRealm("REALM", "REALM");
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    CreateRequest mockCreateRequest = mock(CreateRequest.class);
    Subject subject = new Subject();
    given(mockSSOTokenContext.getCallerSubject()).willReturn(subject);
    applicationsResource = new ApplicationsResource(debug, applicationManagerWrapper, applicationTypeManagerWrapper, queryAttributes, resourceErrorHandler) {

        @Override
        protected ApplicationWrapper createApplicationWrapper(JsonValue jsonValue, Subject mySubject) throws EntitlementException {
            throw new EntitlementException(317);
        }
    };
    //when
    Promise<ResourceResponse, ResourceException> result = applicationsResource.createInstance(mockServerContext, mockCreateRequest);
    //then
    result.getOrThrowUninterruptibly();
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Context(org.forgerock.services.context.Context) RealmContext(org.forgerock.openam.rest.RealmContext) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) Subject(javax.security.auth.Subject) EntitlementException(com.sun.identity.entitlement.EntitlementException) ApplicationWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationWrapper) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 20 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class Requester method create.

/**
     * Request to create a resource at a specified endpoint.
     *
     * @param location Endpoint destination of this request. May not be null.
     * @param resourceId Resource ID to be created. May be null.
     * @param payload Payload of the resource to generate. May not be null.
     * @param context Context of this request.
     * @return The {@link org.forgerock.json.JsonValue} returned from the endpoint.
     * @throws ResourceException If any exception occurred during processing.
     */
public JsonValue create(String location, String resourceId, JsonValue payload, Context context) throws ResourceException {
    Reject.ifTrue(StringUtils.isEmpty(location), "The endpoint destination may not be null or empty.");
    Reject.ifNull(payload, "The payload object to create must not be null.");
    final Router rootRouter = router.get();
    final CreateRequest createRequest = Requests.newCreateRequest(location, payload);
    if (resourceId != null) {
        createRequest.setNewResourceId(resourceId);
    }
    return rootRouter.handleCreate(context, createRequest).getOrThrowUninterruptibly().getContent();
}
Also used : CreateRequest(org.forgerock.json.resource.CreateRequest) Router(org.forgerock.json.resource.Router)

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