Containerization feature of SO
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / onap / so / client / appc / ApplicationControllerClientV2Test.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.appc;
22
23 import org.junit.Before;
24 import org.junit.BeforeClass;
25 import org.junit.Ignore;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.InjectMocks;
29 import org.mockito.Mock;
30 import org.mockito.runners.MockitoJUnitRunner;
31 import org.onap.appc.client.lcm.model.Action;
32 import org.onap.appc.client.lcm.model.ActionIdentifiers;
33 import org.onap.appc.client.lcm.model.CheckLockInput;
34 import org.onap.appc.client.lcm.model.Status;
35 import org.onap.so.BaseTest;
36
37 import java.util.Properties;
38 import java.util.UUID;
39
40 import static org.junit.Assert.assertEquals;
41 import static org.mockito.Mockito.when;
42
43 @RunWith(MockitoJUnitRunner.class)
44 public class ApplicationControllerClientV2Test {
45
46         @Mock
47         ApplicationControllerSupport applicationControllerSupport;
48
49         @Mock
50         ApplicationControllerConfiguration applicationControllerConfiguration;
51
52         @InjectMocks
53         ApplicationControllerClientV2 client;
54
55
56         @Before
57         public void setup(){
58                 when(applicationControllerConfiguration.getReadTopic()).thenReturn("APPC-TEST-AMDOCS2");
59                 when(applicationControllerConfiguration.getReadTimeout()).thenReturn("120000");
60                 when(applicationControllerConfiguration.getResponseTimeout()).thenReturn("120000");
61                 when(applicationControllerConfiguration.getWrite()).thenReturn("APPC-TEST-AMDOCS1-DEV3");
62                 when(applicationControllerConfiguration.getService()).thenReturn("ueb");
63                 when(applicationControllerConfiguration.getPoolMembers()).thenReturn("localhost:3904,localhost:3904,localhost:3904");
64                 when(applicationControllerConfiguration.getClientKey()).thenReturn("iaEMAfjsVsZnraBP");
65                 when(applicationControllerConfiguration.getClientSecret()).thenReturn("wcivUjsjXzmGFBfxMmyJu9dz");
66                 //client.buildClient();
67         }
68         @BeforeClass
69         public static void beforeClass() {
70                 System.setProperty("mso.config.path", "src/test/resources");
71         }
72         @Ignore
73         @Test
74         public void createRequest_CheckLock_RequestBuilt() {
75                 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
76                 actionIdentifiers.setVnfId("vnfId");
77         //      when(applicationControllerSupport.getInput(eq(Action.CheckLock.name()))).thenReturn(new CheckLockInput());
78                 CheckLockInput checkLockInput = (CheckLockInput) client.createRequest(Action.CheckLock, actionIdentifiers, null,
79                                 "requestId");
80                 assertEquals(checkLockInput.getAction().name(), "CheckLock");
81         }
82         @Ignore
83         @Test
84         public void runCommand_liveAppc() {
85                 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
86                 //actionIdentifiers.setVnfId("ca522254-2ba4-4fbd-b15b-0ef0d9cfda5f");
87                 actionIdentifiers.setVnfId("2d2bf10e-81a5-");
88                 Status status;
89                 //when(applicationControllerSupport.getInput(eq(Action.Lock.name()))).thenReturn(new LockInput());
90                 //when(applicationControllerSupport.getAPIMethod(anyString(),any(),anyBoolean())).thenCallRealMethod();
91                 try {
92                         status = client.runCommand(Action.Lock, actionIdentifiers, null, UUID.randomUUID().toString());
93                 } catch (ApplicationControllerOrchestratorException e) {
94                         status = new Status();
95                         status.setCode(e.getAppcCode());
96                         status.setMessage(e.getMessage());
97                 }
98                 assertEquals("Status of run command is correct", status.getCode(), 306);
99         }
100
101         @Ignore
102         @Test
103         public void runCommand_CheckLock_RequestBuilt() {
104                 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
105                 actionIdentifiers.setVnfId("fusion-vpp-vnf-001");
106                 Status status;
107                 try {
108                         status = client.runCommand(Action.Unlock, actionIdentifiers, null, "requestId");
109                 } catch (ApplicationControllerOrchestratorException e) {
110                         status = new Status();
111                         status.setCode(e.getAppcCode());
112                         status.setMessage(e.getMessage());
113                 }
114                 assertEquals("Status of run command is correct", status.getCode(), 309);
115         }
116
117         @Ignore
118         @Test
119         public void test_getLCMPropertiesHelper() {
120                 Properties properties = client.getLCMProperties("");
121                 assertEquals(properties.get("topic.write"), "APPC-TEST-AMDOCS1-DEV3");
122                 assertEquals(properties.get("topic.read.timeout"), "120000");
123                 assertEquals(properties.get("client.response.timeout"), "120000");
124                 assertEquals(properties.get("topic.read"), "APPC-TEST-AMDOCS2");
125                 assertEquals(properties.get("poolMembers"),
126                                 "localhost:3904,localhost:3904,localhost:3904");
127                 assertEquals(properties.get("client.key"), "iaEMAfjsVsZnraBP");
128                 assertEquals(properties.get("client.secret"), "wcivUjsjXzmGFBfxMmyJu9dz");
129         }
130
131 }