/** * Simple call to connector test() method. * * @throws Exception */ @Test public void test310TestConnectionNegative() throws Exception { final String TEST_NAME = "test310TestConnectionNegative"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(TEST_NAME); ConnectorInstance badConnector = factory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(badResourceType), "bad resource", "bad resource description"); badConnector.configure(badResourceType.getConnectorConfiguration().asPrismContainerValue(), result); // WHEN badConnector.test(result); // THEN result.computeStatus("test failed"); display("Test result (FAILURE EXPECTED)", result); AssertJUnit.assertNotNull(result); OperationResult connectorConnectionResult = result.getSubresults().get(1); AssertJUnit.assertNotNull(connectorConnectionResult); System.out.println("Test \"connector connection\" result: " + connectorConnectionResult + " (FAILURE EXPECTED)"); AssertJUnit.assertTrue("Unexpected success of bad connector test", !connectorConnectionResult.isSuccess()); AssertJUnit.assertTrue(!result.isSuccess()); }
@Test public void test500FetchObject() throws Exception { final String TEST_NAME = "test500FetchObject"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN ResourceAttributeContainer resourceObject = createResourceObject( "uid=Teell,ou=People,dc=example,dc=com", "Teell William", "Teell"); OperationResult addResult = new OperationResult(this.getClass().getName() + "." + TEST_NAME); PrismObject<ShadowType> shadow = wrapInShadow(ShadowType.class, resourceObject); // Add a testing object cc.addObject(shadow, null, null, addResult); ObjectClassComplexTypeDefinition accountDefinition = resourceObject.getDefinition().getComplexTypeDefinition(); Collection<ResourceAttribute<?>> identifiers = resourceObject.getPrimaryIdentifiers(); // Determine object class from the schema ResourceObjectIdentification identification = new ResourceObjectIdentification(accountDefinition, identifiers, null); OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME); // WHEN PrismObject<ShadowType> ro = cc.fetchObject(identification, null, null, result); // THEN AssertJUnit.assertNotNull(ro); System.out.println("Fetched object " + ro); System.out.println("Result:"); System.out.println(result.debugDump()); }
@Test public void test100AddDeleteObject() throws Exception { final String TEST_NAME = "test100AddDeleteObject"; TestUtil.displayTestTitle(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 (SchemaConstants.ICFS_UID.equals(resourceAttribute.getElementName())) { uid = resourceAttribute.getValue(String.class).getValue(); System.out.println("uuuuid:" + uid); assertNotNull(uid); } } ObjectClassComplexTypeDefinition accountDefinition = resourceSchema.findObjectClassDefinition(OpenDJController.OBJECT_CLASS_INETORGPERSON_NAME); cc.deleteObject(accountDefinition, null, null, identifiers, null, result); ResourceObjectIdentification identification = ResourceObjectIdentification.createFromAttributes( accountDefinition, identifiers); PrismObject<ShadowType> resObj = null; try { resObj = cc.fetchObject(identification, null, null, result); Assert.fail(); } catch (ObjectNotFoundException ex) { AssertJUnit.assertNull(resObj); } }
@Test public void test100FetchEmptyChanges() throws Exception { final String TEST_NAME = "test100FetchEmptyChanges"; TestUtil.displayTestTitle(this, TEST_NAME); OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME); ObjectClassComplexTypeDefinition accountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT); // WHEN PrismProperty<Integer> lastToken = cc.fetchCurrentToken(accountDefinition, null, result); assertNotNull("No last sync token", lastToken); System.out.println("Property:"); System.out.println(lastToken.debugDump()); PrismPropertyDefinition<Integer> lastTokenDef = lastToken.getDefinition(); assertNotNull("No last sync token definition", lastTokenDef); assertEquals("Last sync token definition has wrong type", DOMUtil.XSD_INT, lastTokenDef.getTypeName()); assertTrue("Last sync token definition is NOT dynamic", lastTokenDef.isDynamic()); // WHEN List<Change> changes = cc.fetchChanges(accountDefinition, lastToken, null, null, result); AssertJUnit.assertEquals(0, changes.size()); }
@Test public void test110SearchNonBlocking() throws Exception { final String TEST_NAME = "test100SearchNonBlocking"; TestUtil.displayTestTitle(TEST_NAME); // GIVEN final ObjectClassComplexTypeDefinition accountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT); // Determine object class from the schema final List<PrismObject<ShadowType>> searchResults = new ArrayList<>(); ShadowResultHandler handler = new ShadowResultHandler() { @Override public boolean handle(PrismObject<ShadowType> shadow) { System.out.println("Search: found: " + shadow); checkUcfShadow(shadow, accountDefinition); searchResults.add(shadow); return true; } }; OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME); // WHEN cc.search(accountDefinition, null, handler, null, null, null, null, result); // THEN assertEquals("Unexpected number of search results", 1, searchResults.size()); ConnectorOperationalStatus opStat = cc.getOperationalStatus(); display("stats", opStat); assertEquals("Wrong pool active", (Integer)0, opStat.getPoolStatusNumActive()); assertEquals("Wrong pool active", (Integer)1, opStat.getPoolStatusNumIdle()); }
PrismContainerValue<ConnectorConfigurationType> connectorConfiguration = connectorSpec.getConnectorConfiguration().getValue(); connector.configure(connectorConfiguration, configResult); connector.initialize(previousResourceSchema, previousCapabilities, ResourceTypeUtil.isCaseIgnoreAttributeNames(connectorSpec.getResource().asObjectable()), configResult); connector.test(parentResult); InternalMonitor.recordCount(InternalCounters.CONNECTOR_CAPABILITIES_FETCH_COUNT); Collection<Object> retrievedCapabilities = connector.fetchCapabilities(capabilitiesResult);
@BeforeMethod public void initUcf() throws Exception { TestUtil.displayTestTitle("initUcf"); // Resource PrismObject<ResourceType> resource = PrismTestUtil.parseObject(RESOURCE_OPENDJ_FILE); resourceType = resource.asObjectable(); // Resource: Second copy for negative test cases PrismObject<ResourceType> badResource = PrismTestUtil.parseObject(RESOURCE_OPENDJ_BAD_FILE); badResourceType = badResource.asObjectable(); // Connector PrismObject<ConnectorType> connector = PrismTestUtil.parseObject(CONNECTOR_LDAP_FILE); connectorType = connector.asObjectable(); factory = connectorFactoryIcfImpl; connectorSchema = factory.generateConnectorConfigurationSchema(connectorType); AssertJUnit.assertNotNull("Cannot generate connector schema", connectorSchema); display("Connector schema", connectorSchema); cc = factory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(resourceType), "OpenDJ resource", "description of OpenDJ connector instance"); 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 test031ResourceSchemaAccountObjectClass() throws Exception { final String TEST_NAME = "test031ResourceSchemaAccountObjectClass"; TestUtil.displayTestTitle(TEST_NAME); OperationResult result = new OperationResult(TestUcfDummy.class + "." + TEST_NAME); cc = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(resourceType), "dummy", "description of dummy test connector instance"); assertNotNull("Failed to instantiate connector", cc); PrismContainerValue<ConnectorConfigurationType> configContainer = resourceType.getConnectorConfiguration().asPrismContainerValue(); display("Configuration container", configContainer); cc.configure(configContainer, result); List<QName> objectClassesToGenerate = new ArrayList<>(); QName accountObjectClass = new QName(resource.asObjectable().getNamespace(), "AccountObjectClass"); objectClassesToGenerate.add(accountObjectClass); // WHEN resourceSchema = cc.fetchResourceSchema(objectClassesToGenerate, result); // THEN display("Generated resource schema", resourceSchema); assertEquals("Unexpected number of definitions", 1, resourceSchema.getDefinitions().size()); assertEquals("Unexpected number of object class definitions", 1, resourceSchema.getObjectClassDefinitions().size()); display("RESOURCE SCHEMA DEFINITION" + resourceSchema.getDefinitions().iterator().next().getTypeName()); }
/** * Simple call to connector test() method. * * @throws Exception */ @Test public void test300TestConnection() throws Exception { final String TEST_NAME = "test300TestConnection"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(TEST_NAME); // WHEN cc.test(result); // THEN result.computeStatus("test failed"); AssertJUnit.assertNotNull(result); OperationResult connectorConnectionResult = result.getSubresults().get(0); AssertJUnit.assertNotNull(connectorConnectionResult); System.out.println("Test \"connector connection\" result: " + connectorConnectionResult); AssertJUnit.assertTrue(connectorConnectionResult.isSuccess()); AssertJUnit.assertTrue(result.isSuccess()); }
accountDefinition, identifiers); cc.modifyObject(identification, null, changes, null, null, result); PrismObject<ShadowType> shadow = cc.fetchObject(identification, null, null, result); ResourceAttributeContainer resObj = ShadowUtil.getAttributesContainer(shadow);
private ConnectorInstance createConfiguredConnectorInstance(ConnectorSpec connectorSpec, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException { ConnectorInstance connector = createConnectorInstance(connectorSpec, result); PrismContainerValue<ConnectorConfigurationType> connectorConfigurationVal = connectorSpec.getConnectorConfiguration() != null ? connectorSpec.getConnectorConfiguration().getValue() : null; if (connectorConfigurationVal == null) { SchemaException e = new SchemaException("No connector configuration in "+connectorSpec); result.recordFatalError(e); throw e; } try { connector.configure(connectorConfigurationVal, result); ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(connectorSpec.getResource(), prismContext); Collection<Object> capabilities = ResourceTypeUtil.getNativeCapabilitiesCollection(connectorSpec.getResource().asObjectable()); connector.initialize(resourceSchema, capabilities, ResourceTypeUtil.isCaseIgnoreAttributeNames(connectorSpec.getResource().asObjectable()), result); } catch (GenericFrameworkException e) { // Not expected. Transform to system exception result.recordFatalError("Generic provisioning framework error", e); throw new SystemException("Generic provisioning framework error: " + e.getMessage(), e); } catch (CommunicationException e) { result.recordFatalError(e); throw e; } catch (ConfigurationException e) { result.recordFatalError(e); throw e; } return connector; }
List<Change> changes = connector.fetchChanges(ctx.getObjectClassDefinition(), lastToken, attrsToReturn, ctx, parentResult); identification.validatePrimaryIdenfiers(); LOGGER.trace("Re-fetching object {} because of attrsToReturn", identification); currentShadow = connector.fetchObject(identification, shadowAttrsToReturn, ctx, parentResult);
cc.addObject(shadow, null, null, addResult); accountDefinition, identifiers); cc.modifyObject(identification, null, changes, null, null, result);
public List<ConnectorOperationalStatus> getConnectorOperationalStatus(PrismObject<ResourceType> resource, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException { List<ConnectorOperationalStatus> statuses = new ArrayList<>(); for (ConnectorSpec connectorSpec: getAllConnectorSpecs(resource)) { ConnectorInstance connectorInstance = connectorManager.getConfiguredConnectorInstance(connectorSpec, false, result); ConnectorOperationalStatus operationalStatus = connectorInstance.getOperationalStatus(); if (operationalStatus != null) { operationalStatus.setConnectorName(connectorSpec.getConnectorName()); statuses.add(operationalStatus); } } return statuses; }
cc.addObject(shadow, additionalOperations, null, addResult);
@Test public void test410Capabilities() throws Exception { final String TEST_NAME = "test410Capabilities"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN OperationResult result = new OperationResult(TEST_NAME); // WHEN Collection<Object> capabilities = cc.fetchCapabilities(result); // THEN result.computeStatus("getCapabilities failed"); TestUtil.assertSuccess("getCapabilities failed (result)", result); assertFalse("Empty capabilities returned", capabilities.isEmpty()); CredentialsCapabilityType capCred = CapabilityUtil.getCapability(capabilities, CredentialsCapabilityType.class); assertNotNull("password capability not present", capCred.getPassword()); PagedSearchCapabilityType capPage = CapabilityUtil.getCapability(capabilities, PagedSearchCapabilityType.class); assertNotNull("paged search capability not present", capPage); }
identification = resolvePrimaryIdentifiers(ctx, identification, parentResult); identification.validatePrimaryIdenfiers(); return connector.fetchObject(identification, attributesToReturn, ctx, parentResult); } catch (ObjectNotFoundException e) {
private ResourceSchema fetchResourceSchema(PrismObject<ResourceType> resource, Map<String,Collection<Object>> capabilityMap, Task task, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, ConfigurationException, ObjectNotFoundException, SchemaException { ConnectorSpec connectorSpec = selectConnectorSpec(resource, capabilityMap, SchemaCapabilityType.class); if (connectorSpec == null) { LOGGER.trace("No connector has schema capability, cannot fetch resource schema"); return null; } InternalMonitor.recordCount(InternalCounters.RESOURCE_SCHEMA_FETCH_COUNT); List<QName> generateObjectClasses = ResourceTypeUtil.getSchemaGenerationConstraints(resource); ConnectorInstance connectorInstance = connectorManager.getConfiguredConnectorInstance(connectorSpec, false, parentResult); LOGGER.trace("Trying to get schema from {}", connectorSpec); ResourceSchema resourceSchema = connectorInstance.fetchResourceSchema(generateObjectClasses, parentResult); if (ResourceTypeUtil.isValidateSchema(resource.asObjectable())) { ResourceTypeUtil.validateSchema(resourceSchema, resource); } return resourceSchema; }
@SuppressWarnings("rawtypes") public PrismProperty fetchCurrentToken(ProvisioningContext ctx, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, ExpressionEvaluationException { Validate.notNull(parentResult, "Operation result must not be null."); LOGGER.trace("Fetcing current sync token for {}", ctx); PrismProperty lastToken; ConnectorInstance connector = ctx.getConnector(LiveSyncCapabilityType.class, parentResult); try { lastToken = connector.fetchCurrentToken(ctx.getObjectClassDefinition(), ctx, parentResult); } catch (GenericFrameworkException e) { parentResult.recordFatalError("Generic error in the connector: " + e.getMessage(), e); throw new CommunicationException("Generic error in the connector: " + e.getMessage(), e); } catch (CommunicationException ex) { parentResult.recordFatalError( "Error communicating with the connector " + connector + ": " + ex.getMessage(), ex); throw new CommunicationException("Error communicating with the connector " + connector + ": " + ex.getMessage(), ex); } LOGGER.trace("Got last token: {}", SchemaDebugUtil.prettyPrint(lastToken)); computeResultStatus(parentResult); return lastToken; }
@Test public void test020CreateConfiguredConnector() throws Exception { final String TEST_NAME = "test020CreateConfiguredConnector"; TestUtil.displayTestTitle(TEST_NAME); cc = connectorFactory.createConnectorInstance(connectorType, ResourceTypeUtil.getResourceNamespace(resourceType), "dummy", "description of dummy test connector instance"); assertNotNull("Failed to instantiate connector", cc); OperationResult result = new OperationResult(TestUcfDummy.class.getName() + "." + TEST_NAME); PrismContainerValue<ConnectorConfigurationType> configContainer = resourceType.getConnectorConfiguration().asPrismContainerValue(); display("Configuration container", configContainer); // WHEN cc.configure(configContainer, result); // THEN result.computeStatus(); TestUtil.assertSuccess(result); }