use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldNotUpdateInstanceIfApplicationNotFound.
@Test(expectedExceptions = NotFoundException.class)
public void shouldNotUpdateInstanceIfApplicationNotFound() 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";
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(applicationManagerWrapper.getApplication(subject, "REALM", resourceId)).willReturn(null);
given(applicationWrapper.getApplication()).willReturn(mockApplication);
//When
Promise<ResourceResponse, ResourceException> result = applicationsResource.updateInstance(context, resourceId, request);
//Then
result.getOrThrowUninterruptibly();
}
use of org.forgerock.openam.rest.RealmContext 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();
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class ConditionTypesResourceTest method testSuccessfulJsonificationAndReadAndNamePropertyRemoved.
@Test
public void testSuccessfulJsonificationAndReadAndNamePropertyRemoved() throws JsonMappingException, ExecutionException, InterruptedException {
//given
SubjectContext mockSubjectContext = mock(SubjectContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
ReadRequest mockRequest = mock(ReadRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, TEST_CONDITION_WITH_NAME, mockRequest);
//then
Map resultMap = result.get().getContent().asMap();
assertThat(resultMap.containsKey("title")).isTrue();
assertThat(resultMap.containsKey("config")).isTrue();
assertThat(resultMap.containsKey("logical")).isTrue();
assertThat(resultMap.get("title")).isEqualTo(TEST_CONDITION_WITH_NAME);
assertThat(resultMap.get("logical")).isEqualTo(false);
assertThat(resultMap.get("config")).isInstanceOf(JsonSchema.class);
JsonSchema resultSchema = (JsonSchema) resultMap.get("config");
assertThat(resultSchema.toString().equals("{\"type\":\"object\",\"properties\":{}}")).isTrue();
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class ConditionTypesResourceTest method testSuccessfulJsonificationAndLogicalIsCorrect.
@Test
public void testSuccessfulJsonificationAndLogicalIsCorrect() throws JsonMappingException, ExecutionException, InterruptedException {
//given
SubjectContext mockSubjectContext = mock(SubjectContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
ReadRequest mockRequest = mock(ReadRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, TEST_LOGICAL_CONDITION, mockRequest);
//then
Map resultMap = result.get().getContent().asMap();
assertThat(resultMap.containsKey("logical")).isTrue();
assertThat(resultMap.get("logical")).isEqualTo(true);
}
use of org.forgerock.openam.rest.RealmContext in project OpenAM by OpenRock.
the class DecisionCombinersResourceTest method shouldThrowErrorWthInvalidCondition.
@Test(expectedExceptions = NotFoundException.class)
public void shouldThrowErrorWthInvalidCondition() throws JsonMappingException, ResourceException {
//given
SubjectContext mockSubjectContext = mock(SubjectContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
ReadRequest mockRequest = mock(ReadRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, "invalidCondition", mockRequest);
//then
result.getOrThrowUninterruptibly();
}
Aggregations