2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.tosca.datatypes.model;
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.onap.sdc.tosca.datatypes.model.*;
26 import org.onap.sdc.tosca.services.YamlUtil;
27 import org.openecomp.sdc.tosca.services.ToscaConstants;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
36 * @since September 06, 2016.
38 public class CapabilityDefinitionTest {
41 public void cloneTest() {
42 CapabilityDefinition capDef1 = new CapabilityDefinition();
43 Map<String, AttributeDefinition> attributes = new HashMap<>();
44 attributes.put("key1", getAttributeDefinition());
45 capDef1.setAttributes(attributes);
47 capDef1.setDescription("This is my desc");
48 capDef1.setOccurrences(getMockOccurrences());
50 Map<String, PropertyDefinition> properties = new HashMap<>();
51 PropertyDefinition propertyDefinition = getMockPropertyDefinition();
52 properties.put("key1", propertyDefinition);
53 capDef1.setProperties(properties);
54 capDef1.setType("My Type");
55 List<String> valid_source_types = new ArrayList<>();
56 valid_source_types.add("nonono");
57 capDef1.setValid_source_types(valid_source_types);
59 CapabilityDefinition capDef2 = capDef1.clone();
60 NodeType nodeType = new NodeType();
61 nodeType.setCapabilities(new HashMap<>());
62 nodeType.getCapabilities().put("cap1", capDef1);
63 nodeType.getCapabilities().put("cap2", capDef2);
65 String yamlString = new YamlUtil().objectToYaml(nodeType);
66 Boolean passResult = !yamlString.contains("&") && !yamlString.contains("*");
67 Assert.assertEquals(true, passResult);
70 private PropertyDefinition getMockPropertyDefinition() {
71 PropertyDefinition propertyDefinition = new PropertyDefinition();
72 propertyDefinition.setConstraints(getMockConstraints());
73 propertyDefinition.setDescription("desc");
74 propertyDefinition.setType("typeProp");
75 propertyDefinition.set_default(5);
76 propertyDefinition.setEntry_schema(getMockEntrySchema());
77 propertyDefinition.setRequired(false);
78 propertyDefinition.setStatus(Status.UNSUPPORTED);
79 return propertyDefinition;
82 private Object[] getMockOccurrences() {
83 Object[] occurrences = new Object[2];
85 occurrences[1] = ToscaConstants.UNBOUNDED;
89 private ArtifactDefinition getMockArtifactDefinition() {
90 ArtifactDefinition artifactDefinition = new ArtifactDefinition();
91 artifactDefinition.setType("type1");
92 artifactDefinition.setDescription("description of openecomp def");
93 artifactDefinition.setDeploy_path("my deployment path");
94 artifactDefinition.setFile("my file");
95 artifactDefinition.setRepository("my repository");
96 return artifactDefinition;
99 private AttributeDefinition getAttributeDefinition() {
100 AttributeDefinition attributeDefinition = new AttributeDefinition();
101 attributeDefinition.setDescription("desc1");
102 attributeDefinition.setType("type1");
103 attributeDefinition.set_default("none");
104 attributeDefinition.setEntry_schema(getMockEntrySchema());
105 attributeDefinition.setStatus(Status.UNSUPPORTED);
106 return attributeDefinition;
109 private EntrySchema getMockEntrySchema() {
110 EntrySchema entrySchema = new EntrySchema();
111 entrySchema.setType("string");
112 entrySchema.setDescription("string for string");
113 List<Constraint> constraints = getMockConstraints();
114 entrySchema.setConstraints(constraints);
118 private List<Constraint> getMockConstraints() {
119 List<Constraint> constraints = new ArrayList<>();
120 Constraint constraint = new Constraint();
121 constraint.setEqual("5");
122 constraints.add(constraint);