diff options
author | 2019-04-08 14:14:34 -0400 | |
---|---|---|
committer | 2019-04-08 14:24:59 -0400 | |
commit | f47919f1fe367b612fa9c96d34c59f01a541e882 (patch) | |
tree | 5b6aa2fc36747d868897e68ccbec0c6db0aee81c /mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap | |
parent | 54452b80a1cf4d22ef750bc1377f8c1b05431d57 (diff) |
Replaced all tabs with spaces in java and pom.xml
Added in maven plugins to enforce coding style rules
Added in eclipse java formatting xml
Change-Id: I3727bbf4ce8dc66abfd8ad21b6cfd0890c5d3ff0
Issue-ID: SO-1765
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap')
6 files changed, 158 insertions, 179 deletions
diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/TestApplication.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/TestApplication.java index 9bb5cab9b5..1b8fc9755e 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/TestApplication.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/TestApplication.java @@ -27,12 +27,12 @@ import org.springframework.context.annotation.Profile; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; -@SpringBootApplication(scanBasePackages = { "org.onap.so" }) +@SpringBootApplication(scanBasePackages = {"org.onap.so"}) @Profile("test") public class TestApplication { - public static void main(String... args) { - SpringApplication.run(TestApplication.class, args); - System.getProperties().setProperty("mso.db", "MARIADB"); - System.getProperties().setProperty("server.name", "Springboot"); - } + public static void main(String... args) { + SpringApplication.run(TestApplication.class, args); + System.getProperties().setProperty("mso.db", "MARIADB"); + System.getProperties().setProperty("server.name", "Springboot"); + } } diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/OperationStatusTest.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/OperationStatusTest.java index f3be5a154b..09aa252309 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/OperationStatusTest.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/OperationStatusTest.java @@ -23,11 +23,8 @@ package org.onap.so.db.request; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; - import java.util.Date; - import javax.transaction.Transactional; - import org.junit.Test; import org.junit.runner.RunWith; import org.onap.so.TestApplication; @@ -43,43 +40,43 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") -public class OperationStatusTest { - - @Autowired - private OperationStatusRepository repository; - - @Test - @Transactional - public void timeStampCreated() throws InterruptedException, NoEntityFoundException { - - final String testServiceId = "test-service-id"; - final String testOperationId = "test-operation-id"; - final OperationStatusId id = new OperationStatusId(testServiceId, testOperationId); - OperationStatus status = new OperationStatus(); - - status.setServiceId(testServiceId); - status.setOperationId(testOperationId); - - status = repository.saveAndFlush(status); - - OperationStatus found = repository.findById(id). - orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation")); - - Date operateAt = found.getOperateAt(); - assertNotNull(operateAt); - assertEquals(testServiceId, found.getServiceId()); - Date finishedAt = found.getFinishedAt(); - status.setProgress("test-progress"); - //timestamps only set to save on 1 second changes - Thread.sleep(1000); - repository.saveAndFlush(status); - - OperationStatus foundUpdate = repository.findById(id). - orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation")); +public class OperationStatusTest { + + @Autowired + private OperationStatusRepository repository; + + @Test + @Transactional + public void timeStampCreated() throws InterruptedException, NoEntityFoundException { + + final String testServiceId = "test-service-id"; + final String testOperationId = "test-operation-id"; + final OperationStatusId id = new OperationStatusId(testServiceId, testOperationId); + OperationStatus status = new OperationStatus(); + + status.setServiceId(testServiceId); + status.setOperationId(testOperationId); + + status = repository.saveAndFlush(status); + + OperationStatus found = + repository.findById(id).orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation")); + + Date operateAt = found.getOperateAt(); + assertNotNull(operateAt); + assertEquals(testServiceId, found.getServiceId()); + Date finishedAt = found.getFinishedAt(); + status.setProgress("test-progress"); + // timestamps only set to save on 1 second changes + Thread.sleep(1000); + repository.saveAndFlush(status); + + OperationStatus foundUpdate = + repository.findById(id).orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation")); - assertEquals(operateAt.toString(), foundUpdate.getOperateAt().toString()); - assertNotNull(foundUpdate.getFinishedAt()); - assertNotEquals(finishedAt.toString(), foundUpdate.getFinishedAt().toString()); - assertEquals("test-progress", foundUpdate.getProgress()); - } + assertEquals(operateAt.toString(), foundUpdate.getOperateAt().toString()); + assertNotNull(foundUpdate.getFinishedAt()); + assertNotEquals(finishedAt.toString(), foundUpdate.getFinishedAt().toString()); + assertEquals("test-progress", foundUpdate.getProgress()); + } } diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/OperationalEnvServiceModelStatusTest.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/OperationalEnvServiceModelStatusTest.java index f1f26fa7cc..94dc777763 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/OperationalEnvServiceModelStatusTest.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/OperationalEnvServiceModelStatusTest.java @@ -21,7 +21,6 @@ package org.onap.so.db.request; import static org.junit.Assert.assertEquals; - import org.junit.Test; import org.junit.runner.RunWith; import org.onap.so.TestApplication; @@ -40,47 +39,49 @@ import org.springframework.test.context.junit4.SpringRunner; @ActiveProfiles("test") public class OperationalEnvServiceModelStatusTest { - @Autowired - private OperationalEnvServiceModelStatusRepository repository; - - - @Test - public void updateWithoutAllKeys() throws Exception { - - OperationalEnvServiceModelStatus status = new OperationalEnvServiceModelStatus(); - status.setRequestId("request-id-1"); - status.setOperationalEnvId("oper-env-id-1"); - status.setServiceModelVersionId("service-model-ver-id-1"); - status.setVnfOperationalEnvId("vnf-oper-env-id-1"); - status.setRetryCount(0); - - repository.saveAndFlush(status); - OperationalEnvServiceModelStatus status2 = repository.findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId("oper-env-id-1", "service-model-ver-id-1", "request-id-1"); - status2.setRetryCount(1); - assertEquals("request-id-1", status2.getRequestId()); - assertEquals("vnf-oper-env-id-1", status2.getVnfOperationalEnvId()); - - repository.saveAndFlush(status2); - - OperationalEnvServiceModelStatus status3 = new OperationalEnvServiceModelStatus(); + @Autowired + private OperationalEnvServiceModelStatusRepository repository; + + + @Test + public void updateWithoutAllKeys() throws Exception { + + OperationalEnvServiceModelStatus status = new OperationalEnvServiceModelStatus(); + status.setRequestId("request-id-1"); + status.setOperationalEnvId("oper-env-id-1"); + status.setServiceModelVersionId("service-model-ver-id-1"); + status.setVnfOperationalEnvId("vnf-oper-env-id-1"); + status.setRetryCount(0); + + repository.saveAndFlush(status); + OperationalEnvServiceModelStatus status2 = + repository.findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId("oper-env-id-1", + "service-model-ver-id-1", "request-id-1"); + status2.setRetryCount(1); + assertEquals("request-id-1", status2.getRequestId()); + assertEquals("vnf-oper-env-id-1", status2.getVnfOperationalEnvId()); + + repository.saveAndFlush(status2); + + OperationalEnvServiceModelStatus status3 = new OperationalEnvServiceModelStatus(); + + status3.setRequestId("request-id-2"); + status3.setOperationalEnvId("oper-env-id-1"); + status3.setServiceModelVersionId("service-model-ver-id-2"); + status3.setVnfOperationalEnvId("vnf-oper-env-id-2"); + status3.setRetryCount(2); + + repository.saveAndFlush(status3); - status3.setRequestId("request-id-2"); - status3.setOperationalEnvId("oper-env-id-1"); - status3.setServiceModelVersionId("service-model-ver-id-2"); - status3.setVnfOperationalEnvId("vnf-oper-env-id-2"); - status3.setRetryCount(2); - - repository.saveAndFlush(status3); - - OperationalEnvServiceModelStatus exampleObj = new OperationalEnvServiceModelStatus(); - exampleObj.setOperationalEnvId("oper-env-id-1"); - exampleObj.setServiceModelVersionId("service-model-ver-id-1"); - ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("requestId"); - OperationalEnvServiceModelStatus foundStatus = repository.findOne(Example.of(exampleObj,matcher)) - .orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation")); - if(foundStatus== null) - throw new Exception("No status found"); + OperationalEnvServiceModelStatus exampleObj = new OperationalEnvServiceModelStatus(); + exampleObj.setOperationalEnvId("oper-env-id-1"); + exampleObj.setServiceModelVersionId("service-model-ver-id-1"); + ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("requestId"); + OperationalEnvServiceModelStatus foundStatus = repository.findOne(Example.of(exampleObj, matcher)) + .orElseThrow(() -> new NoEntityFoundException("Cannot Find Operation")); + if (foundStatus == null) + throw new Exception("No status found"); - assertEquals(new Integer(1), foundStatus.getRetryCount()); - } + assertEquals(new Integer(1), foundStatus.getRetryCount()); + } } diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/RequestDBConfig.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/RequestDBConfig.java index 9c270d619b..26ff25833f 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/RequestDBConfig.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/RequestDBConfig.java @@ -22,11 +22,9 @@ package org.onap.so.db.request; import java.util.TimeZone; - import javax.annotation.PostConstruct; import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; - import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder; @@ -42,45 +40,35 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @Configuration @EnableTransactionManagement -@EnableJpaRepositories( - entityManagerFactoryRef = "requestEntityManagerFactory",transactionManagerRef = "requestTransactionManager", - basePackages = { "org.onap.so.db.request.data.repository" } - ) +@EnableJpaRepositories(entityManagerFactoryRef = "requestEntityManagerFactory", + transactionManagerRef = "requestTransactionManager", basePackages = {"org.onap.so.db.request.data.repository"}) public class RequestDBConfig { - @Primary - @Bean(name = "requestDataSource") - @ConfigurationProperties(prefix = "spring.datasource") - public DataSource dataSource() { - return DataSourceBuilder.create().build(); - } + @Primary + @Bean(name = "requestDataSource") + @ConfigurationProperties(prefix = "spring.datasource") + public DataSource dataSource() { + return DataSourceBuilder.create().build(); + } + + @Primary + @Bean(name = "requestEntityManagerFactory") + public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder, + @Qualifier("requestDataSource") DataSource dataSource) { + return builder.dataSource(dataSource).packages("org.onap.so.db.request.beans").persistenceUnit("requestDB") + .build(); + } - @Primary - @Bean(name = "requestEntityManagerFactory") - public LocalContainerEntityManagerFactoryBean - entityManagerFactory( - EntityManagerFactoryBuilder builder, - @Qualifier("requestDataSource") DataSource dataSource - ) { - return builder - .dataSource(dataSource) - .packages("org.onap.so.db.request.beans") - .persistenceUnit("requestDB") - .build(); - } + @Primary + @Bean(name = "requestTransactionManager") + public PlatformTransactionManager transactionManager( + @Qualifier("requestEntityManagerFactory") EntityManagerFactory entityManagerFactory) { + return new JpaTransactionManager(entityManagerFactory); + } - @Primary - @Bean(name = "requestTransactionManager") - public PlatformTransactionManager transactionManager( - @Qualifier("requestEntityManagerFactory") EntityManagerFactory - entityManagerFactory - ) { - return new JpaTransactionManager(entityManagerFactory); - } - - @PostConstruct - public void started() { - TimeZone.setDefault(TimeZone.getTimeZone("UTC")); - } + @PostConstruct + public void started() { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + } } diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/SiteStatusTest.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/SiteStatusTest.java index 1f99e92d97..93218a2057 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/SiteStatusTest.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/SiteStatusTest.java @@ -22,9 +22,7 @@ package org.onap.so.db.request; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; - import javax.transaction.Transactional; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,47 +43,45 @@ import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") public class SiteStatusTest { - - @Autowired - private SiteStatusRepository repository; - - @Test - @Transactional - public void timeStampCreated() throws InterruptedException, NoEntityFoundException { - SiteStatus found = repository.findById("test name4"). - orElseThrow(() -> new NoEntityFoundException("Cannot Find Site")); - - assertNotNull(found.getCreated()); - assertEquals("test name4", found.getSiteName()); - } - - @Test - public void sortByCreated() { - - final PageRequest page1 = new PageRequest( - 0, 20, Direction.DESC, "created" - ); - - SiteStatus example = new SiteStatus(); - example.setStatus(true); - Page<SiteStatus> found = repository.findAll(Example.of(example), page1); - - assertEquals("test name4", found.getContent().get(0).getSiteName()); - - } - - @Test - public void updateStatus() throws NoEntityFoundException { - - SiteStatus status = repository.findById("test name update"). - orElseThrow(() -> new NoEntityFoundException("Cannot Find Site")); - status.setStatus(false); - - repository.saveAndFlush(status); - status = repository.findById("test name update"). - orElseThrow(() -> new NoEntityFoundException("Cannot Find Site")); - assertEquals(false, status.getStatus()); - - } - + + @Autowired + private SiteStatusRepository repository; + + @Test + @Transactional + public void timeStampCreated() throws InterruptedException, NoEntityFoundException { + SiteStatus found = + repository.findById("test name4").orElseThrow(() -> new NoEntityFoundException("Cannot Find Site")); + + assertNotNull(found.getCreated()); + assertEquals("test name4", found.getSiteName()); + } + + @Test + public void sortByCreated() { + + final PageRequest page1 = new PageRequest(0, 20, Direction.DESC, "created"); + + SiteStatus example = new SiteStatus(); + example.setStatus(true); + Page<SiteStatus> found = repository.findAll(Example.of(example), page1); + + assertEquals("test name4", found.getContent().get(0).getSiteName()); + + } + + @Test + public void updateStatus() throws NoEntityFoundException { + + SiteStatus status = repository.findById("test name update") + .orElseThrow(() -> new NoEntityFoundException("Cannot Find Site")); + status.setStatus(false); + + repository.saveAndFlush(status); + status = repository.findById("test name update") + .orElseThrow(() -> new NoEntityFoundException("Cannot Find Site")); + assertEquals(false, status.getStatus()); + + } + } diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImplTest.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImplTest.java index 4dd500d86d..ca30604e06 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImplTest.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImplTest.java @@ -31,18 +31,15 @@ import static org.mockito.Mockito.mock; import static org.onap.so.db.request.data.repository.InfraActiveRequestsRepositoryImpl.ACTION; import static org.onap.so.db.request.data.repository.InfraActiveRequestsRepositoryImpl.REQUEST_ID; import static org.onap.so.db.request.data.repository.InfraActiveRequestsRepositoryImpl.SERVICE_INSTANCE_ID; - import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; - import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; - import org.junit.Test; import org.junit.runner.RunWith; import org.onap.so.TestApplication; @@ -94,8 +91,8 @@ public class InfraActiveRequestsRepositoryImplTest { public void test_GetInfraActiveRequests_invalidFiltersMap() { final Map<String, String[]> filters = new HashMap<>(); filters.put("OverTheMoon", new String[] {"Humpty Dumpty Sat On The Wall"}); - final List<Predicate> predicates = - objUnderTest.getPredicates(filters, mock(CriteriaBuilder.class), (Root<InfraActiveRequests>)mock(Root.class)); + final List<Predicate> predicates = objUnderTest.getPredicates(filters, mock(CriteriaBuilder.class), + (Root<InfraActiveRequests>) mock(Root.class)); assertTrue(predicates.isEmpty()); } @@ -224,8 +221,8 @@ public class InfraActiveRequestsRepositoryImplTest { assertFalse(actualRequests.isEmpty()); assertEquals(3, actualRequests.size()); - assertEquals("ShouldReturnInSearchQuery_1,ShouldReturnInSearchQuery_2,ShouldReturnInSearchQuery_3", - actualRequests.stream().map(item -> item.getServiceInstanceName()).collect(Collectors.joining(","))); + assertEquals("ShouldReturnInSearchQuery_1,ShouldReturnInSearchQuery_2,ShouldReturnInSearchQuery_3", + actualRequests.stream().map(item -> item.getServiceInstanceName()).collect(Collectors.joining(","))); } } |