Code Improvement
[clamp.git] / src / test / java / org / onap / clamp / clds / model / prop / ModelPropertiesTest.java
index 54a7a4a..60056d4 100644 (file)
@@ -5,16 +5,16 @@
  * Copyright (C) 2017 AT&T Intellectual Property. All rights
  *                             reserved.
  * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); 
- * you may not use this file except in compliance with the License. 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software 
- * distributed under the License is distributed on an "AS IS" BASIS, 
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
- * See the License for the specific language governing permissions and 
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
  * limitations under the License.
  * ============LICENSE_END============================================
  * ===================================================================
 
 package org.onap.clamp.clds.model.prop;
 
-import org.onap.clamp.clds.transform.TransformUtil;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.clamp.clds.model.CldsModel;
+import org.onap.clamp.clds.util.ResourceFileUtil;
 
 /**
  * Test org.onap.clamp.ClampDesigner.model.prop package using ModelProperties.
  */
 public class ModelPropertiesTest {
 
+    @Before
+    public void registerNewClasses() {
+        ModelProperties.registerModelElement(Holmes.class, Holmes.getType());
+    }
+
     @Test
-    public void testJsonParse() throws IOException {
-        String modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnProp.json");
-        String modelProp = TransformUtil.getResourceAsString("example/modelProp.json");
-        String modName = "example-model-name";
-        String controlName = "example-control-name";
+    public void testHolmes() throws IOException {
 
-        ModelProperties prop = new ModelProperties(modName, controlName, null, modelBpmnProp, modelProp);
-        Assert.assertEquals(modName, prop.getModelName());
-        Assert.assertEquals(controlName, prop.getControlName());
-        Assert.assertEquals(null, prop.getActionCd());
+        String modelBpmnProp = ResourceFileUtil.getResourceAsString("example/model-properties/modelBpmnProp.json");
+        String modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/modelBpmn.json");
 
-        Global g = prop.getGlobal();
-        Assert.assertEquals("df6fcd2b-1932-429e-bb13-0cd0d32113cb", g.getService());
-        Assert.assertEquals("[SNDGCA64, ALPRGAED]", g.getLocation().toString());
-        Assert.assertEquals("[4b49acee-cf70-4b20-b956-a4fe0c1a8239]", g.getResourceVf().toString());
+        ModelProperties prop = new ModelProperties("example-model-name", "example-control-name", null, true, modelBpmn,
+                modelBpmnProp);
 
-        Collector c = prop.getCollector();
-        Assert.assertEquals("Collector_", c.getId());
-        Assert.assertEquals("DCAE-COLLECTOR-UCSNMP", c.getTopicPublishes());
+        Policy policy = prop.getType(Policy.class);
+        assertTrue(policy.isFound());
+        assertEquals(1, policy.getPolicyChains().size());
+        assertEquals("0", policy.getPolicyChains().get(0).getPolicyId());
+        assertEquals(1, policy.getPolicyChains().get(0).getPolicyItems().size());
+        assertEquals("resourceid", policy.getPolicyChains().get(0).getPolicyItems().get(0).getTargetResourceId());
+        assertEquals(180, policy.getPolicyChains().get(0).getPolicyItems().get(0).getRetryTimeLimit());
+        assertEquals(3, policy.getPolicyChains().get(0).getPolicyItems().get(0).getMaxRetries());
+        assertEquals("", policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicy());
+        assertEquals(null, policy.getPolicyChains().get(0).getPolicyItems().get(0).getParentPolicyConditions());
 
-        StringMatch sm = prop.getStringMatch();
-        Assert.assertEquals("StringMatch_", sm.getId());
-        Assert.assertEquals("DCAE-CL-EVENT", sm.getTopicPublishes());
+        Tca tca = prop.getType(Tca.class);
+        assertTrue(tca.isFound());
+        assertEquals(1, tca.getTcaItems().size());
+        assertEquals(0, tca.getTcaItems().get(0).getTcaThreshholds().size());
 
-        Policy p = prop.getPolicy();
-        Assert.assertEquals("Policy_", p.getId());
-        Assert.assertEquals(null, p.getTopicPublishes());
-        Assert.assertEquals("DCAE-CL-EVENT", p.getTopicSubscribes());
-        Assert.assertEquals(500, p.getTimeout().intValue());
-        
-        Tca t = prop.getTca();
-        Assert.assertEquals("Narra", t.getTcaItems().get(0).getTcaName());
-        Assert.assertEquals(Integer.valueOf(4), t.getTcaItems().get(0).getTcaThreshholds().get(0).getThreshhold());
+        Holmes holmes = prop.getType(Holmes.class);
+        assertTrue(holmes.isFound());
+        assertEquals("policy1", holmes.getOperationalPolicy());
+        assertEquals("blabla", holmes.getCorrelationLogic());
     }
 
+    @Test
+    public void testGetVf() throws IOException {
+        CldsModel cldsModel = new CldsModel();
+        cldsModel.setPropText(
+                ResourceFileUtil.getResourceAsString("example/model-properties/modelBpmnPropWithGlobal.json"));
+        assertEquals("f5213e3a-9191-4362-93b5-b67f8d770e44", ModelProperties.getVf(cldsModel));
+    }
 }
\ No newline at end of file