Springboot 2.0 upgrade
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / onap / so / bpmn / common / validation / BuildingBlockValidatorRunnerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.common.validation;
22
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;
27
28 import java.util.Arrays;
29 import java.util.List;
30
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;
43
44 @RunWith(SpringJUnit4ClassRunner.class)
45 @ContextConfiguration(classes = {ValidationConfig.class})
46 public class BuildingBlockValidatorRunnerTest {
47
48         @Rule
49     public ExpectedException thrown= ExpectedException.none();
50         
51         @Autowired
52         private BuildingBlockValidatorRunner runner;
53         
54         @Test
55         public void filterValidatorTest() {
56                 
57                 MyPreValidatorOne one = new MyPreValidatorOne();
58                 MyPreValidatorTwo two = new MyPreValidatorTwo();
59                 MyPreValidatorThree three = new MyPreValidatorThree();
60                 List<BuildingBlockValidator> validators = Arrays.asList(one, two, three);
61
62                 List<BuildingBlockValidator> result = runner.filterValidators(validators, "test");
63
64                 List<BuildingBlockValidator> expected = Arrays.asList(two, one);
65                 
66                 assertEquals(expected, result);
67         }
68         
69         @Test
70         public void testValidate() {
71                 
72                 BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
73                 execution.setVariable("testProcessKey", "1234");
74                 try {
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());
80                 }
81                 runner.preValidate("test2", mock(BuildingBlockExecution.class));
82         }
83         
84         @Test
85         public void testEmptyList() {
86                 boolean result = runner.preValidate("test3", mock(BuildingBlockExecution.class));
87                 
88                 assertTrue(result);
89         }
90 }