Search in sources :

Example 1 with StubPrivilege

use of org.forgerock.openam.entitlement.rest.StubPrivilege 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 2 with StubPrivilege

use of org.forgerock.openam.entitlement.rest.StubPrivilege in project OpenAM by OpenRock.

the class XacmlServiceTest method testImportXACML.

@Test
public void testImportXACML() throws Exception {
    //given
    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(false));
    //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)

Aggregations

XACMLExportImport (com.sun.identity.entitlement.xacml3.XACMLExportImport)2 ImportStep (com.sun.identity.entitlement.xacml3.XACMLExportImport.ImportStep)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Subject (javax.security.auth.Subject)2 StubPrivilege (org.forgerock.openam.entitlement.rest.StubPrivilege)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 JacksonRepresentation (org.restlet.ext.jackson.JacksonRepresentation)2 Representation (org.restlet.representation.Representation)2 Test (org.testng.annotations.Test)2