@Test public void testUserSimplePropertyDiffReplace() throws Exception { System.out.println("\n\n===[ testUserSimplePropertyDiffReplace ]===\n"); // GIVEN PrismObjectDefinition<UserType> userDef = getUserTypeDefinition(); PrismObject<UserType> user1 = userDef.instantiate(); user1.setOid(USER_JACK_OID); user1.setPropertyRealValue(UserType.F_NAME, PrismTestUtil.createPolyString("test name")); PrismObject<UserType> user2 = userDef.instantiate(); user2.setOid(USER_JACK_OID); user2.setPropertyRealValue(UserType.F_NAME, PrismTestUtil.createPolyString("other name")); // WHEN ObjectDelta<UserType> delta = user1.diff(user2); // THEN assertNotNull(delta); System.out.println(delta.debugDump()); assertEquals("Unexpected number of midifications", 1, delta.getModifications().size()); PrismAsserts.assertPropertyReplace( delta, UserType.F_NAME, PrismTestUtil.createPolyString("other name")); assertEquals("Wrong OID", USER_JACK_OID, delta.getOid()); delta.checkConsistence(); }
@Test public void testContainerValueDiffDesciptionNoPath() throws Exception { System.out.println("\n\n===[ testContainerValueDiffDesciptionNoPath ]===\n"); // GIVEN PrismObjectDefinition<UserType> userDef = getUserTypeDefinition(); PrismContainerDefinition<AssignmentType> assignmentContDef = userDef.findContainerDefinition(UserType.F_ASSIGNMENT); PrismContainer<AssignmentType> ass1 = assignmentContDef.instantiate(); PrismContainerValue<AssignmentType> ass1cval = ass1.createNewValue(); ass1cval.setPropertyRealValue( AssignmentType.F_DESCRIPTION, "blah blah", PrismTestUtil.getPrismContext()); PrismContainer<AssignmentType> ass2 = assignmentContDef.instantiate(); PrismContainerValue<AssignmentType> ass2cval = ass2.createNewValue(); ass2cval.setPropertyRealValue( AssignmentType.F_DESCRIPTION, "chamalalia patlama paprtala", PrismTestUtil.getPrismContext()); // WHEN Collection<? extends ItemDelta> modifications = ass1cval.diff(ass2cval); // THEN assertNotNull(modifications); System.out.println(DebugUtil.debugDump(modifications)); assertEquals("Unexpected number of midifications", 1, modifications.size()); PrismAsserts.assertPropertyReplace( modifications, new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_DESCRIPTION), "chamalalia patlama paprtala"); ItemDelta.checkConsistence(modifications); }
@BeforeSuite public void setup() throws SchemaException, SAXException, IOException { PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX); PrismTestUtil.resetPrismContext(MidPointPrismContextFactory.FACTORY); prismContext = PrismTestUtil.createInitializedPrismContext(); ObjectResolver resolver = new DirectoryFileObjectResolver(MidPointTestConstants.OBJECTS_DIR); AESProtector protector = ExpressionTestUtil.createInitializedProtector(prismContext); expressionFactory = ExpressionTestUtil.createInitializedExpressionFactory( resolver, protector, prismContext, null); }
@Test public void testIterationCondition() throws Exception { final String TEST_NAME = "testIterationCondition"; TestUtil.displayTestTile(TEST_NAME); // GIVEN OperationResult result = new OperationResult(TestExpression.class.getName() + "." + TEST_NAME); rememberScriptExecutionCount(); ExpressionType expressionType = PrismTestUtil.parseAtomicValue( EXPRESSION_ITERATION_CONDITION_FILE, ExpressionType.COMPLEX_TYPE); PrismPropertyDefinition<Boolean> outputDefinition = new PrismPropertyDefinitionImpl<Boolean>( ExpressionConstants.OUTPUT_ELMENT_NAME, DOMUtil.XSD_BOOLEAN, prismContext); Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(expressionType, outputDefinition, TEST_NAME, null, result); ExpressionVariables variables = new ExpressionVariables(); PrismObject<UserType> user = PrismTestUtil.parseObject(USER_JACK_FILE); variables.addVariableDefinition(ExpressionConstants.VAR_FOCUS, user); variables.addVariableDefinition(ExpressionConstants.VAR_USER, user); PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMYFILE); variables.addVariableDefinition(ExpressionConstants.VAR_SHADOW, account); variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION, 1); variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION_TOKEN, "001"); ExpressionEvaluationContext expressionContext = new ExpressionEvaluationContext(null, variables, TEST_NAME, null, result); // WHEN PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = expression.evaluate(expressionContext); // THEN assertNotNull(outputTriple); outputTriple.checkConsistence(); // Make sure that the script is executed only once. There is no delta in the variables, no need // to do it twice. assertScriptExecutionIncrement(1); }
protected void assertMonkeyIslandOrgSanity(int expectedFictional) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException { Task task = taskManager.createTaskInstance( AbstractInitializedModelIntegrationTest.class.getName() + ".assertMonkeyIslandOrgSanity"); OperationResult result = task.getResult(); PrismObject<OrgType> orgGovernorOffice = modelService.getObject(OrgType.class, ORG_GOVERNOR_OFFICE_OID, null, task, result); result.computeStatus(); TestUtil.assertSuccess(result); OrgType orgGovernorOfficeType = orgGovernorOffice.asObjectable(); assertEquals( "Wrong governor office name", PrismTestUtil.createPolyStringType("F0001"), orgGovernorOfficeType.getName()); List<PrismObject<OrgType>> governorSubOrgs = searchOrg(ORG_GOVERNOR_OFFICE_OID, OrgFilter.Scope.ONE_LEVEL, task, result); if (verbose) display("governor suborgs", governorSubOrgs); assertEquals("Unexpected number of governor suborgs", 3, governorSubOrgs.size()); List<PrismObject<OrgType>> functionalOrgs = searchOrg(ORG_GOVERNOR_OFFICE_OID, OrgFilter.Scope.SUBTREE, task, result); if (verbose) display("functional orgs (null)", functionalOrgs); assertEquals( "Unexpected number of functional orgs (null)", NUM_FUNCTIONAL_ORGS - 1 + expectedFictional, functionalOrgs.size()); List<PrismObject<OrgType>> prootSubOrgs = searchOrg(ORG_PROJECT_ROOT_OID, OrgFilter.Scope.ONE_LEVEL, task, result); if (verbose) display("project root suborgs", prootSubOrgs); assertEquals("Unexpected number of governor suborgs", 2, prootSubOrgs.size()); List<PrismObject<OrgType>> projectOrgs = searchOrg(ORG_PROJECT_ROOT_OID, OrgFilter.Scope.SUBTREE, task, result); if (verbose) display("project orgs (null)", projectOrgs); assertEquals( "Unexpected number of functional orgs (null)", NUM_PROJECT_ORGS - 1, projectOrgs.size()); PrismObject<OrgType> orgScummBar = modelService.getObject(OrgType.class, ORG_SCUMM_BAR_OID, null, task, result); List<AssignmentType> scummBarInducements = orgScummBar.asObjectable().getInducement(); assertEquals( "Unexpected number of scumm bar inducements: " + scummBarInducements, 1, scummBarInducements.size()); ResultHandler<OrgType> handler = getOrgSanityCheckHandler(); if (handler != null) { modelService.searchObjectsIterative(OrgType.class, null, handler, null, task, result); } }
@BeforeMethod public void initUcf() throws Exception { TestUtil.displayTestTile("initUcf"); File file = new File(FILENAME_RESOURCE_OPENDJ); FileInputStream fis = new FileInputStream(file); // Resource PrismObject<ResourceType> resource = PrismTestUtil.parseObject(new File(FILENAME_RESOURCE_OPENDJ)); resourceType = resource.asObjectable(); // Resource: Second copy for negative test cases PrismObject<ResourceType> badResource = PrismTestUtil.parseObject(new File(FILENAME_RESOURCE_OPENDJ_BAD)); badResourceType = badResource.asObjectable(); // Connector PrismObject<ConnectorType> connector = PrismTestUtil.parseObject(new File(FILENAME_CONNECTOR_LDAP)); connectorType = connector.asObjectable(); factory = connectorFactoryIcfImpl; cc = factory.createConnectorInstance( connectorType, ResourceTypeUtil.getResourceNamespace(resourceType), "test connector"); AssertJUnit.assertNotNull("Cannot create connector instance", cc); connectorSchema = cc.generateConnectorSchema(); AssertJUnit.assertNotNull("Cannot generate connector schema", cc); display("Connector schema", connectorSchema); OperationResult result = new OperationResult("initUcf"); cc.configure(resourceType.getConnectorConfiguration().asPrismContainerValue(), result); cc.initialize(null, null, false, result); // TODO: assert something resourceSchema = cc.fetchResourceSchema(null, result); display("Resource schema", resourceSchema); AssertJUnit.assertNotNull(resourceSchema); }
@Test public void testParseModelContextPrism() throws Exception { System.out.println("===[ testParseModelContextPrism ]==="); // GIVEN PrismContext prismContext = PrismTestUtil.getPrismContext(); // WHEN PrismContainer<LensContextType> lensContextType = prismContext.parseContainer( MODEL_CONTEXT_FILE, LensContextType.class, PrismContext.LANG_XML); // THEN System.out.println("Parsed LensContextType: " + lensContextType.getValue().asContainerable()); }
@Test public void testParseTaskFile() throws Exception { System.out.println("===[ testParseTaskFile ]==="); // GIVEN PrismContext prismContext = PrismTestUtil.getPrismContext(); // WHEN PrismObject<TaskType> task = prismContext.parseObject(TASK_FILE, PrismContext.LANG_XML); // THEN System.out.println("Parsed task:"); System.out.println(task.debugDump()); assertTask(task); }
@Test public void testParseTaskRoundtrip() throws Exception { System.out.println("===[ testParseTaskRoundtrip ]==="); // GIVEN PrismContext prismContext = PrismTestUtil.getPrismContext(); PrismObject<TaskType> task = prismContext.parseObject(TASK_FILE); System.out.println("Parsed task:"); System.out.println(task.debugDump()); assertTask(task); // SERIALIZE String serializedTask = prismContext.serializeObjectToString(task, PrismContext.LANG_XML); System.out.println("serialized task:"); System.out.println(serializedTask); // RE-PARSE PrismObject<TaskType> reparsedTask = prismContext.parseObject(serializedTask); System.out.println("Re-parsed task:"); System.out.println(reparsedTask.debugDump()); // Cannot assert here. It will cause parsing of some of the raw values and diff will fail assertTask(reparsedTask); ObjectDelta<TaskType> objectDelta = task.diff(reparsedTask); System.out.println("Delta:"); System.out.println(objectDelta.debugDump()); assertTrue("Delta is not empty", objectDelta.isEmpty()); PrismAsserts.assertEquivalent("Task re-parsed equivalence", task, reparsedTask); }
private void assertTask(PrismObject<TaskType> task) { task.checkConsistence(); assertEquals("Wrong oid", "44444444-4444-4444-4444-000000001111", task.getOid()); PrismObjectDefinition<TaskType> usedDefinition = task.getDefinition(); assertNotNull("No task definition", usedDefinition); PrismAsserts.assertObjectDefinition( usedDefinition, new QName(SchemaConstantsGenerated.NS_COMMON, "task"), TaskType.COMPLEX_TYPE, TaskType.class); assertEquals("Wrong class in task", TaskType.class, task.getCompileTimeClass()); TaskType taskType = task.asObjectable(); assertNotNull("asObjectable resulted in null", taskType); assertPropertyValue(task, "name", PrismTestUtil.createPolyString("Task2")); assertPropertyDefinition(task, "name", PolyStringType.COMPLEX_TYPE, 0, 1); assertPropertyValue(task, "taskIdentifier", "44444444-4444-4444-4444-000000001111"); assertPropertyDefinition(task, "taskIdentifier", DOMUtil.XSD_STRING, 0, 1); assertPropertyDefinition( task, "executionStatus", JAXBUtil.getTypeQName(TaskExecutionStatusType.class), 1, 1); PrismProperty<TaskExecutionStatusType> executionStatusProperty = task.findProperty(TaskType.F_EXECUTION_STATUS); PrismPropertyValue<TaskExecutionStatusType> executionStatusValue = executionStatusProperty.getValue(); TaskExecutionStatusType executionStatus = executionStatusValue.getValue(); assertEquals("Wrong execution status", TaskExecutionStatusType.RUNNABLE, executionStatus); PrismContainer extension = task.getExtension(); PrismContainerValue extensionValue = extension.getValue(); assertTrue("Extension parent", extensionValue.getParent() == extension); assertNull("Extension ID", extensionValue.getId()); }
@Test(enabled = true) public void test010FormatUser() throws Exception { // GIVEN PrismObject<UserType> jack = PrismTestUtil.parseObject(new File(USER_JACK_FILE)); System.out.println(jack.debugDump()); // WHEN String jackFormattedHideNone = textFormatter.formatObject(jack, null, true); System.out.println("no hidden paths + show operational attributes: " + jackFormattedHideNone); String jackFormattedHideOper = textFormatter.formatObject(jack, null, false); System.out.println("no hidden paths + hide operational attributes: " + jackFormattedHideOper); String jackFormattedHideAux = textFormatter.formatObject(jack, auxiliaryPaths, true); System.out.println( "hide auxiliary paths + show operational attributes: " + jackFormattedHideAux); String jackFormattedHideAuxAndOper = textFormatter.formatObject(jack, auxiliaryPaths, false); System.out.println( "hide auxiliary paths + hide operational attributes: " + jackFormattedHideAuxAndOper); // THEN assertTrue( "hidden operational attribute when it should be shown ('hide none')", jackFormattedHideNone.contains("createTimestamp:")); assertTrue( "hidden auxiliary attribute (effective status) when it should be shown ('hide none')", jackFormattedHideNone.contains("Effective Status: ENABLED")); assertTrue( "hidden auxiliary attribute (family name) when it should be shown ('hide none')", jackFormattedHideNone.contains("Family Name: Sparrow")); assertTrue( "hidden standard attribute when it should be shown ('hide none')", jackFormattedHideNone.contains("ship: Black Pearl")); assertTrue( "shown operational attribute when it should be hidden ('hide oper')", !jackFormattedHideOper.contains("createTimestamp:")); assertTrue( "hidden auxiliary attribute when it should be shown ('hide oper')", jackFormattedHideOper.contains("Effective Status: ENABLED")); assertTrue( "hidden auxiliary attribute (family name) when it should be shown ('hide oper')", jackFormattedHideOper.contains("Family Name: Sparrow")); assertTrue( "hidden standard attribute when it should be shown ('hide oper')", jackFormattedHideOper.contains("ship: Black Pearl")); assertTrue( "shown auxiliary attribute (metadata) when it should be hidden ('hide aux')", !jackFormattedHideAux.contains("createTimestamp:")); assertTrue( "shown auxiliary attribute (family name) when it should be hidden ('hide aux')", !jackFormattedHideAux.contains("Family Name: Sparrow")); assertTrue( "shown auxiliary attribute (effective status) when it should be hidden ('hide aux')", !jackFormattedHideAux.contains("Effective Status: ENABLED")); assertTrue( "hidden standard attribute when it should be shown ('hide aux')", jackFormattedHideAux.contains("ship: Black Pearl")); assertTrue( "shown operational attribute when it should be hidden ('hide aux and oper')", !jackFormattedHideAuxAndOper.contains("createTimestamp:")); assertTrue( "shown auxiliary attribute (effective status) when it should be hidden ('hide aux and oper')", !jackFormattedHideAuxAndOper.contains("Effective Status: ENABLED")); assertTrue( "shown auxiliary attribute (family name) when it should be hidden ('hide aux and oper')", !jackFormattedHideAuxAndOper.contains("Family Name: Sparrow")); assertTrue( "hidden standard attribute when it should be shown ('hide aux and oper')", jackFormattedHideAuxAndOper.contains("ship: Black Pearl")); }
@BeforeSuite public void setup() throws SchemaException, SAXException, IOException { PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX); PrismTestUtil.resetPrismContext(MidPointPrismContextFactory.FACTORY); }
private ObjectDelta<UserType> parseDelta(String filename) throws JAXBException, SchemaException, IOException { ObjectModificationType modElement = PrismTestUtil.parseAtomicValue(new File(filename), ObjectModificationType.COMPLEX_TYPE); return DeltaConvertor.createObjectDelta(modElement, UserType.class, prismContext); }
@Test(enabled = true) public void test030FormatAccount() throws Exception { // GIVEN PrismObject<ShadowType> jack = PrismTestUtil.parseObject(new File(ACCOUNT_JACK_FILE)); System.out.println(jack.debugDump()); // WHEN String jackFormattedHideNone = textFormatter.formatAccountAttributes(jack.asObjectable(), null, true); System.out.println("no hidden paths + show operational attributes: " + jackFormattedHideNone); String jackFormattedHideAux = textFormatter.formatAccountAttributes(jack.asObjectable(), auxiliaryPaths, true); System.out.println( "hide auxiliary paths + show operational attributes: " + jackFormattedHideAux); // THEN assertTrue("account name is not shown", jackFormattedHideNone.contains("Name: jack")); assertTrue( "account password is not shown", jackFormattedHideNone.contains("(protected string)")); assertTrue( "administrative status is not shown", jackFormattedHideNone.contains("Administrative Status: ENABLED")); assertTrue( "effective status is not shown", jackFormattedHideNone.contains("Effective Status: ENABLED")); assertTrue("account name is not shown", jackFormattedHideAux.contains("Name: jack")); assertTrue( "account password is not shown", jackFormattedHideAux.contains("(protected string)")); assertTrue( "administrative status is not shown", jackFormattedHideAux.contains("Administrative Status: ENABLED")); assertTrue( "effective status is shown although it should be hidden", !jackFormattedHideAux.contains("Effective Status: ENABLED")); // AssertJUnit.assertTrue("hidden operational attribute when it should be shown ('hide // none')", jackFormattedHideNone.contains("createTimestamp:")); // AssertJUnit.assertTrue("hidden auxiliary attribute (effective status) when it should // be shown ('hide none')", jackFormattedHideNone.contains("Effective Status: ENABLED")); // AssertJUnit.assertTrue("hidden auxiliary attribute (family name) when it should be // shown ('hide none')", jackFormattedHideNone.contains("Family Name: Sparrow")); // AssertJUnit.assertTrue("hidden standard attribute when it should be shown ('hide // none')", jackFormattedHideNone.contains("ship: Black Pearl")); // // AssertJUnit.assertTrue("shown operational attribute when it should be hidden ('hide // oper')", !jackFormattedHideOper.contains("createTimestamp:")); // AssertJUnit.assertTrue("hidden auxiliary attribute when it should be shown ('hide // oper')", jackFormattedHideOper.contains("Effective Status: ENABLED")); // AssertJUnit.assertTrue("hidden auxiliary attribute (family name) when it should be // shown ('hide oper')", jackFormattedHideOper.contains("Family Name: Sparrow")); // AssertJUnit.assertTrue("hidden standard attribute when it should be shown ('hide // oper')", jackFormattedHideOper.contains("ship: Black Pearl")); // // AssertJUnit.assertTrue("shown auxiliary attribute (metadata) when it should be hidden // ('hide aux')", !jackFormattedHideAux.contains("createTimestamp:")); // AssertJUnit.assertTrue("shown auxiliary attribute (family name) when it should be // hidden ('hide aux')", !jackFormattedHideAux.contains("Family Name: Sparrow")); // AssertJUnit.assertTrue("shown auxiliary attribute (effective status) when it should be // hidden ('hide aux')", !jackFormattedHideAux.contains("Effective Status: ENABLED")); // AssertJUnit.assertTrue("hidden standard attribute when it should be shown ('hide // aux')", jackFormattedHideAux.contains("ship: Black Pearl")); // // AssertJUnit.assertTrue("shown operational attribute when it should be hidden ('hide // aux and oper')", !jackFormattedHideAuxAndOper.contains("createTimestamp:")); // AssertJUnit.assertTrue("shown auxiliary attribute (effective status) when it should be // hidden ('hide aux and oper')", !jackFormattedHideAuxAndOper.contains("Effective Status: // ENABLED")); // AssertJUnit.assertTrue("shown auxiliary attribute (family name) when it should be // hidden ('hide aux and oper')", !jackFormattedHideAuxAndOper.contains("Family Name: // Sparrow")); // AssertJUnit.assertTrue("hidden standard attribute when it should be shown ('hide aux // and oper')", jackFormattedHideAuxAndOper.contains("ship: Black Pearl")); }
@Test(enabled = true) public void test020FormatUserModification() throws Exception { // GIVEN ObjectDelta<UserType> delta = parseDelta(USER_JACK_MODIFICATION_FILE); PrismObject<UserType> jack = PrismTestUtil.parseObject(new File(USER_JACK_FILE)); System.out.println(delta.debugDump()); // WHEN String deltaFormattedHideNone = textFormatter.formatObjectModificationDelta(delta, null, true, jack, null); System.out.println("no hidden paths + show operational attributes: " + deltaFormattedHideNone); String deltaFormattedHideOper = textFormatter.formatObjectModificationDelta(delta, null, false, jack, null); System.out.println("no hidden paths + hide operational attributes: " + deltaFormattedHideOper); String deltaFormattedHideAux = textFormatter.formatObjectModificationDelta(delta, auxiliaryPaths, true, jack, null); System.out.println( "hide auxiliary paths + show operational attributes: " + deltaFormattedHideAux); String deltaFormattedHideAuxAndOper = textFormatter.formatObjectModificationDelta(delta, auxiliaryPaths, false, jack, null); System.out.println( "hide auxiliary paths + hide operational attributes: " + deltaFormattedHideAuxAndOper); // THEN checkNotes(deltaFormattedHideAux); checkNotes(deltaFormattedHideAuxAndOper); checkNotes(deltaFormattedHideNone); checkNotes(deltaFormattedHideOper); assertTrue( "hidden operational attribute when it should be shown ('hide none')", deltaFormattedHideNone.contains("createTimestamp:")); assertTrue( "hidden auxiliary attribute (family name) when it should be shown ('hide none')", deltaFormattedHideNone.contains("SPARROW")); assertTrue( "hidden password change when it should be shown ('hide none')", deltaFormattedHideNone.contains("(protected string)")); assertTrue( "hidden standard attribute when it should be shown ('hide none')", deltaFormattedHideNone.contains("BLACK PEARL")); assertTrue( "shown operational attribute when it should be hidden ('hide oper')", !deltaFormattedHideOper.contains("createTimestamp:")); assertTrue( "hidden auxiliary attribute (family name) when it should be shown ('hide oper')", deltaFormattedHideOper.contains("SPARROW")); assertTrue( "hidden password change when it should be shown ('hide oper')", deltaFormattedHideOper.contains("(protected string)")); assertTrue( "hidden standard attribute when it should be shown ('hide oper')", deltaFormattedHideOper.contains("BLACK PEARL")); assertTrue( "shown auxiliary attribute (metadata) when it should be hidden ('hide aux')", !deltaFormattedHideAux.contains("createTimestamp:")); assertTrue( "shown auxiliary attribute (family name) when it should be hidden ('hide aux')", !deltaFormattedHideAux.contains("SPARROW")); assertTrue( "hidden standard attribute when it should be shown ('hide aux')", deltaFormattedHideAux.contains("BLACK PEARL")); assertTrue( "shown operational attribute when it should be hidden ('hide aux and oper')", !deltaFormattedHideAuxAndOper.contains("createTimestamp:")); assertTrue( "shown auxiliary attribute (family name) when it should be hidden ('hide aux and oper')", !deltaFormattedHideAuxAndOper.contains("SPARROW")); assertTrue( "hidden standard attribute when it should be shown ('hide aux and oper')", deltaFormattedHideAuxAndOper.contains("BLACK PEARL")); }
@BeforeSuite public void setupDebug() throws SchemaException, SAXException, IOException { PrettyPrinter.setDefaultNamespacePrefix(DEFAULT_NAMESPACE_PREFIX); PrismTestUtil.resetPrismContext(new PrismInternalTestUtil()); }