aboutsummaryrefslogtreecommitdiffstats
path: root/mso-catalog-db/src
diff options
context:
space:
mode:
Diffstat (limited to 'mso-catalog-db/src')
-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.java55
2 files changed, 64 insertions, 15 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 0219e304cb..0efcb484cb 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
@@ -958,28 +958,28 @@ public class CatalogDatabase implements Closeable {
* Return the newest version of a vfModule - 1607
*
*/
- public VfModule getVfModuleModelName (String modelName) {
+ public VfModule getVfModuleModelName(String modelName) {
- long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get vfModuleModelName with name " + modelName);
+ long startTime = System.currentTimeMillis();
+ LOGGER.debug("Catalog database - get vfModuleModelName with name " + modelName);
String hql = "FROM VfModule WHERE modelName = :model_name";
- Query query = getSession ().createQuery (hql);
- query.setParameter ("model_name", modelName);
+ Query query = getSession().createQuery(hql);
+ query.setParameter("model_name", modelName);
@SuppressWarnings("unchecked")
- List <VfModule> resultList = query.list ();
+ List<VfModule> 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. VF not found", "CatalogDB", "getVfModuleModelName", null);
+ if (resultList.isEmpty()) {
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleModelName", 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", "getVfModuleModelName", null);
- return resultList.get (0);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
+ return resultList.get(0);
}
public VfModule getVfModuleModelName (String modelName, String model_version) {
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 219e70ea87..2ec75d7582 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
@@ -1443,9 +1443,58 @@ public class CatalogDatabaseTest {
VnfResource vnf = cd.getVnfResourceById(19299);
}
- @Test(expected = Exception.class)
- public void getVfModuleModelNameTestException(){
- VfModule vnf = cd.getVfModuleModelName("tetes");
+ @Test
+ public void getVfModuleModelName(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<VfModule> list() throws Exception {
+ VfModule vfModule = new VfModule();
+ vfModule.setModelUUID("123-uuid");
+ return Arrays.asList(vfModule);
+ }
+ };
+
+ 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();
+ }
+ };
+ VfModule vfModule = cd.getVfModuleModelName("vfmodule");
+ assertEquals("123-uuid", vfModule.getModelUUID());
+ }
+
+ @Test
+ public void getVfModuleModelNameExceptionTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<VfModule> 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();
+ }
+ };
+ VfModule vfModule = cd.getVfModuleModelName("vfmodule");
+ assertEquals(null, vfModule);
}
@Test(expected = Exception.class)