summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2018-01-19 05:46:23 +0000
committerGerrit Code Review <gerrit@onap.org>2018-01-19 05:46:23 +0000
commitd41ceec907809356784f6324d965f0b37a9a32a4 (patch)
treee017c96cd34b93a88c47c6d16bb40aeff7507da3
parentf9dc5780551a99937b997cd98e8ee5cc70638863 (diff)
parent2c83c8aefe45d0dd5a3486482f296de1da67b2dc (diff)
Merge "Improve UT for catalog DB"
-rw-r--r--mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java24
-rw-r--r--mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java53
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 0804d3c162..b65b6670ff 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
@@ -854,31 +854,31 @@ public class CatalogDatabase implements Closeable {
*/
public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationName (String modelCustomizationName, String modelVersionId) {
- long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " serviceModelUUID " + modelVersionId);
+ long startTime = System.currentTimeMillis();
+ LOGGER.debug("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " serviceModelUUID " + modelVersionId);
String hql = "SELECT vrc FROM VnfResourceCustomization as vrc WHERE vrc.modelCustomizationUuid IN "
+ "(SELECT src.resourceModelCustomizationUUID FROM ServiceToResourceCustomization src "
+ "WHERE src.serviceModelUUID = :modelVersionId)"
+ "AND vrc.modelInstanceName = :modelCustomizationName";
- Query query = getSession ().createQuery (hql);
- query.setParameter ("modelCustomizationName", modelCustomizationName);
- query.setParameter ("modelVersionId", modelVersionId);
+ Query query = getSession().createQuery(hql);
+ query.setParameter("modelCustomizationName", modelCustomizationName);
+ query.setParameter("modelVersionId", modelVersionId);
@SuppressWarnings("unchecked")
- List <VnfResourceCustomization> resultList = query.list ();
+ List<VnfResourceCustomization> resultList = query.list();
- if (resultList.isEmpty ()) {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null);
+ if (resultList.isEmpty()) {
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", 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", "getVnfResourceCustomizationByModelCustomizationName", null);
- return resultList.get (0);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", 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 5b595a6720..53ce265709 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
@@ -1277,9 +1277,58 @@ public class CatalogDatabaseTest {
ServiceRecipe ht = cd.getServiceRecipe(1001,"3992");
}
- @Test(expected = Exception.class)
- public void getVnfResourceCustomizationByModelCustomizationNameTestException(){
+ @Test
+ public void getVnfResourceCustomizationByModelCustomizationNameTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<VnfResourceCustomization> list() throws Exception {
+ VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
+ vnfResourceCustomization.setVnfResourceModelUUID("123-uuid");
+ return Arrays.asList(vnfResourceCustomization);
+ }
+ };
+
+ 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();
+ }
+ };
+ VnfResourceCustomization vnf = cd.getVnfResourceCustomizationByModelCustomizationName("test", "test234");
+ assertEquals("123-uuid", vnf.getVnfResourceModelUUID());
+ }
+
+ @Test
+ public void getVnfResourceCustomizationByModelCustomizationNameEmptyTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<VnfResourceCustomization> list() throws Exception {
+ 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();
+ }
+ };
VnfResourceCustomization vnf = cd.getVnfResourceCustomizationByModelCustomizationName("test", "test234");
+ assertEquals(null, vnf);
}
@Test(expected = Exception.class)