diff options
Diffstat (limited to 'mso-catalog-db/src/test/java/org/onap')
11 files changed, 777 insertions, 0 deletions
diff --git a/mso-catalog-db/src/test/java/org/onap/so/EmbeddedMariaDbConfig.java b/mso-catalog-db/src/test/java/org/onap/so/EmbeddedMariaDbConfig.java new file mode 100644 index 0000000000..60f8de6c2e --- /dev/null +++ b/mso-catalog-db/src/test/java/org/onap/so/EmbeddedMariaDbConfig.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so; +import ch.vorburger.exec.ManagedProcessException; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; +import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import javax.sql.DataSource; + +@Configuration +@Profile({"test","local"}) +public class EmbeddedMariaDbConfig { + + @Bean + MariaDB4jSpringService mariaDB4jSpringService() { + return new MariaDB4jSpringService(); + } + + @Bean + DataSource dataSource(MariaDB4jSpringService mariaDB4jSpringService, + @Value("${mariaDB4j.databaseName}") String databaseName, + @Value("${spring.datasource.username}") String datasourceUsername, + @Value("${spring.datasource.password}") String datasourcePassword, + @Value("${spring.datasource.driver-class-name}") String datasourceDriver) throws ManagedProcessException { + //Create our database with default root user and no password + mariaDB4jSpringService.getDB().createDB(databaseName); + + DBConfigurationBuilder config = mariaDB4jSpringService.getConfiguration(); + + return DataSourceBuilder + .create() + .username(datasourceUsername) + .password(datasourcePassword) + .url(config.getURL(databaseName)) + .driverClassName(datasourceDriver) + .build(); + } +} diff --git a/mso-catalog-db/src/test/java/org/onap/so/TestApplication.java b/mso-catalog-db/src/test/java/org/onap/so/TestApplication.java new file mode 100644 index 0000000000..6ee88e407d --- /dev/null +++ b/mso-catalog-db/src/test/java/org/onap/so/TestApplication.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.Profile; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +@SpringBootApplication(scanBasePackages = { "org.onap"}) +@EnableJpaRepositories("org.onap.so.db.catalog.data.repository") +@EntityScan("org.onap.so.db.catalog.beans") +@Profile("test") +public class TestApplication { + private static final String LOGS_DIR = "logs_dir"; + + private static void setLogsDir() { + if (System.getProperty(LOGS_DIR) == null) { + System.getProperties().setProperty(LOGS_DIR, "./logs/catdb/"); + } + } + + public static void main(String... args) { + SpringApplication.run(TestApplication.class, args); + System.getProperties().setProperty("mso.db", "MARIADB"); + System.getProperties().setProperty("server.name", "Springboot"); + setLogsDir(); + } +} diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/BuildingBlockDetailTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/BuildingBlockDetailTest.java new file mode 100644 index 0000000000..7a9fc19fcb --- /dev/null +++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/BuildingBlockDetailTest.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.catalog; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.TestApplication; +import org.onap.so.db.catalog.beans.BuildingBlockDetail; +import org.onap.so.db.catalog.beans.OrchestrationAction; +import org.onap.so.db.catalog.beans.ResourceType; +import org.onap.so.db.catalog.data.repository.BuildingBlockDetailRepository; +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; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class BuildingBlockDetailTest { + @Autowired + private BuildingBlockDetailRepository buildingBlockDetailRepository; + + @Test + public void BuildingBlockDetailSingleLookupValidationTest() { + String buildingBlockName = "AssignServiceInstanceBB"; + + BuildingBlockDetail buildingBlockDetail = buildingBlockDetailRepository.findOneByBuildingBlockName(buildingBlockName); + assertEquals(buildingBlockName, buildingBlockDetail.getBuildingBlockName()); + assertEquals(ResourceType.SERVICE, buildingBlockDetail.getResourceType()); + assertEquals(OrchestrationAction.ASSIGN, buildingBlockDetail.getTargetAction()); + } +} diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/MavenVersioningTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/MavenVersioningTest.java new file mode 100644 index 0000000000..b5d6271f7c --- /dev/null +++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/MavenVersioningTest.java @@ -0,0 +1,187 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.catalog; + + +import static org.junit.Assert.*; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import org.junit.Test; + +import org.onap.so.db.catalog.utils.MavenLikeVersioningComparator; +import org.onap.so.db.catalog.utils.MavenLikeVersioning; + + +public class MavenVersioningTest { + + @Test + public final void testVersion () { + MavenLikeVersioning mavenVersioning = new MavenLikeVersioning (); + assertFalse(mavenVersioning.isMoreRecentThan("0.0.0")); + assertFalse(mavenVersioning.isMoreRecentThan(null)); + mavenVersioning.setVersion("0.0.1"); + + assertFalse(mavenVersioning.isMoreRecentThan(null)); + assertTrue(mavenVersioning.isMoreRecentThan("0.0.0")); + assertTrue(mavenVersioning.isMoreRecentThan("0.0.0.1")); + + assertFalse(mavenVersioning.isMoreRecentThan("0.0.2")); + assertFalse(mavenVersioning.isMoreRecentThan("0.0.1")); + assertFalse(mavenVersioning.isMoreRecentThan("00.00.01")); + + assertFalse(mavenVersioning.isMoreRecentThan("0.1")); + assertFalse(mavenVersioning.isMoreRecentThan("1")); + assertFalse(mavenVersioning.isMoreRecentThan("0.1.0.2")); + + assertFalse(mavenVersioning.isMoreRecentThan("0.1.1")); + assertFalse(mavenVersioning.isMoreRecentThan("2.1.1")); + + mavenVersioning.setVersion("1.0.1"); + assertTrue(mavenVersioning.isMoreRecentThan("0.0.0")); + assertTrue(mavenVersioning.isMoreRecentThan("0.5.2")); + assertTrue(mavenVersioning.isMoreRecentThan("1.0.0")); + + assertFalse(mavenVersioning.isMoreRecentThan("2.1.1")); + assertFalse(mavenVersioning.isMoreRecentThan("02.001.0001")); + assertFalse(mavenVersioning.isMoreRecentThan("1.0.1")); + assertFalse(mavenVersioning.isMoreRecentThan("1.0.2")); + assertFalse(mavenVersioning.isMoreRecentThan("1.1.1")); + assertFalse(mavenVersioning.isMoreRecentThan("1.0.10")); + + + mavenVersioning.setVersion("100.0.1"); + assertTrue(mavenVersioning.isMoreRecentThan("0.0.0")); + assertTrue(mavenVersioning.isMoreRecentThan("0.5.2")); + assertTrue(mavenVersioning.isMoreRecentThan("1.0.0")); + + assertFalse(mavenVersioning.isMoreRecentThan("101.1.1")); + assertFalse(mavenVersioning.isMoreRecentThan("100.0.1")); + assertFalse(mavenVersioning.isMoreRecentThan("100.0.2")); + assertFalse(mavenVersioning.isMoreRecentThan("100.1.1")); + + assertFalse(mavenVersioning.isMoreRecentThan("100.0.1.4")); + } + + @Test + public final void testOneDigitVersion() { + MavenLikeVersioning oneDigit = new MavenLikeVersioning(); + oneDigit.setVersion("1"); + assertFalse(oneDigit.isMoreRecentThan("2")); + assertFalse(oneDigit.isMoreRecentThan("2.0")); + assertFalse(oneDigit.isMoreRecentThan("1.0")); + + oneDigit.setVersion("1.0"); + assertTrue(oneDigit.isMoreRecentThan("1")); + + oneDigit.setVersion("1"); + assertFalse(oneDigit.isTheSameVersion("1.1")); + assertFalse(oneDigit.isTheSameVersion("1.0")); + assertFalse(oneDigit.isTheSameVersion("1.0.0")); + + oneDigit.setVersion("2"); + assertTrue(oneDigit.isMoreRecentThan("1")); + assertTrue(oneDigit.isMoreRecentThan("1.0")); + assertTrue(oneDigit.isMoreRecentThan("1.1")); + assertTrue(oneDigit.isMoreRecentThan("0.1")); + assertFalse(oneDigit.isMoreRecentThan("2.0")); + + } + + @Test + public final void testVersionEquals () { + + MavenLikeVersioning heatTemplate = new MavenLikeVersioning(); + assertFalse(heatTemplate.isTheSameVersion("100.0")); + assertTrue(heatTemplate.isTheSameVersion(null)); + heatTemplate.setVersion("100.0.1"); + assertFalse(heatTemplate.isTheSameVersion(null)); + assertFalse(heatTemplate.isTheSameVersion("100.0")); + assertFalse(heatTemplate.isTheSameVersion("100")); + assertFalse(heatTemplate.isTheSameVersion("100.0.1.1")); + assertTrue(heatTemplate.isTheSameVersion("100.0.1")); + assertTrue(heatTemplate.isTheSameVersion("00100.000.0001")); + assertFalse(heatTemplate.isTheSameVersion("0.0.1")); + assertTrue(heatTemplate.isTheSameVersion("100.0.01")); + + } + + @Test + public final void testListSort () { + MavenLikeVersioning test1 = new MavenLikeVersioning(); + test1.setVersion("1.1"); + MavenLikeVersioning test2 = new MavenLikeVersioning(); + test2.setVersion("1.10"); + MavenLikeVersioning test3 = new MavenLikeVersioning(); + test3.setVersion("1.2"); + MavenLikeVersioning test4 = new MavenLikeVersioning(); + test4.setVersion("1.20"); + MavenLikeVersioning test5 = new MavenLikeVersioning(); + test5.setVersion("1.02"); + MavenLikeVersioning test6 = new MavenLikeVersioning(); + test6.setVersion("2.02"); + MavenLikeVersioning test7 = new MavenLikeVersioning(); + test7.setVersion("0.02"); + MavenLikeVersioning test8 = new MavenLikeVersioning(); + test8.setVersion("2.02"); + MavenLikeVersioning test9 = new MavenLikeVersioning(); + test9.setVersion("10.2004"); + MavenLikeVersioning test10 = new MavenLikeVersioning(); + test10.setVersion("2"); + MavenLikeVersioning test11 = new MavenLikeVersioning(); + test11.setVersion("12"); + MavenLikeVersioning test12 = new MavenLikeVersioning(); + test12.setVersion("2.0"); + + List<MavenLikeVersioning> list= new LinkedList<MavenLikeVersioning>(); + list.add(test1); + list.add(test2); + list.add(test3); + list.add(test4); + list.add(test5); + list.add(test6); + list.add(test7); + list.add(test8); + list.add(test9); + list.add(test10); + list.add(test11); + list.add(test12); + + Collections.sort(list,new MavenLikeVersioningComparator()); + //Collections.reverse(list); + assertTrue(list.get(0).getVersion().equals("0.02")); + assertTrue(list.get(1).getVersion().equals("1.1")); + assertTrue(list.get(2).getVersion().equals("1.02") || list.get(3).getVersion().equals("1.02")); + assertTrue(list.get(3).getVersion().equals("1.2") || list.get(2).getVersion().equals("1.2")); + assertTrue(list.get(4).getVersion().equals("1.10")); + assertTrue(list.get(5).getVersion().equals("1.20")); + assertTrue(list.get(6).getVersion().equals("2")); + assertTrue(list.get(7).getVersion().equals("2.0")); + assertTrue(list.get(8).getVersion().equals("2.02")); + assertTrue(list.get(9).getVersion().equals("2.02")); + assertTrue(list.get(10).getVersion().equals("10.2004")); + assertTrue(list.get(11).getVersion().equals("12")); + + } +} + diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/NetworkTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/NetworkTest.java new file mode 100644 index 0000000000..55c5c8351b --- /dev/null +++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/NetworkTest.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.catalog; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.TestApplication; +import org.onap.so.db.catalog.beans.NetworkResource; +import org.onap.so.db.catalog.data.repository.NetworkResourceRepository; +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; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class NetworkTest { + @Autowired + private NetworkResourceRepository networkRepo; + + @Test + public void BuildingBlockDetailSingleLookupValidationTest() { + NetworkResource latestNetwork = networkRepo.findFirstByModelNameOrderByModelVersionDesc("CONTRAIL30_GNDIRECT"); + assertEquals("10b36f65-f4e6-4be6-ae49-9596dc1c47fz",latestNetwork.getModelUUID()); + } +} diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/OrchestrationStatusStateTransitionDirectiveTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/OrchestrationStatusStateTransitionDirectiveTest.java new file mode 100644 index 0000000000..52cac88402 --- /dev/null +++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/OrchestrationStatusStateTransitionDirectiveTest.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.catalog; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.TestApplication; +import org.onap.so.db.catalog.beans.OrchestrationAction; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.onap.so.db.catalog.beans.OrchestrationStatusStateTransitionDirective; +import org.onap.so.db.catalog.beans.OrchestrationStatusValidationDirective; +import org.onap.so.db.catalog.beans.ResourceType; +import org.onap.so.db.catalog.data.repository.OrchestrationStatusStateTransitionDirectiveRepository; +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; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class OrchestrationStatusStateTransitionDirectiveTest { + @Autowired + private OrchestrationStatusStateTransitionDirectiveRepository orchestrationStatusStateTransitionDirectiveRepository; + + @Test + public void OrchestrationStatusTransitionDBSingleLookupValidationTest() { + OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = orchestrationStatusStateTransitionDirectiveRepository.findOneByResourceTypeAndOrchestrationStatusAndTargetAction(ResourceType.SERVICE, OrchestrationStatus.ASSIGNED, OrchestrationAction.ASSIGN); + assertEquals(ResourceType.SERVICE, orchestrationStatusStateTransitionDirective.getResourceType()); + assertEquals(OrchestrationStatus.ASSIGNED, orchestrationStatusStateTransitionDirective.getOrchestrationStatus()); + assertEquals(OrchestrationAction.ASSIGN, orchestrationStatusStateTransitionDirective.getTargetAction()); + assertEquals(OrchestrationStatusValidationDirective.SILENT_SUCCESS, orchestrationStatusStateTransitionDirective.getFlowDirective()); + } +} diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/ServiceTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/ServiceTest.java new file mode 100644 index 0000000000..0ecaa5fbba --- /dev/null +++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/ServiceTest.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.catalog; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.TestApplication; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.data.repository.ServiceRepository; +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; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class ServiceTest { + @Autowired + private ServiceRepository serviceRepo; + + @Test + public void Find_LatestService_Test() { + Service latestVersionService = serviceRepo.findFirstByModelNameOrderByModelVersionDesc("MSOTADevInfra_vSAMP10a_Service"); + assertEquals("5df8b6de-2083-11e7-93ae-92361f002675",latestVersionService.getModelUUID()); + } + + + @Test + public void Find_LatestService_Test_2() { + Service latestVersionService = serviceRepo.findByModelNameOrderByModelVersionDesc("MSOTADevInfra_vSAMP10a_Service"); + assertEquals("5df8b6de-2083-11e7-93ae-92361f002675",latestVersionService.getModelUUID()); + } + + + @Test + public void Find_LatestService_Test_Invariant_UUID() { + List<Service> latestVersionService = serviceRepo.findByModelInvariantUUIDOrderByModelVersionDesc("9647dfc4-2083-11e7-93ae-92361f002671"); + assertEquals("5df8b6de-2083-11e7-93ae-92361f002675",latestVersionService.get(0).getModelUUID()); + assertEquals("5df8b6de-2083-11e7-93ae-92361f002674",latestVersionService.get(1).getModelUUID()); + assertEquals("5df8b6de-2083-11e7-93ae-92361f002673",latestVersionService.get(2).getModelUUID()); + assertEquals("5df8b6de-2083-11e7-93ae-92361f002672",latestVersionService.get(3).getModelUUID()); + assertEquals("5df8b6de-2083-11e7-93ae-92361f002671",latestVersionService.get(4).getModelUUID()); + } + + @Test + public void Find_LatestService_Test_4() { + Service latestVersionService = serviceRepo.findOneByModelUUIDOrderByModelVersionDesc("5df8b6de-2083-11e7-93ae-92361f002671"); + assertEquals("5df8b6de-2083-11e7-93ae-92361f002671",latestVersionService.getModelUUID()); + } + + @Test + public void Find_LatestService_Test_5() { + Service latestVersionService = serviceRepo.findFirstByModelInvariantUUIDOrderByModelVersionDesc("9647dfc4-2083-11e7-93ae-92361f002671"); + assertEquals("5df8b6de-2083-11e7-93ae-92361f002675",latestVersionService.getModelUUID()); + } +} diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/TempNetworkHeatTemplateLookupTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/TempNetworkHeatTemplateLookupTest.java new file mode 100644 index 0000000000..b09ec7193d --- /dev/null +++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/TempNetworkHeatTemplateLookupTest.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.catalog; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup; + +/** + */ + +public class TempNetworkHeatTemplateLookupTest { + + @Test + public final void tempNetworkHeatTemplateLookupDataTest() { + TempNetworkHeatTemplateLookup tempNetworkHeatTemplateLookup = new TempNetworkHeatTemplateLookup(); + tempNetworkHeatTemplateLookup.setAicVersionMax("aicVersionMax"); + assertTrue(tempNetworkHeatTemplateLookup.getAicVersionMax().equalsIgnoreCase("aicVersionMax")); + tempNetworkHeatTemplateLookup.setAicVersionMin("aicVersionMin"); + assertTrue(tempNetworkHeatTemplateLookup.getAicVersionMin().equalsIgnoreCase("aicVersionMin")); + tempNetworkHeatTemplateLookup.setHeatTemplateArtifactUuid("heatTemplateArtifactUuid"); + assertTrue(tempNetworkHeatTemplateLookup.getHeatTemplateArtifactUuid() + .equalsIgnoreCase("heatTemplateArtifactUuid")); + tempNetworkHeatTemplateLookup.setNetworkResourceModelName("networkResourceModelName"); + assertTrue(tempNetworkHeatTemplateLookup.getNetworkResourceModelName() + .equalsIgnoreCase("networkResourceModelName")); +// assertTrue(tempNetworkHeatTemplateLookup.toString() != null); + + } + +} diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/VFModuleTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/VFModuleTest.java new file mode 100644 index 0000000000..44e7a03855 --- /dev/null +++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/VFModuleTest.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.catalog; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.TestApplication; +import org.onap.so.db.catalog.beans.VfModule; +import org.onap.so.db.catalog.data.repository.VFModuleRepository; +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; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class VFModuleTest { + @Autowired + private VFModuleRepository vfModuleRepo; + + @Test + public void VFModule_Versioned_LookUp() { + VfModule latestModule = vfModuleRepo.findFirstByModelNameOrderByModelVersionDesc("vSAMP10aDEV::PCM::module-1"); + assertEquals("066de97e-253e-11e7-93ae-92361f002675",latestModule.getModelUUID()); + } + + @Test + public void VFModule_Versioned_LookUp_LIst() { + List<VfModule> moduleList = vfModuleRepo.findByModelInvariantUUIDOrderByModelVersionDesc("64efd51a-2544-11e7-93ae-92361f002671"); + assertEquals("066de97e-253e-11e7-93ae-92361f002675",moduleList.get(0).getModelUUID()); + assertEquals("066de97e-253e-11e7-93ae-92361f002674",moduleList.get(1).getModelUUID()); + assertEquals("066de97e-253e-11e7-93ae-92361f002673",moduleList.get(2).getModelUUID()); + } +} diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/beans/BeansTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/beans/BeansTest.java new file mode 100644 index 0000000000..44439ede22 --- /dev/null +++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/beans/BeansTest.java @@ -0,0 +1,100 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.catalog.beans; + +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.onap.so.openpojo.rules.HasAnnotationMatcher.hasAnnotation; +import static org.onap.so.openpojo.rules.HasAnnotationPropertyWithValueMatcher.hasAnnotationPropertyWithValue; + +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.Temporal; + +import org.junit.Test; +import org.onap.so.openpojo.rules.CustomSetterMustExistRule; +import org.onap.so.openpojo.rules.EqualsAndHashCodeTester; +import org.onap.so.openpojo.rules.HasEqualsAndHashCodeRule; +import org.onap.so.openpojo.rules.HasToStringRule; +import org.onap.so.openpojo.rules.ToStringTester; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterEnum; +import com.openpojo.reflection.filters.FilterNonConcrete; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.BusinessKeyMustExistRule; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.NoNestedClassRule; +import com.openpojo.validation.rule.impl.NoPrimitivesRule; +import com.openpojo.validation.rule.impl.NoPublicFieldsExceptStaticFinalRule; +import com.openpojo.validation.rule.impl.NoStaticExceptFinalRule; +import com.openpojo.validation.rule.impl.SerializableMustHaveSerialVersionUIDRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + + +public class BeansTest { + + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + private PojoClassFilter enumFilter = new FilterEnum(); + + + + @Test + public void pojoStructure() { + test("org.onap.so.db.catalog.beans"); + test("org.onap.so.db.catalog.beans.macro"); + } + + private void test(String pojoPackage) { + Validator validator = ValidatorBuilder.create() + .with(new GetterMustExistRule()) + .with(new NoPrimitivesRule()) + .with(new NoNestedClassRule()) + .with(new NoStaticExceptFinalRule()) + .with(new SerializableMustHaveSerialVersionUIDRule()) + .with(new HasToStringRule()) + .with(new EqualsAndHashCodeTester()) + .with(new NoPublicFieldsExceptStaticFinalRule()) + .with(new CustomSetterMustExistRule().exclude( + allOf(hasAnnotationPropertyWithValue(Column.class, "updatable", equalTo(false)), hasAnnotation(GeneratedValue.class)), + hasAnnotation(Temporal.class))) + + .with(new SetterTester()) + .with(new GetterTester()) + .with(new ToStringTester()) + .with(new HasEqualsAndHashCodeRule()) + + .build(); + + + validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses,enumFilter,new FilterNonConcrete()); + } + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } +} diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/test/RecordNotFoundExceptionTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/test/RecordNotFoundExceptionTest.java new file mode 100644 index 0000000000..506a6b73c9 --- /dev/null +++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/test/RecordNotFoundExceptionTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.catalog.test; + +import org.junit.Test; +import org.onap.so.db.catalog.beans.VfModule; +import org.onap.so.db.catalog.utils.RecordNotFoundException; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertEquals; + + +public class RecordNotFoundExceptionTest { + + @Test + public void paramConstructor(){ + RecordNotFoundException ex = new RecordNotFoundException("Exceoption raised", new Exception()); + assertNotNull(ex); + assertNotNull(ex.getMessage()); + } +} |