summaryrefslogtreecommitdiffstats
path: root/adapters/mso-vnfm-adapter
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-vnfm-adapter')
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java12
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java30
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java12
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java43
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/Sol003PackageManagementControllerExceptionHandler.java (renamed from adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java)2
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgConflictException.java2
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgNotFoundException.java2
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java118
8 files changed, 184 insertions, 37 deletions
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java
index a73958e544..d4063951bd 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java
@@ -20,8 +20,8 @@
package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
import java.util.Optional;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
/**
* Provides methods for invoking REST calls to the ETSI Catalog Manager.
@@ -53,4 +53,14 @@ public interface EtsiCatalogServiceProvider {
*/
Optional<InlineResponse2001> getVnfPackage(final String vnfPkgId);
+ /**
+ * GET Package Artifact, from VNF Package.
+ *
+ * @param vnfPkgId The ID of the VNF Package from which the artifact will be retrieved.
+ * @param artifactPath Sequence of one or more path segments representing the path of the artifact within the VNF
+ * Package, e.g., foo/bar/run.sh
+ * @return The Package Artifact of a VNF Package ("vnfPkgId", "artifactPath").
+ */
+ Optional<byte[]> getVnfPackageArtifact(final String vnfPkgId, final String artifactPath);
+
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java
index 96b01f04e4..11a59c2ec8 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java
@@ -23,10 +23,7 @@ package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
import java.util.Optional;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfPkgInfo;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
-import org.onap.so.adapters.vnfmadapter.rest.exceptions.EtsiCatalogManagerRequestFailureException;
-import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgBadRequestException;
-import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgConflictException;
-import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgNotFoundException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.*;
import org.onap.so.rest.exceptions.HttpResouceNotFoundException;
import org.onap.so.rest.exceptions.InvalidRestRequestException;
import org.onap.so.rest.exceptions.RestProcessingException;
@@ -88,6 +85,31 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide
}
@Override
+ public Optional<byte[]> getVnfPackageArtifact(final String vnfPkgId, final String artifactPath) {
+ try {
+ final ResponseEntity<byte[]> response = httpServiceProvider.getHttpResponse(
+ etsiCatalogUrlProvider.getVnfPackageArtifactUrl(vnfPkgId, artifactPath), byte[].class);
+ logger.info("getVnfPackageArtifact Request to ETSI Catalog Manager Status Code: {}",
+ response.getStatusCodeValue());
+ if (response.getStatusCode() == HttpStatus.OK) {
+ return Optional.ofNullable(response.getBody());
+ }
+ } catch (final HttpResouceNotFoundException httpResouceNotFoundException) {
+ logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException);
+ throw new VnfPkgNotFoundException("No Vnf Package Artifact found with vnfPkgId: \"" + vnfPkgId
+ + "\" and artifactPath: \"" + artifactPath + "\".");
+ } catch (final RestProcessingException restProcessingException) {
+ logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(),
+ restProcessingException);
+ if (restProcessingException.getStatusCode() == HttpStatus.CONFLICT.value()) {
+ throw new VnfPkgConflictException("A conflict occurred with the state of the resource,\n"
+ + "due to the attribute: onboardingState not being set to ONBOARDED.");
+ }
+ }
+ throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.");
+ }
+
+ @Override
public Optional<InlineResponse2001[]> getVnfPackages() {
try {
final ResponseEntity<VnfPkgInfo[]> response =
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java
index d233c3f0fd..cc2c7a62a4 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java
@@ -79,4 +79,16 @@ public class EtsiCatalogUrlProvider {
return url;
}
+ /**
+ * Get the URL for retrieving VNF Package Artifacts
+ *
+ * @param vnfPkgId The ID of the VNF Package
+ * @param artifactPath The path to the Artifact
+ * @return the URL for the GET operation
+ */
+ public String getVnfPackageArtifactUrl(final String vnfPkgId, final String artifactPath) {
+ final String url = msbEndpoint + vnfpkgmServiceUrl + "/vnf_packages/" + vnfPkgId + "/artifacts/" + artifactPath;
+ logger.info("getVnfPackageArtifactUrl: {}", url);
+ return url;
+ }
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java
index 76ec492bd4..3f975fbc9c 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java
@@ -49,7 +49,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
public class Sol003PackageManagementController {
private final EtsiCatalogServiceProvider etsiCatalogServiceProvider;
- private static final String LOG_REQUEST_RECEIVED = "VNF PackageManagement Controller: {} {} {}";
+ private static final String LOG_REQUEST_RECEIVED = "VNF PackageManagement Controller: {} {} {} {}";
private static final Logger logger = getLogger(Sol003PackageManagementController.class);
@Autowired
@@ -64,18 +64,18 @@ public class Sol003PackageManagementController {
* @return An Array of all VNF packages. Object: InlineResponse2001[] Response Code: 200 OK
*/
@GetMapping(value = "/vnf_packages", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- public ResponseEntity getVnfPackages() {
+ public ResponseEntity<?> getVnfPackages() {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackages.");
final Optional<InlineResponse2001[]> response = etsiCatalogServiceProvider.getVnfPackages();
if (response.isPresent()) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackages Response: ", HttpStatus.OK);
- return new ResponseEntity(response.get(), HttpStatus.OK);
+ return ResponseEntity.ok().body(response.get());
}
final String errorMessage = "An error occurred, a null response was received by the\n"
+ " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" \n"
+ "endpoint.";
logger.error(errorMessage);
- return new ResponseEntity(buildProblemDetails(errorMessage), HttpStatus.INTERNAL_SERVER_ERROR);
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(buildProblemDetails(errorMessage));
}
/**
@@ -86,18 +86,18 @@ public class Sol003PackageManagementController {
* @return A VNF package based on vnfPkgId. Object: VnfPkgInfo Response Code: 200 OK
*/
@GetMapping(value = "/vnf_packages/{vnfPkgId}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- public ResponseEntity getVnfPackage(@PathVariable("vnfPkgId") final String vnfPkgId) {
+ public ResponseEntity<?> getVnfPackage(@PathVariable("vnfPkgId") final String vnfPkgId) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackage: ", vnfPkgId);
final Optional<InlineResponse2001> response = etsiCatalogServiceProvider.getVnfPackage(vnfPkgId);
if (response.isPresent()) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackage Response: ", HttpStatus.OK);
- return new ResponseEntity(response.get(), HttpStatus.OK);
+ return ResponseEntity.ok().body(response.get());
}
final String errorMessage = "An error occurred, a null response was received by the\n"
+ " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" by vnfPkgId: \""
+ vnfPkgId + "\" \n" + "endpoint.";
logger.error(errorMessage);
- return new ResponseEntity(buildProblemDetails(errorMessage), HttpStatus.INTERNAL_SERVER_ERROR);
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(buildProblemDetails(errorMessage));
}
/**
@@ -109,7 +109,7 @@ public class Sol003PackageManagementController {
*/
@GetMapping(value = "/vnf_packages/{vnfPkgId}/vnfd",
produces = {MediaType.TEXT_PLAIN, APPLICATION_ZIP, MediaType.APPLICATION_JSON})
- public ResponseEntity<byte[]> getVnfPackageVnfd(@PathVariable("vnfPkgId") final String vnfPkgId) {
+ public ResponseEntity<?> getVnfPackageVnfd(@PathVariable("vnfPkgId") final String vnfPkgId) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageVnfd: ", vnfPkgId);
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
@@ -123,17 +123,18 @@ public class Sol003PackageManagementController {
*/
@GetMapping(value = "/vnf_packages/{vnfPkgId}/package_content",
produces = {MediaType.APPLICATION_JSON, APPLICATION_ZIP, MediaType.APPLICATION_OCTET_STREAM})
- public ResponseEntity getVnfPackageContent(@PathVariable("vnfPkgId") final String vnfPkgId) {
+ public ResponseEntity<?> getVnfPackageContent(@PathVariable("vnfPkgId") final String vnfPkgId) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageContent Endpoint Invoked with VNF Package ID: ", vnfPkgId);
final Optional<byte[]> response = etsiCatalogServiceProvider.getVnfPackageContent(vnfPkgId);
if (response.isPresent()) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageContent Response: ", HttpStatus.OK);
- return new ResponseEntity(response.get(), HttpStatus.OK);
+ return ResponseEntity.ok().body(response.get());
}
- logger.error("Null response was received from the EtsiCatalogManager using the GET \"package_content\"");
- return new ResponseEntity(buildProblemDetails("An error occurred, a null response was received by the\n"
+ final String errorMessage = "An error occurred, a null response was received by the\n"
+ " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"package_content\" \n"
- + "endpoint."), HttpStatus.INTERNAL_SERVER_ERROR);
+ + "endpoint.";
+ logger.error(errorMessage);
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(buildProblemDetails(errorMessage));
}
/**
@@ -146,10 +147,20 @@ public class Sol003PackageManagementController {
*/
@GetMapping(value = "/vnf_packages/{vnfPkgId}/artifacts/{artifactPath}",
produces = {MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
- public ResponseEntity<byte[]> getVnfPackageArtifact(@PathVariable("vnfPkgId") final String vnfPkgId,
+ public ResponseEntity<?> getVnfPackageArtifact(@PathVariable("vnfPkgId") final String vnfPkgId,
@PathVariable("artifactPath") final String artifactPath) {
- logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageArtifact: vnfPkgId=", vnfPkgId, " artifactPath=", artifactPath);
- return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageArtifact: vnfPkgId= ", vnfPkgId, " artifactPath=",
+ artifactPath);
+ final Optional<byte[]> response = etsiCatalogServiceProvider.getVnfPackageArtifact(vnfPkgId, artifactPath);
+ if (response.isPresent()) {
+ logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageArtifact Response: ", HttpStatus.OK);
+ return ResponseEntity.ok().body(response.get());
+ }
+ final String errorMessage = "An error occurred, a null response was received by the\n"
+ + " Sol003PackageManagementController from the EtsiCatalogManager using the\n GET \"vnf_packages\" by vnfPkgId: \""
+ + vnfPkgId + "\" for artifactPath: \"" + artifactPath + "\"\n" + "endpoint.";
+ logger.error(errorMessage);
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(buildProblemDetails(errorMessage));
}
/**
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/Sol003PackageManagementControllerExceptionHandler.java
index 2a97bb47e4..a49063a72f 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/Sol003PackageManagementControllerExceptionHandler.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.so.adapters.vnfmadapter;
+package org.onap.so.adapters.vnfmadapter.rest.exceptions;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails;
import org.onap.so.adapters.vnfmadapter.rest.Sol003PackageManagementController;
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgConflictException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgConflictException.java
index 0cc9c5bd7e..f9aa2a0e21 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgConflictException.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgConflictException.java
@@ -23,7 +23,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
- * Exception for a Vnfpkg Conflict failure, due to state of resource.
+ * Exception for a VnfPkg Conflict failures, due to state of resource.
*
* @author gareth.roper@est.tech
*/
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgNotFoundException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgNotFoundException.java
index 0f9f214643..c15e7052ab 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgNotFoundException.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgNotFoundException.java
@@ -23,7 +23,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
- * Exception for a Vnfpkg Not Found Failure
+ * Exception for VnfPkg Not Found Failures
*
* @author gareth.roper@est.tech
*/
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java
index 857bd7dc3e..dbc8ef251d 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java
@@ -44,11 +44,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
+import org.springframework.http.*;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.MockRestServiceServer;
@@ -207,6 +203,109 @@ public class Sol003PackageManagementControllerTest {
}
@Test
+ public void testGetPackageArtifact_ValidArray_Success() {
+ final byte[] responseArray = buildByteArrayWithRandomData(10);
+
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess(responseArray, MediaType.APPLICATION_OCTET_STREAM));
+
+ final String testURL = "http://localhost:" + port + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/"
+ + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH;
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ final ResponseEntity<byte[]> responseEntity =
+ restTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request, byte[].class);
+
+ assertEquals(byte[].class, responseEntity.getBody().getClass());
+ assertArrayEquals(responseEntity.getBody(), responseArray);
+ assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageArtifact_Conflict_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.CONFLICT));
+
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.CONFLICT, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageArtifact_NotFound_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_FOUND));
+
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageArtifact_UnauthorizedClient_Fail() {
+ final String testURL = "http://localhost:" + port + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/"
+ + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH;
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ final ResponseEntity<ProblemDetails> responseEntity =
+ restTemplate.exchange(testURL, HttpMethod.GET, request, ProblemDetails.class);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.UNAUTHORIZED, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageArtifact_InternalServerError_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
+
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageArtifact_BadRequest_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.BAD_REQUEST));
+
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageArtifact_UnauthorizedServer_InternalError_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED));
+
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testGetPackageArtifact_SuccessResponseFromServerWithNullPackage_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET)).andRespond(withSuccess());
+
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
public void testVnfPackagesReceivedAsInlineResponse2001ListIfGetVnfPackagesSuccessful() {
final VnfPkgInfo[] responses = createVnfPkgArray();
@@ -369,20 +468,13 @@ public class Sol003PackageManagementControllerTest {
+ VNF_PACKAGE_ID + "\" \n" + "endpoint.", problemDetails.getDetail());
}
- // The below 2 test methods are here to improve code coverage and provide a foundation for writing future tests
+ // The below test method is here to improve code coverage and provide a foundation for writing future tests
@Test
public void testGetVnfd_Not_Implemented() {
final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd");
assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
}
- @Test
- public void testGetArtifact_Not_Implemented() {
- final ResponseEntity<ProblemDetails> responseEntity =
- sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
- assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
- }
-
// Simply returns a byte array filled with random data, for use in the tests.
private byte[] buildByteArrayWithRandomData(final int sizeInKb) {
final Random rnd = new Random();