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.ArtifactDefinition;
26 import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
27 import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
28 import org.onap.sdc.tosca.datatypes.model.Constraint;
29 import org.onap.sdc.tosca.datatypes.model.EntrySchema;
30 import org.onap.sdc.tosca.datatypes.model.NodeType;
31 import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
32 import org.onap.sdc.tosca.datatypes.model.Status;
33 import org.openecomp.sdc.tosca.services.ToscaConstants;
34 import org.onap.sdc.tosca.services.YamlUtil;
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
43 * @since September 06, 2016.
45 public class CapabilityDefinitionTest {
48 public void cloneTest() {
49 CapabilityDefinition capDef1 = new CapabilityDefinition();
50 Map<String, AttributeDefinition> attributes = new HashMap<>();
51 attributes.put("key1", getAttributeDefinition());
52 capDef1.setAttributes(attributes);
54 capDef1.setDescription("This is my desc");
55 capDef1.setOccurrences(getMockOccurrences());
57 Map<String, PropertyDefinition> properties = new HashMap<>();
58 PropertyDefinition propertyDefinition = getMockPropertyDefinition();
59 properties.put("key1", propertyDefinition);
60 capDef1.setProperties(properties);
61 capDef1.setType("My Type");
62 List<String> valid_source_types = new ArrayList<>();
63 valid_source_types.add("nonono");
64 capDef1.setValid_source_types(valid_source_types);
66 CapabilityDefinition capDef2 = capDef1.clone();
67 NodeType nodeType = new NodeType();
68 nodeType.setCapabilities(new HashMap<>());
69 nodeType.getCapabilities().put("cap1", capDef1);
70 nodeType.getCapabilities().put("cap2", capDef2);
72 String yamlString = new YamlUtil().objectToYaml(nodeType);
73 Boolean passResult = !yamlString.contains("&") && !yamlString.contains("*");
74 Assert.assertEquals(true, passResult);
77 private PropertyDefinition getMockPropertyDefinition() {
78 PropertyDefinition propertyDefinition = new PropertyDefinition();
79 propertyDefinition.setConstraints(getMockConstraints());
80 propertyDefinition.setDescription("desc");
81 propertyDefinition.setType("typeProp");
82 propertyDefinition.set_default(5);
83 propertyDefinition.setEntry_schema(getMockEntrySchema());
84 propertyDefinition.setRequired(false);
85 propertyDefinition.setStatus(Status.UNSUPPORTED);
86 return propertyDefinition;
89 private Object[] getMockOccurrences() {
90 Object[] occurrences = new Object[2];
92 occurrences[1] = ToscaConstants.UNBOUNDED;
96 private ArtifactDefinition getMockArtifactDefinition() {
97 ArtifactDefinition artifactDefinition = new ArtifactDefinition();
98 artifactDefinition.setType("type1");
99 artifactDefinition.setDescription("description of openecomp def");
100 artifactDefinition.setDeploy_path("my deployment path");
101 artifactDefinition.setFile("my file");
102 artifactDefinition.setRepository("my repository");
103 return artifactDefinition;
106 private AttributeDefinition getAttributeDefinition() {
107 AttributeDefinition attributeDefinition = new AttributeDefinition();
108 attributeDefinition.setDescription("desc1");
109 attributeDefinition.setType("type1");
110 attributeDefinition.set_default("none");
111 attributeDefinition.setEntry_schema(getMockEntrySchema());
112 attributeDefinition.setStatus(Status.UNSUPPORTED);
113 return attributeDefinition;
116 private EntrySchema getMockEntrySchema() {
117 EntrySchema entrySchema = new EntrySchema();
118 entrySchema.setType("string");
119 entrySchema.setDescription("string for string");
120 List<Constraint> constraints = getMockConstraints();
121 entrySchema.setConstraints(constraints);
125 private List<Constraint> getMockConstraints() {
126 List<Constraint> constraints = new ArrayList<>();
127 Constraint constraint = new Constraint();
128 constraint.setEqual("5");
129 constraints.add(constraint);