Search in sources :

Example 6 with ResourceSetDescription

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);
}
Also used : ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Test(org.testng.annotations.Test)

Example 7 with 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);
}
Also used : ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Test(org.testng.annotations.Test)

Example 8 with ResourceSetDescription

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;
    }
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) BadRequestException(org.forgerock.oauth2.core.exceptions.BadRequestException) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Test(org.testng.annotations.Test)

Example 9 with ResourceSetDescription

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);
    }
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription)

Example 10 with ResourceSetDescription

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();
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) JsonPointer(org.forgerock.json.JsonPointer) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Aggregations

ResourceSetDescription (org.forgerock.oauth2.resources.ResourceSetDescription)59 Test (org.testng.annotations.Test)33 ResourceException (org.forgerock.json.resource.ResourceException)19 HashSet (java.util.HashSet)15 UmaPolicy (org.forgerock.openam.uma.UmaPolicy)15 Context (org.forgerock.services.context.Context)14 JsonValue (org.forgerock.json.JsonValue)12 QueryResponse (org.forgerock.json.resource.QueryResponse)12 Collection (java.util.Collection)11 ResourceSetStore (org.forgerock.oauth2.resources.ResourceSetStore)11 RealmContext (org.forgerock.openam.rest.RealmContext)11 HashMap (java.util.HashMap)10 Responses.newQueryResponse (org.forgerock.json.resource.Responses.newQueryResponse)10 RootContext (org.forgerock.services.context.RootContext)10 Pair (org.forgerock.util.Pair)10 ServerException (org.forgerock.oauth2.core.exceptions.ServerException)9 QueryFilter (org.forgerock.util.query.QueryFilter)9 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)9 List (java.util.List)8 ResourceSetLabel (org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel)8