diff options
author | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2018-01-19 05:46:06 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-01-19 05:46:06 +0000 |
commit | d56c590e00ad8c773fcb4ab815880027dc7cf698 (patch) | |
tree | eb75cc8b444ad1dfe7af817cc76387cae7ecec30 /mso-catalog-db | |
parent | e365ccf60763693611c45e75b287c38b551866f8 (diff) | |
parent | 487482d147a46e237b6f4f8c1ae07762e3f49b05 (diff) |
Merge "UT improvement for catalog DB"
Diffstat (limited to 'mso-catalog-db')
-rw-r--r-- | mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java | 22 | ||||
-rw-r--r-- | mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java | 55 |
2 files changed, 63 insertions, 14 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 d1e91f39b7..079d105dd4 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 @@ -733,26 +733,26 @@ public class CatalogDatabase implements Closeable { */ public VnfResource getVnfResource (String vnfType) { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get vnf resource with model_name " + vnfType); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get vnf resource with model_name " + vnfType); String hql = "FROM VnfResource WHERE modelName = :vnf_name"; - Query query = getSession ().createQuery (hql); - query.setParameter ("vnf_name", vnfType); + Query query = getSession().createQuery(hql); + query.setParameter("vnf_name", vnfType); @SuppressWarnings("unchecked") - List <VnfResource> resultList = query.list (); + List <VnfResource> resultList = query.list(); // See if something came back. Name is unique, so - if (resultList.isEmpty ()) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF not found", "CatalogDB", "getVnfResource", null); + if (resultList.isEmpty()) { + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF not found", "CatalogDB", "getVnfResource", null); return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); - Collections.reverse (resultList); + Collections.sort(resultList, new MavenLikeVersioningComparator()); + Collections.reverse(resultList); - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null); - return resultList.get (0); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null); + return resultList.get(0); } /** 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 445ca12892..cad4093936 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 @@ -1026,9 +1026,58 @@ public class CatalogDatabaseTest { VnfComponent ht = cd.getVnfComponent(123,"vnf"); } - @Test(expected = Exception.class) - public void getVnfResourceTestException() throws Exception{ - VnfResource ht = cd.getVnfResource("vnf"); + @Test + public void getVnfResourceTest() throws Exception{ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VnfResource> list() { + VnfResource vnfResource = new VnfResource(); + vnfResource.setModelUuid("123-uuid"); + return Arrays.asList(vnfResource); + } + }; + + 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(); + } + }; + VnfResource vnfResource = cd.getVnfResource("vnf"); + assertEquals("123-uuid", vnfResource.getModelUuid()); + } + + @Test + public void getVnfResourceEmptyTest() throws Exception{ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VnfResource> list() { + return Arrays.asList(); + } + }; + + 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(); + } + }; + VnfResource vnfResource = cd.getVnfResource("vnf"); + assertEquals(null, vnfResource); } @Test(expected = Exception.class) |