Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / MSOCoreBPMN / src / test / java / org / onap / so / bpmn / core / UrnPropertiesReaderTest.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.bpmn.core;
22
23 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity;
24 import org.junit.Assert;
25 import org.junit.Test;
26 import org.springframework.core.env.Environment;
27 import static org.mockito.Mockito.*;
28
29 public class UrnPropertiesReaderTest {
30
31     @Test
32     public void testGetVariableFromExecution() {
33         ExecutionEntity mockExecution = mock(ExecutionEntity.class);
34         when(mockExecution.getVariable("testKey")).thenReturn("testValue");
35         String value = UrnPropertiesReader.getVariable("testKey", mockExecution);
36         Assert.assertEquals("testValue", value);
37         verify(mockExecution).getVariable("testKey");
38         verify(mockExecution, never()).setVariable("testKey", value);
39     }
40
41     @Test
42     public void testGetVariableFromEnvironment() {
43         ExecutionEntity mockExecution = mock(ExecutionEntity.class);
44         Environment mockEnvironment = mock(Environment.class);
45         when(mockEnvironment.getProperty("testKey")).thenReturn("testValue");
46         UrnPropertiesReader urnPropertiesReader = new UrnPropertiesReader();
47         urnPropertiesReader.setEnvironment(mockEnvironment);
48         String value = UrnPropertiesReader.getVariable("testKey", mockExecution);
49         Assert.assertEquals("testValue", value);
50         verify(mockExecution).getVariable("testKey");
51         verify(mockExecution).setVariable("testKey", value);
52     }
53
54     @Test
55     public void testGetVariableNotExist() {
56         ExecutionEntity mockExecution = mock(ExecutionEntity.class);
57         String value = UrnPropertiesReader.getVariable("notExist", mockExecution);
58         Assert.assertEquals(null, value);
59         verify(mockExecution).getVariable("notExist");
60         verify(mockExecution, never()).setVariable("notExist", value);
61     }
62 }