Search in sources :

Example 1 with Migrator

use of com.evolveum.midpoint.model.impl.migrator.Migrator in project midpoint by Evolveum.

the class TestMigrator method testUserCredentials.

@Test
public void testUserCredentials() throws Exception {
    Migrator migrator = createMigrator();
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    PrismObject<UserType> oldUser = prismContext.parseObject(new File(TEST_DIR + "/user-migrate-credentials.xml"));
    PrismObject<UserType> newUser = migrator.migrate(oldUser);
    UserType newUserType = newUser.asObjectable();
    assertNull("Credentials in migrated object must be null.", newUserType.getCredentials());
    assertNotNull("Migrated user must contain assignment.", newUserType.getAssignment());
    assertEquals("Migrated user must contain 1 assignment.", newUserType.getAssignment().size(), 1);
    AssignmentType superUserRole = newUserType.getAssignment().get(0);
    assertNotNull("Target ref in the user's assignment must not be null.", superUserRole.getTargetRef());
    assertEquals(superUserRole.getTargetRef().getOid(), SystemObjectsType.ROLE_SUPERUSER.value());
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) Migrator(com.evolveum.midpoint.model.impl.migrator.Migrator) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 2 with Migrator

use of com.evolveum.midpoint.model.impl.migrator.Migrator in project midpoint by Evolveum.

the class TestMigrator method assertSimpleMigration.

private <O extends ObjectType> void assertSimpleMigration(File fileOld, File fileNew) throws SchemaException, IOException {
    // GIVEN
    Migrator migrator = createMigrator();
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    PrismObject<O> objectOld = prismContext.parseObject(fileOld);
    // WHEN
    PrismObject<O> objectNew = migrator.migrate(objectOld);
    // THEN
    IntegrationTestTools.display("Migrated object " + fileOld.getName(), objectNew);
    assertNotNull("No migrated object " + fileOld.getName(), objectNew);
    IntegrationTestTools.display("Migrated object " + fileOld.getName(), objectNew);
    String migratedXml = PrismTestUtil.serializeObjectToString(objectNew, PrismContext.LANG_XML);
    IntegrationTestTools.display("Migrated object XML " + fileOld.getName(), migratedXml);
    PrismObject<O> expectedObject = prismContext.parseObject(fileNew);
    IntegrationTestTools.display("Expected object " + fileOld.getName(), expectedObject);
    String expectedXml = PrismTestUtil.serializeObjectToString(expectedObject, PrismContext.LANG_XML);
    IntegrationTestTools.display("Expected object XML " + fileOld.getName(), expectedXml);
    List<String> expectedXmlLines = MiscUtil.splitLines(expectedXml);
    Patch patch = DiffUtils.diff(expectedXmlLines, MiscUtil.splitLines(migratedXml));
    List<String> diffLines = DiffUtils.generateUnifiedDiff(fileOld.getPath(), fileNew.getPath(), expectedXmlLines, patch, 3);
    IntegrationTestTools.display("XML textual diff", StringUtils.join(diffLines, '\n'));
    PrismAsserts.assertEquivalent("Unexpected migration result for " + fileOld.getName(), expectedObject, objectNew);
    assertEquals("Unexpected element name for " + fileOld.getName(), expectedObject.getElementName(), objectNew.getElementName());
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) Migrator(com.evolveum.midpoint.model.impl.migrator.Migrator) Patch(difflib.Patch)

Aggregations

Migrator (com.evolveum.midpoint.model.impl.migrator.Migrator)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1 Patch (difflib.Patch)1 File (java.io.File)1 Test (org.testng.annotations.Test)1