aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2019-03-13 13:27:02 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-13 13:27:02 +0000
commit934719ae963294c125eec4323e41284e5035eec3 (patch)
tree5172155c3b89f71cee0f1aa2785a72872c93da2e
parentc6c5958e9827e9ba5f4df8ca5862c3770116813d (diff)
parent3621cfaad16e698c21d4bf73e453d6158bfbd853 (diff)
Merge "db search logic/unit test now works as expected"
-rw-r--r--mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java16
-rw-r--r--mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/RequestDBConfig.java11
-rw-r--r--mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImplTest.java30
-rw-r--r--mso-api-handlers/mso-requests-db-repositories/src/test/resources/schema.sql2
4 files changed, 32 insertions, 27 deletions
diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java
index 761aaa1446..e3f15764d7 100644
--- a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java
+++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java
@@ -551,6 +551,7 @@ public class InfraActiveRequestsRepositoryImpl implements InfraActiveRequestsRep
}
try {
final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
+
final CriteriaQuery<InfraActiveRequests> criteriaQuery =
criteriaBuilder.createQuery(InfraActiveRequests.class);
final Root<InfraActiveRequests> tableRoot = criteriaQuery.from(InfraActiveRequests.class);
@@ -558,17 +559,12 @@ public class InfraActiveRequestsRepositoryImpl implements InfraActiveRequestsRep
final Timestamp minTime = new Timestamp(startTime);
final Timestamp maxTime = new Timestamp(endTime);
- predicates.add(criteriaBuilder.greaterThanOrEqualTo(tableRoot.get(START_TIME), minTime));
- predicates.add(criteriaBuilder.lessThanOrEqualTo(tableRoot.get(END_TIME), maxTime));
-
final Predicate basePredicate = criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
-
- final Predicate additionalPredicate = criteriaBuilder.and(tableRoot.get(END_TIME).isNull(),
- criteriaBuilder.greaterThanOrEqualTo(tableRoot.get(START_TIME), minTime),
- criteriaBuilder.lessThanOrEqualTo(tableRoot.get(START_TIME), maxTime));
-
- criteriaQuery.where(criteriaBuilder.or(basePredicate, additionalPredicate));
+ final Predicate additionalPredicate = criteriaBuilder.and(
+ criteriaBuilder.greaterThanOrEqualTo(tableRoot.get(START_TIME), minTime),
+ criteriaBuilder.or(tableRoot.get(END_TIME).isNull(), criteriaBuilder.lessThanOrEqualTo(tableRoot.get(END_TIME), maxTime)));
+ criteriaQuery.where(criteriaBuilder.and(basePredicate, additionalPredicate));
if (maxResult != null) {
return entityManager.createQuery(criteriaQuery).setMaxResults(maxResult).getResultList();
}
@@ -579,7 +575,7 @@ public class InfraActiveRequestsRepositoryImpl implements InfraActiveRequestsRep
}
}
- private List<Predicate> getPredicates(final Map<String, String[]> filters, final CriteriaBuilder criteriaBuilder,
+ protected List<Predicate> getPredicates(final Map<String, String[]> filters, final CriteriaBuilder criteriaBuilder,
final Root<InfraActiveRequests> tableRoot) {
final List<Predicate> predicates = new LinkedList<>();
for (final Entry<String, String[]> entry : filters.entrySet()) {
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(",")));
}
}
diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/resources/schema.sql b/mso-api-handlers/mso-requests-db-repositories/src/test/resources/schema.sql
index 3358d770e2..4ff7025dee 100644
--- a/mso-api-handlers/mso-requests-db-repositories/src/test/resources/schema.sql
+++ b/mso-api-handlers/mso-requests-db-repositories/src/test/resources/schema.sql
@@ -112,7 +112,7 @@ INSERT INTO PUBLIC.INFRA_ACTIVE_REQUESTS(REQUEST_ID, CLIENT_REQUEST_ID, ACTION,
('a1abeab2-f8ef-43ab-b76c-9c3c2cb9980f', null, 'activateInstance', 'FAILED', '2019-01-01 13:00:00', '2019-01-01 14:00:00', 'f7712652-b516-4925-a243-64550d26fd84', 'ShouldReturnInSearchQuery_3'),
('81b8e152-ee89-49f4-b82b-08b0dcae27cd', null, 'createInstance', 'COMPLETE', '2019-01-01 14:10:00', '2019-01-01 15:00:00', 'f7712652-b516-4925-a243-64550d26fd84', 'SHOULD_NOT_RETURN_1'),
('0c28cad2-ff79-4dfa-a04a-9e44996fd7f7', null, 'createInstance', 'IN_PROGRESS', '2019-01-01 13:30:00', '2019-01-01 15:00:00', 'f7712652-b516-4925-a243-64550d26fd84', 'SHOULD_NOT_RETURN_2'),
-('d0d995a7-549b-4e7e-9101-2bab17ec24ea', null, 'createInstance', 'IN_PROGRESS', '2019-01-01 14:15:00', null, 'f7712652-b516-4925-a243-64550d26fd84', 'SHOULD_NOT_RETURN_3');
+('d0d995a7-549b-4e7e-9101-2bab17ec24ea', null, 'createInstance', 'IN_PROGRESS', '2019-01-01 11:15:00', null, 'f7712652-b516-4925-a243-64550d26fd84', 'SHOULD_NOT_RETURN_3');
CREATE CACHED TABLE PUBLIC.ARCHIVED_INFRA_REQUESTS(
REQUEST_ID VARCHAR NOT NULL SELECTIVITY 100,