diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2020-08-20 09:59:05 +0100 |
---|---|---|
committer | waqas.ikram <waqas.ikram@est.tech> | 2020-09-04 17:20:54 +0100 |
commit | 21a476895dc40402dced615cb0f1b112b1796355 (patch) | |
tree | 860bfd5b810a37236372e876e0234bb812527ec6 /so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src | |
parent | fd32f8a06d39cc122c030aea7e65a40fe08e8ee1 (diff) |
Implementing Create NS
Change-Id: Ib54e7476820fe716137e6d5e08e4d0deb9f104b9
Issue-ID: SO-3179
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src')
12 files changed, 436 insertions, 6 deletions
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/JobAction.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/JobAction.java index 50573b42f5..8a22689f8a 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/JobAction.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/JobAction.java @@ -21,6 +21,7 @@ package org.onap.so.etsi.nfvo.ns.lcm.database.beans; /** * @author Waqas Ikram (waqas.ikram@est.tech) + * */ public enum JobAction { CREATE, INSTANTIATE, TERMINATE, DELETE; diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJobStatus.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJobStatus.java index 9bd05924ad..89e07701ed 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJobStatus.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJobStatus.java @@ -47,7 +47,7 @@ public class NfvoJobStatus { @Column(name = "STATUS") private JobStatusEnum status; - @Column(name = "DESCRIPTION") + @Column(name = "DESCRIPTION", columnDefinition = "LONGTEXT") private String description; @Column(name = "UPDATED_TIME") diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNsInst.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNsInst.java index fdd053c49e..dd8448fe56 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNsInst.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNsInst.java @@ -59,7 +59,7 @@ public class NfvoNsInst { @Column(name = "NSD_INVARIANT_ID") private String nsdInvariantId; - @Column(name = "DESCRIPTION") + @Column(name = "DESCRIPTION", columnDefinition = "LONGTEXT") private String description; @Enumerated(EnumType.STRING) diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/config/NfvoDatabaseConfiguration.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/config/NfvoDatabaseConfiguration.java index 0438a4258c..8f146e5378 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/config/NfvoDatabaseConfiguration.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/config/NfvoDatabaseConfiguration.java @@ -48,11 +48,12 @@ import com.zaxxer.hikari.HikariDataSource; basePackages = {"org.onap.so.etsi.nfvo.ns.lcm.database.repository"}) public class NfvoDatabaseConfiguration { + private static final String PERSISTENCE_UNIT = "nfvo"; + private static final String NFVO_DATA_SOURCE_QUALIFIER = "nfvoDataSource"; + @Autowired(required = false) private MBeanExporter mBeanExporter; - private static final String NFVO_DATA_SOURCE_QUALIFIER = "nfvoDataSource"; - @Bean @ConfigurationProperties(prefix = "spring.datasource.hikari.nfvo") public HikariConfig nfvoDbConfig() { @@ -72,8 +73,8 @@ public class NfvoDatabaseConfiguration { @Bean(name = "entityManagerFactory") public LocalContainerEntityManagerFactoryBean entityManagerFactory(final EntityManagerFactoryBuilder builder, @Qualifier(NFVO_DATA_SOURCE_QUALIFIER) final DataSource dataSource) { - return builder.dataSource(dataSource).packages(NfvoJob.class.getPackage().getName()).persistenceUnit("nfvo") - .build(); + return builder.dataSource(dataSource).packages(NfvoJob.class.getPackage().getName()) + .persistenceUnit(PERSISTENCE_UNIT).build(); } @Primary diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoJobRepository.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoJobRepository.java new file mode 100644 index 0000000000..844f60827e --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoJobRepository.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.repository; + +import java.util.Optional; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.springframework.data.repository.CrudRepository; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface NfvoJobRepository extends CrudRepository<NfvoJob, String> { + + Optional<NfvoJob> findByResourceId(final String resourceId); + + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNsInstRepository.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNsInstRepository.java new file mode 100644 index 0000000000..beeeacf8cf --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNsInstRepository.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.repository; + +import java.util.Optional; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.springframework.data.repository.CrudRepository; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface NfvoNsInstRepository extends CrudRepository<NfvoNsInst, String> { + + Optional<NfvoNsInst> findByName(final String name); + + Optional<NfvoNsInst> findByNsInstId(final String nsInstId); + + boolean existsNfvoNsInstByName(final String name); + + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java new file mode 100644 index 0000000000..420d916014 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.service; + +import java.util.Optional; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.repository.NfvoJobRepository; +import org.onap.so.etsi.nfvo.ns.lcm.database.repository.NfvoNsInstRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ + +@Service +public class DatabaseServiceProvider { + private static final Logger logger = LoggerFactory.getLogger(DatabaseServiceProvider.class); + + private final NfvoJobRepository nfvoJobRepository; + + private final NfvoNsInstRepository nfvoNsInstRepository; + + @Autowired + public DatabaseServiceProvider(final NfvoJobRepository nfvoJobRepository, + final NfvoNsInstRepository nfvoNsInstRepository) { + this.nfvoJobRepository = nfvoJobRepository; + this.nfvoNsInstRepository = nfvoNsInstRepository; + } + + public boolean addJob(final NfvoJob job) { + logger.info("Adding NfvoJob: {} to database", job); + return nfvoJobRepository.save(job) != null; + } + + public Optional<NfvoJob> getJob(final String jobId) { + logger.info("Querying database for NfvoJob using jobId: {}", jobId); + return nfvoJobRepository.findById(jobId); + } + + public Optional<NfvoJob> getJobByResourceId(final String resourceId) { + logger.info("Querying database for NfvoJob using resourceId: {}", resourceId); + return nfvoJobRepository.findByResourceId(resourceId); + } + + public boolean isNsInstExists(final String name) { + logger.info("Checking if NfvoNsInst entry exists in database using name: {}", name); + return nfvoNsInstRepository.existsNfvoNsInstByName(name); + } + + public boolean saveNfvoNsInst(final NfvoNsInst nfvoNsInst) { + logger.info("Saving NfvoNsInst: {} to database", nfvoNsInst); + return nfvoNsInstRepository.save(nfvoNsInst) != null; + } + + public Optional<NfvoNsInst> getNfvoNsInst(final String nsInstId) { + logger.info("Querying database for NfvoNsInst using nsInstId: {}", nsInstId); + return nfvoNsInstRepository.findById(nsInstId); + } + + public Optional<NfvoNsInst> getNfvoNsInstByName(final String name) { + logger.info("Querying database for NfvoNsInst using name: {}", name); + return nfvoNsInstRepository.findByName(name); + } + + public Optional<NfvoNsInst> getNfvoNsInstByNsInstId(final String nsInstId) { + logger.info("Querying database for NfvoNsInst using nsInstId: {}", nsInstId); + return nfvoNsInstRepository.findByNsInstId(nsInstId); + } + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql index e4c959d6e3..f41a8206e0 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql @@ -14,6 +14,8 @@ CREATE TABLE IF NOT EXISTS `JOB` ( PRIMARY KEY (`JOB_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + CREATE TABLE IF NOT EXISTS `JOB_STATUS` ( `ID` INT NOT NULL AUTO_INCREMENT, `UPDATED_TIME` DATETIME NOT NULL, diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java new file mode 100644 index 0000000000..03488e9176 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import java.time.LocalDateTime; +import java.util.Optional; +import java.util.UUID; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobAction; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJobStatus; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; +import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class DatabaseServiceProviderTest { + + private static final String RANDOM_ID = UUID.randomUUID().toString(); + private static final String DUMMY_NAME = "NAME"; + private static final LocalDateTime CURRENT_DATE_TIME = LocalDateTime.now(); + @Autowired + private DatabaseServiceProvider databaseServiceProvider; + + @Test + public void testAddJob_StoredInDatabase() { + final NfvoJob expected = new NfvoJob().jobType("TYPE").jobAction(JobAction.CREATE).resourceId(RANDOM_ID) + .resourceName(DUMMY_NAME).startTime(CURRENT_DATE_TIME).status(JobStatusEnum.STARTED); + databaseServiceProvider.addJob(expected); + + final Optional<NfvoJob> actual = databaseServiceProvider.getJob(expected.getJobId()); + assertEquals(expected, actual.get()); + } + + @Test + public void testAddJobWithJobStatus_StoredInDatabase() { + final NfvoJob job = new NfvoJob().jobType("TYPE").jobAction(JobAction.CREATE).resourceId(RANDOM_ID) + .resourceName(DUMMY_NAME).startTime(CURRENT_DATE_TIME).status(JobStatusEnum.STARTED); + databaseServiceProvider.addJob(job); + + final NfvoJobStatus jobStatus = new NfvoJobStatus().status(JobStatusEnum.STARTED) + .description("Create NS workflow process started").updatedTime(CURRENT_DATE_TIME); + databaseServiceProvider.addJob(job.nfvoJobStatus(jobStatus)); + + final Optional<NfvoJob> actual = databaseServiceProvider.getJob(job.getJobId()); + final NfvoJob actualNfvoJob = actual.get(); + + assertEquals(job.getJobId(), actualNfvoJob.getJobId()); + assertFalse(actualNfvoJob.getNfvoJobStatuses().isEmpty()); + assertEquals(job.getJobId(), actualNfvoJob.getNfvoJobStatuses().get(0).getNfvoJob().getJobId()); + + } + + @Test + public void testAddNsInst_StoredInDatabase_ableTofindByQuery() { + + final NfvoNsInst nsInst = new NfvoNsInst().name(DUMMY_NAME).nsdId(RANDOM_ID).status(State.NOT_INSTANTIATED) + .nsdInvariantId(RANDOM_ID).statusUpdatedTime(CURRENT_DATE_TIME); + + databaseServiceProvider.saveNfvoNsInst(nsInst); + + Optional<NfvoNsInst> actual = databaseServiceProvider.getNfvoNsInst(nsInst.getNsInstId()); + NfvoNsInst actualNfvoNsInst = actual.get(); + assertEquals(nsInst.getNsInstId(), actualNfvoNsInst.getNsInstId()); + assertEquals(RANDOM_ID, actualNfvoNsInst.getNsdId()); + assertEquals(State.NOT_INSTANTIATED, actualNfvoNsInst.getStatus()); + assertEquals(RANDOM_ID, actualNfvoNsInst.getNsdInvariantId()); + assertEquals(CURRENT_DATE_TIME, actualNfvoNsInst.getStatusUpdatedTime()); + + actual = databaseServiceProvider.getNfvoNsInstByName(DUMMY_NAME); + actualNfvoNsInst = actual.get(); + + assertEquals(nsInst.getNsInstId(), actualNfvoNsInst.getNsInstId()); + assertEquals(RANDOM_ID, actualNfvoNsInst.getNsdId()); + assertEquals(State.NOT_INSTANTIATED, actualNfvoNsInst.getStatus()); + assertEquals(RANDOM_ID, actualNfvoNsInst.getNsdInvariantId()); + assertEquals(CURRENT_DATE_TIME, actualNfvoNsInst.getStatusUpdatedTime()); + + + assertTrue(databaseServiceProvider.isNsInstExists(DUMMY_NAME)); + } + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/TestApplication.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/TestApplication.java new file mode 100644 index 0000000000..921cae2343 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/TestApplication.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.etsi.nfvo.ns.lcm.database; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.ComponentScan.Filter; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@SpringBootApplication(scanBasePackages = {"org.onap.so"}) +@EnableAutoConfiguration(exclude = {JacksonAutoConfiguration.class}) +@ComponentScan(basePackages = {"org.onap"}, + excludeFilters = {@Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class)}) +public class TestApplication { + + public static void main(final String[] args) { + new SpringApplication(TestApplication.class).run(args); + } + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/UtilsTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/UtilsTest.java new file mode 100644 index 0000000000..632bda937c --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/UtilsTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import java.util.Arrays; +import java.util.Collections; +import org.junit.Test; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class UtilsTest { + + @Test + public void testTwoEmptyLists_equal() { + assertTrue(Utils.isEquals(Collections.emptyList(), Collections.emptyList())); + } + + @Test + public void testEmptyListAndNonEmpty_notEqual() { + assertFalse(Utils.isEquals(Collections.emptyList(), Arrays.asList("A"))); + } + + @Test + public void testTwoNullLists_equal() { + assertTrue(Utils.isEquals(null, null)); + } + + @Test + public void testNullListAndEmptyList_notEqual() { + assertFalse(Utils.isEquals(null, Collections.emptyList())); + } + + @Test + public void testTwoNotEmptyListsContainSameObjects_equal() { + assertTrue(Utils.isEquals(Arrays.asList("A"), Arrays.asList("A"))); + } + + @Test + public void testTwoNotEmptyListsContainsDifferentObjects_equal() { + assertFalse(Utils.isEquals(Arrays.asList("A"), Arrays.asList(1))); + } + + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/resources/application.yaml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/resources/application.yaml new file mode 100644 index 0000000000..8b7550d8ef --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/resources/application.yaml @@ -0,0 +1,35 @@ +# Copyright © 2020 Nordix Foundation +# +# 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. +spring: + main: + web-application-type: none + datasource: + hikari: + nfvo: + jdbcUrl: jdbc:h2:mem:nfvo;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS nfvo; + driver-class-name: org.h2.Driver + pool-name: ns-lcm-bpmn-pool + registerMbeans: true + jpa: + generate-ddl: true + hibernate: + ddl-auto: create + +logging: + level: + org.flywaydb: DEBUG +hibernate: + dialect: org.hibernate.dialect.H2Dialect + hbm2ddl: + auto: create
\ No newline at end of file |