aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml2
-rw-r--r--asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java26
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java3
-rw-r--r--bpmn/MSOCoreBPMN/pom.xml7
-rw-r--r--bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/JsonUtilsTest.java438
-rw-r--r--bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/TestBaseTask.java1
-rw-r--r--bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/utils/CamundaDBSetup.java (renamed from bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/CamundaDBSetup.java)5
-rw-r--r--mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java184
-rw-r--r--mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/NetworkResource.java38
-rw-r--r--mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/Service.java19
-rw-r--r--mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/VnfResource.java36
-rw-r--r--mso-catalog-db/src/main/resources/NetworkResource.hbm.xml2
-rw-r--r--mso-catalog-db/src/main/resources/Service.hbm.xml1
-rw-r--r--mso-catalog-db/src/main/resources/VnfResource.hbm.xml2
-rw-r--r--mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java733
15 files changed, 1113 insertions, 384 deletions
diff --git a/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml b/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml
index cd97471b5b..66ea46fcc9 100644
--- a/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml
+++ b/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml
@@ -16,7 +16,7 @@
</context-param>
<context-param>
<param-name>mso.configuration</param-name>
- <param-value>MSO_PROP_NETWORK_ADAPTER=mso.vfc.properties,MSO_PROP_TOPOLOGY=topology.properties</param-value>
+ <param-value>MSO_PROP_VFC_ADAPTER=mso.vfc.properties,MSO_PROP_TOPOLOGY=topology.properties</param-value>
</context-param>
<context-param>
<param-name>mso.cloud_config.configuration</param-name>
diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java
index 390bf40e44..b998be9a69 100644
--- a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java
+++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java
@@ -563,7 +563,10 @@ public class ToscaResourceInstaller {// implements IVfResourceInstaller {
createNetworkResource(vlNode, toscaResourceStruct, networkHeatTemplateLookup.get(0));
} else {
- throw new ArtifactInstallerException("No NetworkResourceName found in TempNetworkHeatTemplateLookup for " + networkResourceModelName);
+ logger.info(MessageEnum.ASDC_GENERAL_INFO,
+ "No NetworkResourceName found in TempNetworkHeatTemplateLookup for" + networkResourceModelName, "ASDC",
+ "createVfModuleStructures");
+ createNetworkResource(vlNode, toscaResourceStruct, null);
}
@@ -787,6 +790,7 @@ public class ToscaResourceInstaller {// implements IVfResourceInstaller {
service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
//service.setVersion(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
+ service.setCategory(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
service.setToscaCsarArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID());
//service.setCreated(getCurrentTimeStamp());
}
@@ -831,11 +835,16 @@ public class ToscaResourceInstaller {// implements IVfResourceInstaller {
networkResource.setModelVersion(testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
networkResource.setAicVersionMax(testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
- networkResource.setAicVersionMin(networkHeatTemplateLookup.getAicVersionMin());
+ String aicVersionMin = networkHeatTemplateLookup != null ? networkHeatTemplateLookup.getAicVersionMin() : "2.5";
+ networkResource.setAicVersionMin(aicVersionMin);
networkResource.setToscaNodeType(networkNodeTemplate.getType());
networkResource.setDescription(testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
networkResource.setOrchestrationMode("HEAT");
- networkResource.setHeatTemplateArtifactUUID(networkHeatTemplateLookup.getHeatTemplateArtifactUuid());
+ networkResource.setCategory(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
+ networkResource.setSubCategory(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
+ //for tosca NS ,there is no heat for network VL
+ String heatTemplateArtifactUUID = networkHeatTemplateLookup != null ? networkHeatTemplateLookup.getHeatTemplateArtifactUuid() : "null";
+ networkResource.setHeatTemplateArtifactUUID(heatTemplateArtifactUUID);
toscaResourceStructure.setCatalogNetworkResource(networkResource);
@@ -1019,11 +1028,12 @@ public class ToscaResourceInstaller {// implements IVfResourceInstaller {
vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType()));
vnfResource.setAicVersionMax(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES).trim()));
vnfResource.setAicVersionMin(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES).trim()));
- //vnfResource.setHeatTemplateArtifactUUId(toscaResourceStructure.getHeatTemplateUUID());
-
- // vfNodeTemplate.getProperties()
- toscaResourceStructure.setCatalogVnfResource(vnfResource);
-
+ // vnfResource.setHeatTemplateArtifactUUId(toscaResourceStructure.getHeatTemplateUUID());
+ vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
+ vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
+ // vfNodeTemplate.getProperties()
+ toscaResourceStructure.setCatalogVnfResource(vnfResource);
+
VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
vnfResourceCustomization.setModelCustomizationUuid(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).trim()));
vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName());
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java
index 15dc4f4609..ce8eb7afec 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/WorkflowTest.java
@@ -61,7 +61,6 @@ import org.custommonkey.xmlunit.DetailedDiff;
import org.custommonkey.xmlunit.XMLUnit;
import org.jboss.resteasy.spi.AsynchronousResponse;
import org.json.JSONArray;
-import org.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
import org.openecomp.mso.bpmn.common.adapter.sdnc.CallbackHeader;
@@ -78,7 +77,7 @@ import org.openecomp.mso.bpmn.common.workflow.service.VnfAdapterNotifyServiceImp
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowAsyncResource;
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowMessageResource;
import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
-import org.openecomp.mso.bpmn.core.CamundaDBSetup;
+import org.openecomp.mso.bpmn.core.utils.CamundaDBSetup;
import org.openecomp.mso.bpmn.core.PropertyConfigurationSetup;
import org.openecomp.mso.bpmn.core.domain.Resource;
import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition;
diff --git a/bpmn/MSOCoreBPMN/pom.xml b/bpmn/MSOCoreBPMN/pom.xml
index 6884c1e33b..267f175533 100644
--- a/bpmn/MSOCoreBPMN/pom.xml
+++ b/bpmn/MSOCoreBPMN/pom.xml
@@ -158,9 +158,10 @@
<version>20160212</version>
</dependency>
<dependency>
- <groupId>xmlunit</groupId>
- <artifactId>xmlunit</artifactId>
- <version>1.6</version>
+ <groupId>org.xmlunit</groupId>
+ <artifactId>xmlunit-core</artifactId>
+ <version>2.5.1</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.openecomp.so</groupId>
diff --git a/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/JsonUtilsTest.java b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/JsonUtilsTest.java
index 7f922ce30e..58f1ae264d 100644
--- a/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/JsonUtilsTest.java
+++ b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/JsonUtilsTest.java
@@ -36,26 +36,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- */
+ */
package org.openecomp.mso.bpmn.core;
-import java.io.BufferedReader;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.CharBuffer;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import org.junit.BeforeClass;
import org.junit.Test;
-import org.xml.sax.SAXException;
-import org.custommonkey.xmlunit.Diff;
-
import org.openecomp.mso.bpmn.core.json.JsonUtils;
import org.openecomp.mso.bpmn.core.xml.XmlTool;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.diff.DefaultNodeMatcher;
+import org.xmlunit.diff.Diff;
+import org.xmlunit.diff.ElementSelectors;
/**
* @version 1.0
@@ -63,8 +61,8 @@ import org.openecomp.mso.bpmn.core.xml.XmlTool;
public class JsonUtilsTest {
private static final String EOL = "\n";
- private String xmlReq =
- "<vnf-request xmlns=\"http://org.openecomp/mso/infra/vnf-request/v1\">" + EOL +
+ private static final String XML_REQ =
+ "<vnf-request xmlns=\"http://org.openecomp/mso/infra/vnf-request/v1\">" + EOL +
" <request-info>" + EOL +
" <request-id>DEV-VF-0021</request-id>" + EOL +
" <action>CREATE_VF_MODULE</action>" + EOL +
@@ -93,9 +91,9 @@ public class JsonUtilsTest {
" <param name=\"server\">server1111</param>" + EOL +
" </vnf-params> " + EOL +
"</vnf-request>" + EOL;
-
- private String xmlReqNoAttrs =
- "<vnf-request xmlns=\"http://org.openecomp/mso/infra/vnf-request/v1\">" + EOL +
+
+ private static final String XML_REQ_NO_ATTRS =
+ "<vnf-request xmlns=\"http://org.openecomp/mso/infra/vnf-request/v1\">" + EOL +
" <request-info>" + EOL +
" <action>DELETE_VF_MODULE</action>" + EOL +
" <source>PORTAL</source>" + EOL +
@@ -115,246 +113,214 @@ public class JsonUtilsTest {
" <vnf-params xmlns:tns=\"http://org.openecomp/mso/infra/vnf-request/v1\"/>" + EOL +
"</vnf-request>" + EOL;
- private String xmlArrayReq =
- "<ucpeInfo>" + EOL +
+ private static final String XML_ARRAY_REQ =
+ "<ucpeInfo>" + EOL +
" <outOfBandManagementModem>BROADBAND</outOfBandManagementModem>" + EOL +
- " <internetTopology>IVLAN</internetTopology>" + EOL +
- " <ucpeAliasHostName>SHELLUCPE31</ucpeAliasHostName>" + EOL +
- " <wanList>" + EOL +
- " <wanInfo>" + EOL +
- " <wanType>AVPN</wanType>" + EOL +
- " <interfaceType>1000BASE-T</interfaceType>" + EOL +
- " <transportProviderName>ATT</transportProviderName>" + EOL +
- " <circuitId>BT/SLIR/70911</circuitId>" + EOL +
- " <dualMode>Active</dualMode>" + EOL +
- " <wanPortNumber>WAN1</wanPortNumber>" + EOL +
- " <transportManagementOption>ATT</transportManagementOption>" + EOL +
- " <transportVendorTotalBandwidth>100</transportVendorTotalBandwidth>" + EOL +
- " <mediaType>ELECTRICAL</mediaType>" + EOL +
- " </wanInfo>" + EOL +
- " <wanInfo>" + EOL +
- " <wanType>AVPN</wanType>" + EOL +
- " <interfaceType>10/100/1000BASE-T</interfaceType>" + EOL +
- " <transportProviderName>ATT</transportProviderName>" + EOL +
- " <circuitId>AS/KRFN/34611</circuitId>" + EOL +
- " <dualMode>Active</dualMode>" + EOL +
- " <wanPortNumber>WAN2</wanPortNumber>" + EOL +
- " <transportManagementOption>ATT</transportManagementOption>" + EOL +
- " <transportVendorTotalBandwidth>10000</transportVendorTotalBandwidth>" + EOL +
- " <mediaType>MMF</mediaType>" + EOL +
- " </wanInfo>" + EOL +
- " </wanList>" + EOL +
- " <ucpeActivationCode>ASD-987-M31</ucpeActivationCode>" + EOL +
- " <ucpeHostName>USOSTCDALTX0101UJZZ31</ucpeHostName>" + EOL +
- " <ucpePartNumber>FG-VM00*</ucpePartNumber>" + EOL +
+ " <internetTopology>IVLAN</internetTopology>" + EOL +
+ " <ucpeAliasHostName>SHELLUCPE31</ucpeAliasHostName>" + EOL +
+ " <wanList>" + EOL +
+ " <wanInfo>" + EOL +
+ " <wanType>AVPN</wanType>" + EOL +
+ " <interfaceType>1000BASE-T</interfaceType>" + EOL +
+ " <transportProviderName>ATT</transportProviderName>" + EOL +
+ " <circuitId>BT/SLIR/70911</circuitId>" + EOL +
+ " <dualMode>Active</dualMode>" + EOL +
+ " <wanPortNumber>WAN1</wanPortNumber>" + EOL +
+ " <transportManagementOption>ATT</transportManagementOption>" + EOL +
+ " <transportVendorTotalBandwidth>100</transportVendorTotalBandwidth>" + EOL +
+ " <mediaType>ELECTRICAL</mediaType>" + EOL +
+ " </wanInfo>" + EOL +
+ " <wanInfo>" + EOL +
+ " <wanType>AVPN</wanType>" + EOL +
+ " <interfaceType>10/100/1000BASE-T</interfaceType>" + EOL +
+ " <transportProviderName>ATT</transportProviderName>" + EOL +
+ " <circuitId>AS/KRFN/34611</circuitId>" + EOL +
+ " <dualMode>Active</dualMode>" + EOL +
+ " <wanPortNumber>WAN2</wanPortNumber>" + EOL +
+ " <transportManagementOption>ATT</transportManagementOption>" + EOL +
+ " <transportVendorTotalBandwidth>10000</transportVendorTotalBandwidth>" + EOL +
+ " <mediaType>MMF</mediaType>" + EOL +
+ " </wanInfo>" + EOL +
+ " </wanList>" + EOL +
+ " <ucpeActivationCode>ASD-987-M31</ucpeActivationCode>" + EOL +
+ " <ucpeHostName>USOSTCDALTX0101UJZZ31</ucpeHostName>" + EOL +
+ " <ucpePartNumber>FG-VM00*</ucpePartNumber>" + EOL +
"</ucpeInfo>";
// JSON request w/ embedded XML will be read from a file
- private String jsonReq = null;
- private String jsonReqArray = null;
-
- @Before
- public void initialize() {
- File file = new File("src/test/resources/request.json");
- File file2 = new File("src/test/resources/requestArray.json");
- FileInputStream fis = null;
+ private static String jsonReq;
+ private static String jsonReqArray;
+
+ @BeforeClass
+ public static void initialize() throws Exception {
+ jsonReq = readFileToString("src/test/resources/request.json");
+ jsonReqArray = readFileToString("src/test/resources/requestArray.json");
+ }
- try {
- fis = new FileInputStream(file);
- BufferedReader br = new BufferedReader(new InputStreamReader(fis));
- CharBuffer cbuf = CharBuffer.allocate((int)file.length()+1);
- br.read(cbuf);
- cbuf.flip();
- jsonReq = cbuf.toString();
- if (jsonReq != null) {
- System.out.println("initialize(): json request: " + jsonReq);
- } else {
- System.out.println("initialize(): failed to read json request from src/test/resources/request.json");
- }
- fis.close();
- fis = new FileInputStream(file2);
- br = new BufferedReader(new InputStreamReader(fis));
- cbuf = CharBuffer.allocate((int)file.length()+1);
- br.read(cbuf);
- cbuf.flip();
- jsonReqArray = cbuf.toString();
- if (jsonReq != null) {
- System.out.println("initialize(): json request w/ array: " + jsonReqArray);
- } else {
- System.out.println("initialize(): failed to read json request from src/test/resources/request2.json");
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- if (fis != null)
- fis.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
+ private static String readFileToString(String path) throws IOException {
+ File file = new File(path);
+ return new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
}
-
- @After
- public void cleanup(){
+
+ @Test
+ public void shouldConvertXmlToJsonAndBackToSameXml() throws Exception {
+ // Note: the current version of the JsonUtils.json2xml() method
+ // does not support converting the JSONObject representation
+ // of XML attributes (JSONArray) back to XML. So this test will
+ // only succeed if the original XML does not contain attributes
+
+ // given
+ String xmlIn = XmlTool.removeNamespaces(XML_REQ_NO_ATTRS);
+ // when
+ String json = JsonUtils.xml2json(XML_REQ_NO_ATTRS);
+ String xmlOut = JsonUtils.json2xml(json);
+ // then
+ Diff diffXml = DiffBuilder.compare(xmlIn).withTest(xmlOut).ignoreWhitespace()
+ .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName)).checkForSimilar().build();
+
+ assertThat(diffXml.hasDifferences()).withFailMessage(diffXml.toString()).isFalse();
}
@Test
-// @Ignore
- public void testConversion() {
- // Note: the current version of the JsonUtils.json2xml() method
- // does not support converting the JSONObject representation
- // of XML attributes (JSONArray) back to XML. So this test will
- // only succeed if the original XML does not contain attributes
-
- // save a copy of the xml with the namespaces removed
- String xmlIn = XmlTool.removeNamespaces(xmlReqNoAttrs);
- // strip all the non-data whitespace
- xmlIn = xmlIn.replaceAll(">\\s*<", "><");
- String json = JsonUtils.xml2json(xmlReqNoAttrs);
- System.out.println("testConversion(): xml request to json: " + json);
- String xmlOut = JsonUtils.json2xml(json);
- System.out.println("testConversion(): json request back to xml: " + xmlOut);
-
- // strip all the non-data whitespace
- xmlOut = xmlOut.replaceAll(">\\s*<", "><");
+ public void shouldReadValuesForAbsoluteJsonPaths() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ // when, then
+ assertThat(JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.vnf-name")).isEqualTo("STMTN5MMSC21");
+ assertThat(JsonUtils.getJsonValue(json, "vnf-request.request-info.action")).isEqualTo("CREATE_VF_MODULE");
+ assertThat(JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.persona-model-version")).isEqualTo("1");
+ assertThat(JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.vnf-persona-model-version")).isEqualTo("1.5");
+ assertThat(JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.is-base-module")).isEqualTo("true");
+ }
- Diff diffXml;
- try {
- diffXml = new Diff(xmlIn, xmlOut);
- Assert.assertTrue(diffXml.similar());
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ @Test
+ public void shouldReturnValueForJsonKey() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ // when, then
+ assertThat(JsonUtils.getJsonValueForKey(json, "source")).isEqualTo("PORTAL");
}
@Test
-// @Ignore
- public void testRetrieval() {
- String json = JsonUtils.xml2json(xmlReq);
- System.out.println("testRetrieval(): xml request to json: " + json);
- // full JSON path
- String value = JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.vnf-name");
- Assert.assertEquals(value, "STMTN5MMSC21");
- value = JsonUtils.getJsonValue(json, "vnf-request.request-info.action");
- Assert.assertEquals(value, "CREATE_VF_MODULE");
- // retrieving an integer
- value = JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.persona-model-version");
- Assert.assertEquals(value, "1");
- // retrieving a float
- value = JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.vnf-persona-model-version");
- Assert.assertEquals(value, "1.5");
- // retrieving a boolean
- value = JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.is-base-module");
- Assert.assertEquals(value, "true");
- // attempt to retrieve a value for a non-existent field
- value = JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.bad");
- Assert.assertEquals(value, null);
- // retrieving a parameter/array value (originally a XML attribute)
- value = JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "name");
- Assert.assertEquals(value, "network");
- value = JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "content");
- Assert.assertEquals(value, "network1111");
- // retrieving a parameter/array value by index
- value = JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "content", 1);
- Assert.assertEquals(value, "server1111");
- value = JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "name", 1);
- Assert.assertEquals(value, "server");
- // failure due to invalid parameter name
- value = JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "badParam");
- Assert.assertEquals(value, null);
- // failure due to array index out of bounds
- value = JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "name", 2);
- Assert.assertEquals(value, null);
- // by field name/key
- value = JsonUtils.getJsonValueForKey(json, "source");
- Assert.assertEquals(value, "PORTAL");
- value = JsonUtils.getJsonValueForKey(json, "vnf-module");
- Assert.assertEquals(value, null);
+ public void shouldReturnNullForNonexistentJsonNode() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ // when, then
+ assertThat(JsonUtils.getJsonValueForKey(json, "nonexistent-node")).isNull();
}
@Test
-// @Ignore
- public void testUpdate() {
- String json = JsonUtils.xml2json(xmlReq);
- System.out.println("testUpdate(): xml request to json: " + json);
- // the add should be successful
- String jsonUpd = JsonUtils.addJsonValue(json, "vnf-request.request-info.comment", "Some comment");
- String value = JsonUtils.getJsonValue(jsonUpd, "vnf-request.request-info.comment");
- Assert.assertEquals(value, "Some comment");
- // the add should be ignored as the field already exists
- jsonUpd = JsonUtils.addJsonValue(jsonUpd, "vnf-request.vnf-inputs.vnf-name", "STMTN5MMSC22");
- value = JsonUtils.getJsonValue(jsonUpd, "vnf-request.vnf-inputs.vnf-name");
- Assert.assertEquals(value, "STMTN5MMSC21");
- // the update should be successful
- jsonUpd = JsonUtils.updJsonValue(jsonUpd, "vnf-request.vnf-inputs.vnf-name", "STMTN5MMSC22");
- value = JsonUtils.getJsonValue(jsonUpd, "vnf-request.vnf-inputs.vnf-name");
- Assert.assertEquals(value, "STMTN5MMSC22");
- // the delete should be successful
- jsonUpd = JsonUtils.delJsonValue(jsonUpd, "vnf-request.request-info.comment");
- value = JsonUtils.getJsonValue(jsonUpd, "vnf-request.request-info.comment");
- Assert.assertEquals(value, null);
- // the delete should fail as field 'vnf-model' does not exist
- String jsonCur = jsonUpd;
- jsonUpd = JsonUtils.delJsonValue(jsonUpd, "vnf-request.vnf-inputs.vnf-module");
- Assert.assertEquals(jsonCur, jsonUpd);
+ public void shouldReturnNullForNonExistentParameter() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ // when, then
+ assertThat(JsonUtils.getJsonValue(json, "vnf-request.vnf-inputs.bad")).isNull();
}
-
+
@Test
-// @Ignore
- public void testEmbededXmlRetrievalConversion() {
- try {
- // extract the embedded XML from the request
- String value = JsonUtils.getJsonValue(jsonReq, "variables.bpmnRequest.value");
- String xmlReq = XmlTool.removeNamespaces(XmlTool.normalize(value));
- System.out.println("testEmbededXmlRetrievalConversion(): xml payload: " + xmlReq);
- String json = JsonUtils.xml2json(xmlReq);
- System.out.println("testEmbededXmlRetrievalConversion(): xml request to json: " + json);
- String xmlOut = JsonUtils.json2xml(json);
- System.out.println("testEmbededXmlRetrievalConversion(): json request back to xml: " + xmlOut);
- Diff diffXml;
- try {
- // compare the XML before and after
- diffXml = new Diff(xmlReq, xmlOut);
- Assert.assertTrue(diffXml.similar());
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
+ public void shouldGetJasonParametersFromArray() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ // when, then
+ assertThat(JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "name")).isEqualTo("network");
+ assertThat(JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "content"))
+ .isEqualTo("network1111");
+ assertThat(JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "name", 1)).isEqualTo("server");
+ assertThat(JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "content", 1))
+ .isEqualTo("server1111");
+ assertThat(JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "badParam"))
+ .withFailMessage("Expected null for nonexistent param").isNull();
+ assertThat(JsonUtils.getJsonParamValue(json, "vnf-request.vnf-params.param", "name", 2))
+ .withFailMessage("Expected null for index out of bound").isNull();
}
@Test
-// @Ignore
- // Tests the conversion of a JSON Doc containing a JSON Array to XML
- public void testConversionArray() {
- try {
- String jsonParm = JsonUtils.getJsonNodeValue(jsonReqArray, "requestDetails.requestParameters.ucpeInfo");
- System.out.println("testConversionArray(): json value: " + JsonUtils.prettyJson(jsonParm));
- String xmlOut = JsonUtils.json2xml(jsonParm);
- System.out.println("testConversionArray(): json parameters to xml: " + xmlOut);
- // strip all the non-data whitespace
- xmlOut = xmlOut.replaceAll(">\\s*<", "><");
- System.out.println("testConversionArray(): XML after removing whitespace:" + xmlOut);
- String xmlTest = xmlArrayReq.replaceAll(">\\s*<", "><");
+ public void shouldAddJsonValue() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ String key = "vnf-request.request-info.comment";
+ String value = "Some comment";
+ // when
+ String jsonUpd = JsonUtils.addJsonValue(json, key, value);
+ // then
+ String extractedValue = JsonUtils.getJsonValue(jsonUpd, key);
+ assertThat(extractedValue).isEqualTo(value);
+ }
- Diff diffXml;
- try {
- diffXml = new Diff(xmlTest, xmlOut);
- Assert.assertTrue(diffXml.similar());
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
+ @Test
+ public void shouldIgnoreAddIfFieldAlreadyExists() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ String key = "vnf-request.vnf-inputs.vnf-name";
+ String newValue = "STMTN5MMSC22";
+ String oldValue = JsonUtils.getJsonValue(json, key);
+ // when
+ String jsonUpd = JsonUtils.addJsonValue(json, key, newValue);
+ // then
+ String extractedValue = JsonUtils.getJsonValue(jsonUpd, key);
+ assertThat(extractedValue).isEqualTo(oldValue).isNotEqualTo(newValue);
+ }
+
+ @Test
+ public void shouldUpdateValueInJson() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ String key = "vnf-request.vnf-inputs.vnf-name";
+ String newValue = "STMTN5MMSC22";
+ String oldValue = JsonUtils.getJsonValue(json, key);
+ // when
+ String jsonUpd = JsonUtils.updJsonValue(json, key, newValue);
+ // then
+ String extractedValue = JsonUtils.getJsonValue(jsonUpd, key);
+ assertThat(extractedValue).isNotEqualTo(oldValue).isEqualTo(newValue);
+ }
+
+ @Test
+ public void shouldDeleteValue() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ String key = "vnf-request.vnf-inputs.vnf-name";
+ String oldValue = JsonUtils.getJsonValue(json, key);
+ // when
+ String jsonUpd = JsonUtils.delJsonValue(json, key);
+ // then
+ String extractedValue = JsonUtils.getJsonValue(jsonUpd, key);
+ assertThat(extractedValue).isNotEqualTo(oldValue).isNull();
+ }
+
+ @Test
+ public void shouldReturnOriginalJsonWhenTryingToRemoveNonexistentField() throws Exception {
+ // given
+ String json = JsonUtils.xml2json(XML_REQ);
+ String key = "vnf-request.vnf-inputs.does-not-exist";
+ // when
+ String jsonUpd = JsonUtils.delJsonValue(json, key);
+ // then
+ assertThat(jsonUpd).isEqualTo(json);
+ }
+
+ @Test
+ public void shouldConvertXmlToJsonAndBackToSameXmlExtractedFromTheRequest() throws Exception {
+ // given
+ String value = JsonUtils.getJsonValue(jsonReq, "variables.bpmnRequest.value");
+ String xmlReq = XmlTool.removeNamespaces(XmlTool.normalize(value));
+ // when
+ String json = JsonUtils.xml2json(xmlReq);
+ String xmlOut = JsonUtils.json2xml(json);
+ // then
+ Diff diffXml = DiffBuilder.compare(xmlReq).withTest(xmlOut).ignoreWhitespace()
+ .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName)).checkForSimilar().build();
+ assertThat(diffXml.hasDifferences()).withFailMessage(diffXml.toString()).isFalse();
+ }
+
+ @Test
+ public void shouldConvertJsonContainingArrayToXml() throws Exception {
+ // when
+ String jsonParm = JsonUtils.getJsonNodeValue(jsonReqArray, "requestDetails.requestParameters.ucpeInfo");
+ String xmlOut = JsonUtils.json2xml(jsonParm);
+ // then
+ Diff diffXml = DiffBuilder.compare(XML_ARRAY_REQ).withTest(xmlOut).ignoreWhitespace()
+ .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName)).checkForSimilar().build();
+ assertThat(diffXml.hasDifferences()).withFailMessage(diffXml.toString()).isFalse();
}
}
diff --git a/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/TestBaseTask.java b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/TestBaseTask.java
index 862cb76146..9730b129be 100644
--- a/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/TestBaseTask.java
+++ b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/TestBaseTask.java
@@ -35,6 +35,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.openecomp.mso.bpmn.core.utils.CamundaDBSetup;
import org.openecomp.mso.logger.MsoLogger;
/**
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/CamundaDBSetup.java b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/utils/CamundaDBSetup.java
index 9a8cad6b86..f29ccc75e0 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/CamundaDBSetup.java
+++ b/bpmn/MSOCoreBPMN/src/test/java/org/openecomp/mso/bpmn/core/utils/CamundaDBSetup.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.bpmn.core;
+package org.openecomp.mso.bpmn.core.utils;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -35,9 +35,6 @@ public class CamundaDBSetup {
private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
private CamundaDBSetup() {
- /**
- * Constructor.
- */
}
public static synchronized void configure() throws SQLException {
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..aefe0d5a8b 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,43 +958,43 @@ 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) {
+ public VfModule getVfModuleModelName(String modelName, String model_version) {
- long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
+ long startTime = System.currentTimeMillis();
+ LOGGER.debug("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
String hql = "FROM VfModule WHERE Name = :model_name and version = :model_version";
- Query query = getSession ().createQuery (hql);
- query.setParameter ("modelName", modelName);
- query.setParameter ("model_version", model_version);
+ Query query = getSession().createQuery(hql);
+ query.setParameter("modelName", modelName);
+ query.setParameter("model_version", model_version);
VfModule module = null;
try {
- module = (VfModule) query.uniqueResult ();
+ module = (VfModule) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: type='" + modelName + "', asdc_service_model_version='" + model_version + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type=" + modelName);
@@ -1012,9 +1012,9 @@ public class CatalogDatabase implements Closeable {
throw e;
}
if (module == null) {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
} else {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
}
return module;
}
@@ -1026,21 +1026,21 @@ public class CatalogDatabase implements Closeable {
*@author cb645j
*
*/
- public VfModuleCustomization getVfModuleCustomizationByModelName (String modelName) {
+ public VfModuleCustomization getVfModuleCustomizationByModelName(String modelName) {
- long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get VfModuleCustomization By VfModule's ModelName: " + modelName);
+ long startTime = System.currentTimeMillis();
+ LOGGER.debug("Catalog database - get VfModuleCustomization By VfModule's ModelName: " + modelName);
String hql = "SELECT VfModuleCustomization FROM VfModuleCustomization as vfmc LEFT OUTER JOIN VfModule as vfm on vfm.modelUUID = vfmc.vfModuleModelUuid where vfm.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<VfModuleCustomization> resultList = query.list();
// See if something came back. Name is unique, so
- if (resultList.isEmpty ()) {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query but Vf module NOT found", "CatalogDB", "getVfModuleCustomizationByModelName", null);
+ if (resultList.isEmpty()) {
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query but Vf module NOT found", "CatalogDB", "getVfModuleCustomizationByModelName", null);
return null;
}
@@ -1055,28 +1055,28 @@ public class CatalogDatabase implements Closeable {
* @param networkType
* @return NetworkResource object or null if none found
*/
- public NetworkResource getNetworkResource (String networkType) {
+ public NetworkResource getNetworkResource(String networkType) {
- long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get network resource with type " + networkType);
+ long startTime = System.currentTimeMillis();
+ LOGGER.debug("Catalog database - get network resource with type " + networkType);
String hql = "FROM NetworkResource WHERE model_name = :network_type";
- Query query = getSession ().createQuery (hql);
- query.setParameter ("network_type", networkType);
+ Query query = getSession().createQuery(hql);
+ query.setParameter("network_type", networkType);
@SuppressWarnings("unchecked")
- List <NetworkResource> resultList = query.list ();
+ List <NetworkResource> 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. Network Resource not found", "CatalogDB", "getNetworkResource", null);
+ if (resultList.isEmpty()) {
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Network Resource not found", "CatalogDB", "getNetworkResource", null);
return null;
}
- Collections.sort (resultList, new MavenLikeVersioningComparator ());
- Collections.reverse (resultList);
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null);
- return resultList.get (0);
+ Collections.sort(resultList, new MavenLikeVersioningComparator());
+ Collections.reverse(resultList);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null);
+ return resultList.get(0);
}
/**
@@ -1087,46 +1087,46 @@ public class CatalogDatabase implements Closeable {
* @param serviceType The service Name, if null or empty is provided, it won't be taken into account
* @return VnfRecipe object or null if none found
*/
- public VnfRecipe getVnfRecipe (String vnfType, String action, String serviceType) {
+ public VnfRecipe getVnfRecipe(String vnfType, String action, String serviceType) {
boolean withServiceType = false;
- StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
+ StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
// If query c
- if (serviceType == null || serviceType.isEmpty ()) {
- hql.append ("AND serviceType is NULL ");
+ if (serviceType == null || serviceType.isEmpty()) {
+ hql.append("AND serviceType is NULL ");
} else {
- hql.append ("AND serviceType = :serviceType ");
+ hql.append("AND serviceType = :serviceType ");
withServiceType = true;
}
- long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
+ long startTime = System.currentTimeMillis();
+ LOGGER.debug("Catalog database - get VNF recipe with name " + vnfType
+ " and action "
+ action
+ " and service type "
+ serviceType);
- Query query = getSession ().createQuery (hql.toString ());
- query.setParameter (VNF_TYPE, vnfType);
- query.setParameter (ACTION, action);
+ Query query = getSession().createQuery(hql.toString());
+ query.setParameter(VNF_TYPE, vnfType);
+ query.setParameter(ACTION, action);
if (withServiceType) {
- query.setParameter (SERVICE_TYPE, serviceType);
+ query.setParameter(SERVICE_TYPE, serviceType);
}
@SuppressWarnings("unchecked")
- List <VnfRecipe> resultList = query.list ();
+ List <VnfRecipe> resultList = query.list();
- if (resultList.isEmpty ()) {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
+ if (resultList.isEmpty()) {
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", 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", "getVnfRecipe", null);
- return resultList.get (0);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
+ return resultList.get(0);
}
/**
@@ -1136,31 +1136,31 @@ public class CatalogDatabase implements Closeable {
* @param action
* @return VnfRecipe object or null if none found
*/
- public VnfRecipe getVnfRecipe (String vnfType, String action) {
- StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
+ public VnfRecipe getVnfRecipe(String vnfType, String action) {
+ StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action ");
- long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType
+ long startTime = System.currentTimeMillis();
+ LOGGER.debug("Catalog database - get VNF recipe with name " + vnfType
+ " and action "
+ action);
- Query query = getSession ().createQuery (hql.toString ());
- query.setParameter (VNF_TYPE, vnfType);
- query.setParameter (ACTION, action);
+ Query query = getSession().createQuery(hql.toString());
+ query.setParameter(VNF_TYPE, vnfType);
+ query.setParameter(ACTION, action);
@SuppressWarnings("unchecked")
- List <VnfRecipe> resultList = query.list ();
+ List <VnfRecipe> resultList = query.list();
- if (resultList.isEmpty ()) {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null);
+ if (resultList.isEmpty()) {
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", 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", "getVnfRecipe", null);
- return resultList.get (0);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null);
+ return resultList.get(0);
}
/**
@@ -1170,30 +1170,30 @@ public class CatalogDatabase implements Closeable {
* @param action
* @return VnfRecipe object or null if none found
*/
- public VnfRecipe getVnfRecipeByVfModuleId (String vnfType, String vfModuleId, String action) {
+ public VnfRecipe getVnfRecipeByVfModuleId(String vnfType, String vfModuleId, String action) {
- StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action ");
+ StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action ");
- long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId);
+ long startTime = System.currentTimeMillis();
+ LOGGER.debug("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId);
- Query query = getSession ().createQuery (hql.toString ());
- query.setParameter (VF_MODULE_MODEL_UUID, vfModuleId);
- query.setParameter (ACTION, action);
+ Query query = getSession().createQuery(hql.toString ());
+ query.setParameter(VF_MODULE_MODEL_UUID, vfModuleId);
+ query.setParameter(ACTION, action);
@SuppressWarnings("unchecked")
- List <VnfRecipe> resultList = query.list ();
+ List <VnfRecipe> resultList = query.list();
- if (resultList.isEmpty ()) {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe Entry not found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
+ if (resultList.isEmpty()) {
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe Entry not found", "CatalogDB", "getVnfRecipeByVfModuleId", 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. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
- return resultList.get (0);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null);
+ return resultList.get(0);
}
public VfModule getVfModuleTypeByUuid(String modelCustomizationUuid) {
@@ -1299,7 +1299,7 @@ public class CatalogDatabase implements Closeable {
query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid);
VnfResource vnfResource = null;
try {
- vnfResource = (VnfResource) query.uniqueResult ();
+ vnfResource = (VnfResource) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid);
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid==" + serviceModelInvariantUuid);
@@ -1317,23 +1317,23 @@ public class CatalogDatabase implements Closeable {
throw e;
}
if (vnfResource == null) {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null);
} else {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null);
}
return vnfResource;
}
public VnfResource getVnfResourceByVnfUuid(String vnfResourceModelInvariantUuid) {
long startTime = System.currentTimeMillis();
- LOGGER.debug ("Catalog database - get vfModuleType with vnfResourceModelInvariantUuid " + vnfResourceModelInvariantUuid);
+ LOGGER.debug("Catalog database - get vfModuleType with vnfResourceModelInvariantUuid " + vnfResourceModelInvariantUuid);
String hql = "FROM VnfResource WHERE vnfResourceModelInvariantUuid = :vnfResourceModelInvariantUuid";
Query query = getSession().createQuery(hql);
- query.setParameter ("vnfResourceModelInvariantUuid", vnfResourceModelInvariantUuid);
+ query.setParameter("vnfResourceModelInvariantUuid", vnfResourceModelInvariantUuid);
VnfResource vnfResource = null;
try {
- vnfResource = (VnfResource) query.uniqueResult ();
+ vnfResource = (VnfResource) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid);
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResourceModelInvariantUuid==" + vnfResourceModelInvariantUuid);
diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/NetworkResource.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/NetworkResource.java
index b6151f176d..025b13b708 100644
--- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/NetworkResource.java
+++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/NetworkResource.java
@@ -41,6 +41,8 @@ public class NetworkResource extends MavenLikeVersioning implements Serializable
private String toscaNodeType;
private Timestamp created;
private String modelUUID;
+ private String category;
+ private String subCategory;
private String heatTemplateArtifactUUID;
public NetworkResource() {}
@@ -123,8 +125,40 @@ public class NetworkResource extends MavenLikeVersioning implements Serializable
public void setModelUUID(String modelUUID) {
this.modelUUID = modelUUID;
}
-
- public String getHeatTemplateArtifactUUID() {
+
+
+ /**
+ * @return Returns the category.
+ */
+ public String getCategory() {
+ return category;
+ }
+
+
+ /**
+ * @param category The category to set.
+ */
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+
+ /**
+ * @return Returns the subCategory.
+ */
+ public String getSubCategory() {
+ return subCategory;
+ }
+
+
+ /**
+ * @param subCategory The subCategory to set.
+ */
+ public void setSubCategory(String subCategory) {
+ this.subCategory = subCategory;
+ }
+
+ public String getHeatTemplateArtifactUUID() {
return heatTemplateArtifactUUID;
}
diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/Service.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/Service.java
index fe7b7a3b8c..beb021ac11 100644
--- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/Service.java
+++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/Service.java
@@ -39,6 +39,7 @@ public class Service extends MavenLikeVersioning implements Serializable {
private Timestamp created;
private String toscaCsarArtifactUUID;
private String modelVersion;
+ private String category;
private String serviceType;
private String serviceRole;
private Map<String,ServiceRecipe> recipes;
@@ -115,8 +116,22 @@ public class Service extends MavenLikeVersioning implements Serializable {
this.modelVersion = modelVersion;
}
-
- public String getServiceType() {
+ /**
+ * @return Returns the category.
+ */
+ public String getCategory() {
+ return category;
+ }
+
+
+ /**
+ * @param category The category to set.
+ */
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getServiceType() {
return serviceType;
}
diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/VnfResource.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/VnfResource.java
index 8fe8127383..0872f146ad 100644
--- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/VnfResource.java
+++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/VnfResource.java
@@ -43,6 +43,8 @@ public class VnfResource extends MavenLikeVersioning implements Serializable {
private String orchestrationMode;
private String aicVersionMin;
private String aicVersionMax;
+ private String category;
+ private String subCategory;
private String heatTemplateArtifactUUId;
private Timestamp created;
private String modelVersion;
@@ -108,7 +110,39 @@ public class VnfResource extends MavenLikeVersioning implements Serializable {
this.aicVersionMax = aicVersionMax;
}
- public String getModelInvariantUuid() {
+
+ /**
+ * @return Returns the category.
+ */
+ public String getCategory() {
+ return category;
+ }
+
+
+ /**
+ * @param category The category to set.
+ */
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+
+ /**
+ * @return Returns the subCategory.
+ */
+ public String getSubCategory() {
+ return subCategory;
+ }
+
+
+ /**
+ * @param subCategory The subCategory to set.
+ */
+ public void setSubCategory(String subCategory) {
+ this.subCategory = subCategory;
+ }
+
+ public String getModelInvariantUuid() {
return this.modelInvariantUuid;
}
diff --git a/mso-catalog-db/src/main/resources/NetworkResource.hbm.xml b/mso-catalog-db/src/main/resources/NetworkResource.hbm.xml
index 1599cf5c66..41e049ad8d 100644
--- a/mso-catalog-db/src/main/resources/NetworkResource.hbm.xml
+++ b/mso-catalog-db/src/main/resources/NetworkResource.hbm.xml
@@ -35,6 +35,8 @@
<property name="neutronNetworkType" column="NEUTRON_NETWORK_TYPE" type="string" length="20"/>
<property name="description" column="DESCRIPTION" type="string" length="1200"/>
<property name="orchestrationMode" column="ORCHESTRATION_MODE" type="string" length="20"/>
+ <property name="category" column="RESOURCE_CATEGORY" type="string" length="20"/>
+ <property name="subCategory" column="RESOURCE_SUB_CATEGORY" type="string" length="20"/>
<property name="heatTemplateArtifactUUID" column="HEAT_TEMPLATE_ARTIFACT_UUID" type="string" length="200" not-null="true" />
<property name="aicVersionMin" type="string" >
diff --git a/mso-catalog-db/src/main/resources/Service.hbm.xml b/mso-catalog-db/src/main/resources/Service.hbm.xml
index 5bdb0f62bd..70f5731b7d 100644
--- a/mso-catalog-db/src/main/resources/Service.hbm.xml
+++ b/mso-catalog-db/src/main/resources/Service.hbm.xml
@@ -39,6 +39,7 @@
<property name="modelInvariantUUID" type="string">
<column name="MODEL_INVARIANT_UUID" default="'MANUAL_RECORD'" not-null="true" length="200"/>
</property>
+ <property name="category" column="SERVICE_CATEGORY" type="string" length="20"/>
<property name="serviceType" column="SERVICE_TYPE" type="string" length="20"/>
<property name="serviceRole" column="SERVICE_ROLE" type="string" length="20"/>
diff --git a/mso-catalog-db/src/main/resources/VnfResource.hbm.xml b/mso-catalog-db/src/main/resources/VnfResource.hbm.xml
index 2647a0fcc2..03d1de544c 100644
--- a/mso-catalog-db/src/main/resources/VnfResource.hbm.xml
+++ b/mso-catalog-db/src/main/resources/VnfResource.hbm.xml
@@ -36,6 +36,8 @@
<property name="orchestrationMode" type="string" column="ORCHESTRATION_MODE" length="20" not-null="true"/>
<property name="aicVersionMin" type="string" column="AIC_VERSION_MIN" length="20"/>
<property name="aicVersionMax" type="string" column="AIC_VERSION_MAX" length="20"/>
+ <property name="category" type="string" column="RESOURCE_CATEGORY" length="20"/>
+ <property name="subCategory" type="string" column="RESOURCE_SUB_CATEGORY" length="20"/>
<property name="heatTemplateArtifactUUId" type="string" column="HEAT_TEMPLATE_ARTIFACT_UUID" length="200" />
<property name="created" type="timestamp" generated="insert" update="false" insert="false" not-null="true">
<column name="CREATION_TIMESTAMP" default="CURRENT_TIMESTAMP"/>
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..e9f080b1dd 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
@@ -53,12 +53,7 @@ import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
import org.openecomp.mso.db.catalog.utils.RecordNotFoundException;
import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -1443,39 +1438,445 @@ 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(expected = Exception.class)
- public void getVfModuleModelName2TestException(){
- VfModule vnf = cd.getVfModuleModelName("tetes","4kidsl");
+ @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)
- public void ggetVfModuleCustomizationByModelNameTestException(){
- VfModuleCustomization vnf = cd.getVfModuleCustomizationByModelName("tetes");
+ @Test
+ public void getVfModuleModelNameTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() {
+ VfModule vfModule = new VfModule();
+ vfModule.setModelUUID("123-uuid");
+ return 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("tetes","4kidsl");
+ assertEquals("123-uuid", vfModule.getModelUUID());
}
- @Test(expected = Exception.class)
- public void getNetworkResourceTestException(){
- NetworkResource vnf = cd.getNetworkResource("tetes");
+ @Test(expected = NonUniqueResultException.class)
+ public void getVfModuleModelNameNURExceptionTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() {
+ 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();
+ }
+ };
+
+ VfModule vfModule = cd.getVfModuleModelName("tetes","4kidsl");
}
- @Test(expected = Exception.class)
- public void getVnfRecipeTestException(){
- VnfRecipe vnf = cd.getVnfRecipe("tetes","ergfedrf","4993493");
+ @Test(expected = HibernateException.class)
+ public void getVfModuleModelNameHibernateExceptionTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() {
+ throw new HibernateException("hibernate exception");
+ }
+ };
+
+ 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("tetes","4kidsl");
}
@Test(expected = Exception.class)
- public void getVnfRecipe2TestException(){
- VnfRecipe vnf = cd.getVnfRecipe("tetes","4993493");
+ public void getVfModuleModelNameGenericExceptionTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() throws Exception {
+ throw new Exception();
+ }
+ };
+
+ 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("tetes","4kidsl");
}
- @Test(expected = Exception.class)
- public void getVnfRecipeByVfModuleIdTestException(){
- VnfRecipe vnf = cd.getVnfRecipeByVfModuleId("tetes","4993493","vnf");
+ @Test
+ public void ggetVfModuleCustomizationByModelNameTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<VfModuleCustomization> list() throws Exception {
+ VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
+ vfModuleCustomization.setVfModuleModelUuid("123-uuid");
+ return Arrays.asList(vfModuleCustomization);
+ }
+ };
+
+ 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();
+ }
+ };
+ VfModuleCustomization vfModuleCustomization = cd.getVfModuleCustomizationByModelName("tetes");
+ assertEquals("123-uuid", vfModuleCustomization.getVfModuleModelUuid());
+ }
+
+ @Test
+ public void ggetVfModuleCustomizationByModelNameEmptyTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<VfModuleCustomization> 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();
+ }
+ };
+ VfModuleCustomization vfModuleCustomization = cd.getVfModuleCustomizationByModelName("tetes");
+ assertEquals(null, vfModuleCustomization);
+ }
+
+ @Test
+ public void getNetworkResourceTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<NetworkResource> list() throws Exception {
+ NetworkResource networkResource = new NetworkResource();
+ networkResource.setModelUUID("123-uuid");
+ return Arrays.asList(networkResource);
+ }
+ };
+
+ 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();
+ }
+ };
+ NetworkResource networkResource = cd.getNetworkResource("tetes");
+ assertEquals("123-uuid", networkResource.getModelUUID());
+ }
+
+ @Test
+ public void getNetworkResourceTestEmptyException(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<NetworkResource> 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();
+ }
+ };
+ NetworkResource networkResource = cd.getNetworkResource("tetes");
+ assertEquals(null, networkResource);
+ }
+
+ @Test
+ public void getVnfRecipeTest(){
+
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<VnfRecipe> list() throws Exception {
+ VnfRecipe vnfRecipe = new VnfRecipe();
+ vnfRecipe.setVfModuleId("123-id");
+ return Arrays.asList(vnfRecipe);
+ }
+ };
+
+ 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();
+ }
+ };
+
+ VnfRecipe vnfRecipe = cd.getVnfRecipe("tetes","ergfedrf","4993493");
+ assertEquals("123-id", vnfRecipe.getVfModuleId());
+ }
+
+ @Test
+ public void getVnfRecipeEmptyTest(){
+
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<VnfRecipe> list() throws Exception {
+ return Collections.emptyList();
+ }
+ };
+
+ 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();
+ }
+ };
+
+ VnfRecipe vnfRecipe = cd.getVnfRecipe("tetes","ergfedrf","4993493");
+ assertEquals(null, vnfRecipe);
+ }
+
+ @Test
+ public void getVnfRecipe2Test(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<VnfRecipe> list() throws Exception {
+ VnfRecipe vnfRecipe = new VnfRecipe();
+ vnfRecipe.setId(1);
+ return Arrays.asList(vnfRecipe);
+ }
+ };
+
+ 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();
+ }
+ };
+ VnfRecipe vnfRecipe = cd.getVnfRecipe("tetes","4993493");
+ assertEquals(1, vnfRecipe.getId());
+ }
+
+ @Test
+ public void getVnfRecipe2EmptyTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<VnfRecipe> list() throws Exception {
+ return Collections.emptyList();
+ }
+ };
+
+ 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();
+ }
+ };
+ VnfRecipe vnfRecipe = cd.getVnfRecipe("tetes","4993493");
+ assertEquals(null, vnfRecipe);
+ }
+
+ @Test
+ public void getVnfRecipeByVfModuleIdTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<VnfRecipe> list() throws Exception {
+ VnfRecipe vnfRecipe = new VnfRecipe();
+ vnfRecipe.setId(1);
+ return Arrays.asList(vnfRecipe);
+ }
+ };
+
+ 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();
+ }
+ };
+
+ VnfRecipe vnfRecipe = cd.getVnfRecipeByVfModuleId("tetes","4993493","vnf");
+ assertEquals(1, vnfRecipe.getId());
+ }
+
+ @Test
+ public void getVnfRecipeByVfModuleIdEmptyTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<VnfRecipe> list() throws Exception {
+ return Collections.emptyList();
+ }
+ };
+
+ 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();
+ }
+ };
+
+ VnfRecipe vnfRecipe = cd.getVnfRecipeByVfModuleId("tetes","4993493","vnf");
+ assertEquals(null, vnfRecipe);
}
@Test(expected = Exception.class)
@@ -1487,18 +1888,284 @@ public class CatalogDatabaseTest {
public void getVfModuleType2TestException(){
VfModule vnf = cd.getVfModuleType("4993493","vnf");
}
- @Test(expected = Exception.class)
- public void getVnfResourceByServiceUuidTestException(){
- VnfResource vnf = cd.getVnfResourceByServiceUuid("4993493");
+ @Test
+ public void getVnfResourceByServiceUuidTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() {
+ VnfResource vnfResource = new VnfResource();
+ vnfResource.setModelUuid("123-uuid");
+ return 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.getVnfResourceByServiceUuid("4993493");
+ assertEquals("123-uuid", vnfResource.getModelUuid());
+ }
+
+ @Test(expected = NonUniqueResultException.class)
+ public void getVnfResourceByServiceUuidNURExceptionTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() {
+ 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();
+ }
+ };
+ VnfResource vnfResource = cd.getVnfResourceByServiceUuid("4993493");
+ }
+
+ @Test(expected = HibernateException.class)
+ public void getVnfResourceByServiceUuidHibernateExceptionTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() {
+ throw new HibernateException("hibernate exception");
+ }
+ };
+
+ 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.getVnfResourceByServiceUuid("4993493");
}
+
@Test(expected = Exception.class)
- public void getVnfResourceByVnfUuidTestException(){
- VnfResource vnf = cd.getVnfResourceByVnfUuid("4993493");
+ public void getVnfResourceByServiceUuidExceptionTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() throws Exception {
+ throw new Exception();
+ }
+ };
+
+ 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.getVnfResourceByServiceUuid("4993493");
+ }
+
+ @Test
+ public void getVnfResourceByVnfUuidTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() {
+ VnfResource vnfResource = new VnfResource();
+ vnfResource.setModelUuid("123-uuid");
+ return 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.getVnfResourceByVnfUuid("4993493");
+ assertEquals("123-uuid", vnfResource.getModelUuid());
}
+
+ @Test(expected = NonUniqueResultException.class)
+ public void getVnfResourceByVnfUuidNURExceptionTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() {
+ 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();
+ }
+ };
+
+ VnfResource vnfResource = cd.getVnfResourceByVnfUuid("4993493");
+ }
+
+ @Test(expected = HibernateException.class)
+ public void getVnfResourceByVnfUuidHibernateExceptionTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() {
+ throw new HibernateException("hibernate exception");
+ }
+ };
+
+ 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.getVnfResourceByVnfUuid("4993493");
+ }
+
@Test(expected = Exception.class)
- public void getVfModuleByModelInvariantUuidTestException(){
- VfModule vnf = cd.getVfModuleByModelInvariantUuid("4993493");
+ public void getVnfResourceByVnfUuidExceptionTest(){
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() throws Exception {
+ throw new Exception();
+ }
+ };
+
+ 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.getVnfResourceByVnfUuid("4993493");
+ }
+
+ @Test
+ public void getVfModuleByModelInvariantUuidTest(){
+
+ 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.getVfModuleByModelInvariantUuid("4993493");
+ assertEquals("123-uuid", vfModule.getModelUUID());
}
+
+ @Test
+ public void getVfModuleByModelInvariantUuidEmptyTest(){
+
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public List<VfModule> list() throws Exception {
+ return Collections.emptyList();
+ }
+ };
+
+ 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.getVfModuleByModelInvariantUuid("4993493");
+ assertEquals(null, vfModule);
+ }
+
@Test(expected = Exception.class)
public void getVfModuleByModelCustomizationUuidTestException(){
VfModuleCustomization vnf = cd.getVfModuleByModelCustomizationUuid("4993493");