use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class ApplicationsResourceTest method updateInstanceShouldReturnForbiddenWhenUpdatingFailsDueToNotAuthorized.
@Test(expectedExceptions = ForbiddenException.class)
public void updateInstanceShouldReturnForbiddenWhenUpdatingFailsDueToNotAuthorized() 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";
UpdateRequest request = mock(UpdateRequest.class);
Subject subject = new Subject();
JsonValue content = mock(JsonValue.class);
Application mockApplication = mock(Application.class);
given(subjectContext.getCallerSubject()).willReturn(subject);
given(request.getContent()).willReturn(content);
given(applicationWrapper.getApplication()).willReturn(mockApplication);
given(applicationManagerWrapper.getApplication(subject, "/REALM", resourceId)).willReturn(mockApplication);
doThrow(new EntitlementException(326)).when(applicationManagerWrapper).updateApplication(any(Application.class), any(Application.class), any(Subject.class), anyString());
//When
Promise<ResourceResponse, ResourceException> result = applicationsResource.updateInstance(context, resourceId, request);
//Then
result.getOrThrowUninterruptibly();
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldUpdateInstance.
@Test
public void shouldUpdateInstance() 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";
UpdateRequest request = mock(UpdateRequest.class);
Subject subject = new Subject();
JsonValue content = mock(JsonValue.class);
Application application = mock(Application.class);
Application newApplication = mock(Application.class);
JsonValue response = mock(JsonValue.class);
given(subjectContext.getCallerSubject()).willReturn(subject);
given(request.getContent()).willReturn(content);
given(applicationManagerWrapper.getApplication(subject, "/REALM", resourceId)).willReturn(application);
given(applicationWrapper.getName()).willReturn("APP_NAME");
given(applicationWrapper.getApplication()).willReturn(newApplication);
given(newApplication.getLastModifiedDate()).willReturn(1000L);
given(applicationWrapper.toJsonValue()).willReturn(response);
//When
Promise<ResourceResponse, ResourceException> result = applicationsResource.updateInstance(context, resourceId, request);
//Then
verify(applicationManagerWrapper).updateApplication(application, applicationWrapper.getApplication(), subject, "/REALM");
ResourceResponse resource = result.getOrThrowUninterruptibly();
assertEquals(resource.getId(), "APP_NAME");
assertEquals(resource.getRevision(), "1000");
assertEquals(resource.getContent(), response);
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class ApplicationV1FilterTest method updateModifiesUnderlyingResourceType.
/**
* Verifies that the underlying associated resource type is updated to reflect changes in a v1.0 application.
*/
@Test
public void updateModifiesUnderlyingResourceType() throws Exception {
// Given
given(contextHelper.getRealm(context)).willReturn("/abc");
given(contextHelper.getSubject(context)).willReturn(subject);
// Build application JSON representation.
JsonValue jsonValue = json(object(TestData.DATA_SET_1.getResources().asJson(), TestData.DATA_SET_1.getActions().asJson(), field("realm", "/abc")));
UpdateRequest updateRequest = mock(UpdateRequest.class);
given(updateRequest.getContent()).willReturn(jsonValue);
given(updateRequest.getResourcePath()).willReturn("testApplication");
given(applicationServiceFactory.create(subject, "/abc")).willReturn(applicationService);
Application application = mock(Application.class);
given(applicationService.getApplication("testApplication")).willReturn(application);
Set<String> resourceTypeUUIDs = new HashSet<>(CollectionUtils.asSet("abc-def-ghi"));
given(application.getResourceTypeUuids()).willReturn(resourceTypeUUIDs);
ResourceType resourceType = ResourceType.builder().setName("test").setUUID("abc-def-ghi").setActions(TestData.DATA_SET_2.getActions().getUnderlyingMap()).setPatterns(TestData.DATA_SET_2.getResources().getUnderlyingSet()).build();
given(resourceTypeService.getResourceType(subject, "/abc", "abc-def-ghi")).willReturn(resourceType);
// When
filter.filterUpdate(context, updateRequest, requestHandler);
// Then
assertThat(jsonValue.get("resourceTypeUuids").asSet(String.class)).containsOnly("abc-def-ghi");
verify(resourceTypeService).updateResourceType(eq(subject), eq("/abc"), resourceTypeCaptor.capture());
verify(requestHandler).handleUpdate(eq(context), eq(updateRequest));
ResourceType capturedResourceType = resourceTypeCaptor.getValue();
assertThat(capturedResourceType.getUUID()).isEqualTo("abc-def-ghi");
assertThat(capturedResourceType.getActions()).isEqualTo(TestData.DATA_SET_1.getActions().getUnderlyingMap());
assertThat(capturedResourceType.getPatterns()).isEqualTo(TestData.DATA_SET_1.getResources().getUnderlyingSet());
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class ApplicationV1FilterTest method updateFailsWithManyResourceTypes.
/**
* Verifies that update fails when the mentioned application has more than one resource type.
*/
@Test(expectedExceptions = BadRequestException.class)
public void updateFailsWithManyResourceTypes() throws Exception {
// Given
given(contextHelper.getRealm(context)).willReturn("/abc");
given(contextHelper.getSubject(context)).willReturn(subject);
// Build application JSON representation.
JsonValue jsonValue = json(object(TestData.DATA_SET_1.getResources().asJson(), TestData.DATA_SET_1.getActions().asJson(), field("realm", "/abc")));
UpdateRequest updateRequest = mock(UpdateRequest.class);
given(updateRequest.getContent()).willReturn(jsonValue);
given(applicationServiceFactory.create(subject, "/abc")).willReturn(applicationService);
Application application = mock(Application.class);
given(updateRequest.getResourcePath()).willReturn("testApplication");
given(applicationService.getApplication("testApplication")).willReturn(application);
Set<String> resourceTypeUUIDs = new HashSet<>(CollectionUtils.asSet("abc-def-ghi", "jkl-mno-qrs"));
given(application.getResourceTypeUuids()).willReturn(resourceTypeUUIDs);
// When
Promise<ResourceResponse, ResourceException> result = filter.filterUpdate(context, updateRequest, requestHandler);
// Then
result.getOrThrowUninterruptibly();
}
use of com.sun.identity.entitlement.Application 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);
}
Aggregations