ffdf5d40b47769a851e73f2db20a1917a094f60e
[so.git] /
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.openecomp.mso.apihandlerinfra;
22
23 import static org.junit.Assert.assertTrue;
24
25 import mockit.Mock;
26 import mockit.MockUp;
27 import org.apache.http.HttpResponse;
28 import org.apache.http.ProtocolVersion;
29 import org.apache.http.client.ClientProtocolException;
30 import org.apache.http.entity.BasicHttpEntity;
31 import org.apache.http.message.BasicHttpResponse;
32 import org.junit.AfterClass;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.openecomp.mso.apihandler.common.CamundaClient;
36 import org.openecomp.mso.apihandlerinfra.volumebeans.ActionType;
37 import org.openecomp.mso.apihandlerinfra.volumebeans.RequestStatusType;
38 import org.openecomp.mso.apihandlerinfra.volumebeans.VolumeRequest;
39 import org.openecomp.mso.db.catalog.CatalogDatabase;
40 import org.openecomp.mso.db.catalog.beans.NetworkRecipe;
41 import org.openecomp.mso.db.catalog.beans.VfModule;
42 import org.openecomp.mso.db.catalog.beans.VnfResource;
43 import org.openecomp.mso.properties.MsoPropertiesFactory;
44 import org.openecomp.mso.requestsdb.InfraActiveRequests;
45 import org.openecomp.mso.requestsdb.InfraRequests;
46 import org.openecomp.mso.requestsdb.RequestsDatabase;
47
48 import javax.ws.rs.core.Response;
49 import java.io.ByteArrayInputStream;
50 import java.io.IOException;
51 import java.io.InputStream;
52 import java.sql.Timestamp;
53 import java.time.LocalDateTime;
54 import java.util.Collections;
55 import java.util.List;
56
57 public class VolumeInfoHandlerTest {
58
59         VolumeInfoHandler handler = new VolumeInfoHandler();
60
61         private static MockUp<RequestsDatabase> mockRDB;
62
63         @BeforeClass
64         public static void setUp() throws Exception {
65                 MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
66                 msoPropertiesFactory.removeAllMsoProperties();
67                 msoPropertiesFactory.initializeMsoProperties(Constants.MSO_PROP_APIHANDLER_INFRA, "src/test/resources/mso.apihandler-infra.properties");
68
69                 mockRDB = new MockUp<RequestsDatabase>() {
70                         @Mock
71                         public List<InfraActiveRequests> getRequestListFromInfraActive (String queryAttributeName,
72                                                                                                                                                         String queryValue,
73                                                                                                                                                         String requestType) {
74                                 final InfraActiveRequests requests = new InfraActiveRequests();
75                                 requests.setAction(ActionType.CREATE.name());
76                                 requests.setRequestStatus(RequestStatusType.IN_PROGRESS.name());
77                                 requests.setStartTime(Timestamp.valueOf(LocalDateTime.now()));
78                                 return Collections.singletonList(requests);
79                         }
80                         @Mock
81                         public InfraActiveRequests getRequestFromInfraActive (String requestId, String requestType) {
82                                 final InfraActiveRequests requests = new InfraActiveRequests();
83                                 requests.setAction(ActionType.CREATE.name());
84                                 requests.setRequestStatus(RequestStatusType.IN_PROGRESS.name());
85                                 requests.setStartTime(Timestamp.valueOf(LocalDateTime.now()));
86                                 return requests;
87                         }
88                 };
89
90         }
91
92         @AfterClass
93         public static void tearDown() {
94                 mockRDB.tearDown();
95         }
96
97         @Test
98         public void fillVnfRequestTestV3(){
99                 VolumeRequest qr = new VolumeRequest();
100                 InfraRequests ar = new InfraRequests();
101                 ar.setVnfId("2990102");
102                 ar.setVnfParams("test");
103                 handler.fillVolumeRequest(qr, ar, "v3");
104                 String vnfid = (String)qr.getVolumeParams();
105                 assertTrue(vnfid.equals("test"));
106         }
107         
108         @Test
109         public void fillVnfRequestTestV2(){
110                 VolumeRequest qr = new VolumeRequest();
111                 InfraRequests ar = new InfraRequests();
112                 ar.setVnfId("2990102");
113                 ar.setVnfParams("test");
114                 handler.fillVolumeRequest(qr, ar, "v2");
115                 String vnfid = (String)qr.getVolumeParams();
116                 assertTrue(vnfid.equals("test"));
117         }
118
119         @Test
120         public void queryFilters() {
121                 final Response response = handler.queryFilters("vnf-type", "svc-type", "aicNode", "tenant-id",
122                                 "vg-id", "vg-name", "v3");
123         }
124
125         @Test
126         public void queryFilters2() {
127                 final Response response = handler.queryFilters(null, "svc-type", "aicNode", "tenant-id",
128                                 "vg-id", "vg-name", "v3");
129         }
130
131         @Test
132         public void getRequest() {
133                 final Response response = handler.getRequest("request-id", "v3");
134         }
135 }