diff options
author | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2019-03-09 11:10:18 -0500 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2019-03-09 11:10:18 -0500 |
commit | 3621cfaad16e698c21d4bf73e453d6158bfbd853 (patch) | |
tree | a3c10a688f7c103fcfe9582b3de6880d45313878 /mso-api-handlers/mso-requests-db-repositories/src/test/java | |
parent | e77d365050c7a465278908f7774464ee8095f4a1 (diff) |
db search logic/unit test now works as expected
modified search predicate to inclue null or endtime
do not duplicate time boundaries in predicate
Change-Id: I5a3b0f323c0e08717419669a8b2a11461ca2b990
Issue-ID: SO-1615
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-api-handlers/mso-requests-db-repositories/src/test/java')
2 files changed, 25 insertions, 16 deletions
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 9026571720..9c270d619b 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 @@ -21,11 +21,15 @@ 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.jdbc.DataSourceBuilder; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -73,5 +77,10 @@ public class RequestDBConfig { ) { return new JpaTransactionManager(entityManagerFactory); } + + @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/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 def999b556..4dd500d86d 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 @@ -19,11 +19,15 @@ */ package org.onap.so.db.request.data.repository; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +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; @@ -33,6 +37,11 @@ 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; @@ -43,7 +52,6 @@ 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") @@ -73,7 +81,7 @@ public class InfraActiveRequestsRepositoryImplTest { private static final String SERVICE_INSTANCE_ID_VALUE = "e3b5744d-2ad1-4cdd-8390-c999a38829bc"; @Autowired - private InfraActiveRequestsRepository objUnderTest; + private InfraActiveRequestsRepositoryImpl objUnderTest; @Test public void test_GetInfraActiveRequests_emptyFiltersMap() { @@ -86,11 +94,9 @@ 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 long startTime = START_TIME_IN_MILISEC - TimeUnit.DAYS.toMillis(20); - final long endTime = END_TIME_IN_MILISEC - TimeUnit.DAYS.toMillis(20); - final List<InfraActiveRequests> actualRequests = - objUnderTest.getInfraActiveRequests(filters, startTime, endTime, null); - assertTrue(actualRequests.isEmpty()); + final List<Predicate> predicates = + objUnderTest.getPredicates(filters, mock(CriteriaBuilder.class), (Root<InfraActiveRequests>)mock(Root.class)); + assertTrue(predicates.isEmpty()); } @Test @@ -218,14 +224,8 @@ public class InfraActiveRequestsRepositoryImplTest { assertFalse(actualRequests.isEmpty()); assertEquals(3, actualRequests.size()); - final Map<String, InfraActiveRequests> result = new HashMap<>(); - for (final InfraActiveRequests actualActiveRequests : actualRequests) { - result.put(actualActiveRequests.getRequestId(), actualActiveRequests); - - } - final InfraActiveRequests actualInfraActiveRequests = result.get("9383dc81-7a6c-4673-8082-650d50a82a1a"); - assertNull(actualInfraActiveRequests.getEndTime()); - assertEquals("IN_PROGRESS", actualInfraActiveRequests.getRequestStatus()); + assertEquals("ShouldReturnInSearchQuery_1,ShouldReturnInSearchQuery_2,ShouldReturnInSearchQuery_3", + actualRequests.stream().map(item -> item.getServiceInstanceName()).collect(Collectors.joining(","))); } } |