diff options
author | rajesh.kumar <rk00747546@techmahindra.com> | 2022-09-06 11:47:18 +0000 |
---|---|---|
committer | rajesh.kumar <rk00747546@techmahindra.com> | 2022-11-18 06:37:38 +0000 |
commit | cec0cb7254ede8a790ec6f70ad5e31d10e2d32d7 (patch) | |
tree | 07e240bf7e384290b7bff198395e50af51eea994 /cps-ri/src | |
parent | d2a1f36a78fdc69d43b39f0a7852d47d78924ed5 (diff) |
Added get APIs for dataspace.
Issue-ID: CPS-1186
Change-ID: I73f97f986a817d423f93a8d922dcd9647b0829aa
Signed-off-by: rajesh.kumar <rk00747546@techmahindra.com>
Diffstat (limited to 'cps-ri/src')
-rwxr-xr-x | cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java | 19 | ||||
-rw-r--r-- | cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy | 28 |
2 files changed, 47 insertions, 0 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java index 20a39f98e3..2cebfc72c0 100755 --- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java @@ -3,6 +3,7 @@ * Copyright (C) 2020-2022 Nordix Foundation. * Modifications Copyright (C) 2020-2022 Bell Canada. * Modifications Copyright (C) 2021 Pantheon.tech + * Modifications Copyright (C) 2022 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +40,7 @@ import org.onap.cps.spi.exceptions.DataspaceInUseException; import org.onap.cps.spi.exceptions.DataspaceNotFoundException; import org.onap.cps.spi.exceptions.ModuleNamesNotFoundException; import org.onap.cps.spi.model.Anchor; +import org.onap.cps.spi.model.Dataspace; import org.onap.cps.spi.repository.AnchorRepository; import org.onap.cps.spi.repository.DataspaceRepository; import org.onap.cps.spi.repository.SchemaSetRepository; @@ -82,6 +84,19 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic } @Override + public Dataspace getDataspace(final String dataspaceName) { + final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName); + return toDataspace(dataspaceEntity); + } + + @Override + public Collection<Dataspace> getAllDataspaces() { + final Collection<DataspaceEntity> dataspaceEntities = dataspaceRepository.findAll(); + return dataspaceEntities.stream().map(CpsAdminPersistenceServiceImpl::toDataspace) + .collect(Collectors.toSet()); + } + + @Override public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) { final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName); final var schemaSetEntity = @@ -155,6 +170,10 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic .build(); } + private static Dataspace toDataspace(final DataspaceEntity dataspaceEntity) { + return Dataspace.builder().name(dataspaceEntity.getName()).build(); + } + private void validateDataspaceAndModuleNames(final String dataspaceName, final Collection<String> inputModuleNames) { final Collection<String> retrievedModuleReferences = diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy index cdb3e6c735..99d44aac89 100644 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy @@ -3,6 +3,7 @@ * Copyright (C) 2021-2022 Nordix Foundation * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2022 Bell Canada + * Modifications Copyright (C) 2022 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +31,7 @@ import org.onap.cps.spi.exceptions.DataspaceInUseException import org.onap.cps.spi.exceptions.DataspaceNotFoundException import org.onap.cps.spi.exceptions.SchemaSetNotFoundException import org.onap.cps.spi.model.Anchor +import org.onap.cps.spi.model.Dataspace import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.jdbc.Sql import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper @@ -68,6 +70,32 @@ class CpsAdminPersistenceServiceSpec extends CpsPersistenceSpecBase { } @Sql([CLEAR_DATA, SET_DATA]) + def 'Get a dataspace.'() { + when: 'dataspace is retrieved' + def dataspace = objectUnderTest.getDataspace(DATASPACE_NAME) + then: ' the response contains expected dataspace' + assert dataspace.getName().equals(DATASPACE_NAME); + } + + @Sql([CLEAR_DATA, SET_DATA]) + def 'Get all dataspaces.'() { + when: 'all dataspaces are retrieved' + def dataspaces = objectUnderTest.getAllDataspaces() + then: 'the response contains expected dataspaces' + def expectedDataspaces = Set.of(new Dataspace(name: 'DATASPACE-001'), new Dataspace(name: 'DATASPACE-002-NO-DATA'), + new Dataspace(name: 'DATASPACE-003')) + assert dataspaces == expectedDataspaces + } + + @Sql([CLEAR_DATA, SET_DATA]) + def 'Get non existing dataspace.'() { + when: 'attempting to retrieve a non-existing dataspace' + def dataspace = objectUnderTest.getDataspace('non_existing_dataspace') + then: 'an DataspaceNotFoundException is thrown' + thrown(DataspaceNotFoundException) + } + + @Sql([CLEAR_DATA, SET_DATA]) def 'Create and retrieve a new anchor.'() { when: 'a new anchor is created' def newAnchorName = 'my-new-anchor' |