Search in sources :

Example 1 with AbortMissionCommandOps

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);
}
Also used : LaunchTelemetryConverter(com.github.nagyesta.abortmission.core.telemetry.converter.LaunchTelemetryConverter) InOrder(org.mockito.InOrder) AbortMissionCommandOps(com.github.nagyesta.abortmission.core.AbortMissionCommandOps) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with AbortMissionCommandOps

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);
}
Also used : LaunchTelemetryConverter(com.github.nagyesta.abortmission.core.telemetry.converter.LaunchTelemetryConverter) InOrder(org.mockito.InOrder) AbortMissionCommandOps(com.github.nagyesta.abortmission.core.AbortMissionCommandOps) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with AbortMissionCommandOps

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());
}
Also used : ClassTelemetry(com.github.nagyesta.abortmission.core.telemetry.stats.ClassTelemetry) MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) AbstractMissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.impl.AbstractMissionHealthCheckEvaluator) AbortMissionCommandOps(com.github.nagyesta.abortmission.core.AbortMissionCommandOps) AbstractTelemetryTest(com.github.nagyesta.abortmission.core.telemetry.stats.AbstractTelemetryTest) Test(org.junit.jupiter.api.Test)

Example 4 with AbortMissionCommandOps

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());
}
Also used : Consumer(java.util.function.Consumer) AbortMissionCommandOps(com.github.nagyesta.abortmission.core.AbortMissionCommandOps) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with AbortMissionCommandOps

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);
}
Also used : MissionOutline(com.github.nagyesta.abortmission.core.outline.MissionOutline) MissionHealthCheckEvaluator(com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator) java.util(java.util) AbortMissionCommandOps(com.github.nagyesta.abortmission.core.AbortMissionCommandOps) Logger(org.slf4j.Logger) Result(io.cucumber.plugin.event.Result) Scenario(io.cucumber.java.Scenario) LoggerFactory(org.slf4j.LoggerFactory) Status(io.cucumber.plugin.event.Status) ScenarioUriMatcher(com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioUriMatcher) Field(java.lang.reflect.Field) StageTimeStopwatch(com.github.nagyesta.abortmission.core.telemetry.watch.StageTimeStopwatch) Consumer(java.util.function.Consumer) MissionControl(com.github.nagyesta.abortmission.core.MissionControl) MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) ScenarioNameMatcher(com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioNameMatcher) AbortMissionCommandOps(com.github.nagyesta.abortmission.core.AbortMissionCommandOps)

Aggregations

AbortMissionCommandOps (com.github.nagyesta.abortmission.core.AbortMissionCommandOps)5 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MissionHealthCheckEvaluator (com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator)2 LaunchTelemetryConverter (com.github.nagyesta.abortmission.core.telemetry.converter.LaunchTelemetryConverter)2 Consumer (java.util.function.Consumer)2 InOrder (org.mockito.InOrder)2 ScenarioNameMatcher (com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioNameMatcher)1 ScenarioUriMatcher (com.github.nagyesta.abortmission.booster.cucumber.matcher.ScenarioUriMatcher)1 MissionControl (com.github.nagyesta.abortmission.core.MissionControl)1 AbstractMissionHealthCheckEvaluator (com.github.nagyesta.abortmission.core.healthcheck.impl.AbstractMissionHealthCheckEvaluator)1 MissionHealthCheckMatcher (com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher)1 MissionOutline (com.github.nagyesta.abortmission.core.outline.MissionOutline)1 AbstractTelemetryTest (com.github.nagyesta.abortmission.core.telemetry.stats.AbstractTelemetryTest)1 ClassTelemetry (com.github.nagyesta.abortmission.core.telemetry.stats.ClassTelemetry)1 StageTimeStopwatch (com.github.nagyesta.abortmission.core.telemetry.watch.StageTimeStopwatch)1 Scenario (io.cucumber.java.Scenario)1 Result (io.cucumber.plugin.event.Result)1 Status (io.cucumber.plugin.event.Status)1 Field (java.lang.reflect.Field)1