use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class OpenAMResourceSetStoreTest method shouldUpdateResourceSetToken.
@Test
public void shouldUpdateResourceSetToken() 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.update(resourceSetDescription);
//Then
verify(dataStore).update(resourceSetDescription);
}
use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class OpenAMResourceSetStoreTest method shouldReadResourceSetToken.
@Test
public void shouldReadResourceSetToken() throws Exception {
//Given
ResourceSetDescription resourceSetDescription = new ResourceSetDescription("RESOURCE_SET_ID", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
given(dataStore.query(QueryFilter.and(QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_SET_ID, "RESOURCE_SET_ID"), QueryFilter.equalTo(ResourceSetTokenField.REALM, "REALM")))).willReturn(Collections.singleton(resourceSetDescription));
//When
ResourceSetDescription readResourceSetDescription = store.read("RESOURCE_SET_ID", "RESOURCE_OWNER_ID");
//Then
assertThat(readResourceSetDescription).isEqualTo(readResourceSetDescription);
}
use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class OpenAMResourceSetStoreTest method shouldNotCreateDuplicateResourceSetWithSameId.
@Test(enabled = false, expectedExceptions = BadRequestException.class)
public void shouldNotCreateDuplicateResourceSetWithSameId() 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"));
resourceSetDescription.setRealm("REALM");
given(dataStore.query(Matchers.<QueryFilter<String>>anyObject())).willReturn(Collections.singleton(resourceSetDescription));
//When
try {
store.create(request, resourceSetDescription);
} catch (BadRequestException e) {
//Then
assertThat(resourceSetDescription.getPolicyUri()).isNull();
verify(dataStore, never()).create(any(ResourceSetDescription.class));
throw e;
}
}
use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class OpenAMResourceSetStore method delete.
@Override
public void delete(String resourceSetId, String resourceOwnerId) throws NotFoundException, ServerException {
try {
ResourceSetDescription token = read(resourceSetId, resourceOwnerId);
delegate.delete(token.getId());
} catch (org.forgerock.openam.sm.datalayer.store.NotFoundException e) {
throw new NotFoundException("Could not find resource set");
} catch (org.forgerock.openam.sm.datalayer.store.ServerException e) {
throw new ServerException(e);
}
}
use of org.forgerock.oauth2.resources.ResourceSetDescription in project OpenAM by OpenRock.
the class ResourceSetResourceTest method shouldReadResourceSet.
@Test
public void shouldReadResourceSet() throws Exception {
//Given
Context context = mock(Context.class);
ReadRequest request = mock(ReadRequest.class);
given(request.getFields()).willReturn(Arrays.asList(new JsonPointer("/fred")));
ResourceSetDescription resourceSet = new ResourceSetDescription();
resourceSet.setDescription(json(object()));
Promise<ResourceSetDescription, ResourceException> resourceSetPromise = Promises.newResultPromise(resourceSet);
given(contextHelper.getRealm(context)).willReturn("REALM");
given(contextHelper.getUserId(context)).willReturn("RESOURCE_OWNER_ID");
given(resourceSetService.getResourceSet(context, "REALM", "RESOURCE_SET_ID", "RESOURCE_OWNER_ID", false)).willReturn(resourceSetPromise);
//When
Promise<ResourceResponse, ResourceException> readPromise = resource.readInstance(context, "RESOURCE_SET_ID", request);
//Then
assertThat(readPromise).succeeded().withObject().isNotNull();
}
Aggregations