aboutsummaryrefslogtreecommitdiffstats
path: root/plans
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@est.tech>2021-02-02 10:03:58 +0000
committerwaqas.ikram <waqas.ikram@est.tech>2021-02-02 10:24:29 +0000
commitd2d0cdcc534eb1f08c030c1907ae14a70fd41b04 (patch)
treed815bfecc06c066308066684458f010df0b93c17 /plans
parentc6e2d2268b8b95ec1fe513a31e585ad09834f867 (diff)
Implementing download service CSAR endpoint
Change-Id: If0de06835d0bfc2a1531fddba0b0298a4bc15af8 Issue-ID: INT-1839 Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'plans')
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/CatalogController.java31
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProviderImpl.java2
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java17
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/providers/AssetProviderImplTest.java2
4 files changed, 39 insertions, 13 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/CatalogController.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/CatalogController.java
index f22bcf69..eebc08c6 100644
--- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/CatalogController.java
+++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/controller/CatalogController.java
@@ -44,23 +44,23 @@ import org.springframework.web.bind.annotation.RequestMapping;
public class CatalogController {
private static final Logger LOGGER = LoggerFactory.getLogger(CatalogController.class);
- private AssetProvider resourceProvider;
+ private final AssetProvider assetProvider;
@Autowired
- public CatalogController(final AssetProvider resourceProvider) {
- this.resourceProvider = resourceProvider;
+ public CatalogController(final AssetProvider assetProvider) {
+ this.assetProvider = assetProvider;
}
@GetMapping(value = "/resources", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public ResponseEntity<?> getResources() {
LOGGER.info("Running getResources ...");
- return ResponseEntity.ok().body(resourceProvider.getAssetInfo(AssetType.RESOURCES));
+ return ResponseEntity.ok().body(assetProvider.getAssetInfo(AssetType.RESOURCES));
}
@GetMapping(value = "/resources/{csarId}/toscaModel", produces = MediaType.APPLICATION_OCTET_STREAM)
- public ResponseEntity<byte[]> getCsar(@PathVariable("csarId") final String csarId) {
+ public ResponseEntity<byte[]> getResourceCsar(@PathVariable("csarId") final String csarId) {
LOGGER.info("Running getCsar for {} ...", csarId);
- final Optional<byte[]> resource = resourceProvider.getAsset(csarId, AssetType.RESOURCES);
+ final Optional<byte[]> resource = assetProvider.getAsset(csarId, AssetType.RESOURCES);
if (resource.isPresent()) {
return new ResponseEntity<>(resource.get(), HttpStatus.OK);
}
@@ -73,7 +73,7 @@ public class CatalogController {
produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public ResponseEntity<Metadata> getResourceMetadata(@PathVariable("csarId") final String csarId) {
LOGGER.info("Running getResourceMetadata for {} ...", csarId);
- final Optional<Metadata> resource = resourceProvider.getMetadata(csarId, AssetType.RESOURCES);
+ final Optional<Metadata> resource = assetProvider.getMetadata(csarId, AssetType.RESOURCES);
if (resource.isPresent()) {
return new ResponseEntity<>(resource.get(), HttpStatus.OK);
}
@@ -86,14 +86,27 @@ public class CatalogController {
@GetMapping(value = "/services", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public ResponseEntity<?> getServices() {
LOGGER.info("Running getServices ...");
- return ResponseEntity.ok().body(resourceProvider.getAssetInfo(AssetType.SERVICES));
+ return ResponseEntity.ok().body(assetProvider.getAssetInfo(AssetType.SERVICES));
}
+ @GetMapping(value = "/services/{csarId}/toscaModel", produces = MediaType.APPLICATION_OCTET_STREAM)
+ public ResponseEntity<byte[]> getServiceCsar(@PathVariable("csarId") final String csarId) {
+ LOGGER.info("Running getServiceCsar for {} ...", csarId);
+ final Optional<byte[]> resource = assetProvider.getAsset(csarId, AssetType.SERVICES);
+ if (resource.isPresent()) {
+ return new ResponseEntity<>(resource.get(), HttpStatus.OK);
+ }
+ LOGGER.error("Unable to find csar: {}", csarId);
+
+ return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+
+
@GetMapping(value = "/services/{csarId}/metadata",
produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public ResponseEntity<Metadata> getServiceMetadata(@PathVariable("csarId") final String csarId) {
LOGGER.info("Running getServiceMetadata for {} ...", csarId);
- final Optional<Metadata> resource = resourceProvider.getMetadata(csarId, AssetType.SERVICES);
+ final Optional<Metadata> resource = assetProvider.getMetadata(csarId, AssetType.SERVICES);
if (resource.isPresent()) {
return new ResponseEntity<>(resource.get(), HttpStatus.OK);
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProviderImpl.java
index 28800b51..8996d249 100644
--- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProviderImpl.java
+++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/main/java/org/onap/so/sdcsimulator/providers/AssetProviderImpl.java
@@ -191,7 +191,7 @@ public class AssetProviderImpl implements AssetProvider {
}
private Optional<InputStream> getInputStream(final String csarId, final AssetType assetType) throws IOException {
- final Path filePath = Paths.get(resourceLocation, csarId + DOT_CSAR);
+ final Path filePath = Paths.get(resourceLocation, assetType.toString(), csarId + DOT_CSAR);
if (Files.exists(filePath)) {
LOGGER.info("Found csar on file system using path: {}", filePath);
return Optional.of(Files.newInputStream(filePath));
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java
index 57db74c3..e3d040da 100644
--- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java
+++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/controller/CatalogControllerTest.java
@@ -27,7 +27,6 @@ import java.util.Set;
import java.util.UUID;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.onap.so.sdcsimulator.models.Metadata;
import org.onap.so.sdcsimulator.models.ResourceAssetInfo;
import org.onap.so.sdcsimulator.models.ResourceMetadata;
import org.onap.so.sdcsimulator.models.ServiceAssetInfo;
@@ -80,7 +79,7 @@ public class CatalogControllerTest {
private UserCredentials userCredentials;
@Test
- public void test_getCsar_validCsarId_matchContent() {
+ public void test_getResourceCsar_validCsarId_matchContent() {
final String url = getBaseUrl() + "/resources/" + RESOURCE_ID + "/toscaModel";
@@ -94,6 +93,20 @@ public class CatalogControllerTest {
}
@Test
+ public void test_getServiceCsar_validCsarId_matchContent() {
+
+ final String url = getBaseUrl() + "/services/" + SERVICE_ID + "/toscaModel";
+
+ final ResponseEntity<byte[]> response =
+ restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), byte[].class);
+
+ assertEquals(HttpStatus.OK, response.getStatusCode());
+ assertTrue(response.hasBody());
+ assertEquals(147743, response.getBody().length);
+
+ }
+
+ @Test
public void test_getResources_validResourcesFromClassPath() {
final ResponseEntity<Set<ResourceAssetInfo>> response =
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/providers/AssetProviderImplTest.java b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/providers/AssetProviderImplTest.java
index 293d70d2..24f5c754 100644
--- a/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/providers/AssetProviderImplTest.java
+++ b/plans/so/integration-etsi-testing/so-simulators/sdc-simulator/src/test/java/org/onap/so/sdcsimulator/providers/AssetProviderImplTest.java
@@ -62,7 +62,7 @@ public class AssetProviderImplTest {
Files.write(file, DUMMY_CONTENT.getBytes());
- final AssetProviderImpl objUnderTest = new AssetProviderImpl(folder.getPath(), resourcePatternResolver);
+ final AssetProviderImpl objUnderTest = new AssetProviderImpl(folder.getParent(), resourcePatternResolver);
assertArrayEquals(DUMMY_CONTENT.getBytes(), objUnderTest.getAsset(uuid, RESOURCES).get());
}