9f6bd25038c1a68c21190aed230a17ae62f751e5
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  * Modifications copyright (c) 2019 Nokia
20  * ================================================================================
21  */
22
23 package org.openecomp.sdc.tosca.datatypes.model;
24
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.onap.sdc.tosca.datatypes.model.NodeType;
28 import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
29 import org.onap.sdc.tosca.services.YamlUtil;
30
31 import java.util.ArrayList;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35
36 import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
37 import static org.hamcrest.MatcherAssert.assertThat;
38
39 /**
40  * @author shiria
41  * @since September 07, 2016.
42  */
43 public class RequirementDefinitionTest {
44   @Test
45   public void shouldHaveValidGettersAndSetters() {
46     assertThat(RequirementDefinition.class, hasValidGettersAndSetters());
47   }
48
49   @Test
50   public void cloneTest() {
51     RequirementDefinition reqDef1 = new RequirementDefinition();
52     reqDef1.setNode("node1");
53     reqDef1.setRelationship("my Relationship");
54     reqDef1.setCapability("capabilities");
55     reqDef1.setOccurrences(new Object[]{1, 1});
56
57     RequirementDefinition reqDef2 = reqDef1.clone();
58     NodeType nodeType = new NodeType();
59
60     List<Map<String, RequirementDefinition>> requirements = new ArrayList<>();
61     Map<String, RequirementDefinition> reqMap1 = new HashMap<>();
62     reqMap1.put("req1", reqDef1);
63     requirements.add(reqMap1);
64     Map<String, RequirementDefinition> reqMap2 = new HashMap<>();
65     reqMap2.put("req2", reqDef2);
66     requirements.add(reqMap2);
67     nodeType.setRequirements(requirements);
68
69     String yamlString = new YamlUtil().objectToYaml(nodeType);
70     Boolean passResult = !yamlString.contains("&") && !yamlString.contains("*");
71     Assert.assertEquals(true, passResult);
72   }
73
74
75 }