Search in sources :

Example 16 with DeleteRequest

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

the class TrustedDevicesResourceTest method shouldNotDeleteTrustedDeviceWhenNotFound.

@Test(expectedExceptions = NotFoundException.class)
public void shouldNotDeleteTrustedDeviceWhenNotFound() throws ResourceException {
    //Given
    DeleteRequest request = Requests.newDeleteRequest("UUID_3");
    Connection connection = newInternalConnection(newCollection(resource));
    List<JsonValue> devices = new ArrayList<JsonValue>();
    devices.add(json(object(field("uuid", "UUID_1"), field("name", "NAME_1"))));
    devices.add(json(object(field("uuid", "UUID_2"), field("name", "NAME_2"))));
    given(dao.getDeviceProfiles(anyString(), anyString())).willReturn(devices);
    //When
    connection.delete(ctx(), request);
//Then
//Expected NotFoundException
}
Also used : Resources.newInternalConnection(org.forgerock.json.resource.Resources.newInternalConnection) Connection(org.forgerock.json.resource.Connection) ArrayList(java.util.ArrayList) JsonValue(org.forgerock.json.JsonValue) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Test(org.testng.annotations.Test)

Example 17 with DeleteRequest

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

the class ApplicationsResourceTest method deleteInstanceShouldHandleFailedDeleteApplication.

@Test(expectedExceptions = NotFoundException.class)
public void deleteInstanceShouldHandleFailedDeleteApplication() throws EntitlementException, ResourceException {
    //Given
    SSOTokenContext subjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(subjectContext);
    realmContext.setSubRealm("REALM", "REALM");
    Context context = ClientContext.newInternalClientContext(realmContext);
    String resourceId = "RESOURCE_ID";
    DeleteRequest request = mock(DeleteRequest.class);
    Subject subject = new Subject();
    given(subjectContext.getCallerSubject()).willReturn(subject);
    doThrow(EntitlementException.class).when(applicationManagerWrapper).deleteApplication(any(Subject.class), anyString(), eq(resourceId));
    //When
    Promise<ResourceResponse, ResourceException> result = applicationsResource.deleteInstance(context, resourceId, request);
    //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) ResourceException(org.forgerock.json.resource.ResourceException) Matchers.anyString(org.mockito.Matchers.anyString) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 18 with DeleteRequest

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

the class ApplicationV1FilterTest method forwardOnDelete.

/**
     * Verify that delete requests are forwarded on.
     */
@Test
public void forwardOnDelete() {
    // Given
    DeleteRequest deleteRequest = mock(DeleteRequest.class);
    // When
    filter.filterDelete(context, deleteRequest, requestHandler);
    // Then
    verify(requestHandler).handleDelete(context, deleteRequest);
}
Also used : DeleteRequest(org.forgerock.json.resource.DeleteRequest) Test(org.testng.annotations.Test)

Example 19 with DeleteRequest

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

the class ApplicationsResourceTest method shouldReturnNotFoundDeleteInstance.

@Test(expectedExceptions = NotFoundException.class)
public void shouldReturnNotFoundDeleteInstance() throws EntitlementException, ResourceException {
    //Given
    SSOTokenContext subjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(subjectContext);
    realmContext.setSubRealm("REALM", "REALM");
    Context context = ClientContext.newInternalClientContext(realmContext);
    String resourceId = "RESOURCE_ID";
    DeleteRequest request = mock(DeleteRequest.class);
    Subject subject = new Subject();
    given(subjectContext.getCallerSubject()).willReturn(subject);
    //When
    Promise<ResourceResponse, ResourceException> result = applicationsResource.deleteInstance(context, resourceId, request);
    //Then
    verify(applicationManagerWrapper, never()).deleteApplication(subject, "REALM", resourceId);
    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) ResourceException(org.forgerock.json.resource.ResourceException) Matchers.anyString(org.mockito.Matchers.anyString) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 20 with DeleteRequest

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

the class ApplicationsResourceTest method shouldDeleteInstance.

@Test
public void shouldDeleteInstance() throws EntitlementException, ResourceException {
    //Given
    SSOTokenContext subjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(subjectContext);
    realmContext.setSubRealm("REALM", "REALM");
    Context context = ClientContext.newInternalClientContext(realmContext);
    String resourceId = "iPlanetAMWebAgentService";
    DeleteRequest request = mock(DeleteRequest.class);
    Subject subject = new Subject();
    Application mockApplication = mock(Application.class);
    given(subjectContext.getCallerSubject()).willReturn(subject);
    given(applicationManagerWrapper.getApplication(any(Subject.class), anyString(), anyString())).willReturn(mockApplication);
    //When
    Promise<ResourceResponse, ResourceException> result = applicationsResource.deleteInstance(context, resourceId, request);
    //Then
    verify(applicationManagerWrapper).deleteApplication(subject, "/REALM", resourceId);
    ResourceResponse resource = result.getOrThrowUninterruptibly();
    assertEquals(resource.getId(), resourceId);
}
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) ResourceException(org.forgerock.json.resource.ResourceException) Matchers.anyString(org.mockito.Matchers.anyString) DeleteRequest(org.forgerock.json.resource.DeleteRequest) Application(com.sun.identity.entitlement.Application) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Aggregations

DeleteRequest (org.forgerock.json.resource.DeleteRequest)32 Test (org.testng.annotations.Test)27 ResourceResponse (org.forgerock.json.resource.ResourceResponse)24 ResourceException (org.forgerock.json.resource.ResourceException)23 Context (org.forgerock.services.context.Context)15 JsonValue (org.forgerock.json.JsonValue)9 RealmContext (org.forgerock.openam.rest.RealmContext)7 ArrayList (java.util.ArrayList)6 Subject (javax.security.auth.Subject)6 Matchers.anyString (org.mockito.Matchers.anyString)6 HashSet (java.util.HashSet)5 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)5 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)4 ClientContext (org.forgerock.services.context.ClientContext)4 EntitlementException (com.sun.identity.entitlement.EntitlementException)3 List (java.util.List)3 CreateRequest (org.forgerock.json.resource.CreateRequest)3 Connection (org.forgerock.json.resource.Connection)2 QueryRequest (org.forgerock.json.resource.QueryRequest)2 QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)2