Step I Test preparation: Initialize the mocked Rainbow, the mocked PortFactory and the GaugeDescription clase
Here is an example for setting a probe test. This works for all probes. For different probe, you need to specify their different configuration yaml file. Your should put the input file of probe under the folder /resource/
private File tempInput = extractResource("/blackhole/probe-input.txt");
public BlackholeProbeTest() throws IOException {
}
@Before
public void setUp() {
RainbowMocker.injectRainbow();
IRainbowConnectionPortFactory mockedPortFactory = mockConnectionPortFactory();
stubPortFactoryForProbe(mockedPortFactory);
RainbowMocker.injectPortFactory(mockedPortFactory);
}-
Now your create the unit test
@Test public void goodPath() { }
-
You can new a probe you want to test using the tempInput read from a file
AbstractProbe probe = new BlackholeProbe("blackhole", 0L, new String[]{tempInput.toString()});
-
Start the Probe
probe.create(); probe.activate();
-
You can then compare the output with your ideal input
assertEquals("127.0.0.1, 1.0.0.1, 192.168.0.1", ProbeTestingUtil.waitForOutput());
public class BlackholeProbeTest {
private File tempInput = extractResource("/blackhole/probe-input.txt");
public BlackholeProbeTest() throws IOException {
}
@Before
public void setUp() {
RainbowMocker.injectRainbow();
IRainbowConnectionPortFactory mockedPortFactory = mockConnectionPortFactory();
stubPortFactoryForProbe(mockedPortFactory);
RainbowMocker.injectPortFactory(mockedPortFactory);
}
@Test
public void goodPath() {
AbstractProbe probe = new BlackholeProbe("blackhole", 0L, new String[]{tempInput.toString()});
probe.create();
probe.activate();
assertEquals("127.0.0.1, 1.0.0.1, 192.168.0.1", ProbeTestingUtil.waitForOutput());
}
}