2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.common.validation;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26 import static org.mockito.Mockito.mock;
28 import java.util.Arrays;
29 import java.util.List;
31 import org.camunda.bpm.engine.delegate.BpmnError;
32 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.rules.ExpectedException;
36 import org.junit.runner.RunWith;
37 import org.onap.so.bpmn.common.BuildingBlockExecution;
38 import org.onap.so.bpmn.common.DelegateExecutionImpl;
39 import org.onap.so.bpmn.core.WorkflowException;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.test.context.ContextConfiguration;
42 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
44 @RunWith(SpringJUnit4ClassRunner.class)
45 @ContextConfiguration(classes = {ValidationConfig.class})
46 public class BuildingBlockValidatorRunnerTest {
49 public ExpectedException thrown= ExpectedException.none();
52 private BuildingBlockValidatorRunner runner;
55 public void filterValidatorTest() {
57 MyPreValidatorOne one = new MyPreValidatorOne();
58 MyPreValidatorTwo two = new MyPreValidatorTwo();
59 MyPreValidatorThree three = new MyPreValidatorThree();
60 List<BuildingBlockValidator> validators = Arrays.asList(one, two, three);
62 List<BuildingBlockValidator> result = runner.filterValidators(validators, "test");
64 List<BuildingBlockValidator> expected = Arrays.asList(two, one);
66 assertEquals(expected, result);
70 public void testValidate() {
72 BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
73 execution.setVariable("testProcessKey", "1234");
75 runner.preValidate("test", execution);
76 fail("exception not thrown");
77 } catch (BpmnError e) {
78 WorkflowException workflowException = execution.getVariable("WorkflowException");
79 assertEquals("Failed Validations:\norg.onap.so.bpmn.common.validation.MyPreValidatorTwo\norg.onap.so.bpmn.common.validation.MyPreValidatorOne", workflowException.getErrorMessage());
81 runner.preValidate("test2", mock(BuildingBlockExecution.class));
85 public void testEmptyList() {
86 boolean result = runner.preValidate("test3", mock(BuildingBlockExecution.class));