5f34b5510adb2b6a55f7d501d0948caeb2b7088f
[ccsdk/cds.git] /
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.Before;\r
23 import org.junit.Test;\r
24 import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;\r
25 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
26 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory;\r
27 import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils;\r
28 import com.att.eelf.configuration.EELFLogger;\r
29 import com.att.eelf.configuration.EELFManager;\r
30 \r
31 import java.io.File;\r
32 import java.nio.charset.Charset;\r
33 import java.util.List;\r
34 \r
35 public class ServiceTemplateValidationTest {\r
36     private static EELFLogger log = EELFManager.getInstance().getLogger(ServiceTemplateValidationTest.class);\r
37 \r
38     @Before\r
39     public void setUp(){\r
40         ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("db", "source-db");\r
41         ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("input", "source-input");\r
42         ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("default", "source-default");\r
43         ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("mdsal", "source-rest");\r
44     }\r
45 \r
46     @Test\r
47     public void testBluePrintDirs() {\r
48         List<String> dirs = ConfigModelUtils.getBlueprintNames("load/blueprints");\r
49         Assert.assertNotNull("Failed to get blueprint directories", dirs);\r
50         Assert.assertEquals("Failed to get actual directories", 1, dirs.size());\r
51     }\r
52 \r
53     @Test\r
54     public void validateServiceTemplate() throws Exception {\r
55         validateServiceTemplate("load/blueprints/vrr-test/Definitions/vrr-test.json");\r
56     }\r
57 \r
58     @Test\r
59     public void validateEnhancedServiceTemplate() throws Exception {\r
60         ServiceTemplate serviceTemplate = JacksonUtils\r
61                 .readValueFromClassPathFile("enhance/enhanced-template.json", ServiceTemplate.class);\r
62         ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator();\r
63         Boolean valid = serviceTemplateValidator.validateServiceTemplate(serviceTemplate);\r
64         Assert.assertTrue("Failed to validate blueprints", valid);\r
65     }\r
66 \r
67     private void validateServiceTemplate(String fileName) throws Exception {\r
68         String serviceTemplateContent =\r
69                 FileUtils.readFileToString(new File(fileName), Charset.defaultCharset());\r
70         ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator();\r
71         serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent);\r
72         Assert.assertNotNull("Failed to validate blueprints", serviceTemplateValidator);\r
73     }\r
74 }\r