Testing Components

It is important to write focused and concise unit tests for your custom components. Attivio provides a number of testing utilities and mock implementations to make writing good unit tests simple. This archetype generation referenced by the README page provides examples of the techniques described here.

Create the component

MyComponent component = new MyComponent();

Configure your component

// some example properties
component.setRate(20.3);
component.setLabel("label");

Optionally "start" your component

If your component uses any of the lifecycle or miscellaneous mix-ins, there is a test utility that will call them and set them up with appropriate mock implementations as needed:

SdkTestUtils.startTransformer(component);

Create a sample document to use in your test

AttivioDocument doc = new AttivioDocument("doc1");
doc.setField("text", "some text");
doc.setField("cost", 2800.23);

Process the document with your component

SdkTestUtils.processDocument(doc, component);

Assert conditions on the document

Assert.assertTrue(doc.containsField("newField"));

Last updated