use of org.restlet.ext.json.JsonRepresentation in project OpenAM by OpenRock.
the class PermissionRequestEndpointTest method shouldThrowInvalidScopeExceptionWhenScopeIsNotASetOfStrings.
@Test(expectedExceptions = UmaException.class)
public void shouldThrowInvalidScopeExceptionWhenScopeIsNotASetOfStrings() throws Exception {
//Given
JsonRepresentation entity = mock(JsonRepresentation.class);
JSONObject requestBody = mock(JSONObject.class);
ResourceSetDescription resourceSetDescription = new ResourceSetDescription("RESOURCE_SET_ID", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
given(entity.getJsonObject()).willReturn(requestBody);
given(requestBody.toString()).willReturn("{\"resource_set_id\":\"RESOURCE_SET_ID\", \"scopes\":\"SCOPE\"}");
given(resourceSetStore.read("RESOURCE_SET_ID", "RESOURCE_OWNER_ID")).willReturn(resourceSetDescription);
//When
try {
endpoint.registerPermissionRequest(entity);
} catch (UmaException e) {
//Then
assertThat(e.getStatusCode()).isEqualTo(400);
assertThat(e.getError()).isEqualTo("invalid_scope");
assertThat(e.getMessage()).contains("Required attribute", "'scopes'", "must be an array of Strings");
throw e;
}
}
use of org.restlet.ext.json.JsonRepresentation in project OpenAM by OpenRock.
the class PermissionRequestEndpointTest method shouldReturnPermissionTicket.
@Test
@SuppressWarnings("unchecked")
public void shouldReturnPermissionTicket() throws Exception {
//Given
JsonRepresentation entity = mock(JsonRepresentation.class);
JSONObject requestBody = mock(JSONObject.class);
given(entity.getJsonObject()).willReturn(requestBody);
given(requestBody.toString()).willReturn("{\"resource_set_id\":\"RESOURCE_SET_ID\", " + "\"scopes\":[\"SCOPE_A\", \"SCOPE_B\"]}");
setupResourceSetStore();
PermissionTicket ticket = new PermissionTicket("abc", null, null, null);
given(umaTokenStore.createPermissionTicket(eq("RESOURCE_SET_ID"), anySetOf(String.class), eq("CLIENT_ID"))).willReturn(ticket);
//When
Representation responseBody = endpoint.registerPermissionRequest(entity);
//Then
Map<String, String> permissionTicket = (Map<String, String>) new ObjectMapper().readValue(responseBody.getText(), Map.class);
assertThat(permissionTicket).containsEntry("ticket", "abc");
verify(permissionRequestFilter).onPermissionRequest(any(ResourceSetDescription.class), anySetOf(String.class), anyString());
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
verify(response).setStatus(statusCaptor.capture());
assertThat(statusCaptor.getValue().getCode()).isEqualTo(201);
}
use of org.restlet.ext.json.JsonRepresentation in project OpenAM by OpenRock.
the class PermissionRequestEndpointTest method shouldThrowInvalidScopeExceptionWhenNoScope.
@Test(expectedExceptions = UmaException.class)
public void shouldThrowInvalidScopeExceptionWhenNoScope() throws Exception {
//Given
JsonRepresentation entity = mock(JsonRepresentation.class);
JSONObject requestBody = mock(JSONObject.class);
ResourceSetDescription resourceSetDescription = new ResourceSetDescription("RESOURCE_SET_ID", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
given(entity.getJsonObject()).willReturn(requestBody);
given(requestBody.toString()).willReturn("{\"resource_set_id\":\"RESOURCE_SET_ID\"}");
given(resourceSetStore.read("RESOURCE_SET_ID", "RESOURCE_OWNER_ID")).willReturn(resourceSetDescription);
//When
try {
endpoint.registerPermissionRequest(entity);
} catch (UmaException e) {
//Then
assertThat(e.getStatusCode()).isEqualTo(400);
assertThat(e.getError()).isEqualTo("invalid_scope");
assertThat(e.getMessage()).contains("Missing required attribute", "'scopes'");
throw e;
}
}
use of org.restlet.ext.json.JsonRepresentation in project OpenAM by OpenRock.
the class PermissionRequestEndpointTest method shouldThrowInvalidResourceSetIdExceptionWhenNoResourceSetId.
@Test(expectedExceptions = UmaException.class)
public void shouldThrowInvalidResourceSetIdExceptionWhenNoResourceSetId() throws Exception {
//Given
JsonRepresentation entity = mock(JsonRepresentation.class);
JSONObject requestBody = mock(JSONObject.class);
given(entity.getJsonObject()).willReturn(requestBody);
given(requestBody.toString()).willReturn("");
//When
try {
endpoint.registerPermissionRequest(entity);
} catch (UmaException e) {
//Then
assertThat(e.getStatusCode()).isEqualTo(400);
assertThat(e.getError()).isEqualTo("invalid_resource_set_id");
assertThat(e.getMessage()).contains("Missing required attribute", "'resource_set_id'");
throw e;
}
}
use of org.restlet.ext.json.JsonRepresentation in project OpenAM by OpenRock.
the class PermissionRequestEndpointTest method shouldThrowInvalidResourceSetIdExceptionWhenResourceSetIdIsNotAString.
@Test(expectedExceptions = UmaException.class)
public void shouldThrowInvalidResourceSetIdExceptionWhenResourceSetIdIsNotAString() throws Exception {
//Given
JsonRepresentation entity = mock(JsonRepresentation.class);
JSONObject requestBody = mock(JSONObject.class);
given(entity.getJsonObject()).willReturn(requestBody);
given(requestBody.toString()).willReturn("{\"resource_set_id\":[]}");
//When
try {
endpoint.registerPermissionRequest(entity);
} catch (UmaException e) {
//Then
assertThat(e.getStatusCode()).isEqualTo(400);
assertThat(e.getError()).isEqualTo("invalid_resource_set_id");
assertThat(e.getMessage()).contains("Required attribute", "'resource_set_id'", "must be a String");
throw e;
}
}
Aggregations