Search in sources :

Example 56 with ResourceSetDescription

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));
}
Also used : InOrder(org.mockito.InOrder) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) Representation(org.restlet.representation.Representation) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JSONObject(org.json.JSONObject) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 57 with ResourceSetDescription

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

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

Example 59 with ResourceSetDescription

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

Example 60 with ResourceSetDescription

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");
}
Also used : ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) ResourceSetLabel(org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel) 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