use of com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory in project bender by Nextdoor.
the class OperationProcessorTest method testNullPayloadFiltering.
@Test
public void testNullPayloadFiltering() throws JsonSyntaxException, UnsupportedEncodingException, IOException, OperationException {
/*
* Setup mocks for test
*/
DummyOperation op = spy(new DummyOperation());
InternalEvent retEvent = new InternalEvent("foo", null, 1);
retEvent.setEventObj(new DummyDeserializerHelper.DummyDeserializedEvent(null));
when(op.perform(any(InternalEvent.class))).thenReturn(retEvent);
DummyOperationFactory operationFactory = new DummyOperationFactory(op);
OperationProcessor processor = new OperationProcessor(operationFactory);
/*
* Do call
*/
Stream<InternalEvent> stream = processor.perform(Stream.of(new InternalEvent("foo", null, 1)));
List<InternalEvent> output = stream.collect(Collectors.toList());
/*
* Verify nothing came out
*/
assertEquals(0, output.size());
}
use of com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory in project bender by Nextdoor.
the class OperationProcessorTest method testNullDeserializedEventFiltering.
@Test
public void testNullDeserializedEventFiltering() throws JsonSyntaxException, UnsupportedEncodingException, IOException, OperationException {
/*
* Setup mocks for test
*/
DummyOperation op = spy(new DummyOperation());
InternalEvent retEvent = new InternalEvent("foo", null, 1);
retEvent.setEventObj(null);
when(op.perform(any(InternalEvent.class))).thenReturn(retEvent);
DummyOperationFactory operationFactory = new DummyOperationFactory(op);
OperationProcessor processor = new OperationProcessor(operationFactory);
/*
* Do call
*/
Stream<InternalEvent> stream = processor.perform(Stream.of(new InternalEvent("foo", null, 1)));
List<InternalEvent> output = stream.collect(Collectors.toList());
/*
* Verify nothing came out
*/
assertEquals(0, output.size());
}
use of com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory in project bender by Nextdoor.
the class OperationProcessorTest method testNullInternalEventFiltering.
@Test
public void testNullInternalEventFiltering() throws JsonSyntaxException, UnsupportedEncodingException, IOException, OperationException {
/*
* Setup mocks for test
*/
DummyOperation op = spy(new DummyOperation());
when(op.perform(any(InternalEvent.class))).thenReturn(null);
DummyOperationFactory operationFactory = new DummyOperationFactory(op);
OperationProcessor processor = new OperationProcessor(operationFactory);
/*
* Do call
*/
Stream<InternalEvent> stream = processor.perform(Stream.of(new InternalEvent("foo", null, 1)));
List<InternalEvent> output = stream.collect(Collectors.toList());
/*
* Verify nothing came out
*/
assertEquals(0, output.size());
}
use of com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory in project bender by Nextdoor.
the class OperationProcessorTest method testStatsLoggingOnError.
@Test
public void testStatsLoggingOnError() {
DummyOperation operation = mock(DummyOperation.class);
DummyOperationFactory mutatorFactory = new DummyOperationFactory(operation);
OperationProcessor processor = new OperationProcessor(mutatorFactory);
InternalEvent ievent = new InternalEvent("a", null, 1);
doThrow(new OperationException("Expceted")).when(operation).perform(ievent);
/*
* Mock the Stat object
*/
Stat runtimeStat = mock(Stat.class);
Stat successStat = mock(Stat.class);
Stat errorStat = mock(Stat.class);
processor.setRuntimeStat(runtimeStat);
processor.setSuccessCountStat(successStat);
processor.setErrorCountStat(errorStat);
Stream<InternalEvent> stream = processor.perform(Stream.of(ievent));
List<InternalEvent> output = stream.collect(Collectors.toList());
/*
* Verify start, stop are called, increment error count and never increment success count.
*/
verify(runtimeStat, times(1)).start();
verify(runtimeStat, times(1)).stop();
verify(successStat, never()).increment();
verify(errorStat, times(1)).increment();
/*
* Verify contents of output stream
*/
assertEquals(0, output.size());
}
use of com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory in project bender by Nextdoor.
the class OperationProcessorTest method testStatsLogging.
@Test
public void testStatsLogging() throws JsonSyntaxException, UnsupportedEncodingException, IOException, OperationException {
DummyOperationFactory mutatorFactory = new DummyOperationFactory();
OperationProcessor processor = new OperationProcessor(mutatorFactory);
/*
* Mock the Stat object
*/
Stat runtimeStat = mock(Stat.class);
Stat successStat = mock(Stat.class);
Stat errorStat = mock(Stat.class);
processor.setRuntimeStat(runtimeStat);
processor.setSuccessCountStat(successStat);
processor.setErrorCountStat(errorStat);
InternalEvent ievent = new InternalEvent("foo", null, 1);
ievent.setEventObj(new DummyDeserializerHelper.DummyDeserializedEvent("test"));
Stream<InternalEvent> stream = processor.perform(Stream.of(ievent));
List<InternalEvent> output = stream.collect(Collectors.toList());
/*
* Verify start, stop, increment success count, and never increment error count.
*/
verify(runtimeStat, times(1)).start();
verify(runtimeStat, times(1)).stop();
verify(successStat, times(1)).increment();
verify(errorStat, never()).increment();
/*
* Verify contents of output stream
*/
assertEquals(1, output.size());
}
Aggregations