Skip to content

Commit

Permalink
fix test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Harzenetter <lharzenetter@gmx.de>
  • Loading branch information
lharzenetter committed Jul 27, 2021
1 parent 6f33f4b commit 900ac42
Show file tree
Hide file tree
Showing 39 changed files with 727 additions and 1,051 deletions.
Expand Up @@ -29,10 +29,10 @@
import org.eclipse.winery.compliance.checking.ServiceTemplateCheckingResult;
import org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker;
import org.eclipse.winery.compliance.checking.ToscaComplianceRuleMatcher;
import org.eclipse.winery.model.ids.extensions.ComplianceRuleId;
import org.eclipse.winery.model.ids.definitions.DefinitionsChildId;
import org.eclipse.winery.model.ids.definitions.NodeTypeId;
import org.eclipse.winery.model.ids.definitions.ServiceTemplateId;
import org.eclipse.winery.model.ids.extensions.ComplianceRuleId;
import org.eclipse.winery.model.tosca.TExtensibleElements;
import org.eclipse.winery.model.tosca.TNodeTemplate;
import org.eclipse.winery.model.tosca.TNodeType;
Expand Down Expand Up @@ -75,9 +75,10 @@ private void persist(HashMap<DefinitionsChildId, TExtensibleElements> allEntitie

@Test
public void testTComplianceRulePersistence() throws Exception {
OTComplianceRule rule = new OTComplianceRule(new OTComplianceRule.Builder());
rule.setName("test");
rule.setTargetNamespace(TEST_TARGET_NAMESPACE);
OTComplianceRule rule = new OTComplianceRule.Builder("test")
.setName("test")
.setTargetNamespace(TEST_TARGET_NAMESPACE)
.build();

ComplianceRuleId id = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test"));
BackendUtils.persist(repository, id, rule);
Expand Down
Expand Up @@ -72,7 +72,7 @@ public static TTopologyTemplate determineStatefulComponents(TTopologyTemplate to
.filter(nodeTemplate -> {
TNodeType type = nodeTypes.get(nodeTemplate.getType());
if (Objects.nonNull(type.getTags())) {
return type.getTags().getTag()
return type.getTags()
.stream()
.anyMatch(
tag -> "stateful".equalsIgnoreCase(tag.getName())
Expand Down
Expand Up @@ -139,7 +139,7 @@ private static TTopologyTemplate completeModel(ServiceTemplateId serviceTemplate
placementServiceTemplate.setId(placementServiceTemplate.getName());

// resolve open requirements until the topology is completed
while (!splitting.getOpenRequirements(topology).isEmpty()) {
while (topology != null && !splitting.getOpenRequirements(topology).isEmpty()) {
// add a target label to the topology based on the provider and location assignment
assignNodesToTargetLabels(topology);
placementServiceTemplate.setTopologyTemplate(topology);
Expand Down Expand Up @@ -563,7 +563,7 @@ private static List<TServiceTemplate> getServiceTemplatesWithTags() {
*/
private static boolean isUnsuitedProvider(TServiceTemplate template, TNodeTemplate node, String location,
Map<String, List<String>> blackList) {
List<TTag> tags = template.getTags().getTag();
List<TTag> tags = template.getTags();
TTag providerTag = getTag(tags, TAG_NAME_PROVIDER);
TTag locationTag = getTag(tags, TAG_NAME_LOCATION);

Expand Down Expand Up @@ -614,13 +614,13 @@ private static List<String> getViableProviders(TNodeTemplate node, String locati
if (Objects.nonNull(node.getPolicies())) {
for (TPolicy policy : node.getPolicies().getPolicy()) {
// check the tags of the provider for the policy name
if (Objects.isNull(getTag(template.getTags().getTag(), policy.getPolicyType().toString()))) {
if (Objects.isNull(getTag(template.getTags(), policy.getPolicyType().toString()))) {
continue template;
}
}
}

providers.add(getTag(template.getTags().getTag(), TAG_NAME_PROVIDER).getValue());
providers.add(getTag(template.getTags(), TAG_NAME_PROVIDER).getValue());
}
return providers;
}
Expand Down
@@ -0,0 +1,101 @@
/*******************************************************************************
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*******************************************************************************/

package org.eclipse.winery.model.tosca;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlTransient;

import io.github.adr.embedded.ADR;
import org.eclipse.jdt.annotation.Nullable;

@XmlTransient
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class HasIdAndTags extends HasId implements HasTags {

@XmlElementWrapper(name = "Tags")
@XmlElement(name = "Tag", required = true)
protected List<TTag> tags;

public HasIdAndTags(Builder<?> builder) {
super(builder);
this.tags = builder.tags;
}

@Deprecated
public HasIdAndTags() {
}

public List<TTag> getTags() {
return tags;
}

public void setTags(@Nullable List<TTag> value) {
this.tags = value;
}

@ADR(11)
public abstract static class Builder<T extends Builder<T>> extends HasId.Builder<T> {

private List<TTag> tags;

public Builder(String id) {
super(id);
}

public Builder(TExtensibleElements extensibleElements) {
this.addDocumentation(extensibleElements.getDocumentation());
this.addAny(extensibleElements.getAny());
this.addOtherAttributes(extensibleElements.getOtherAttributes());
}

public T addTags(List<TTag> tags) {
if (tags == null || tags.isEmpty()) {
return self();
}

if (this.tags == null) {
this.tags = tags;
} else {
this.tags.addAll(tags);
}
return self();
}

public T addTag(TTag tag) {
if (tag == null) {
return self();
}

ArrayList<TTag> tmp = new ArrayList<>();
tmp.add(tag);
return addTags(tmp);
}

public T addTag(String key, String value) {
if (value == null) {
return self();
}

TTag tag = new TTag.Builder(key, value).build();
return addTag(tag);
}
}
}
Expand Up @@ -14,7 +14,9 @@

package org.eclipse.winery.model.tosca;

import java.util.List;

public interface HasTags {

TTags getTags();
List<TTag> getTags();
}
Expand Up @@ -68,13 +68,10 @@
TPolicyType.class,
TDataType.class,
})
public abstract class TEntityType extends TExtensibleElements implements HasName, HasInheritance, HasTargetNamespace {
public abstract class TEntityType extends TExtensibleElementWithTags implements HasName, HasInheritance, HasTargetNamespace {

public static final String NS_SUFFIX_PROPERTIES_DEFINITION_WINERY = "propertiesdefinition/winery";

@XmlElement(name = "Tags")
protected TTags tags;

@XmlElement(name = "DerivedFrom")
protected TEntityType.DerivedFrom derivedFrom;

Expand Down Expand Up @@ -115,7 +112,6 @@ public TEntityType() {

public TEntityType(Builder<?> builder) {
super(builder);
this.tags = builder.tags;
this.derivedFrom = builder.derivedFrom;
this.properties = builder.properties;
this.name = builder.name;
Expand Down Expand Up @@ -153,15 +149,6 @@ public void setAttributeDefinitions(List<AttributeDefinition> attributeDefinitio
this.attributeDefinitions = attributeDefinitions;
}

@Nullable
public TTags getTags() {
return tags;
}

public void setTags(@Nullable TTags value) {
this.tags = value;
}

public TEntityType.@Nullable DerivedFrom getDerivedFrom() {
return derivedFrom;
}
Expand Down Expand Up @@ -245,13 +232,13 @@ public WinerysPropertiesDefinition getWinerysPropertiesDefinition() {
return null;
}
WinerysPropertiesDefinition res = (WinerysPropertiesDefinition) properties;
// we put defaults if elementname and namespace have not been set
// we put defaults if element name and namespace have not been set
if (res.getElementName() == null) {
res.setElementName("Properties");
}

if (res.getNamespace() == null) {
// we use the targetnamespace of the original element
// we use the target namespace of the original element
String ns = this.getTargetNamespace();
if (!ns.endsWith("/")) {
ns += "/";
Expand Down Expand Up @@ -313,14 +300,18 @@ public int hashCode() {
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
public static class YamlPropertyDefinition {

private String name;

@XmlAttribute(name = "type", required = true)
private QName type;
private String description;
private Boolean required;

@XmlElement(name = "default")
private Object defaultValue;
private YamlPropertyDefinition.Status status;

@XmlElement
private List<ConstraintClauseKV> constraints;

Expand All @@ -329,6 +320,7 @@ public static class YamlPropertyDefinition {
@XmlElement(name = "key_schema")
private TSchema keySchema;

@SuppressWarnings("unused")
public YamlPropertyDefinition() {
// added for xml serialization!
}
Expand All @@ -345,7 +337,7 @@ private YamlPropertyDefinition(Builder builder) {
this.entrySchema = builder.entrySchema;
}

@XmlEnum(String.class)
@XmlEnum()
public enum Status {
supported,
unsupported,
Expand Down Expand Up @@ -601,11 +593,10 @@ public void setType(QName type) {
}

@ADR(11)
public abstract static class Builder<T extends Builder<T>> extends TExtensibleElements.Builder<T> {
public abstract static class Builder<T extends Builder<T>> extends TExtensibleElementWithTags.Builder<T> {

private final String name;

private TTags tags;
private TEntityType.DerivedFrom derivedFrom;
private PropertiesDefinition properties;
private boolean abstractValue;
Expand All @@ -621,19 +612,13 @@ public Builder(TEntityType entityType) {
super(entityType);
this.name = entityType.getName();
this.derivedFrom = entityType.getDerivedFrom();
this.addTags(entityType.getTags());
this.abstractValue = entityType.getAbstract();
this.finalValue = entityType.getFinal();
this.targetNamespace = entityType.getTargetNamespace();
this.properties = entityType.getProperties();
this.attributeDefinitions = entityType.getAttributeDefinitions();
}

public T setTags(TTags tags) {
this.tags = tags;
return self();
}

public T setDerivedFrom(TEntityType.DerivedFrom derivedFrom) {
this.derivedFrom = derivedFrom;
return self();
Expand Down Expand Up @@ -682,50 +667,6 @@ public T setTargetNamespace(String targetNamespace) {
return self();
}

public T addTags(TTags tags) {
if (tags == null || tags.getTag().isEmpty()) {
return self();
}

if (this.tags == null) {
this.tags = tags;
} else {
this.tags.getTag().addAll(tags.getTag());
}
return self();
}

public T addTags(List<TTag> tags) {
if (tags == null) {
return self();
}

TTags tmp = new TTags();
tmp.getTag().addAll(tags);
return addTags(tmp);
}

public T addTags(TTag tags) {
if (tags == null) {
return self();
}

TTags tmp = new TTags();
tmp.getTag().add(tags);
return addTags(tmp);
}

public T addTags(String key, String value) {
if (value == null) {
return self();
}

TTag tag = new TTag();
tag.setName(key);
tag.setValue(value);
return addTags(tag);
}

public T setAttributeDefinitions(List<AttributeDefinition> attributeDefinitions) {
this.attributeDefinitions = attributeDefinitions;
return self();
Expand Down

0 comments on commit 900ac42

Please sign in to comment.