@Test(expectedExceptions = RuleDefinitionException.class) public void shouldFailDueToQuantityAndResultMismatch() throws RuleDefinitionException, RuleExecutionException { Tag rootTag = Tags.rootTag("Input"); when(dummy.action()).thenReturn("Fail"); when(this.input.getRoot()).thenReturn(rootTag); // Execute and fail. ActionMethod would expect array/collection as result from ruleImpl // implementation. // But receives "Fail" String new ActionMethod(RuleDummy.actionMethod(), "T2", Action.Quantity.MULTIPLE).execute(context); } }
@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 shouldProduceMultipleTagsFromCollection() throws Exception { // prepare Mocks Tag rootTag = Tags.rootTag("Input"); when(dummy.action2()).thenReturn(new String[] { "one", "two", "three" }); when(this.input.getRoot()).thenReturn(rootTag); // Create TestMethod ActionMethod action = new ActionMethod(RuleDummy.action2Method(), "T2", Action.Quantity.MULTIPLE); // execute Collection<Tag> result = action.execute(context); // verify Collection<Tag> tags = Tags.tags("T2", rootTag, "one", "two", "three"); assertThat(result, containsInAnyOrder(tags.toArray())); }
@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 public void shouldProduceMultipleTagsFromSingleArray() throws Exception { Tag rootTag = Tags.rootTag("Input"); // prepare Mocks when(dummy.action2()).thenReturn(new String[] { "one", "two", "three" }); when(this.input.getRoot()).thenReturn(rootTag); // Create TestMethod ActionMethod action = new ActionMethod(RuleDummy.action2Method(), "T2", Action.Quantity.MULTIPLE); // execute Collection<Tag> result = action.execute(context); // verify Collection<Tag> tags = Tags.tags("T2", rootTag, "one", "two", "three"); assertThat(result, containsInAnyOrder(tags.toArray())); }
if (CollectionUtils.isEmpty(conditionFailures)) { conditionFailures = Collections.emptyList(); tags = getActionMethod().execute(ctx); } else { tags = Collections.emptyList();