use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class XacmlServiceTest method testDispositionOfSubSubRealmExport.
@Test
public void testDispositionOfSubSubRealmExport() throws Exception {
//given
query.add(XacmlService.QUERY_PARAM_STRING, "test1");
query.add(XacmlService.QUERY_PARAM_STRING, "test2");
PolicySet policySet = new PolicySet();
doReturn(policySet).when(importExport).exportXACML(eq("/"), any(Subject.class), any(List.class));
//when
Representation result = service.exportXACML("/sub1/sub2");
Disposition disposition = result.getDisposition();
assertThat(disposition.getFilename()).isEqualTo("sub1-sub2-realm-policies.xml");
assertThat(disposition.getType()).isEqualTo(disposition.TYPE_ATTACHMENT);
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class XacmlServiceTest method testExportXACMLEntitlementException.
@Test
public void testExportXACMLEntitlementException() throws Exception {
//given
EntitlementException ee = new EntitlementException(EntitlementException.JSON_PARSE_ERROR);
doThrow(ee).when(importExport).exportXACML(eq("/"), any(Subject.class), any(List.class));
try {
//when
Representation result = service.exportXACML();
//then
fail("Expect exception");
} catch (ResourceException e) {
assertThat(e.getStatus().getCode()).isEqualTo(INTERNAL_ERROR);
assertThat(e.getMessage()).isEqualTo("JSON Exception.");
}
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class XacmlServiceTest method testImportXACMLIOException.
@Test
public void testImportXACMLIOException() throws Exception {
//given
Representation representation = mock(Representation.class);
doThrow(new IOException()).when(representation).getStream();
try {
//when
service.importXACML(representation);
//then
fail("Expect exception");
} catch (ResourceException e) {
assertThat(e.getStatus().getCode()).isEqualTo(BAD_REQUEST);
}
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class XacmlServiceTest method testImportXACMLDryRun.
@Test
public void testImportXACMLDryRun() throws Exception {
//given
query.add("dryrun", "true");
Representation representation = mock(Representation.class);
InputStream is = new ByteArrayInputStream("Hello World".getBytes());
doReturn(is).when(representation).getStream();
StubPrivilege privilege = new StubPrivilege();
privilege.setName("fred");
XACMLExportImport.ImportStep importStep = mock(XACMLExportImport.ImportStep.class);
doReturn(XACMLExportImport.DiffStatus.ADD).when(importStep).getDiffStatus();
doReturn(privilege).when(importStep).getPrivilege();
List<ImportStep> steps = Arrays.asList(importStep);
doReturn(steps).when(importExport).importXacml(eq("/"), eq(is), any(Subject.class), eq(true));
//when
Representation result = service.importXACML(representation);
//then
assertThat(result).isInstanceOf(JacksonRepresentation.class);
Map<String, Object> resultMap = JsonValueBuilder.toJsonArray(result.getText()).get(0).asMap();
assertThat(resultMap).contains(entry("status", "A"), entry("name", "fred"));
verify(response).setStatus(Status.SUCCESS_OK);
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class XacmlServiceTest method testImportXACMLNoPolicies.
@Test
public void testImportXACMLNoPolicies() throws Exception {
//given
Representation representation = mock(Representation.class);
InputStream is = new ByteArrayInputStream("Hello World".getBytes());
doReturn(is).when(representation).getStream();
doReturn(Collections.emptyList()).when(importExport).importXacml(eq("/"), eq(is), any(Subject.class), eq(false));
try {
//when
service.importXACML(representation);
//then
fail("Expect exception");
} catch (ResourceException e) {
assertThat(e.getStatus().getCode()).isEqualTo(BAD_REQUEST);
assertThat(e.getMessage()).isEqualTo("No policies found in XACML document");
}
}
Aggregations