diff options
author | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2018-01-19 05:45:51 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-01-19 05:45:51 +0000 |
commit | e03290040ddfa61dbff42c2830d6a9b8d7b8c613 (patch) | |
tree | da23462c952a5730aff820d103baa0e0f829706b | |
parent | 91688f6679e357eb6a1c9bccb1683fbbd3ad32c7 (diff) | |
parent | 806569f572bf2af202c7f9970fdb85ae1f7da9cd (diff) |
Merge "UT improvement for catalog db"
-rw-r--r-- | mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java | 12 | ||||
-rw-r--r-- | mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java | 56 |
2 files changed, 60 insertions, 8 deletions
diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java index 7d59d2e0ae..b5d8324872 100644 --- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java +++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java @@ -536,12 +536,12 @@ public class CatalogDatabase implements Closeable { } public Service getServiceByVersionAndInvariantId(String modelInvariantId, String modelVersion) throws Exception { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get service with modelInvariantId: " + modelInvariantId + " and modelVersion: " + modelVersion); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get service with modelInvariantId: " + modelInvariantId + " and modelVersion: " + modelVersion); String hql = "FROM Service WHERE modelInvariantUUID = :MODEL_INVARIANT_UUID AND version = :VERSION_STR"; - Query query = getSession ().createQuery (hql); - query.setParameter ("MODEL_INVARIANT_UUID", modelInvariantId); + Query query = getSession().createQuery(hql); + query.setParameter("MODEL_INVARIANT_UUID", modelInvariantId); query.setParameter("VERSION_STR", modelVersion); Service result = null; @@ -554,11 +554,11 @@ public class CatalogDatabase implements Closeable { } // See if something came back. if (result==null) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByVersionAndInvariantId", null); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByVersionAndInvariantId", null); return null; } - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByVersionAndInvariantId", null); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByVersionAndInvariantId", null); return result; } diff --git a/mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java b/mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java index 46c175c9fb..d65928f508 100644 --- a/mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java +++ b/mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java @@ -851,9 +851,61 @@ public class CatalogDatabaseTest { assertEquals(null, service); } + @Test + public void getServiceByVersionAndInvariantIdTest() throws Exception{ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + Service service = new Service(); + service.setModelUUID("123-uuid"); + return service; + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + Service service = cd.getServiceByVersionAndInvariantId("123","tetwe"); + assertEquals("123-uuid", service.getModelUUID()); + } + @Test(expected = Exception.class) - public void getServiceByVersionAndInvariantIdTestException() throws Exception{ - Service ht = cd.getServiceByVersionAndInvariantId("123","tetwe"); + public void getServiceByVersionAndInvariantIdNonUniqueResultTest() throws Exception{ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + throw new NonUniqueResultException(-1); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + Service service = cd.getServiceByVersionAndInvariantId("123","tetwe"); } @Test(expected = Exception.class) |