Search in sources :

Example 1 with ResourceSetDescription

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");
}
Also used : JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) Representation(org.restlet.representation.Representation) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) QueryFilter(org.forgerock.util.query.QueryFilter) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with ResourceSetDescription

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");
}
Also used : QueryFilter(org.forgerock.util.query.QueryFilter) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) Representation(org.restlet.representation.Representation) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Test(org.testng.annotations.Test)

Example 3 with ResourceSetDescription

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

Example 4 with ResourceSetDescription

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

Example 5 with ResourceSetDescription

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