Example #1
0
  @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();
  }
Example #2
0
  @Test
  public void testUserSimpleDiffMultiAdd() throws Exception {
    System.out.println("\n\n===[ testUserSimpleDiffMulti ]===\n");

    // GIVEN
    PrismObjectDefinition<UserType> userDef = getUserTypeDefinition();

    PrismObject<UserType> user1 = userDef.instantiate();
    user1.setOid(USER_JACK_OID);
    PrismProperty<String> anamesProp1 = user1.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES);
    anamesProp1.addRealValue("foo");
    anamesProp1.addRealValue("bar");

    PrismObject<UserType> user2 = userDef.instantiate();
    user2.setOid(USER_JACK_OID);
    PrismProperty<String> anamesProp2 = user2.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES);
    anamesProp2.addRealValue("foo");
    anamesProp2.addRealValue("bar");
    anamesProp2.addRealValue("baz");

    // 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.assertPropertyAdd(delta, UserType.F_ADDITIONAL_NAMES, "baz");
    assertEquals("Wrong OID", USER_JACK_OID, delta.getOid());
    delta.checkConsistence();
  }
  @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);
  }
  @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"));
  }