Add unit test cases
[vfc/nfvo/driver/vnfm/svnfm.git] / nokia / vnfmdriver / vfcadaptorservice / vfcadaptor / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / catalog / impl / CatalogMgmrImpl.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.impl;
18
19 import java.io.IOException;
20
21 import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.bo.CatalogQueryVnfResponse;
22 import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.bo.entity.VnfPackageInfo;
23 import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Component;
31
32 import com.google.gson.Gson;
33
34 @Component
35 public class CatalogMgmrImpl implements CatalogMgmrInf{
36         private static final Logger logger = LoggerFactory.getLogger(CatalogMgmrImpl.class);
37         
38         private Gson gson = new Gson();
39         
40         @Autowired 
41         private AdaptorEnv adaptorEnv;
42         
43         @Autowired
44         HttpClientProcessorInf httpClientProcessor;
45         
46         public VnfPackageInfo queryVnfPackage(String vnfPackageId) throws IOException {
47                 
48                 String url=adaptorEnv.getCatalogApiUriFront() + String.format(CommonConstants.RetrieveVnfPackagePath, vnfPackageId);
49                 
50 //              String responseStr = httpClientProcessor.process(url, RequestMethod.GET, null, null).getContent();
51                 String responseStr = httpClientProcessor.process(url).getContent();
52                 
53                 logger.info("CatalogMgmrImpl -> queryVnfPackage, responseStr is " + responseStr);
54                 
55                 CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
56                 
57                 return resp.getPackageInfo();
58         }
59
60         public void setAdaptorEnv(AdaptorEnv env) {
61                 this.adaptorEnv = env;
62         }
63
64         
65 }