/** * Factory method to create a new Tag. * * @param type * The type of the {@link Tag}. * @param input * The input object to be analyzed. * @param parent * The parent {@link Tag}. * @return A new Tag */ public static Tag tag(String type, Object input, Tag parent) { return new Tag(type, input, parent); }
@Test public void shouldProduceSingleTagWithSingleObjectValue() throws Exception { // prepare Mocks Tag rootTag = Tags.rootTag("Input"); Tag expectedResultTag = new Tag("T1", "oneResult", rootTag); when(dummy.action()).thenReturn("oneResult"); when(input.getRoot()).thenReturn(rootTag); // Create TestMethod ActionMethod action = new ActionMethod(RuleDummy.actionMethod(), "T1", Action.Quantity.SINGLE); // execute Collection<Tag> result = action.execute(context); // verify assertThat(result, hasSize(1)); assertThat(result, hasItem(expectedResultTag)); }
@Test public void shouldProduceSingleTagWithArrayValue() throws Exception { // prepare Mocks Tag rootTag = Tags.rootTag("Input"); Tag expectedResultTag = new Tag("T1", new String[] { "one", "two", "three" }, rootTag); when(dummy.action()).thenReturn(new String[] { "one", "two", "three" }); when(this.input.getRoot()).thenReturn(rootTag); // Create TestMethod ActionMethod action = new ActionMethod(RuleDummy.actionMethod(), "T1", Action.Quantity.SINGLE); // execute Collection<Tag> result = action.execute(context); // verify assertThat(result, hasSize(1)); assertThat(result, containsInAnyOrder(expectedResultTag)); }
@Test(expectedExceptions = RuntimeException.class) public void collectProblemInstancesWithRuntimeExceptionProblemContext() { CauseStructure causeStructure = new CauseStructure(CauseType.SINGLE, SourceType.TIMERDATA); AggregatedDiagnosisData aggregatedInvocationSequenceData = null; aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, secondChildSequence, Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, "Test", tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, aggregatedInvocationSequenceData, tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, causeStructure, tagThree); tagMap.put("D", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(0)); }
@Test(expectedExceptions = RuntimeException.class) public void collectProblemInstancesWithRuntimeExceptionCauseStructure() { AggregatedDiagnosisData aggregatedInvocationSequenceData = null; aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, secondChildSequence, Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, new CauseCluster(secondChildSequence), tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, aggregatedInvocationSequenceData, tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, "Test", tagThree); tagMap.put("D", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(0)); }
@Test(expectedExceptions = RuntimeException.class) public void collectProblemInstancesWithRuntimeExceptionGlobalContext() { CauseStructure causeStructure = new CauseStructure(CauseType.SINGLE, SourceType.TIMERDATA); AggregatedDiagnosisData aggregatedInvocationSequenceData = null; aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, "Test", Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, new CauseCluster(secondChildSequence), tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, aggregatedInvocationSequenceData, tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, causeStructure, tagThree); tagMap.put("D", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(0)); }
@Test public void collectProblemInstances() { CauseStructure causeStructure = new CauseStructure(CauseType.SINGLE, SourceType.TIMERDATA); AggregatedDiagnosisData aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, secondChildSequence, Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, new CauseCluster(secondChildSequence), tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, aggregatedInvocationSequenceData, tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, causeStructure, tagThree); tagMap.put("Test", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(1)); }
@Test(expectedExceptions = RuntimeException.class) public void collectProblemInstancesWithRuntimeExceptionRootCause() { CauseStructure causeStructure = new CauseStructure(CauseType.SINGLE, SourceType.TIMERDATA); AggregatedDiagnosisData aggregatedInvocationSequenceData = null; aggregatedInvocationSequenceData = DiagnosisDataAggregator.getInstance().getAggregatedDiagnosisData(secondChildSequence); DiagnosisDataAggregator.getInstance().aggregate(aggregatedInvocationSequenceData, secondChildSequence); Multimap<String, Tag> tagMap = ArrayListMultimap.create(); Tag tagOne = new Tag(RuleConstants.DIAGNOSIS_TAG_GLOBAL_CONTEXT, secondChildSequence, Tags.rootTag(secondChildSequence)); Tag tagTwo = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CONTEXT, new CauseCluster(secondChildSequence), tagOne); Tag tagThree = new Tag(RuleConstants.DIAGNOSIS_TAG_PROBLEM_CAUSE, "Test", tagTwo); Tag tagFour = new Tag(RuleConstants.DIAGNOSIS_TAG_CAUSE_STRUCTURE, causeStructure, tagThree); tagMap.put("D", tagFour); when(sessionContext.getInput()).thenReturn(secondChildSequence); when(sessionContext.getStorage()).thenReturn(storage); when(storage.mapTags(TagState.LEAF)).thenReturn(tagMap); ProblemOccurrenceResultCollector problemInstanceResultCollector = new ProblemOccurrenceResultCollector(); List<ProblemOccurrence> problemOccurrence = problemInstanceResultCollector.collect(sessionContext); assertThat(problemOccurrence, hasSize(0)); }