From ad502b1340dc62c18ed7eb225d8d392a86cc89b6 Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Mon, 15 Jan 2018 13:00:05 +0000 Subject: Improve TC for catalog database Improve TC for catalog database. Change-Id: I698a6e6b929586c84e43266480a4a459265951ae Issue-ID: SO-360 Signed-off-by: subhash kumar singh --- .../openecomp/mso/db/catalog/CatalogDatabase.java | 6 +-- .../mso/db/catalog/test/CatalogDatabaseTest.java | 61 ++++++++++++++++++++-- 2 files changed, 61 insertions(+), 6 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 e7491b7ec7..7ac188b027 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 @@ -351,11 +351,11 @@ public class CatalogDatabase implements Closeable { */ public Service getServiceByInvariantUUID (String modelInvariantUUID) { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get service with Invariant UUID " + modelInvariantUUID); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get service with Invariant UUID " + modelInvariantUUID); String hql = "FROM Service WHERE modelInvariantUUID = :model_invariant_uuid"; - Query query = getSession ().createQuery (hql); + Query query = getSession().createQuery(hql); query.setParameter ("model_invariant_uuid", modelInvariantUUID); @SuppressWarnings("unchecked") 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 705f64c8cb..7d39dd6409 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 @@ -555,9 +555,64 @@ public class CatalogDatabaseTest { HeatEnvironment he = cd.getHeatEnvironmentByArtifactUuid("123"); } - @Test(expected = Exception.class) - public void getServiceByInvariantUUIDTestException(){ - Service ht = cd.getServiceByInvariantUUID("123"); + @Test + public void getServiceByInvariantUUIDTest(){ + + MockUp mockUpQuery = new MockUp() { + + @Mock + public List list() { + Service service = new Service(); + service.setModelUUID("123-uuid"); + return Arrays.asList(service); + } + }; + + MockUp mockedSession = new MockUp() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + Service service = cd.getServiceByInvariantUUID("123"); + assertEquals("123-uuid", service.getModelUUID()); + } + + @Test + public void getServiceByInvariantUUIDEmptyResultTest(){ + + MockUp mockUpQuery = new MockUp() { + + @Mock + public List list() { + return Arrays.asList(); + } + }; + + MockUp mockedSession = new MockUp() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + Service service = cd.getServiceByInvariantUUID("123"); + assertEquals(null, service); } @Test(expected = Exception.class) -- cgit 1.2.3-korg