1st drop integration with BluePrintCatalogService
[ccsdk/apps.git] / ms / controllerblueprints / modules / service / src / test / java / org / onap / ccsdk / apps / controllerblueprints / service / rs / ModelTypeRestTest.java
index d33349c..bf5db34 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
 \r
 package org.onap.ccsdk.apps.controllerblueprints.service.rs;\r
 \r
-import org.apache.commons.io.FileUtils;\r
-import org.junit.*;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import org.junit.Assert;\r
+import org.junit.FixMethodOrder;\r
+import org.junit.Test;\r
 import org.junit.runner.RunWith;\r
 import org.junit.runners.MethodSorters;\r
 import org.onap.ccsdk.apps.controllerblueprints.TestApplication;\r
-import org.onap.ccsdk.apps.controllerblueprints.TestConfiguration;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
+import org.onap.ccsdk.apps.controllerblueprints.service.controller.ModelTypeController;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
 import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.boot.test.context.SpringBootTest;\r
-import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;\r
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;\r
+import org.springframework.test.annotation.Commit;\r
 import org.springframework.test.context.ContextConfiguration;\r
 import org.springframework.test.context.junit4.SpringRunner;\r
 \r
-import java.io.File;\r
-import java.nio.charset.Charset;\r
 import java.util.List;\r
 \r
 @RunWith(SpringRunner.class)\r
-@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)\r
-@ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class})\r
+@DataJpaTest\r
+@ContextConfiguration(classes = {TestApplication.class})\r
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)\r
 public class ModelTypeRestTest {\r
-    private static Logger log = LoggerFactory.getLogger(ModelTypeRestTest.class);\r
+    private static EELFLogger log = EELFManager.getInstance().getLogger(ModelTypeRestTest.class);\r
     @Autowired\r
-    ModelTypeRest modelTypeRest;\r
+    ModelTypeController modelTypeController;\r
 \r
     String modelName = "test-datatype";\r
 \r
-    @Before\r
-    public void setUp() {\r
-\r
-    }\r
-\r
-\r
-    @After\r
-    public void tearDown() {}\r
-\r
     @Test\r
+    @Commit\r
     public void test01SaveModelType() throws Exception {\r
-        log.info( "**************** test01SaveModelType  ********************");\r
+        log.info("**************** test01SaveModelType  ********************");\r
 \r
-        String content = FileUtils.readFileToString(new File("load/model_type/data_type/datatype-property.json"), Charset.defaultCharset());\r
+        String content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json");\r
         ModelType modelType = new ModelType();\r
         modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
         modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT);\r
         modelType.setDescription("Definition for Sample Datatype ");\r
-        modelType.setDefinition(content);\r
+        modelType.setDefinition(JacksonUtils.jsonNode(content));\r
         modelType.setModelName(modelName);\r
         modelType.setVersion("1.0.0");\r
         modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + ","\r
                 + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
         modelType.setUpdatedBy("xxxxxx@xxx.com");\r
-        modelType = modelTypeRest.saveModelType(modelType);\r
-        log.info( "Saved Mode {}", modelType.toString());\r
+        modelType = modelTypeController.saveModelType(modelType);\r
+        log.info("Saved Mode {}", modelType.toString());\r
         Assert.assertNotNull("Failed to get Saved ModelType", modelType);\r
         Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.getModelName());\r
 \r
-        ModelType dbModelType = modelTypeRest.getModelTypeByName(modelType.getModelName());\r
+        ModelType dbModelType = modelTypeController.getModelTypeByName(modelType.getModelName());\r
         Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType.getModelName() + ")",\r
                 dbModelType);\r
 \r
         // Model Update\r
         modelType.setUpdatedBy("bs2796@xxx.com");\r
-        modelType = modelTypeRest.saveModelType(modelType);\r
+        modelType = modelTypeController.saveModelType(modelType);\r
         Assert.assertNotNull("Failed to get Saved ModelType", modelType);\r
         Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.getUpdatedBy());\r
 \r
@@ -90,41 +83,40 @@ public class ModelTypeRestTest {
 \r
     @Test\r
     public void test02SearchModelTypes() throws Exception {\r
-        log.info( "*********************** test02SearchModelTypes  ***************************");\r
+        log.info("*********************** test02SearchModelTypes  ***************************");\r
 \r
         String tags = "test-datatype";\r
 \r
-        List<ModelType> dbModelTypes = modelTypeRest.searchModelTypes(tags);\r
+        List<ModelType> dbModelTypes = modelTypeController.searchModelTypes(tags);\r
         Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes);\r
-        Assert.assertEquals("Failed to search ResourceMapping by tags count", true, dbModelTypes.size() > 0);\r
+        Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.size() > 0);\r
 \r
     }\r
 \r
     @Test\r
     public void test03GetModelType() throws Exception {\r
-        log.info( "************************* test03GetModelType  *********************************");\r
-        ModelType dbModelType = modelTypeRest.getModelTypeByName(modelName);\r
-        Assert.assertNotNull("Failed to get response for api call getModelByName ", dbModelType);\r
+        log.info("************************* test03GetModelType  *********************************");\r
+        ModelType dbModelType = modelTypeController.getModelTypeByName(modelName);\r
+        Assert.assertNotNull("Failed to get response for api call getModelByName " + modelName, dbModelType);\r
         Assert.assertNotNull("Failed to get Id for api call  getModelByName ", dbModelType.getModelName());\r
 \r
         List<ModelType> dbDatatypeModelTypes =\r
-                modelTypeRest.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
+                modelTypeController.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
         Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes);\r
-        Assert.assertEquals("Failed to find getModelTypeByDefinitionType by count", true,\r
-                dbDatatypeModelTypes.size() > 0);\r
+        Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.size() > 0);\r
     }\r
 \r
     @Test\r
+    @Commit\r
     public void test04DeleteModelType() throws Exception {\r
         log.info(\r
                 "************************ test03DeleteModelType  ***********************");\r
-        ModelType dbResourceMapping = modelTypeRest.getModelTypeByName(modelName);\r
+        ModelType dbResourceMapping = modelTypeController.getModelTypeByName(modelName);\r
         Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping);\r
         Assert.assertNotNull("Failed to get Id for api call  getModelByName ", dbResourceMapping.getModelName());\r
 \r
-        modelTypeRest.deleteModelTypeByName(dbResourceMapping.getModelName());\r
+        modelTypeController.deleteModelTypeByName(dbResourceMapping.getModelName());\r
     }\r
 \r
 \r
-\r
 }\r