Monday Nov 19, 2012

How do you test an ICF based connector using Connector Facade Standalone?

The following code helps in writing a standalone java program to test an ICF based connector. The sample code in this example takes into account an ICF based flatfile connector. It is possible to test various operations like create, update, delete, search etc... It is also possible to set values to the connector configuration parameters, add/remove attributes and their values.

public class FlatFile {

private static final java.lang.String BUNDLE_NAME = "<PACKAGE_NAME>";

//Ex: org.info.icf.flatfile

private static final java.lang.String BUNDLE_VERSION = "1.0.0";

private static final java.lang.String CONNECTOR_NAME = "org.info.icf.flatfile.FlatFileConnector";

// Name of connector class i.e. the class implemting the connector SPI operations

public ConnectorFacade getFacade() throws IOException {

ConnectorInfoManagerFactory fact = ConnectorInfoManagerFactory

.getInstance();

File bundleDirectory = new File("<BUNDLE_LOCATION>");

//Ex: /usr/oracle/connector_bundles/

URL url = IOUtil.makeURL(bundleDirectory,

"org.info.icf.flatfile-1.0.0.jar");

ConnectorInfoManager manager = fact.getLocalManager(url);

ConnectorKey key = new ConnectorKey(BUNDLE_NAME, BUNDLE_VERSION,

CONNECTOR_NAME);

ConnectorInfo info = manager.findConnectorInfo(key);

// From the ConnectorInfo object, create the default APIConfiguration.

APIConfiguration apiConfig = info.createDefaultAPIConfiguration();

// From the default APIConfiguration, retrieve the

// ConfigurationProperties.

ConfigurationProperties properties = apiConfig

.getConfigurationProperties();

// Print out what the properties are (not necessary)

List propertyNames = properties.getPropertyNames();

for (String propName : propertyNames) {

ConfigurationProperty prop = properties.getProperty(propName);

System.out.println("Property Name: " + prop.getName()

+ "\tProperty Type: " + prop.getType());

}

properties

.setPropertyValue("fileLocation",

"/usr/oracle/accounts.csv");

// Set all of the ConfigurationProperties needed by the connector.

// properties.setPropertyValue("host", FOOBAR_HOST);

// properties.setPropertyValue("adminName", FOOBAR_ADMIN);

// properties.setPropertyValue("adminPassword", FOOBAR_PASSWORD);

// properties.setPropertyValue("useSSL", false);

// Use the ConnectorFacadeFactory's newInstance() method to get a new

// connector.

ConnectorFacade connFacade = ConnectorFacadeFactory.getInstance()

.newInstance(apiConfig);

// Make sure we have set up the Configuration properly

connFacade.validate();

return connFacade;

}

public static void main(String[] args) throws IOException {

FlatFile file = new FlatFile();

ConnectorFacade cfac = file.getFacade();

Set attrSet = new HashSet();

attrSet.add(AttributeBuilder.build(Name.NAME, "Test01"));

attrSet.add(AttributeBuilder.build("FIRST_NAME", "Test_First"));

attrSet.add(AttributeBuilder.build("LAST_NAME", "Test_Last"));

//Create

Uid uid = cfac.create(ObjectClass.ACCOUNT, attrSet, null);

//Delete

Uid uidP = new Uid("Test01");

cfac.delete(ObjectClass.ACCOUNT, uidP, null);

}

}

About

OIM11gR2 Blog by NA-TAG Offshore IDAM team

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today