Search in sources :

Example 11 with Representation

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);
}
Also used : Disposition(org.restlet.data.Disposition) List(java.util.List) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Representation(org.restlet.representation.Representation) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with Representation

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.");
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) List(java.util.List) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Representation(org.restlet.representation.Representation) ResourceException(org.restlet.resource.ResourceException) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with Representation

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);
    }
}
Also used : JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Representation(org.restlet.representation.Representation) ResourceException(org.restlet.resource.ResourceException) IOException(java.io.IOException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with Representation

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StubPrivilege(org.forgerock.openam.entitlement.rest.StubPrivilege) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Representation(org.restlet.representation.Representation) XACMLExportImport(com.sun.identity.entitlement.xacml3.XACMLExportImport) ImportStep(com.sun.identity.entitlement.xacml3.XACMLExportImport.ImportStep) Subject(javax.security.auth.Subject) ImportStep(com.sun.identity.entitlement.xacml3.XACMLExportImport.ImportStep) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 15 with Representation

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");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Representation(org.restlet.representation.Representation) ResourceException(org.restlet.resource.ResourceException) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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