191f568f14716fd006346084706bd2f685edd66b
[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.resource.dict.service\r
18 \r
19 import com.att.eelf.configuration.EELFLogger\r
20 import org.junit.Assert\r
21 import org.junit.Test\r
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
23 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
24 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment\r
25 import com.att.eelf.configuration.EELFManager\r
26 import org.junit.Before\r
27 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryTestUtils\r
28 \r
29 /**\r
30  * ResourceAssignmentValidationServiceTest.\r
31  *\r
32  * @author Brinda Santh\r
33  */\r
34 class ResourceAssignmentValidationServiceTest {\r
35     private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationServiceTest::class.java)\r
36     @Before\r
37     fun setUp() {\r
38         // Setup dummy Source Instance Mapping\r
39         ResourceDictionaryTestUtils.setUpResourceSourceMapping()\r
40     }\r
41 \r
42     @Test\r
43     fun testValidateSuccess() {\r
44         log.info("**************** testValidateSuccess *****************")\r
45         val assignments = JacksonUtils.getListFromClassPathFile("validation/success.json", ResourceAssignment::class.java)\r
46         val resourceAssignmentValidator = ResourceAssignmentValidationServiceImpl()\r
47         val result = resourceAssignmentValidator.validate(assignments!!)\r
48         Assert.assertTrue("Failed to Validate", result)\r
49     }\r
50 \r
51     @Test(expected = BluePrintException::class)\r
52     fun testValidateDuplicate() {\r
53         log.info(" **************** testValidateDuplicate *****************")\r
54         val assignments = JacksonUtils.getListFromClassPathFile("validation/duplicate.json", ResourceAssignment::class.java)\r
55         val resourceAssignmentValidator = ResourceAssignmentValidationServiceImpl()\r
56         resourceAssignmentValidator.validate(assignments!!)\r
57     }\r
58 \r
59     @Test(expected = BluePrintException::class)\r
60     fun testValidateCyclic() {\r
61         log.info(" ****************  testValidateCyclic *****************")\r
62         val assignments = JacksonUtils.getListFromClassPathFile("validation/cyclic.json", ResourceAssignment::class.java)\r
63         val resourceAssignmentValidator = ResourceAssignmentValidationServiceImpl()\r
64         resourceAssignmentValidator.validate(assignments!!)\r
65     }\r
66 }