use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class ResourceSetRegistrationEndpointTest method shouldCreateResourceSetDescription.
@Test
@SuppressWarnings("unchecked")
public void shouldCreateResourceSetDescription() throws Exception {
//Given
JsonRepresentation entity = createCreateRequestRepresentation();
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) throws Throwable {
ResourceSetDescription resourceSetDescription = (ResourceSetDescription) invocation.getArguments()[1];
resourceSetDescription.setId("123");
return null;
}
}).when(store).create(any(OAuth2Request.class), any(ResourceSetDescription.class));
setUriResourceSetId();
noConditions();
//When
Representation response = endpoint.createResourceSet(entity);
//Then
ArgumentCaptor<ResourceSetDescription> resourceSetCaptor = ArgumentCaptor.forClass(ResourceSetDescription.class);
InOrder inOrder = inOrder(resourceRegistrationFilter, store, resourceRegistrationFilter);
inOrder.verify(resourceRegistrationFilter).beforeResourceRegistration(any(ResourceSetDescription.class));
inOrder.verify(store).create(Matchers.<OAuth2Request>anyObject(), resourceSetCaptor.capture());
inOrder.verify(resourceRegistrationFilter).afterResourceRegistration(any(ResourceSetDescription.class));
assertThat(resourceSetCaptor.getValue().getId()).isNotNull().isNotEmpty();
assertThat(resourceSetCaptor.getValue().getClientId()).isEqualTo("CLIENT_ID");
assertThat(resourceSetCaptor.getValue().getName()).isEqualTo("NAME");
assertThat(resourceSetCaptor.getValue().getUri()).isEqualTo(URI.create("URI"));
assertThat(resourceSetCaptor.getValue().getType()).isEqualTo("TYPE");
assertThat(resourceSetCaptor.getValue().getScopes()).containsExactly("SCOPE");
assertThat(resourceSetCaptor.getValue().getIconUri()).isEqualTo(URI.create("ICON_URI"));
Map<String, Object> responseBody = (Map<String, Object>) new ObjectMapper().readValue(response.getText(), Map.class);
assertThat(responseBody).containsKey("_id");
verify(hook).resourceSetCreated(anyString(), Matchers.<ResourceSetDescription>anyObject());
verify(labelRegistration).updateLabelsForNewResourceSet(any(ResourceSetDescription.class));
}
use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class OpenAMResourceSetStoreTest method shouldCreateResourceSetToken.
@Test
public void shouldCreateResourceSetToken() throws Exception {
//Given
OAuth2Request request = mock(OAuth2Request.class);
ResourceSetDescription resourceSetDescription = new ResourceSetDescription("RESOURCE_SET_ID", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>singletonMap("name", "RESOURCE_SET_NAME"));
given(dataStore.query(Matchers.<QueryFilter<String>>anyObject())).willReturn(Collections.<ResourceSetDescription>emptySet());
//When
store.create(request, resourceSetDescription);
//Then
assertThat(resourceSetDescription.getPolicyUri()).isEqualTo("POLICY_URI");
verify(dataStore).create(resourceSetDescription);
}
use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class OpenAMResourceSetStoreTest method shouldDeleteResourceSetToken.
@Test
public void shouldDeleteResourceSetToken() throws Exception {
//Given
ResourceSetDescription resourceSetDescription = new ResourceSetDescription("RESOURCE_SET_ID", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
resourceSetDescription.setRealm("REALM");
given(dataStore.query(QueryFilter.and(QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_SET_ID, "RESOURCE_SET_ID"), QueryFilter.equalTo(ResourceSetTokenField.REALM, "REALM")))).willReturn(Collections.singleton(resourceSetDescription));
//When
store.delete("RESOURCE_SET_ID", "RESOURCE_OWNER_ID");
//Then
verify(dataStore).delete("RESOURCE_SET_ID");
}
use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class OpenAMResourceSetStoreTest method shouldQueryResourceSetToken.
@Test
public void shouldQueryResourceSetToken() throws Exception {
//Given
Map<String, Object> queryParameters = new HashMap<String, Object>();
queryParameters.put(ResourceSetTokenField.CLIENT_ID, "CLIENT_ID");
ResourceSetDescription resourceSet1 = new ResourceSetDescription("123", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
ResourceSetDescription resourceSet2 = new ResourceSetDescription("456", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
given(dataStore.query(Matchers.<QueryFilter<String>>anyObject())).willReturn(asSet(resourceSet1, resourceSet2));
resourceSet1.setRealm("REALM");
resourceSet2.setRealm("REALM");
//When
QueryFilter<String> query = QueryFilter.alwaysTrue();
Set<ResourceSetDescription> resourceSetDescriptions = store.query(query);
//Then
assertThat(resourceSetDescriptions).contains(resourceSet1, resourceSet2);
ArgumentCaptor<QueryFilter> tokenFilterCaptor = ArgumentCaptor.forClass(QueryFilter.class);
verify(dataStore).query(tokenFilterCaptor.capture());
assertThat(tokenFilterCaptor.getValue()).isEqualTo(QueryFilter.and(query, QueryFilter.equalTo(ResourceSetTokenField.REALM, "REALM")));
}
use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class ResourceSetLabelRegistrationTest method shouldUpdateLabelUsingClientIdIfClientDisplayNameIsNull.
@Test
public void shouldUpdateLabelUsingClientIdIfClientDisplayNameIsNull() throws Exception {
//Given
ResourceSetDescription resourceSet = newResourceSet("LABEL_ONE");
givenLabelsDoesNotExist("LABEL_ONE");
//When
labelRegistration.updateLabelsForNewResourceSet(resourceSet);
//Then
ArgumentCaptor<ResourceSetLabel> labelCaptor = ArgumentCaptor.forClass(ResourceSetLabel.class);
verify(labelsStore).create(eq("REALM"), eq("RESOURCE_OWNER_ID"), labelCaptor.capture());
assertThat(labelCaptor.getValue().getId()).isEqualTo("CLIENT_ID/LABEL_ONE");
assertThat(labelCaptor.getValue().getName()).isEqualTo("LABEL_ONE");
}
Aggregations