Creating JUnit tests for new opearotrs
Hello,
I have the following simple TestOperator and MyIOObject.
I am trying to make JUnit tests for this operator.
TestOperator
1) Is there any simple way how to create my operator object (TestOperator)? To use a constructor I am missing the OperatorDescription and its constructor seem to be quite complicated (requires additional classes).
2) How can I set the IO object (io) to the input port: ce.getInputPorts().getPortByIndex(0)
Thank you very much for any advice.
radone
I have the following simple TestOperator and MyIOObject.
I am trying to make JUnit tests for this operator.
TestOperator
public class TestOperator extends Operator {IO object
// input port
protected InputPort inParam = getInputPorts().createPort("MyIOObject");
// output port
protected OutputPort outParam = getOutputPorts().createPort("MyIOObject");
public TestOperator(OperatorDescription description) {
super(description);
}
public void doWork() throws OperatorException {
// Read input
MyIOObject ioObj = inParam.getData();
// Increment value
ioObj.setValue( ioObj.getValue() + 1 );
// Deliver output
outParam.deliver(ioObj);
}
}
public class MyIOObject extends ResultObjectAdapter {My idea about JUnit test is such as follows:
private int value = -1;
public void setValue(int value) {
this.value = value;
}
public int getValue() {
return this.value;
}
}
public class CirclePixelsExtractorTest extends TestCase {Please, could anyone help me with:
@Test
public void testMeanValue() throws OperatorException {
// create operator
// ??????????????????????????????????????????????????????
// ???????????????????????? 1 ???????????????????????????
// ??????????????????????????????????????????????????????
OperatorDescription od = null; // (1) ??? HOW TO GET AN OperatorDescription ??;
TestOperator ce = new TestOperator (od);
// create IO input data
MyIOObject io = new MyIOObject();
io.setValue(5);
// provide IO data as an input
// ??????????????????????????????????????????????????????
// ???????????????????????? 2 ???????????????????????????
// ??????????????????????????????????????????????????????
ce.getInputPorts().getPortByIndex(0). // how to set Data ???;
// execute the operator
ce.doWork();
// read output
MyIOObject io2 = ce.getOutputPorts().getPortByIndex(0).getData();
int res = io2.getValue();
// validate
assertEquals(6, res);
}
}
1) Is there any simple way how to create my operator object (TestOperator)? To use a constructor I am missing the OperatorDescription and its constructor seem to be quite complicated (requires additional classes).
2) How can I set the IO object (io) to the input port: ce.getInputPorts().getPortByIndex(0)
Thank you very much for any advice.
radone