Replaced all tabs with spaces in java and pom.xml
[so.git] / adapters / mso-openstack-adapters / src / test / java / org / onap / so / adapters / vnf / QueryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2018 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.adapters.vnf;
22
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.hamcrest.Matchers.hasProperty;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
27 import static org.mockito.Mockito.when;
28 import java.util.Map;
29 import javax.xml.ws.Holder;
30 import org.junit.Rule;
31 import org.junit.Test;
32 import org.junit.rules.ExpectedException;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.Mockito;
37 import org.mockito.junit.MockitoJUnitRunner;
38 import org.onap.so.adapters.vnf.exceptions.VnfException;
39 import org.onap.so.openstack.beans.HeatStatus;
40 import org.onap.so.openstack.beans.StackInfo;
41 import org.onap.so.openstack.beans.VnfStatus;
42 import org.onap.so.openstack.exceptions.MsoException;
43 import org.onap.so.openstack.exceptions.MsoOpenstackException;
44 import org.onap.so.openstack.utils.MsoHeatUtils;
45
46 @RunWith(MockitoJUnitRunner.class)
47 public class QueryTest {
48
49     @Mock
50     private MsoHeatUtils heat;
51     @InjectMocks
52     private MsoVnfAdapterImpl vnfAdapter = new MsoVnfAdapterImpl();
53
54     @Rule
55     public ExpectedException thrown = ExpectedException.none();
56
57     @Test
58     public void testQueryCreatedVnf() throws VnfException, MsoException {
59         StackInfo info = new StackInfo("stackName", HeatStatus.CREATED);
60         when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info);
61         String cloudId = "MT";
62         String cloudOwner = "CloudOwner";
63         String tenantId = "MSO_Test";
64         String vnfName = "VNF_TEST1";
65         Holder<Boolean> vnfExists = new Holder<>();
66         Holder<String> vnfId = new Holder<>();
67         Holder<VnfStatus> status = new Holder<>();
68         Holder<Map<String, String>> outputs = new Holder<>();
69
70         vnfAdapter.queryVnf(cloudId, cloudOwner, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
71
72         assertTrue(vnfExists.value);
73     }
74
75     @Test
76     public void testQueryNotFoundVnf() throws VnfException, MsoException {
77         StackInfo info = new StackInfo("stackName", HeatStatus.NOTFOUND);
78         when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info);
79         String cloudId = "MT";
80         String cloudOwner = "CloudOwner";
81         String tenantId = "MSO_Test";
82         String vnfName = "VNF_TEST1";
83         Holder<Boolean> vnfExists = new Holder<>();
84         Holder<String> vnfId = new Holder<>();
85         Holder<VnfStatus> status = new Holder<>();
86         Holder<Map<String, String>> outputs = new Holder<>();
87
88         vnfAdapter.queryVnf(cloudId, cloudOwner, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
89
90         assertFalse(vnfExists.value);
91     }
92
93     @Test()
94     // @Ignore // 1802 merge
95     public void testQueryVnfWithException() throws VnfException, MsoException {
96         String cloudId = "MT";
97         String cloudOwner = "CloudOwner";
98         String tenantId = "MSO_Test";
99         String vnfName = "VNF_TEST1";
100         Holder<Boolean> vnfExists = new Holder<>();
101         Holder<String> vnfId = new Holder<>();
102         Holder<VnfStatus> status = new Holder<>();
103         Holder<Map<String, String>> outputs = new Holder<>();
104         thrown.expect(VnfException.class);
105         thrown.expectCause(hasProperty("context", is("QueryVNF")));
106         when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
107                 .thenThrow(new MsoOpenstackException(1, "test messsage", "test detail"));
108         vnfAdapter.queryVnf(cloudId, cloudOwner, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
109     }
110 }