Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / onap / so / client / exception / ExceptionBuilderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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.client.exception;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import org.camunda.bpm.engine.delegate.BpmnError;
26 import org.junit.Test;
27 import org.onap.so.bpmn.mock.FileUtil;
28 import org.onap.so.BaseTest;
29
30 public class ExceptionBuilderTest extends BaseTest {
31
32     private static final String RESOURCE_PATH = "__files/";
33     private static final String VALID_ERROR_MESSAGE = "{test error message}";
34
35
36     @Test
37     public void buildAndThrowWorkflowExceptionTest() {
38         try {
39             ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
40             exceptionBuilder.buildAndThrowWorkflowException(execution, 7000,
41                     new NullPointerException(VALID_ERROR_MESSAGE));
42         } catch (BpmnError bpmnException) {
43             assertEquals("MSOWorkflowException", bpmnException.getErrorCode());
44         }
45     }
46
47     @Test
48     public void buildAndThrowWorkflowExceptionInvalidMessageTest() {
49         try {
50             ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
51             String invalidErrorMessage = FileUtil.readResourceFile(RESOURCE_PATH + "invalidErrorMessage.txt");
52             exceptionBuilder.buildAndThrowWorkflowException(execution, 7000,
53                     new NullPointerException(invalidErrorMessage));
54         } catch (BpmnError bpmnException) {
55             assertEquals("MSOWorkflowException", bpmnException.getErrorCode());
56         }
57     }
58
59     @Test
60     public void buildAndThrowWorkflowExceptionInvalidMessageFlagTest() {
61         try {
62             ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
63             String invalidErrorMessage = FileUtil.readResourceFile(RESOURCE_PATH + "invalidErrorMessageFlag.txt");
64             exceptionBuilder.buildAndThrowWorkflowException(execution, 7000,
65                     new NullPointerException(invalidErrorMessage));
66         } catch (BpmnError bpmnException) {
67             assertEquals("MSOWorkflowException", bpmnException.getErrorCode());
68         }
69     }
70
71     @Test
72     public void buildAndThrowWorkflowExceptionNullMessageTest() {
73         try {
74             ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
75             exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, new NullPointerException());
76         } catch (BpmnError bpmnException) {
77             assertEquals("MSOWorkflowException", bpmnException.getErrorCode());
78         }
79     }
80 }