use of org.forgerock.oauth2.resources.ResourceSetDescription 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.forgerock.oauth2.resources.ResourceSetDescription 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.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class ResourceSetLabelRegistrationTest method shouldNotUpdateLabelsForNewResourceSetWithNoLabels.
@Test
public void shouldNotUpdateLabelsForNewResourceSetWithNoLabels() throws Exception {
//Given
ResourceSetDescription resourceSet = newResourceSet();
//When
labelRegistration.updateLabelsForNewResourceSet(resourceSet);
//Then
verify(labelsStore, never()).create(eq("REALM"), eq("RESOURCE_OWNER_ID"), any(ResourceSetLabel.class));
}
use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class ResourceSetLabelRegistrationTest method shouldUpdateLabelsForExistingResourceSet.
@Test
public void shouldUpdateLabelsForExistingResourceSet() throws Exception {
//Given
givenLabelsForResourceSet("LABEL_ONE", "LABEL_TWO");
ResourceSetDescription resourceSet = newResourceSet("LABEL_ONE", "LABEL_THREE", "LABEL_FOUR");
givenLabelsExist("LABEL_ONE", "LABEL_TWO", "LABEL_THREE");
givenLabelsDoesNotExist("LABEL_FOUR");
//When
labelRegistration.updateLabelsForExistingResourceSet(resourceSet);
//Then
ArgumentCaptor<ResourceSetLabel> labelCaptor = ArgumentCaptor.forClass(ResourceSetLabel.class);
verify(labelsStore, times(2)).update(eq("REALM"), eq("RESOURCE_OWNER_ID"), labelCaptor.capture());
verify(labelsStore).create(eq("REALM"), eq("RESOURCE_OWNER_ID"), labelCaptor.capture());
List<ResourceSetLabel> labels = labelCaptor.getAllValues();
for (ResourceSetLabel label : labels) {
if (label.getId().contains("LABEL_TWO")) {
assertThat(label.getResourceSetIds()).isEmpty();
} else if (label.getId().contains("LABEL_THREE")) {
assertThat(label.getResourceSetIds()).containsOnly("RESOURCE_SET_ID");
} else if (label.getId().contains("LABEL_FOUR")) {
assertThat(label.getResourceSetIds()).containsOnly("RESOURCE_SET_ID");
}
}
}
use of org.forgerock.oauth2.resources.ResourceSetDescription 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"));
}
Aggregations