use of org.restlet.ext.json.JsonRepresentation in project OpenAM by OpenRock.
the class ResourceSetRegistrationEndpointTest method createCreateRequestRepresentation.
private JsonRepresentation createCreateRequestRepresentation() throws JSONException, JsonProcessingException, BadRequestException {
JsonRepresentation entity = mock(JsonRepresentation.class);
JSONObject jsonObject = mock(JSONObject.class);
String jsonString = new ObjectMapper().writeValueAsString(RESOURCE_SET_DESCRIPTION_CONTENT.asMap());
given(entity.getJsonObject()).willReturn(jsonObject);
given(jsonObject.toString()).willReturn(jsonString);
given(validator.validate(anyMapOf(String.class, Object.class))).willReturn(RESOURCE_SET_DESCRIPTION_CONTENT.asMap());
return entity;
}
use of org.restlet.ext.json.JsonRepresentation in project OpenAM by OpenRock.
the class ResourceSetRegistrationEndpointTest method shouldNotCreateExistingResourceSetDescription.
@Test
@SuppressWarnings("unchecked")
public void shouldNotCreateExistingResourceSetDescription() throws Exception {
//Given
JsonRepresentation entity = createCreateRequestRepresentation();
when(store.query(any(QueryFilter.class))).thenReturn(asSet(new ResourceSetDescription("id", "CLIENT_ID", "RESOURCE_OWNER_ID", RESOURCE_SET_DESCRIPTION_CONTENT.asMap())));
noConditions();
//When
Representation result = endpoint.createResourceSet(entity);
//Then
ArgumentCaptor<QueryFilter> queryCaptor = ArgumentCaptor.forClass(QueryFilter.class);
verify(store).query(queryCaptor.capture());
verifyZeroInteractions(resourceRegistrationFilter);
String queryString = queryCaptor.getValue().toString();
assertThat(queryString).contains("name eq \"NAME\"").contains("clientId eq \"CLIENT_ID\"").contains("resourceOwnerId eq \"RESOURCE_OWNER_ID\"").doesNotContain(" or ");
verify(response).setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
assertThat(result).isInstanceOf(JsonRepresentation.class);
assertThat(((JsonRepresentation) result).getJsonObject().get("error")).isEqualTo("Bad Request");
assertThat(((JsonRepresentation) result).getJsonObject().getString("error_description")).contains("'NAME' already exists");
}
use of org.restlet.ext.json.JsonRepresentation in project OpenAM by OpenRock.
the class PermissionRequestEndpointTest method shouldThrowInvalidResourceSetIdExceptionWhenResourceSetStoreThrowsServerException.
@Test(expectedExceptions = UmaException.class)
public void shouldThrowInvalidResourceSetIdExceptionWhenResourceSetStoreThrowsServerException() throws Exception {
//Given
JsonRepresentation entity = mock(JsonRepresentation.class);
JSONObject requestBody = mock(JSONObject.class);
given(entity.getJsonObject()).willReturn(requestBody);
given(requestBody.toString()).willReturn("{\"resource_set_id\":\"RESOURCE_SET_ID\", " + "\"scopes\":[\"SCOPE_A\", \"SCOPE_C\"]}");
doThrow(ServerException.class).when(resourceSetStore).read("RESOURCE_SET_ID", "RESOURCE_OWNER_ID");
//When
try {
endpoint.registerPermissionRequest(entity);
} catch (UmaException e) {
//Then
assertThat(e.getStatusCode()).isEqualTo(400);
assertThat(e.getError()).isEqualTo("invalid_resource_set_id");
throw e;
}
}
use of org.restlet.ext.json.JsonRepresentation in project OpenAM by OpenRock.
the class PermissionRequestEndpointTest method shouldThrowInvalidResourceSetIdExceptionWhenResourceSetNotFound.
@Test(expectedExceptions = UmaException.class)
public void shouldThrowInvalidResourceSetIdExceptionWhenResourceSetNotFound() throws Exception {
//Given
JsonRepresentation entity = mock(JsonRepresentation.class);
JSONObject requestBody = mock(JSONObject.class);
given(entity.getJsonObject()).willReturn(requestBody);
given(requestBody.toString()).willReturn("{\"resource_set_id\":\"RESOURCE_SET_ID\", " + "\"scopes\":[\"SCOPE_A\", \"SCOPE_C\"]}");
doThrow(NotFoundException.class).when(resourceSetStore).read("RESOURCE_SET_ID", "RESOURCE_OWNER_ID");
//When
try {
endpoint.registerPermissionRequest(entity);
} catch (UmaException e) {
//Then
assertThat(e.getStatusCode()).isEqualTo(400);
assertThat(e.getError()).isEqualTo("invalid_resource_set_id");
throw e;
}
}
use of org.restlet.ext.json.JsonRepresentation in project OpenAM by OpenRock.
the class PermissionRequestEndpointTest method shouldThrowInvalidScopeExceptionWhenRequestedScopeNotInResourceScope.
@Test(expectedExceptions = UmaException.class)
public void shouldThrowInvalidScopeExceptionWhenRequestedScopeNotInResourceScope() throws Exception {
//Given
JsonRepresentation entity = mock(JsonRepresentation.class);
JSONObject requestBody = mock(JSONObject.class);
given(entity.getJsonObject()).willReturn(requestBody);
given(requestBody.toString()).willReturn("{\"resource_set_id\":\"RESOURCE_SET_ID\", " + "\"scopes\":[\"SCOPE_A\", \"SCOPE_C\"]}");
setupResourceSetStore();
//When
try {
endpoint.registerPermissionRequest(entity);
} catch (UmaException e) {
//Then
assertThat(e.getStatusCode()).isEqualTo(400);
assertThat(e.getError()).isEqualTo("invalid_scope");
assertThat(e.getMessage()).contains("Requested scopes are not in allowed scopes");
throw e;
}
}
Aggregations