package org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.impl;
import java.io.IOException;
+import java.util.HashMap;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.impl.client.HttpClientBuilder;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.inf.AaiMgmrInf;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpRequestProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Autowired
private AdaptorEnv adaptorEnv;
- @Autowired
- private HttpClientBuilder httpClientBuilder;
+ @Autowired
+ HttpClientProcessorInf httpClientProcessor;
private Gson gson = new Gson();
@Override
private String operateHttpTask(Object httpBodyObj, String httpPath, RequestMethod method) throws ClientProtocolException, IOException {
String url=adaptorEnv.getAaiApiUriFront() + httpPath;
- HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, method);
- processor.addHdeader(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
- processor.addPostEntity(gson.toJson(httpBodyObj));
+ HashMap<String, String> map = new HashMap<String, String>();
+ map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
- String responseStr = processor.process(url);
+ String responseStr = httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj)).getContent();
return responseStr;
}
+ public void setAdaptorEnv(AdaptorEnv env) {
+ this.adaptorEnv = env;
+ }
+
}
package org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.impl;
import java.io.IOException;
+import java.util.HashMap;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.impl.client.HttpClientBuilder;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpRequestProcessor;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.VnfPackageInfo;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMethod;
private AdaptorEnv adaptorEnv;
@Autowired
- private HttpClientBuilder httpClientBuilder;
+ HttpClientProcessorInf httpClientProcessor;
public VnfPackageInfo queryVnfPackage(String vnfPackageId) throws ClientProtocolException, IOException {
+
String url=adaptorEnv.getCatalogApiUriFront() + String.format(CommonConstants.RetrieveVnfPackagePath, vnfPackageId);
- HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
+ HashMap<String, String> map = new HashMap<String, String>();
+
+ String bodyPostStr = String.format(CommonConstants.RetrieveCbamTokenPostStr, adaptorEnv.getGrantType(), adaptorEnv.getClientId(), adaptorEnv.getClientSecret());
- String responseStr = processor.process(url);
+ String responseStr = httpClientProcessor.process(url, RequestMethod.GET, map, bodyPostStr).getContent();
logger.info("CbamMgmrImpl -> queryVnfPackage, responseStr is " + responseStr);
return resp.getPackageInfo();
}
+ public void setAdaptorEnv(AdaptorEnv env) {
+ this.adaptorEnv = env;
+ }
+
}
+++ /dev/null
-/*
- * Copyright 2016-2017, Nokia Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.controller;
-
-import java.io.IOException;
-
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.log4j.Logger;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.bo.CatalogQueryVnfResponse;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfRequest;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfResponse;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMOperExecutVnfResponse;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpRequestProcessor;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.MediaType;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-import com.google.gson.Gson;
-
-@Controller
-@RequestMapping(value = "/vnfm/lcm/v3")
-public class CbamController {
- private static final Logger logger = Logger.getLogger(CbamController.class);
- @Autowired
- private AdaptorEnv adaptorEnv;
-
- @Autowired
- private HttpClientBuilder httpClientBuilder;
-
- private Gson gson = new Gson();
-
- @RequestMapping(value = "/vnfs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
- @ResponseBody
- public CBAMCreateVnfResponse createVnf(CBAMInstantiateVnfRequest request) throws ClientProtocolException, IOException
- {
- CBAMCreateVnfResponse response = new CBAMCreateVnfResponse();
- String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamCreateVnfPath);
- HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
-
- String responseStr = processor.process(url);
-
- logger.info("CbamMgmrImpl -> createVnf, responseStr is " + responseStr);
-
- CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
-
-
- return response;
- }
- @RequestMapping(value = "/vnfs/{vnfInstanceId}/instantiate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
- @ResponseBody
- public CBAMInstantiateVnfResponse initiateVnf(CBAMInstantiateVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
- {
- CBAMInstantiateVnfResponse response = new CBAMInstantiateVnfResponse();
- String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamInstantiateVnfPath,vnfInstanceId);
- HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
-
- String responseStr = processor.process(url);
-
- logger.info("CbamMgmrImpl -> initiateVnf, responseStr is " + responseStr);
-
- CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
-
-
- return response;
- }
-
- @RequestMapping(value = "/vnfs/{vnfInstanceId}/terminate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
- @ResponseBody
- public CBAMTerminateVnfResponse terminateVnf(CBAMTerminateVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
- {
- CBAMTerminateVnfResponse response = new CBAMTerminateVnfResponse();
- String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamTerminateVnfPath,vnfInstanceId);
- HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
-
- String responseStr = processor.process(url);
-
- logger.info("CbamMgmrImpl -> terminateVnf, responseStr is " + responseStr);
-
- CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
- return response;
- }
-
- @RequestMapping(value = "/vnfs/{vnfInstanceId}/scale", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
- @ResponseBody
- public CBAMScaleVnfResponse scaleVnf(CBAMScaleVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
- {
- CBAMScaleVnfResponse response = new CBAMScaleVnfResponse();
- String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamScaleVnfPath,vnfInstanceId);
- HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
-
- String responseStr = processor.process(url);
-
- logger.info("CbamMgmrImpl -> scaleVnf, responseStr is " + responseStr);
-
- CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
- return response;
- }
-
- @RequestMapping(value = "/vnfs/{vnfInstanceId}/heal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
- @ResponseBody
- public CBAMHealVnfResponse healVnf(CBAMHealVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
- {
- CBAMHealVnfResponse response = new CBAMHealVnfResponse();
- String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamHealVnfPath,vnfInstanceId);
- HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
-
- String responseStr = processor.process(url);
-
- logger.info("CbamMgmrImpl -> healVnf, responseStr is " + responseStr);
-
- CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
- return response;
- }
-
-
- @RequestMapping(value = "/vnfs/{vnfInstanceId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
- @ResponseBody
- public CBAMQueryVnfResponse queryVnf(@PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException
- {
- CBAMQueryVnfResponse response = new CBAMQueryVnfResponse();
- String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamQueryVnfPath, vnfInstanceId);
- HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
-
- String responseStr = processor.process(url);
-
- logger.info("CbamMgmrImpl -> queryVnfPackage, responseStr is " + responseStr);
-
- CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
-
-
- return response;
- }
-
-
- @RequestMapping(value = "/operation_executions/{operationExecutionId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
- @ResponseBody
- public CBAMOperExecutVnfResponse operVnf(@PathVariable("operationExecutionId") String operationExecutionId) throws ClientProtocolException, IOException
- {
- CBAMOperExecutVnfResponse response = new CBAMOperExecutVnfResponse();
- String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamGetOperStatusPath,operationExecutionId);
- HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET);
-
- String responseStr = processor.process(url);
-
- logger.info("CbamMgmrImpl -> operVnf, responseStr is " + responseStr);
-
- CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class);
- return response;
- }
-
-
-
-
-}
import java.util.HashMap;
import org.apache.http.client.ClientProtocolException;
-import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.json.JSONObject;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpRequestProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
String bodyPostStr = String.format(CommonConstants.RetrieveCbamTokenPostStr, adaptorEnv.getGrantType(), adaptorEnv.getClientId(), adaptorEnv.getClientSecret());
- String responseStr = httpClientProcessor.process(url, RequestMethod.GET, map, bodyPostStr);
+ String responseStr = httpClientProcessor.process(url, RequestMethod.GET, map, bodyPostStr).getContent();
logger.info("CbamMgmrImpl -> retrieveToken, responseStr is " + responseStr);
map.put(CommonConstants.AUTHORIZATION, "bearer " + token);
map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
- String responseStr = httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj));
+ String responseStr = httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj)).getContent();
return responseStr;
}
@Autowired
private HttpClientBuilder httpClientBuilder;
- public String process(String url, RequestMethod methodType, HashMap<String, String> headerMap, String bodyString) throws ClientProtocolException, IOException
+ public HttpResult process(String url, RequestMethod methodType, HashMap<String, String> headerMap, String bodyString) throws ClientProtocolException, IOException
{
HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, methodType);
if(headerMap != null && !headerMap.isEmpty())
import org.springframework.web.bind.annotation.RequestMethod;
public interface HttpClientProcessorInf {
- public String process(String url, RequestMethod methodType, HashMap<String, String> headerMap, String bodyString) throws ClientProtocolException, IOException;
+ public HttpResult process(String url, RequestMethod methodType, HashMap<String, String> headerMap, String bodyString) throws ClientProtocolException, IOException;
}
httpRequest = HttpClientUtils.getHttpRequest(requestMethod);
}
- public String process(String url) throws ClientProtocolException, IOException
+ public HttpResult process(String url) throws ClientProtocolException, IOException
{
httpRequest.setURI(URI.create(url));
HttpResponse response = httpClient.execute(httpRequest);
+
+ HttpResult httpResult = buildHttpResult(response);
+ httpClient.close();
+
+ return httpResult;
+ }
+
+ private HttpResult buildHttpResult(HttpResponse response) throws IOException {
HttpEntity resEntity = response.getEntity();
String responseContent = "";
if (resEntity != null) {
responseContent = EntityUtils.toString(resEntity, CommonConstants.UTF_8);
EntityUtils.consume(resEntity);
}
- httpClient.close();
- return responseContent;
+ HttpResult httpResult = new HttpResult();
+ httpResult.setStatusCode(response.getStatusLine().getStatusCode());
+ httpResult.setStatusCause(response.getStatusLine().getReasonPhrase());
+ httpResult.setHeaders(response.getAllHeaders());
+ httpResult.setContent(responseContent);
+
+ return httpResult;
}
public void addHdeader(String key, String value) {
--- /dev/null
+/*
+ * Copyright 2016-2017, Nokia Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client;
+
+import org.apache.http.Header;
+
+public class HttpResult {
+ private int statusCode;
+ private String statusCause;
+ private Header[] headers;
+ private String content;
+
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ public void setStatusCode(int statusCode) {
+ this.statusCode = statusCode;
+ }
+
+ public String getStatusCause() {
+ return statusCause;
+ }
+
+ public void setStatusCause(String statusCause) {
+ this.statusCause = statusCause;
+ }
+
+ public Header[] getHeaders() {
+ return headers;
+ }
+
+ public void setHeaders(Header[] headers) {
+ this.headers = headers;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+}
HashMap<String, String> map = new HashMap<String, String>();
map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
- String responseStr = httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj));
+ String responseStr = httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj)).getContent();
return responseStr;
}
--- /dev/null
+/*
+ * Copyright 2016-2017, Nokia Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.impl;
+
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+import org.apache.http.client.ClientProtocolException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.AaiVnfmInfo;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpResult;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+public class AaiMgmrInfImplTest {
+ @InjectMocks
+ private AaiMgmrInfImpl aaiMgmr;
+
+ @Mock
+ private HttpClientProcessorInf httpClientProcessor;
+
+ private String vnfmId = "vnfmId_001";
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ AdaptorEnv env = new AdaptorEnv();
+ aaiMgmr.setAdaptorEnv(env);
+ MockitoAnnotations.initMocks(this);
+
+ String json = "{"
+ + "\"vnfm-id\":\"vnfm-id_001\","
+ + "\"esr-system-info-list\":[{\"ip\" : \"1.3.5.6\"}]"
+ + "}"
+ + "";
+ HttpResult httpResult = new HttpResult();
+ httpResult.setContent(json);
+
+ when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult);
+ }
+
+ @Test
+ public void testQueryVnfPackage() throws ClientProtocolException, IOException
+ {
+ AaiVnfmInfo vnfmInfo = aaiMgmr.queryVnfm(vnfmId);
+// Assert.assertEquals("1.3.5.6", vnfmInfo.getEsrSystemInfoList().get(0).getIp());
+ }
+}
package org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.impl;
-import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
+import java.io.IOException;
+import java.util.HashMap;
+
+import org.apache.http.client.ClientProtocolException;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpResult;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.VnfPackageInfo;
+import org.springframework.web.bind.annotation.RequestMethod;
public class CatalogMgmrImplTest {
+ @InjectMocks
+ private CatalogMgmrImpl catalogMgmr;
+ @Mock
+ private HttpClientProcessorInf httpClientProcessor;
+
+ private String vnfPackageId = "vnfPackageId_001";
+
@Before
public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ AdaptorEnv env = new AdaptorEnv();
+ catalogMgmr.setAdaptorEnv(env);
+ MockitoAnnotations.initMocks(this);
+
+ String json = "{"
+ + "\"csarId\":\"vnfPackageId_001\","
+ + "\"packageInfo\":{\"downloadUri\" : \"1.3.5.6\"}"
+ + "}"
+ + "";
+ HttpResult httpResult = new HttpResult();
+ httpResult.setContent(json);
+
+ when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult);
}
@Test
- public void test() {
-// fail("Not yet implemented");
+ public void testQueryVnfPackage() throws ClientProtocolException, IOException
+ {
+ VnfPackageInfo response = catalogMgmr.queryVnfPackage(vnfPackageId);
}
}
import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpResult;
import org.springframework.web.bind.annotation.RequestMethod;
public class CbamMgmrImplTest {
MockitoAnnotations.initMocks(this);
String json = "{\"access_token\":\"1234567\"}";
+ HttpResult httpResult = new HttpResult();
+ httpResult.setContent(json);
- when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(json);
+ when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult);
}
@Test
package org.onap.vfc.nfvo.driver.vnfm.svnfm.msb.impl;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.util.HashMap;
-
-import org.apache.http.client.ClientProtocolException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.onap.msb.sdk.discovery.common.RouteException;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.impl.NslcmMgmrImpl;
-import org.springframework.web.bind.annotation.RequestMethod;
public class MsbMgmrImplTest {
@InjectMocks
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
AdaptorEnv env = new AdaptorEnv();
+ env.setMsbIp("127.0.0.1");
+ env.setMsbPort(80);
msbMgmr.setAdaptorEnv(env);
MockitoAnnotations.initMocks(this);
-
- String json = "{\"access_token\":\"1234567\"}";
-
- when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(json);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testRegister()
+ {
+ msbMgmr.register();
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testunRegister()
+ {
+ msbMgmr.unregister();
+ }
+
+ @Test(expected = RouteException.class)
+ public void testGetServiceUrlInMsbBySeriveNameAndPort() throws RouteException
+ {
+ msbMgmr.getServiceUrlInMsbBySeriveNameAndPort("serviceName", "88");
}
}
import org.mockito.MockitoAnnotations;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpResult;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfRequest;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmGrantVnfResponse;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.NslcmNotifyLCMEventsRequest;
MockitoAnnotations.initMocks(this);
String json = "{\"access_token\":\"1234567\"}";
+ HttpResult httpResult = new HttpResult();
+ httpResult.setContent(json);
- when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(json);
+ when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult);
}
@Test