Search in sources :

Example 16 with Representation

use of org.restlet.representation.Representation in project OpenAM by OpenRock.

the class ResourceSetRegistrationEndpointTest method shouldDeleteResourceSetDescription.

@Test
public void shouldDeleteResourceSetDescription() throws Exception {
    //Given
    setUriResourceSetId();
    addCondition();
    //When
    Representation responseRep = endpoint.deleteResourceSet();
    //Then
    verify(store).delete("RESOURCE_SET_ID", "RESOURCE_OWNER_ID");
    assertThat(responseRep.getText()).isNull();
    ArgumentCaptor<Status> responseStatusCaptor = ArgumentCaptor.forClass(Status.class);
    verify(response).setStatus(responseStatusCaptor.capture());
    assertThat(responseStatusCaptor.getValue().getCode()).isEqualTo(204);
    verify(labelRegistration).updateLabelsForDeletedResourceSet(any(ResourceSetDescription.class));
}
Also used : Status(org.restlet.data.Status) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) Representation(org.restlet.representation.Representation) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Test(org.testng.annotations.Test)

Example 17 with Representation

use of org.restlet.representation.Representation 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 18 with Representation

use of org.restlet.representation.Representation 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 19 with Representation

use of org.restlet.representation.Representation 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)

Example 20 with Representation

use of org.restlet.representation.Representation in project OpenAM by OpenRock.

the class EndSessionTest method shouldAttemptEndSessionAndReturnRedirectAttempt.

@Test
public void shouldAttemptEndSessionAndReturnRedirectAttempt() throws Exception {
    // given
    String requestedUri = "http://www.example.com";
    String registeredUri = "http://www.example.com";
    when(oAuth2Request.getParameter(OAuth2Constants.Params.POST_LOGOUT_REDIRECT_URI)).thenReturn(requestedUri);
    when(client.getPostLogoutRedirectUris()).thenReturn(Collections.singleton(new URI(registeredUri)));
    // when
    Representation result = endSession.endSession();
    // then
    verify(openIDConnectEndSession, times(1)).endSession(any(String.class));
    assertThat(result).isNotNull();
}
Also used : Representation(org.restlet.representation.Representation) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

Representation (org.restlet.representation.Representation)101 HashMap (java.util.HashMap)28 Test (org.testng.annotations.Test)27 StringRepresentation (org.restlet.representation.StringRepresentation)24 Request (org.restlet.Request)23 Response (org.restlet.Response)23 JacksonRepresentation (org.restlet.ext.jackson.JacksonRepresentation)23 ResourceException (org.restlet.resource.ResourceException)21 Reference (org.restlet.data.Reference)19 StringWriter (java.io.StringWriter)17 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)16 IOException (java.io.IOException)14 Map (java.util.Map)14 Form (org.restlet.data.Form)14 VCellApiApplication (org.vcell.rest.VCellApiApplication)14 User (org.vcell.util.document.User)13 Configuration (freemarker.template.Configuration)10 StringReader (java.io.StringReader)10 ZNRecord (org.apache.helix.ZNRecord)10 TypeReference (org.codehaus.jackson.type.TypeReference)10