@Test
  public void test510Search() throws Exception {
    final String TEST_NAME = "test510Search";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME);
    // Determine object class from the schema

    ResultHandler<ShadowType> handler =
        new ResultHandler<ShadowType>() {
          @Override
          public boolean handle(PrismObject<ShadowType> object) {
            System.out.println("Search: found: " + object);
            return true;
          }
        };

    OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME);

    // WHEN
    cc.search(accountDefinition, new ObjectQuery(), handler, null, null, null, result);

    // THEN

  }
  @Test
  public void test110ChangeModifyObject() throws Exception {
    final String TEST_NAME = "test110ChangeModifyObject";
    TestUtil.displayTestTile(this, TEST_NAME);

    OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME);

    Collection<ResourceAttribute<?>> identifiers = addSampleResourceObject("john", "John", "Smith");

    Set<Operation> changes = new HashSet<Operation>();

    changes.add(createAddAttributeChange("employeeNumber", "123123123"));
    changes.add(createReplaceAttributeChange("sn", "Smith007"));
    changes.add(createAddAttributeChange("street", "Wall Street"));
    changes.add(createDeleteAttributeChange("givenName", "John"));

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME);

    cc.modifyObject(accountDefinition, identifiers, changes, result);

    ResourceObjectIdentification identification =
        new ResourceObjectIdentification(accountDefinition, identifiers);
    PrismObject<ShadowType> shadow = cc.fetchObject(ShadowType.class, identification, null, result);
    ResourceAttributeContainer resObj = ShadowUtil.getAttributesContainer(shadow);

    AssertJUnit.assertNull(
        resObj.findAttribute(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "givenName")));

    String addedEmployeeNumber =
        resObj
            .findAttribute(
                new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "employeeNumber"))
            .getValue(String.class)
            .getValue();
    String changedSn =
        resObj
            .findAttribute(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "sn"))
            .getValues(String.class)
            .iterator()
            .next()
            .getValue();
    String addedStreet =
        resObj
            .findAttribute(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "street"))
            .getValues(String.class)
            .iterator()
            .next()
            .getValue();

    System.out.println("changed employee number: " + addedEmployeeNumber);
    System.out.println("changed sn: " + changedSn);
    System.out.println("added street: " + addedStreet);

    AssertJUnit.assertEquals("123123123", addedEmployeeNumber);
    AssertJUnit.assertEquals("Smith007", changedSn);
    AssertJUnit.assertEquals("Wall Street", addedStreet);
  }
  private ResourceAttributeContainer createResourceObject(String dn, String sn, String cn)
      throws SchemaException {
    // Account type is hardcoded now
    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "AccountObjectClass"));
    // Determine identifier from the schema
    ResourceAttributeContainer resourceObject =
        accountDefinition.instantiate(ShadowType.F_ATTRIBUTES);

    ResourceAttributeDefinition road =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "sn"));
    ResourceAttribute roa = road.instantiate();
    roa.setValue(new PrismPropertyValue(sn));
    resourceObject.add(roa);

    road =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "cn"));
    roa = road.instantiate();
    roa.setValue(new PrismPropertyValue(cn));
    resourceObject.add(roa);

    road = accountDefinition.findAttributeDefinition(ConnectorFactoryIcfImpl.ICFS_NAME);
    roa = road.instantiate();
    roa.setValue(new PrismPropertyValue(dn));
    resourceObject.add(roa);

    return resourceObject;
  }
  @Test
  public void test100AddDeleteObject() throws Exception {
    final String TEST_NAME = "test100AddDeleteObject";
    TestUtil.displayTestTile(this, TEST_NAME);

    OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME);

    Collection<ResourceAttribute<?>> identifiers = addSampleResourceObject("john", "John", "Smith");

    String uid = null;
    for (ResourceAttribute<?> resourceAttribute : identifiers) {
      if (ConnectorFactoryIcfImpl.ICFS_UID.equals(resourceAttribute.getElementName())) {
        uid = resourceAttribute.getValue(String.class).getValue();
        System.out.println("uuuuid:" + uid);
        assertNotNull(uid);
      }
    }

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME);

    cc.deleteObject(accountDefinition, null, identifiers, result);

    ResourceObjectIdentification identification =
        new ResourceObjectIdentification(accountDefinition, identifiers);
    PrismObject<ShadowType> resObj = null;
    try {
      resObj = cc.fetchObject(ShadowType.class, identification, null, result);
      Assert.fail();
    } catch (ObjectNotFoundException ex) {
      AssertJUnit.assertNull(resObj);
    }
  }
  /**
   * Test fetching and translating resource schema.
   *
   * @throws Exception
   */
  @Test
  public void test400FetchResourceSchema() throws Exception {
    final String TEST_NAME = "test400FetchResourceSchema";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN

    // WHEN

    // The schema was fetched during test init. Now just check if it was OK.

    // THEN

    AssertJUnit.assertNotNull(resourceSchema);

    System.out.println(resourceSchema.debugDump());

    Document xsdSchema = resourceSchema.serializeToXsd();

    System.out.println(
        "-------------------------------------------------------------------------------------");
    System.out.println(DOMUtil.printDom(xsdSchema));
    System.out.println(
        "-------------------------------------------------------------------------------------");

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME));
    AssertJUnit.assertNotNull(accountDefinition);

    AssertJUnit.assertFalse(
        "No identifiers for account object class ", accountDefinition.getIdentifiers().isEmpty());

    PrismPropertyDefinition uidDefinition =
        accountDefinition.findAttributeDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME));
    AssertJUnit.assertNotNull(uidDefinition);

    for (Definition def : resourceSchema.getDefinitions()) {
      if (def instanceof ResourceAttributeContainerDefinition) {
        ResourceAttributeContainerDefinition rdef = (ResourceAttributeContainerDefinition) def;
        assertNotEmpty("No type name in object class", rdef.getTypeName());
        assertNotEmpty(
            "No native object class for " + rdef.getTypeName(), rdef.getNativeObjectClass());

        // This is maybe not that important, but just for a sake of
        // completeness
        assertNotEmpty("No name for " + rdef.getTypeName(), rdef.getName());
      }
    }
  }
 private PrismProperty createProperty(String propertyName, String propertyValue) {
   ObjectClassComplexTypeDefinition accountDefinition =
       resourceSchema.findObjectClassDefinition(
           new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "AccountObjectClass"));
   ResourceAttributeDefinition propertyDef =
       accountDefinition.findAttributeDefinition(
           new QName(ResourceTypeUtil.getResourceNamespace(resourceType), propertyName));
   ResourceAttribute property = propertyDef.instantiate();
   property.setValue(new PrismPropertyValue(propertyValue));
   return property;
 }
  private Collection<ResourceAttribute<?>> addSampleResourceObject(
      String name, String givenName, String familyName)
      throws CommunicationException, GenericFrameworkException, SchemaException,
          ObjectAlreadyExistsException, ConfigurationException {
    OperationResult result = new OperationResult(this.getClass().getName() + ".testAdd");

    QName objectClassQname =
        new QName(
            ResourceTypeUtil.getResourceNamespace(resourceType),
            ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME);
    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(objectClassQname);
    assertNotNull("No object class definition " + objectClassQname, accountDefinition);
    ResourceAttributeContainer resourceObject =
        accountDefinition.instantiate(ShadowType.F_ATTRIBUTES);

    ResourceAttributeDefinition<String> attributeDefinition =
        accountDefinition.findAttributeDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME));
    ResourceAttribute<String> attribute = attributeDefinition.instantiate();
    attribute.setValue(
        new PrismPropertyValue<String>("uid=" + name + ",ou=people,dc=example,dc=com"));
    resourceObject.add(attribute);

    attributeDefinition =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "sn"));
    attribute = attributeDefinition.instantiate();
    attribute.setValue(new PrismPropertyValue(familyName));
    resourceObject.add(attribute);

    attributeDefinition =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "cn"));
    attribute = attributeDefinition.instantiate();
    attribute.setValue(new PrismPropertyValue(givenName + " " + familyName));
    resourceObject.add(attribute);

    attributeDefinition =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "givenName"));
    attribute = attributeDefinition.instantiate();
    attribute.setValue(new PrismPropertyValue(givenName));
    resourceObject.add(attribute);

    PrismObject<ShadowType> shadow = wrapInShadow(ShadowType.class, resourceObject);

    Set<Operation> operation = new HashSet<Operation>();
    Collection<ResourceAttribute<?>> resourceAttributes = cc.addObject(shadow, operation, result);
    return resourceAttributes;
  }
 private PrismProperty createProperty(String propertyName, String propertyValue) {
   ObjectClassComplexTypeDefinition accountDefinition =
       resourceSchema.findObjectClassDefinition(
           new QName(
               ResourceTypeUtil.getResourceNamespace(resourceType),
               ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME));
   ResourceAttributeDefinition propertyDef =
       accountDefinition.findAttributeDefinition(
           new QName(ResourceTypeUtil.getResourceNamespace(resourceType), propertyName));
   ResourceAttribute property = propertyDef.instantiate();
   property.setValue(new PrismPropertyValue(propertyValue));
   return property;
 }
  /**
   * Test fetching and translating resource schema.
   *
   * @throws Exception
   */
  @Test
  public void testFetchResourceSchema() throws CommunicationException, SchemaException {
    TestUtil.displayTestTile("testFetchResourceSchema");
    // GIVEN

    // WHEN

    // The schema was fetched during test init. Now just check if it was OK.

    // THEN

    AssertJUnit.assertNotNull(resourceSchema);

    System.out.println(resourceSchema.debugDump());

    Document xsdSchema = resourceSchema.serializeToXsd();

    System.out.println(
        "-------------------------------------------------------------------------------------");
    System.out.println(DOMUtil.printDom(xsdSchema));
    System.out.println(
        "-------------------------------------------------------------------------------------");

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "AccountObjectClass"));
    AssertJUnit.assertNotNull(accountDefinition);

    AssertJUnit.assertFalse(
        "No identifiers for account object class ", accountDefinition.getIdentifiers().isEmpty());

    PrismPropertyDefinition uidDefinition =
        accountDefinition.findPropertyDefinition(ConnectorFactoryIcfImpl.ICFS_UID);
    AssertJUnit.assertNotNull(uidDefinition);

    for (Definition def : resourceSchema.getDefinitions()) {
      if (def instanceof ResourceAttributeContainerDefinition) {
        ResourceAttributeContainerDefinition rdef = (ResourceAttributeContainerDefinition) def;
        assertNotEmpty("No type name in object class", rdef.getTypeName());
        assertNotEmpty(
            "No native object class for " + rdef.getTypeName(), rdef.getNativeObjectClass());

        // This is maybe not that important, but just for a sake of
        // completeness
        assertNotEmpty("No name for " + rdef.getTypeName(), rdef.getName());
      }
    }
  }
Esempio n. 10
0
  @Test
  public void test200FetchChanges() throws Exception {
    final String TEST_NAME = "test200FetchChanges";
    TestUtil.displayTestTile(this, TEST_NAME);

    OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME);
    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME);
    PrismProperty<Integer> lastToken = cc.fetchCurrentToken(accountDefinition, result);

    System.out.println("Property:");
    System.out.println(SchemaDebugUtil.prettyPrint(lastToken));
    System.out.println("token " + lastToken.toString());

    assertNotNull("No last token", lastToken);
    assertNotNull("No last token value", lastToken.getRealValue());

    List<Change<ShadowType>> changes = cc.fetchChanges(accountDefinition, lastToken, null, result);
    AssertJUnit.assertEquals(0, changes.size());
  }
Esempio n. 11
0
  private ResourceAttributeContainer createResourceObject(String dn, String sn, String cn)
      throws SchemaException {
    // Account type is hardcoded now
    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME));
    // Determine identifier from the schema
    ResourceAttributeContainer resourceObject =
        accountDefinition.instantiate(ShadowType.F_ATTRIBUTES);

    ResourceAttributeDefinition road =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "sn"));
    ResourceAttribute roa = road.instantiate();
    roa.setValue(new PrismPropertyValue(sn));
    resourceObject.add(roa);

    road =
        accountDefinition.findAttributeDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "cn"));
    roa = road.instantiate();
    roa.setValue(new PrismPropertyValue(cn));
    resourceObject.add(roa);

    road =
        accountDefinition.findAttributeDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME));
    roa = road.instantiate();
    roa.setValue(new PrismPropertyValue(dn));
    resourceObject.add(roa);

    return resourceObject;
  }
Esempio n. 12
0
  @Test
  public void testResourceSchemaSanity() throws Exception {
    TestUtil.displayTestTile("testResourceSchemaSanity");

    QName objectClassQname =
        new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "AccountObjectClass");
    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(objectClassQname);
    assertNotNull("No object class definition " + objectClassQname, accountDefinition);
    assertEquals(
        "Object class " + objectClassQname + " is not account",
        ShadowKindType.ACCOUNT,
        accountDefinition.getKind());
    assertTrue(
        "Object class " + objectClassQname + " is not default account",
        accountDefinition.isDefaultInAKind());
    assertFalse("Object class " + objectClassQname + " is empty", accountDefinition.isEmpty());
    assertFalse("Object class " + objectClassQname + " is empty", accountDefinition.isIgnored());

    Collection<? extends ResourceAttributeDefinition> identifiers =
        accountDefinition.getIdentifiers();
    assertNotNull("Null identifiers for " + objectClassQname, identifiers);
    assertFalse("Empty identifiers for " + objectClassQname, identifiers.isEmpty());
    // TODO

    ResourceAttributeDefinition attributeDefinition =
        accountDefinition.findAttributeDefinition(ConnectorFactoryIcfImpl.ICFS_UID);
    assertNotNull(
        "No definition for attribute " + ConnectorFactoryIcfImpl.ICFS_UID, attributeDefinition);
    assertTrue(
        "Attribute " + ConnectorFactoryIcfImpl.ICFS_UID + " in not an identifier",
        attributeDefinition.isIdentifier(accountDefinition));
    assertTrue(
        "Attribute " + ConnectorFactoryIcfImpl.ICFS_UID + " in not in identifiers list",
        identifiers.contains(attributeDefinition));
  }
Esempio n. 13
0
  @Test
  public void test020ResourceSchemaSanity() throws Exception {
    final String TEST_NAME = "test020ResourceSchemaSanity";
    TestUtil.displayTestTile(TEST_NAME);

    QName objectClassQname =
        new QName(
            ResourceTypeUtil.getResourceNamespace(resourceType),
            ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME);
    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(objectClassQname);
    assertNotNull("No object class definition " + objectClassQname, accountDefinition);
    //		assertEquals("Object class " + objectClassQname + " is not account", ShadowKindType.ACCOUNT,
    // accountDefinition.getKind());
    //		assertTrue("Object class " + objectClassQname + " is not default account",
    // accountDefinition.isDefaultInAKind());
    assertFalse("Object class " + objectClassQname + " is empty", accountDefinition.isEmpty());
    assertFalse("Object class " + objectClassQname + " is empty", accountDefinition.isIgnored());

    Collection<? extends ResourceAttributeDefinition> identifiers =
        accountDefinition.getIdentifiers();
    assertNotNull("Null identifiers for " + objectClassQname, identifiers);
    assertFalse("Empty identifiers for " + objectClassQname, identifiers.isEmpty());

    ResourceAttributeDefinition<String> idPrimaryDef =
        accountDefinition.findAttributeDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME));
    assertNotNull(
        "No definition for attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME,
        idPrimaryDef);
    assertTrue(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME
            + " in not an identifier",
        idPrimaryDef.isIdentifier(accountDefinition));
    assertTrue(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME
            + " in not in identifiers list",
        identifiers.contains(idPrimaryDef));
    assertEquals(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME
            + " has wrong native name",
        ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME,
        idPrimaryDef.getNativeAttributeName());
    assertEquals(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME
            + " has wrong framework name",
        Uid.NAME,
        idPrimaryDef.getFrameworkAttributeName());

    ResourceAttributeDefinition<String> idSecondaryDef =
        accountDefinition.findAttributeDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME));
    assertNotNull(
        "No definition for attribute " + ConnectorFactoryIcfImpl.ICFS_NAME, idSecondaryDef);
    assertTrue(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME
            + " in not secondary identifier",
        idSecondaryDef.isSecondaryIdentifier(accountDefinition));
    assertFalse(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME
            + " in in identifiers list and it should NOT be",
        identifiers.contains(idSecondaryDef));
    assertTrue(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME
            + " in not in secomdary identifiers list",
        accountDefinition.getSecondaryIdentifiers().contains(idSecondaryDef));
    assertEquals(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME
            + " has wrong native name",
        ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME,
        idSecondaryDef.getNativeAttributeName());
    assertEquals(
        "Attribute "
            + ProvisioningTestUtil.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME
            + " has wrong framework name",
        Name.NAME,
        idSecondaryDef.getFrameworkAttributeName());

    assertEquals("Unexpected identifiers: " + identifiers, 1, identifiers.size());
    assertEquals(
        "Unexpected secondary identifiers: " + accountDefinition.getSecondaryIdentifiers(),
        1,
        accountDefinition.getSecondaryIdentifiers().size());
  }