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