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