### Question:
XACMLExportImport { public List<ImportStep> importXacml(String realm, InputStream xacml, Subject admin, boolean dryRun) throws EntitlementException { PrivilegeSet privilegeSet = xacmlToPrivilegeSet(xacml); List<PersistableImportStep> importSteps = generateImportSteps(realm, privilegeSet, admin); applyIfRequired(dryRun, importSteps); return new ArrayList<ImportStep>(importSteps); } @Inject  XACMLExportImport(PrivilegeManagerFactory privilegeManagerFactory,
            XACMLReaderWriter xacmlReaderWriter,
            PrivilegeValidator privilegeValidator,
            SearchFilterFactory searchFilterFactory,
            @Named(XACMLConstants.DEBUG) Debug debug,
            ApplicationServiceFactory applicationServiceFactory,
            ResourceTypeService resourceTypeService); List<ImportStep> importXacml(String realm, InputStream xacml, Subject admin, boolean dryRun); PolicySet exportXACML(String realm, Subject admin, List<String> filters); static final String PREFIX; }### Answer:
@Test public void canImportPrivilegesIntoRealm() throws Exception { Privilege privilegeToUpdate = existing(valid(privilege("p1"))); Privilege privilegeToAdd = notExisting(valid(privilege("p2"))); PrivilegeSet privilegeSet = new PrivilegeSet(); privilegeSet.addPrivilege(privilegeToUpdate); privilegeSet.addPrivilege(privilegeToAdd); given(xacmlReaderWriter.read(eq(NULL_INPUT))).willReturn(privilegeSet); List<ImportStep> importSteps = xacmlExportImport.importXacml(ROOT_REALM, NULL_INPUT, NULL_SUBJECT, false); assertThat(importSteps).hasSize(2); assertImportStep(importSteps.get(0), DiffStatus.UPDATE, privilegeToUpdate); assertImportStep(importSteps.get(1), DiffStatus.ADD, privilegeToAdd); verify(validator).validatePrivilege(privilegeToAdd); verify(validator).validatePrivilege(privilegeToUpdate); verify(pm).add(privilegeToAdd); verify(pm).modify(privilegeToUpdate); }
@Test public void canPerformAnImportDryRun() throws Exception { Privilege privilegeToUpdate = existing(valid(privilege("p1"))); Privilege privilegeToAdd = notExisting(valid(privilege("p2"))); PrivilegeSet privilegeSet = new PrivilegeSet(); privilegeSet.addPrivilege(privilegeToUpdate); privilegeSet.addPrivilege(privilegeToAdd); given(xacmlReaderWriter.read(eq(NULL_INPUT))).willReturn(privilegeSet); List<ImportStep> importSteps = xacmlExportImport.importXacml(ROOT_REALM, NULL_INPUT, NULL_SUBJECT, true); assertThat(importSteps).hasSize(2); assertImportStep(importSteps.get(0), DiffStatus.UPDATE, privilegeToUpdate); assertImportStep(importSteps.get(1), DiffStatus.ADD, privilegeToAdd); verify(validator).validatePrivilege(privilegeToAdd); verify(validator).validatePrivilege(privilegeToUpdate); verify(pm, times(0)).add(nullable(Privilege.class)); verify(pm, times(0)).modify(nullable(Privilege.class)); }
@Test(expectedExceptions = EntitlementException.class) public void throwsAnExceptionIfPrivilegeValidationFails() throws EntitlementException { Privilege invalidPrivilege = invalid(privilege("p1")); PrivilegeSet set = new PrivilegeSet(); set.addPrivilege(invalidPrivilege); given(xacmlReaderWriter.read(eq(NULL_INPUT))).willReturn(set); xacmlExportImport.importXacml(ROOT_REALM, NULL_INPUT, NULL_SUBJECT, true); fail("Expected validation exception"); }