use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class ResourceSetRegistrationEndpointTest method shouldDeleteResourceSetDescription.
@Test
public void shouldDeleteResourceSetDescription() throws Exception {
//Given
setUriResourceSetId();
addCondition();
//When
Representation responseRep = endpoint.deleteResourceSet();
//Then
verify(store).delete("RESOURCE_SET_ID", "RESOURCE_OWNER_ID");
assertThat(responseRep.getText()).isNull();
ArgumentCaptor<Status> responseStatusCaptor = ArgumentCaptor.forClass(Status.class);
verify(response).setStatus(responseStatusCaptor.capture());
assertThat(responseStatusCaptor.getValue().getCode()).isEqualTo(204);
verify(labelRegistration).updateLabelsForDeletedResourceSet(any(ResourceSetDescription.class));
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class ResourceSetRegistrationEndpointTest method shouldListResourceSetDescriptions.
@Test
@SuppressWarnings("unchecked")
public void shouldListResourceSetDescriptions() throws Exception {
//Given
Set<ResourceSetDescription> resourceSetDescriptions = new HashSet<ResourceSetDescription>();
ResourceSetDescription resourceSetDescription = new ResourceSetDescription("RESOURCE_SET_ID", "CLIENT_ID", "RESOURCE_OWNER_ID", RESOURCE_SET_DESCRIPTION_CONTENT.asMap());
ResourceSetDescription resourceSetDescription2 = new ResourceSetDescription("RESOURCE_SET_ID_2", "CLIENT_ID", "RESOURCE_OWNER_ID", RESOURCE_SET_DESCRIPTION_UPDATED_CONTENT.asMap());
resourceSetDescriptions.add(resourceSetDescription);
resourceSetDescriptions.add(resourceSetDescription2);
noUriResourceSetId();
noConditions();
given(store.query(any(QueryFilter.class))).willReturn(resourceSetDescriptions);
//When
Representation responseRep = endpoint.readOrListResourceSet();
//Then
ArgumentCaptor<QueryFilter> queryParametersCaptor = ArgumentCaptor.forClass(QueryFilter.class);
verify(store).query(queryParametersCaptor.capture());
QueryFilter<String> query = queryParametersCaptor.getValue();
Map<String, String> params = query.accept(QUERY_PARAMS_EXTRACTOR, new HashMap<String, String>());
assertThat(params).contains(entry(ResourceSetTokenField.CLIENT_ID, "CLIENT_ID"), entry(ResourceSetTokenField.RESOURCE_OWNER_ID, "RESOURCE_OWNER_ID"));
List<String> responseBody = (List<String>) new ObjectMapper().readValue(responseRep.getText(), List.class);
assertThat(responseBody).contains("RESOURCE_SET_ID", "RESOURCE_SET_ID_2");
}
use of org.restlet.representation.Representation 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.representation.Representation in project OpenAM by OpenRock.
the class ResourceSetRegistrationEndpointTest method shouldReadResourceSetDescription.
@Test
@SuppressWarnings("unchecked")
public void shouldReadResourceSetDescription() throws Exception {
//Given
ResourceSetDescription resourceSetDescription = new ResourceSetDescription("RESOURCE_SET_ID", "CLIENT_ID", "RESOURCE_OWNER_ID", RESOURCE_SET_DESCRIPTION_CONTENT.asMap());
setUriResourceSetId();
given(store.read("RESOURCE_SET_ID", "RESOURCE_OWNER_ID")).willReturn(resourceSetDescription);
//When
Representation responseRep = endpoint.readOrListResourceSet();
//Then
Map<String, Object> responseBody = (Map<String, Object>) new ObjectMapper().readValue(responseRep.getText(), Map.class);
assertThat(responseBody).containsKey("_id");
assertThat(responseBody).contains(entry("name", "NAME"), entry("uri", "URI"), entry("type", "TYPE"), entry("scopes", Collections.singletonList("SCOPE")), entry("icon_uri", "ICON_URI"));
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class EndSessionTest method shouldAttemptEndSessionAndReturnRedirectAttempt.
@Test
public void shouldAttemptEndSessionAndReturnRedirectAttempt() throws Exception {
// given
String requestedUri = "http://www.example.com";
String registeredUri = "http://www.example.com";
when(oAuth2Request.getParameter(OAuth2Constants.Params.POST_LOGOUT_REDIRECT_URI)).thenReturn(requestedUri);
when(client.getPostLogoutRedirectUris()).thenReturn(Collections.singleton(new URI(registeredUri)));
// when
Representation result = endSession.endSession();
// then
verify(openIDConnectEndSession, times(1)).endSession(any(String.class));
assertThat(result).isNotNull();
}
Aggregations