We can’t say this enough: tests are important for code quality. When writing a connector for
Bonita Open Solution, it’s useful to create such tests. And it’s easy to do that.
For each connector, create a classical jUnit TestCase. Then, two kind of tests may be done:
- test if the connector description is well written; and
- test the connector itself.
How to test the description of the connector “MyConnector”
The procedure is quite simple. We get the connector class, call the method
Connector.validateConnector() on it, and then get back the errors. If the connector is
valid, no error is encountered.
[cc lang=“java”]
public void testValidateConnector() throws BonitaException {
Class connectorClass = MyConnector.class;
List errors =
Connector.validateConnector(connectorClass);
assertTrue(errors.isEmpty());
}
[/cc]
How to test the connector itself
[cc lang=“java”]
public void testCreateSubfolder() throws Exception {
// Connector instanciation
MyConnector connector = new MyConnector();
// Call of each setter to initialize the connector
connector.setConnectorVar1(“MyValue”);
// Connector execution
connector.execute();
// Get of the return values
Boolean result connector.getBooleanOutputValue();
// Check of return values
assertTrue(“Should be true !”, result);
}
[/cc]