9ada85fa38f403e40654498e08cc70d2545b4b56
[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
25 import org.camunda.bpm.engine.delegate.BpmnError;
26 import org.junit.Test;
27 import org.onap.so.BaseTest;
28 import org.onap.so.bpmn.mock.FileUtil;
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         @Test
36         public void buildAndThrowWorkflowExceptionTest() {
37                 try {
38                         ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
39                         exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, new NullPointerException(VALID_ERROR_MESSAGE));
40                 } catch (BpmnError bpmnException){
41                         assertEquals("MSOWorkflowException", bpmnException.getErrorCode());
42                 }
43         }
44
45         @Test
46         public void buildAndThrowWorkflowExceptionInvalidMessageTest() {
47                 try{
48                         ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
49                         String invalidErrorMessage = FileUtil.readResourceFile(RESOURCE_PATH + "invalidErrorMessage.txt");
50                         exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, new NullPointerException(invalidErrorMessage));
51                 } catch (BpmnError bpmnException){
52                         assertEquals("MSOWorkflowException", bpmnException.getErrorCode());
53                 }
54         }
55         
56         @Test
57         public void buildAndThrowWorkflowExceptionInvalidMessageFlagTest() {
58                 try{
59                         ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
60                         String invalidErrorMessage = FileUtil.readResourceFile(RESOURCE_PATH + "invalidErrorMessageFlag.txt");
61                         exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, new NullPointerException(invalidErrorMessage));
62                 } catch (BpmnError bpmnException){
63                         assertEquals("MSOWorkflowException", bpmnException.getErrorCode());
64                 }
65         }
66         
67         @Test
68         public void buildAndThrowWorkflowExceptionNullMessageTest() {
69                 try{
70                         ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
71                         exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, new NullPointerException());
72                 } catch (BpmnError bpmnException){
73                         assertEquals("MSOWorkflowException", bpmnException.getErrorCode());
74                 }
75         }
76 }