Add tests 61/74961/1
authorsebdet <sebastien.determe@intl.att.com>
Thu, 20 Dec 2018 08:42:53 +0000 (09:42 +0100)
committersebdet <sebastien.determe@intl.att.com>
Thu, 20 Dec 2018 08:42:53 +0000 (09:42 +0100)
Add tests to Tosca code to increase coverage

Issue-ID: CLAMP-252
Change-Id: Ie18cb94444e7e47b6dfb3e8271a0db238cfeeb1b
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
src/test/java/org/onap/clamp/clds/it/CldsToscaServiceItCase.java
src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java
src/test/resources/http-cache/third_party_proxy.py

index 75579df..d4c7e5c 100644 (file)
@@ -40,7 +40,6 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mockito;
-import org.onap.clamp.clds.dao.CldsDao;
 import org.onap.clamp.clds.model.CldsToscaModel;
 import org.onap.clamp.clds.service.CldsToscaService;
 import org.onap.clamp.clds.util.LoggingUtils;
@@ -67,8 +66,6 @@ public class CldsToscaServiceItCase {
     protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsToscaServiceItCase.class);
     @Autowired
     private CldsToscaService cldsToscaService;
-    @Autowired
-    private CldsDao cldsDao;
     private String toscaModelYaml;
     private Authentication authentication;
     private CldsToscaModel cldsToscaModel;
index d0a0fd9..31594cb 100644 (file)
@@ -39,7 +39,9 @@ import org.onap.clamp.clds.client.req.policy.OperationalPolicyAttributesConstruc
 import org.onap.clamp.clds.client.req.policy.PolicyClient;
 import org.onap.clamp.clds.client.req.tca.TcaRequestFormatter;
 import org.onap.clamp.clds.config.ClampProperties;
+import org.onap.clamp.clds.dao.CldsDao;
 import org.onap.clamp.clds.model.CldsEvent;
+import org.onap.clamp.clds.model.CldsToscaModel;
 import org.onap.clamp.clds.model.properties.ModelProperties;
 import org.onap.clamp.clds.model.properties.Policy;
 import org.onap.clamp.clds.model.properties.PolicyItem;
@@ -65,6 +67,8 @@ import org.springframework.test.context.junit4.SpringRunner;
 @SpringBootTest
 public class PolicyClientItCase {
 
+    @Autowired
+    private CldsDao cldsDao;
     @Autowired
     private ClampProperties refProp;
     @Autowired
@@ -255,6 +259,21 @@ public class PolicyClientItCase {
             Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h_0"),
             Assertions.entry("policyType", "BRMS_Param"), Assertions.entry("policyComponent", "PAP"),
             Assertions.entry("deleteCondition", "ALL"));
+    }
+
+    @Test
+    public void testImportToscaModel() throws IOException {
+        String toscaModelYaml = ResourceFileUtil.getResourceAsString("tosca/tca-policy-test.yaml");
+        CldsToscaModel cldsToscaModel = new CldsToscaModel();
+        cldsToscaModel.setToscaModelName("tca-policy-test");
+        cldsToscaModel.setToscaModelYaml(toscaModelYaml);
+        cldsToscaModel.setUserId("admin");
+        cldsToscaModel.setPolicyType("tca");
+        cldsToscaModel = cldsToscaModel.save(cldsDao, refProp, policyClient, "test");
+        String tosca = policyClient.importToscaModel(cldsToscaModel);
 
+        Assertions.assertThat(tosca).contains(
+            "{\"serviceName\":\"tca-policy-test\",\"description\":\"tca-policy-test\",\"requestID\":null,\"filePath\":\"/tmp/tosca-models/tca-policy-test.yml\",");
+        Assertions.assertThat(tosca).contains(toscaModelYaml);
     }
 }
index de40ca9..30f5107 100755 (executable)
@@ -171,7 +171,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
             with open(cached_file_content, 'w') as f:
                 f.write(jsonGenerated)
         return True
-     elif self.path.startswith("/pdp/api/") and http_type == "PUT" or http_type == "DELETE":
+     elif (self.path.startswith("/pdp/api/") and http_type == "PUT" or http_type == "DELETE") or (self.path.startswith("/pdp/api/policyEngineImport") and http_type == "POST"):
         print "self.path start with /pdp/api/, copying body to response ..."
         if not os.path.exists(cached_file_folder):
             os.makedirs(cached_file_folder, 0777)