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.openecomp.core.utilities.yaml.YamlUtil;
 
  26 import org.openecomp.sdc.tosca.services.ToscaConstants;
 
  28 import java.util.ArrayList;
 
  29 import java.util.HashMap;
 
  30 import java.util.List;
 
  35  * @since September 06, 2016.
 
  37 public class CapabilityDefinitionTest {
 
  40   public void cloneTest() {
 
  41     CapabilityDefinition capDef1 = new CapabilityDefinition();
 
  42     Map<String, AttributeDefinition> attributes = new HashMap<>();
 
  43     attributes.put("key1", getAttributeDefinition());
 
  44     capDef1.setAttributes(attributes);
 
  46     capDef1.setDescription("This is my desc");
 
  47     capDef1.setOccurrences(getMockOccurrences());
 
  49     Map<String, PropertyDefinition> properties = new HashMap<>();
 
  50     PropertyDefinition propertyDefinition = getMockPropertyDefinition();
 
  51     properties.put("key1", propertyDefinition);
 
  52     capDef1.setProperties(properties);
 
  53     capDef1.setType("My Type");
 
  54     List<String> valid_source_types = new ArrayList<>();
 
  55     valid_source_types.add("nonono");
 
  56     capDef1.setValid_source_types(valid_source_types);
 
  58     CapabilityDefinition capDef2 = capDef1.clone();
 
  59     NodeType nodeType = new NodeType();
 
  60     nodeType.setCapabilities(new HashMap<>());
 
  61     nodeType.getCapabilities().put("cap1", capDef1);
 
  62     nodeType.getCapabilities().put("cap2", capDef2);
 
  64     String yamlString = new YamlUtil().objectToYaml(nodeType);
 
  65     Boolean passResult = !yamlString.contains("&") && !yamlString.contains("*");
 
  66     Assert.assertEquals(true, passResult);
 
  69   private PropertyDefinition getMockPropertyDefinition() {
 
  70     PropertyDefinition propertyDefinition = new PropertyDefinition();
 
  71     propertyDefinition.setConstraints(getMockConstraints());
 
  72     propertyDefinition.setDescription("desc");
 
  73     propertyDefinition.setType("typeProp");
 
  74     propertyDefinition.set_default(5);
 
  75     propertyDefinition.setEntry_schema(getMockEntrySchema());
 
  76     propertyDefinition.setRequired(false);
 
  77     propertyDefinition.setStatus(Status.UNSUPPORTED);
 
  78     return propertyDefinition;
 
  81   private Object[] getMockOccurrences() {
 
  82     Object[] occurrences = new Object[2];
 
  84     occurrences[1] = ToscaConstants.UNBOUNDED;
 
  88   private ArtifactDefinition getMockArtifactDefinition() {
 
  89     ArtifactDefinition artifactDefinition = new ArtifactDefinition();
 
  90     artifactDefinition.setType("type1");
 
  91     artifactDefinition.setDescription("description of openecomp def");
 
  92     artifactDefinition.setDeploy_path("my deployment path");
 
  93     artifactDefinition.setFile("my file");
 
  94     artifactDefinition.setRepository("my repository");
 
  95     return artifactDefinition;
 
  98   private AttributeDefinition getAttributeDefinition() {
 
  99     AttributeDefinition attributeDefinition = new AttributeDefinition();
 
 100     attributeDefinition.setDescription("desc1");
 
 101     attributeDefinition.setType("type1");
 
 102     attributeDefinition.set_default("none");
 
 103     attributeDefinition.setEntry_schema(getMockEntrySchema());
 
 104     attributeDefinition.setStatus(Status.UNSUPPORTED);
 
 105     return attributeDefinition;
 
 108   private EntrySchema getMockEntrySchema() {
 
 109     EntrySchema entrySchema = new EntrySchema();
 
 110     entrySchema.setType("string");
 
 111     entrySchema.setDescription("string for string");
 
 112     List<Constraint> constraints = getMockConstraints();
 
 113     entrySchema.setConstraints(constraints);
 
 117   private List<Constraint> getMockConstraints() {
 
 118     List<Constraint> constraints = new ArrayList<>();
 
 119     Constraint constraint = new Constraint();
 
 120     constraint.setEqual("5");
 
 121     constraints.add(constraint);