From d2d0cdcc534eb1f08c030c1907ae14a70fd41b04 Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Tue, 2 Feb 2021 10:03:58 +0000 Subject: Implementing download service CSAR endpoint Change-Id: If0de06835d0bfc2a1531fddba0b0298a4bc15af8 Issue-ID: INT-1839 Signed-off-by: waqas.ikram --- .../sdcsimulator/controller/CatalogController.java | 31 +++++++++++++++------- .../sdcsimulator/providers/AssetProviderImpl.java | 2 +- .../controller/CatalogControllerTest.java | 17 ++++++++++-- .../providers/AssetProviderImplTest.java | 2 +- 4 files changed, 39 insertions(+), 13 deletions(-) (limited to 'plans/so/integration-etsi-testing') 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 getCsar(@PathVariable("csarId") final String csarId) { + public ResponseEntity getResourceCsar(@PathVariable("csarId") final String csarId) { LOGGER.info("Running getCsar for {} ...", csarId); - final Optional resource = resourceProvider.getAsset(csarId, AssetType.RESOURCES); + final Optional 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 getResourceMetadata(@PathVariable("csarId") final String csarId) { LOGGER.info("Running getResourceMetadata for {} ...", csarId); - final Optional resource = resourceProvider.getMetadata(csarId, AssetType.RESOURCES); + final Optional 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 getServiceCsar(@PathVariable("csarId") final String csarId) { + LOGGER.info("Running getServiceCsar for {} ...", csarId); + final Optional 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 getServiceMetadata(@PathVariable("csarId") final String csarId) { LOGGER.info("Running getServiceMetadata for {} ...", csarId); - final Optional resource = resourceProvider.getMetadata(csarId, AssetType.SERVICES); + final Optional 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 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"; @@ -93,6 +92,20 @@ public class CatalogControllerTest { } + @Test + public void test_getServiceCsar_validCsarId_matchContent() { + + final String url = getBaseUrl() + "/services/" + SERVICE_ID + "/toscaModel"; + + final ResponseEntity 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() { 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()); } -- cgit 1.2.3-korg