Controller Blueprints Microservice
[ccsdk/cds.git] / ms / controllerblueprints / modules / service / src / test / java / org / onap / ccsdk / apps / controllerblueprints / service / validator / ServiceTemplateValidationTest.java
1 /*\r
2  *  Copyright © 2017-2018 AT&T Intellectual Property.\r
3  *\r
4  *  Licensed under the Apache License, Version 2.0 (the "License");\r
5  *  you may not use this file except in compliance with the License.\r
6  *  You may obtain a copy of the License at\r
7  *\r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  *  Unless required by applicable law or agreed to in writing, software\r
11  *  distributed under the License is distributed on an "AS IS" BASIS,\r
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  *  See the License for the specific language governing permissions and\r
14  *  limitations under the License.\r
15  */\r
16 \r
17 package org.onap.ccsdk.apps.controllerblueprints.service.validator;\r
18 \r
19 \r
20 import org.apache.commons.io.FileUtils;\r
21 import org.junit.Assert;\r
22 import org.junit.Test;\r
23 import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;\r
24 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
25 import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils;\r
26 import com.att.eelf.configuration.EELFLogger;\r
27 import com.att.eelf.configuration.EELFManager;\r
28 \r
29 import java.io.File;\r
30 import java.nio.charset.Charset;\r
31 import java.util.List;\r
32 \r
33 public class ServiceTemplateValidationTest {\r
34     private static EELFLogger log = EELFManager.getInstance().getLogger(ServiceTemplateValidationTest.class);\r
35 \r
36     @Test\r
37     public void testBluePrintDirs() {\r
38         List<String> dirs = ConfigModelUtils.getBlueprintNames("load/blueprints");\r
39         Assert.assertNotNull("Failed to get blueprint directories", dirs);\r
40         Assert.assertEquals("Failed to get actual directories", 2, dirs.size());\r
41     }\r
42 \r
43     @Test\r
44     public void validateServiceTemplate() throws Exception {\r
45         validateServiceTemplate("load/blueprints/baseconfiguration/Definitions/activation-blueprint.json");\r
46         validateServiceTemplate("load/blueprints/vrr-test/Definitions/vrr-test.json");\r
47     }\r
48 \r
49     //@Test\r
50     public void validateEnhancedServiceTemplate() throws Exception {\r
51         ServiceTemplate serviceTemplate = JacksonUtils\r
52                 .readValueFromClassPathFile("enhance/enhanced-template.json", ServiceTemplate.class);\r
53         ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator();\r
54         Boolean valid = serviceTemplateValidator.validateServiceTemplate(serviceTemplate);\r
55         Assert.assertTrue("Failed to validate blueprints", valid);\r
56     }\r
57 \r
58     private void validateServiceTemplate(String fileName) throws Exception {\r
59         String serviceTemplateContent =\r
60                 FileUtils.readFileToString(new File(fileName), Charset.defaultCharset());\r
61         ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator();\r
62         serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent);\r
63         Assert.assertNotNull("Failed to validate blueprints", serviceTemplateValidator);\r
64     }\r
65 }\r