How do you test an ICF based connector using Connector Facade Standalone?
Posted
by Shashidhar Malyala
on Oracle Blogs
See other posts from Oracle Blogs
or by Shashidhar Malyala
Published on Mon, 19 Nov 2012 12:54:34 +0000
Indexed on
2012/11/19
17:08 UTC
Read the original article
Hit count: 293
/Oracle
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);
}
}
© Oracle Blogs or respective owner