Search in sources :

Example 6 with ImportStep

use of com.sun.identity.entitlement.xacml3.XACMLExportImport.ImportStep 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

ImportStep (com.sun.identity.entitlement.xacml3.XACMLExportImport.ImportStep)6 XACMLExportImport (com.sun.identity.entitlement.xacml3.XACMLExportImport)4 Test (org.testng.annotations.Test)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 Subject (javax.security.auth.Subject)3 EntitlementException (com.sun.identity.entitlement.EntitlementException)2 IPrivilege (com.sun.identity.entitlement.IPrivilege)2 Privilege (com.sun.identity.entitlement.Privilege)2 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)2 FactoryMethods.createArbitraryPrivilege (com.sun.identity.entitlement.xacml3.FactoryMethods.createArbitraryPrivilege)2 FactoryMethods.createArbitraryReferralPrivilege (com.sun.identity.entitlement.xacml3.FactoryMethods.createArbitraryReferralPrivilege)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 SSOToken (com.iplanet.sso.SSOToken)1 CLIException (com.sun.identity.cli.CLIException)1 SearchFilterFactory (com.sun.identity.entitlement.xacml3.SearchFilterFactory)1 XACMLReaderWriter (com.sun.identity.entitlement.xacml3.XACMLReaderWriter)1