use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class PolicyResourceTest method mockCreateRequest.
private CreateRequest mockCreateRequest(String resourceName, JsonValue content) {
CreateRequest mockRequest = mock(CreateRequest.class);
given(mockRequest.getNewResourceId()).willReturn(resourceName);
given(mockRequest.getContent()).willReturn(content);
return mockRequest;
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class RealmContextFilter method filterCreate.
@Override
public Promise<ResourceResponse, ResourceException> filterCreate(Context context, CreateRequest request, RequestHandler next) {
try {
Context newContext = evaluate(context, request);
CreateRequest evaluatedRequest = wasEvaluated(context, newContext) ? copyOfCreateRequest(request).setResourcePath(newContext.asContext(UriRouterContext.class).getRemainingUri()) : request;
return next.handleCreate(evaluate(context, request), evaluatedRequest);
} catch (ResourceException e) {
return newExceptionPromise(e);
}
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class ClientResourceTest method shouldCreateIdentity.
@Test
public void shouldCreateIdentity() throws SSOException, IdRepoException, ResourceException {
// Given
Map<String, ArrayList<String>> client = new HashMap<>();
//must contain userpassword, realm, client_id, "com.forgerock.openam.oauth2provider.clientType"
client.put("client_id", new ArrayList(Arrays.asList("client")));
client.put("userpassword", new ArrayList(Arrays.asList("password")));
client.put("realm", new ArrayList(Arrays.asList("/")));
client.put("com.forgerock.openam.oauth2provider.clientType", new ArrayList(Arrays.asList("Public")));
when(mockSubSchema.getAttributeSchema(eq("client"))).thenReturn(mock(AttributeSchema.class));
when(mockSubSchema.getAttributeSchema(eq("userpassword"))).thenReturn(mock(AttributeSchema.class));
when(mockSubSchema.getAttributeSchema(eq("realm"))).thenReturn(mock(AttributeSchema.class));
when(mockSubSchema.getAttributeSchema(eq("com.forgerock.openam.oauth2provider.clientType"))).thenReturn(mock(AttributeSchema.class));
CreateRequest request = mock(CreateRequest.class);
JsonValue val = mock(JsonValue.class);
when(request.getContent()).thenReturn(val);
when(val.getObject()).thenReturn(client);
Map<String, String> responseVal = new HashMap<String, String>();
responseVal.put("success", "true");
JsonValue response = new JsonValue(responseVal);
ResourceResponse expectedResource = newResourceResponse("results", "1", response);
// When
Promise<ResourceResponse, ResourceException> createInstancePromise = resource.createInstance(null, request);
// Then
assertThat(createInstancePromise).succeeded().withObject().isEqualToIgnoringGivenFields(expectedResource, ResourceResponse.FIELD_REVISION, ResourceResponse.FIELD_CONTENT);
ResourceResponse resourceResponse = createInstancePromise.getOrThrowUninterruptibly();
assertEquals(resourceResponse.getContent().toString(), response.toString());
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class ApplicationV1FilterTest method createFailsWhenNoResourcesDefined.
/**
* Verifies that creation fails when no resources are defined.
*/
@Test(expectedExceptions = BadRequestException.class)
public void createFailsWhenNoResourcesDefined() throws ResourceException {
// Given
// Build application JSON representation.
JsonValue jsonValue = json(object(TestData.DATA_SET_1.getActions().asJson()));
CreateRequest createRequest = mock(CreateRequest.class);
given(createRequest.getContent()).willReturn(jsonValue);
// When
Promise<ResourceResponse, ResourceException> result = filter.filterCreate(context, createRequest, requestHandler);
// Then
result.getOrThrowUninterruptibly();
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldNotCreateApplicationWithInvalidCharactersInName.
@Test(expectedExceptions = BadRequestException.class)
public void shouldNotCreateApplicationWithInvalidCharactersInName() throws 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("new+application");
//when
Promise<ResourceResponse, ResourceException> result = applicationsResource.createInstance(realmContext, mockCreateRequest);
// Then
result.getOrThrowUninterruptibly();
}
Aggregations