use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.
the class ApplicationsResourceTest method updateInstanceShouldReturnConflictWhenUpdatingFailsDueToNeedToDeletePolicies.
@Test(expectedExceptions = ConflictException.class)
public void updateInstanceShouldReturnConflictWhenUpdatingFailsDueToNeedToDeletePolicies() 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(404)).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.EntitlementException in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldHandleApplicationFindFailure.
@Test(expectedExceptions = NotFoundException.class)
public void shouldHandleApplicationFindFailure() throws EntitlementException, ResourceException {
// Given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
realmContext.setSubRealm("abc", "abc");
Context serverContext = ClientContext.newInternalClientContext(realmContext);
// Set the page size to be three starting from the second item.
QueryRequest request = mock(QueryRequest.class);
given(request.getPageSize()).willReturn(3);
given(request.getPagedResultsOffset()).willReturn(1);
QueryResourceHandler handler = mock(QueryResourceHandler.class);
given(handler.handleResource(any(ResourceResponse.class))).willReturn(true);
Subject subject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(subject);
EntitlementException exception = new EntitlementException(EntitlementException.APP_RETRIEVAL_ERROR);
given(applicationManagerWrapper.search(eq(subject), eq("/abc"), any(Set.class))).willThrow(exception);
// When
Promise<QueryResponse, ResourceException> result = applicationsResource.queryCollection(serverContext, request, handler);
// Then
result.getOrThrowUninterruptibly();
}
use of com.sun.identity.entitlement.EntitlementException 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();
}
use of com.sun.identity.entitlement.EntitlementException in project OpenAM by OpenRock.
the class ApplicationsResourceTest method setUp.
@BeforeMethod
public void setUp() {
debug = mock(Debug.class);
applicationManagerWrapper = mock(ApplicationManagerWrapper.class);
applicationTypeManagerWrapper = mock(ApplicationTypeManagerWrapper.class);
applicationWrapper = mock(ApplicationWrapper.class);
queryAttributes = new HashMap<String, QueryAttribute>();
queryAttributes.put(STRING_ATTRIBUTE, new QueryAttribute(AttributeType.STRING, new SearchAttribute(STRING_ATTRIBUTE, "ou")));
queryAttributes.put(NUMERIC_ATTRIBUTE, new QueryAttribute(AttributeType.NUMBER, new SearchAttribute(NUMERIC_ATTRIBUTE, "ou")));
queryAttributes.put(DATE_ATTRIBUTE, new QueryAttribute(AttributeType.TIMESTAMP, new SearchAttribute(DATE_ATTRIBUTE, "ou")));
applicationsResource = new ApplicationsResource(debug, applicationManagerWrapper, applicationTypeManagerWrapper, queryAttributes, resourceErrorHandler) {
@Override
protected ApplicationWrapper createApplicationWrapper(JsonValue jsonValue, Subject mySubject) throws EntitlementException {
return applicationWrapper;
}
};
}
use of com.sun.identity.entitlement.EntitlementException 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();
}
Aggregations