use of com.github.nagyesta.abortmission.core.AbortMissionCommandOps in project abort-mission by nagyesta.
the class DefaultLaunchTelemetryDataSourceTest method testFetchClassStatisticsShouldCallConverterWhenConstructedWithValidData.
@Test
void testFetchClassStatisticsShouldCallConverterWhenConstructedWithValidData() {
// given
final LaunchTelemetryConverter converter = mock(LaunchTelemetryConverter.class);
final Map<String, AbortMissionCommandOps> nameSpaces = spy(new HashMap<>());
final SortedMap<String, ClassTelemetry> classStats = spy(new TreeMap<>());
when(converter.processClassStatistics(same(nameSpaces))).thenReturn(classStats);
final DefaultLaunchTelemetryDataSource underTest = new DefaultLaunchTelemetryDataSource(converter, nameSpaces);
// when
final SortedMap<String, ClassTelemetry> actual = underTest.fetchClassStatistics();
// then
Assertions.assertNotNull(actual);
Assertions.assertSame(classStats, actual);
final InOrder inOrder = inOrder(converter, classStats);
inOrder.verify(converter).processClassStatistics(same(nameSpaces));
inOrder.verifyNoMoreInteractions();
verifyNoInteractions(nameSpaces);
}
use of com.github.nagyesta.abortmission.core.AbortMissionCommandOps in project abort-mission by nagyesta.
the class DefaultLaunchTelemetryTest method testConstructorShouldCallFetchClassStatisticsWhenCalledWithValidData.
@Test
void testConstructorShouldCallFetchClassStatisticsWhenCalledWithValidData() {
// given
final LaunchTelemetryConverter converter = mock(LaunchTelemetryConverter.class);
final Map<String, AbortMissionCommandOps> nameSpaces = spy(new HashMap<>());
final SortedMap<String, ClassTelemetry> classStats = spy(new TreeMap<>());
when(converter.processClassStatistics(same(nameSpaces))).thenReturn(classStats);
final LaunchTelemetryDataSource dataSource = mock(LaunchTelemetryDataSource.class);
when(dataSource.fetchClassStatistics()).thenReturn(classStats);
// when
final DefaultLaunchTelemetry actual = new DefaultLaunchTelemetry(dataSource);
// then
Assertions.assertNotNull(actual);
Assertions.assertSame(classStats, actual.getClasses());
Assertions.assertNotNull(actual.getStats());
final InOrder inOrder = inOrder(dataSource, classStats);
inOrder.verify(dataSource).fetchClassStatistics();
// noinspection ResultOfMethodCallIgnored
inOrder.verify(classStats, times(2)).values();
inOrder.verifyNoMoreInteractions();
verifyNoInteractions(nameSpaces);
}
use of com.github.nagyesta.abortmission.core.AbortMissionCommandOps in project abort-mission by nagyesta.
the class LaunchTelemetryConverterTest method testProcessClassStatisticsShould.
@Test
void testProcessClassStatisticsShould() {
// given
final Map<String, AbortMissionCommandOps> nameSpaces = new HashMap<>();
final LaunchTelemetryConverter underTest = spy(new LaunchTelemetryConverter());
final Stream<MissionHealthCheckEvaluator> stream = Stream.<MissionHealthCheckEvaluator>builder().add(new SimpleEvaluator(MATCHER_1, Arrays.asList(FIRST_FAIL_1_10, FIRST_PASS_1_10), Collections.emptyList())).add(new SimpleEvaluator(MATCHER_2, Arrays.asList(FIRST_FAIL_1_10, FIRST_PASS_1_10), Collections.singletonList(SECOND_PASS_2_20))).add(new SimpleEvaluator(MATCHER_3, Collections.emptyList(), Arrays.asList(THIRD_ABORT_5_5, THIRD_PASS_5_5, THIRD_SUPPRESS_5_5))).build();
doReturn(stream).when(underTest).missionHealthCheckEvaluatorStream(same(nameSpaces));
// when
final SortedMap<String, ClassTelemetry> actual = underTest.processClassStatistics(nameSpaces);
// then
Assertions.assertNotNull(actual);
verify(underTest).missionHealthCheckEvaluatorStream(same(nameSpaces));
Assertions.assertIterableEquals(Collections.singleton(CLASS), actual.keySet());
final ClassTelemetry classTelemetry = actual.get(CLASS);
Assertions.assertEquals(CLASS, classTelemetry.getClassName());
Assertions.assertIterableEquals(Arrays.asList(MATCHER_1, MATCHER_2), classTelemetry.getCountdown().getMatcherNames());
Assertions.assertIterableEquals(Arrays.asList(MATCHER_2, MATCHER_3), classTelemetry.getLaunches().get(METHOD).getMatcherNames());
}
use of com.github.nagyesta.abortmission.core.AbortMissionCommandOps in project abort-mission by nagyesta.
the class MissionOutlineTest method testInitialBriefingShouldAvoidRegisteringTwiceWhenCalledWithTheSameName.
@ParameterizedTest
@ValueSource(strings = { EMPTY, NAME })
void testInitialBriefingShouldAvoidRegisteringTwiceWhenCalledWithTheSameName(final String name) {
// given
final MissionOutline firstOutline = new MissionOutline() {
@Override
protected Map<String, Consumer<AbortMissionCommandOps>> defineOutline() {
return Collections.singletonMap(name, ops -> ops.registerHealthCheck(EVALUATOR));
}
};
final MissionOutline secondOutline = new MissionOutline() {
@Override
protected Map<String, Consumer<AbortMissionCommandOps>> defineOutline() {
return Collections.singletonMap(name, ops -> Assertions.fail("Should have never called."));
}
};
// when
firstOutline.initialBriefing();
secondOutline.initialBriefing();
// then
final AbortMissionCommandOps actual;
if (EMPTY.equals(name)) {
actual = MissionControl.commandOps();
Assertions.assertNotNull(actual);
} else {
actual = MissionControl.commandOps(name);
Assertions.assertNotNull(actual);
}
Assertions.assertIterableEquals(Collections.singleton(EVALUATOR), actual.allEvaluators());
}
use of com.github.nagyesta.abortmission.core.AbortMissionCommandOps in project abort-mission by nagyesta.
the class LaunchAbortHook method findEvaluators.
private Set<MissionHealthCheckEvaluator> findEvaluators(final Scenario scenario) {
final Optional<String> context = scenario.getSourceTagNames().stream().filter(tag -> tag.startsWith("@AbortMission_Context_")).map(tag -> tag.replaceFirst("^@AbortMission_Context_", "")).findFirst();
final AbortMissionCommandOps commandOps = context.map(MissionControl::commandOps).orElse(MissionControl.commandOps());
return Objects.requireNonNull(commandOps, "Mission context is not found: " + context.orElse("'- DEFAULT - '")).matchingEvaluators(scenario);
}
Aggregations