-
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation
public class UnsortedPropertyUtils extends PropertyUtils {
@Override
- protected Set<Property> createPropertySet(final Class clazz, final BeanAccess beanAccess) throws IntrospectionException {
+ protected Set<Property> createPropertySet(final Class clazz, final BeanAccess beanAccess) {
final Collection<Property> fields = getPropertiesMap(clazz, BeanAccess.FIELD).values();
return new LinkedHashSet<>(fields);
}
-}
+}
\ No newline at end of file
private static final String FAILED_TO_GET_DEFAULT_IMPORTS_CONFIGURATION = "convertToToscaTemplate - failed to get Default Imports section from configuration";
private static final String NOT_SUPPORTED_COMPONENT_TYPE = "Not supported component type {}";
private static final String NATIVE_ROOT = "tosca.nodes.Root";
- private static YamlUtil yamlUtil = new YamlUtil();
+ private static final YamlUtil yamlUtil = new YamlUtil();
public ToscaExportHandler() {
}
private static class UnsortedPropertyUtils extends PropertyUtils {
@Override
- protected Set<Property> createPropertySet(Class type, BeanAccess bAccess)
- throws IntrospectionException {
+ protected Set<Property> createPropertySet(Class type, BeanAccess bAccess) {
Collection<Property> fields = getPropertiesMap(type, BeanAccess.FIELD).values();
return new LinkedHashSet<>(fields);
}
<artifactId>onap-generic-artifact-browser-service</artifactId>
<properties>
- <snakeyaml.version>1.21</snakeyaml.version>
<jsurfer.version>1.4.3</jsurfer.version>
<jacoco.skip>false</jacoco.skip>
</properties>
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.tosca.services;
+
+import org.yaml.snakeyaml.introspector.BeanAccess;
+import org.yaml.snakeyaml.introspector.Property;
+import org.yaml.snakeyaml.introspector.PropertyUtils;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+public class MyPropertyUtils extends PropertyUtils {
+ //Unsorted properties
+ @Override
+ protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bnAccess) {
+ return new LinkedHashSet<>(getPropertiesMap(type,
+ BeanAccess.FIELD).values());
+ }
+
+ @Override
+ public Property getProperty(Class<?> type, String name) {
+ String updatedName = name;
+ if (YamlUtil.DEFAULT.equals(updatedName)) {
+ updatedName = YamlUtil.DEFAULT_STR;
+ }
+ return super.getProperty(type, updatedName);
+ }
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.tosca.services;
+
+import org.yaml.snakeyaml.constructor.Constructor;
+import org.yaml.snakeyaml.nodes.MappingNode;
+import org.yaml.snakeyaml.parser.ParserException;
+
+import java.util.AbstractMap;
+import java.util.Map;
+import java.util.Set;
+
+public class StrictMapAppenderConstructor extends Constructor {
+ /**
+ * Instantiates a new Strict map appender constructor.
+ *
+ * @param theRoot the the root
+ */
+ public StrictMapAppenderConstructor(Class<?> theRoot) {
+ super(theRoot);
+ }
+
+ @Override
+ protected Map<Object, Object> createDefaultMap(int initSize) {
+ final Map<Object, Object> delegate = super.createDefaultMap(initSize);
+ return new AbstractMap<>() {
+ @Override
+ public Object put(Object key, Object value) {
+ if (delegate.containsKey(key)) {
+ throw new IllegalStateException("duplicate key: " + key);
+ }
+ return delegate.put(key, value);
+ }
+
+ @Override
+ public Set<Entry<Object, Object>> entrySet() {
+ return delegate.entrySet();
+ }
+ };
+ }
+
+ @Override
+ protected Map<Object, Object> constructMapping(MappingNode node) {
+ try {
+ return super.constructMapping(node);
+ } catch (IllegalStateException exception) {
+ throw new ParserException("while parsing MappingNode",
+ node.getStartMark(), exception.getMessage(),
+ node.getEndMark());
+ }
+ }
+}
public class ToscaPropertyUtilsWithHeatExtension extends MyPropertyUtils {
@Override
- public Property getProperty(Class<? extends Object> type, String name) throws IntrospectionException {
+ public Property getProperty(Class<? extends Object> type, String name) {
Class<? extends Object> classType = type;
try {
if (type.equals(Class.forName(TOSCA_MODEL_PARAMETER_DEFINITION))) {
package org.onap.sdc.tosca.services;
-import java.util.List;
-import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.DumperOptions;
+import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
-import org.yaml.snakeyaml.introspector.BeanAccess;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.introspector.PropertyUtils;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.nodes.Tag;
-import org.yaml.snakeyaml.parser.ParserException;
import org.yaml.snakeyaml.representer.Representer;
-
-import java.beans.IntrospectionException;
import java.io.IOException;
import java.io.InputStream;
-import java.util.AbstractMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
/**
* The type Yaml util.
public class YamlUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(YamlUtil.class.getName());
- private static final String DEFAULT = "default";
- private static final String DEFAULT_STR = "_default";
-
- /**
- * Yaml to object t.
- *
- * @param <T> the type parameter
- * @param yamlContent the yaml content
- * @param typClass the t class
- * @return the t
- */
- public <T> T yamlToObject(String yamlContent, Class<T> typClass) {
- Constructor constructor = getConstructor(typClass);
- constructor.setPropertyUtils(getPropertyUtils());
- TypeDescription yamlFileDescription = new TypeDescription(typClass);
- constructor.addTypeDescription(yamlFileDescription);
- Yaml yaml = new Yaml(constructor);
- T yamlObj = (T) yaml.load(yamlContent);
- //noinspection ResultOfMethodCallIgnored
- yamlObj.toString();
- return yamlObj;
- }
+ static final String DEFAULT = "default";
+ static final String DEFAULT_STR = "_default";
- public InputStream loadYamlFileIs(String yamlFullFileName) {
- return YamlUtil.class.getResourceAsStream(yamlFullFileName);
- }
-
- /**
- * Yaml to object t.
- *
- * @param <T> the type parameter
- * @param yamlContent the yaml content
- * @param typClass the t class
- * @return the t
- */
- public <T> T yamlToObject(InputStream yamlContent, Class<T> typClass) {
- try {
- Constructor constructor = getConstructor(typClass);
- constructor.setPropertyUtils(getPropertyUtils());
- TypeDescription yamlFileDescription = new TypeDescription(typClass);
- constructor.addTypeDescription(yamlFileDescription);
- Yaml yaml = new Yaml(constructor);
- T yamlObj = (T) yaml.load(yamlContent);
- if (yamlObj != null) {
+ /**
+ * Yaml to object t.
+ *
+ * @param <T> the type parameter
+ * @param yamlContent the yaml content
+ * @param typClass the t class
+ * @return the t
+ */
+ public <T> T yamlToObject(String yamlContent, Class<T> typClass) {
+ Constructor constructor = getConstructor(typClass);
+ constructor.setPropertyUtils(getPropertyUtils());
+ TypeDescription yamlFileDescription = new TypeDescription(typClass);
+ constructor.addTypeDescription(yamlFileDescription);
+ T yamlObj = new Yaml(constructor, new Representer(), new DumperOptions(), getLoaderOptions()).load(yamlContent);;
//noinspection ResultOfMethodCallIgnored
yamlObj.toString();
return yamlObj;
- } else {
- throw new RuntimeException();
- }
- } catch (Exception exception) {
- throw new RuntimeException(exception);
- } finally {
- try {
- if (yamlContent != null) {
- yamlContent.close();
+ }
+
+ public InputStream loadYamlFileIs(String yamlFullFileName) {
+ return YamlUtil.class.getResourceAsStream(yamlFullFileName);
+ }
+
+ /**
+ * Yaml to object t.
+ *
+ * @param <T> the type parameter
+ * @param yamlContent the yaml content
+ * @param typClass the t class
+ * @return the t
+ */
+ public <T> T yamlToObject(InputStream yamlContent, Class<T> typClass) {
+ try {
+ Constructor constructor = getConstructor(typClass);
+ constructor.setAllowDuplicateKeys(false);
+ constructor.setPropertyUtils(getPropertyUtils());
+ TypeDescription yamlFileDescription = new TypeDescription(typClass);
+ constructor.addTypeDescription(yamlFileDescription);
+ //No Yaml Constructor takes only Constructor and LoaderOptions, that is why I had to pass anonymous Representer and DumperOptions objects
+ T yamlObj = new Yaml(constructor, new Representer(), new DumperOptions(), getLoaderOptions()).load(yamlContent);
+ if (yamlObj != null) {
+ //noinspection ResultOfMethodCallIgnored
+ yamlObj.toString();
+ return yamlObj;
+ } else {
+ throw new RuntimeException();
+ }
+ } catch (Exception exception) {
+ throw new RuntimeException(exception);
+ } finally {
+ try {
+ if (yamlContent != null) {
+ yamlContent.close();
+ }
+ } catch (IOException ignore) {
+ //do nothing
+ }
}
- } catch (IOException ignore) {
- //do nothing
- }
}
- }
+ private LoaderOptions getLoaderOptions() {
+ LoaderOptions options = new LoaderOptions();
+ options.setAllowDuplicateKeys(false);
+ options.setMaxAliasesForCollections(9999);
+ return options;
+ }
- /**
- * Gets constructor.
- *
- * @param <T> the type parameter
- * @param typClass the t class
- * @return the constructor
- */
- public <T> Constructor getConstructor(Class<T> typClass) {
- return new StrictMapAppenderConstructor(typClass);
- }
- /**
- * Gets property utils.
- *
- * @return the property utils
- */
- protected PropertyUtils getPropertyUtils() {
- return new MyPropertyUtils();
- }
+ /**
+ * Gets constructor.
+ *
+ * @param <T> the type parameter
+ * @param typClass the t class
+ * @return the constructor
+ */
+ public <T> Constructor getConstructor(Class<T> typClass) {
+ return new StrictMapAppenderConstructor(typClass);
+ }
+ /**
+ * Gets property utils.
+ *
+ * @return the property utils
+ */
+ protected PropertyUtils getPropertyUtils() {
+ return new MyPropertyUtils();
+ }
- /**
- * Yaml to map map.
- *
- * @param yamlContent the yaml content
- * @return the map
- */
- public Map<String, LinkedHashMap<String, Object>> yamlToMap(InputStream yamlContent) {
- Yaml yaml = new Yaml();
- return (Map<String, LinkedHashMap<String, Object>>) yaml.load(yamlContent);
- }
+
+ /**
+ * Yaml to map map.
+ *
+ * @param yamlContent the yaml content
+ * @return the map
+ */
+ public Map<String, LinkedHashMap<String, Object>> yamlToMap(InputStream yamlContent) {
+ return new Yaml().load(yamlContent);
+ }
/**
* @return The YAML Object
*/
public static Object read(final InputStream yamlFileInputStream) {
- final Yaml yaml = new Yaml();
- return yaml.load(yamlFileInputStream);
- }
-
- /**
- * Object to yaml string.
- * @param obj the obj
- * @return the string
- */
- public String objectToYaml(Object obj) {
- DumperOptions options = new DumperOptions();
- options.setPrettyFlow(true);
- options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
- Representer representer = new CustomRepresenter();
- representer.addClassTag(obj.getClass(), Tag.MAP);
- representer.setPropertyUtils(new MyPropertyUtils());
-
- Yaml yaml = new Yaml(representer, options);
- return yaml.dump(obj);
- }
-
- /**
- * Is yaml file content valid boolean.
- *
- * @param yamlFullFileName the yaml full file name
- * @return the boolean
- */
- public boolean isYamlFileContentValid(String yamlFullFileName) {
- Yaml yaml = new Yaml();
- try {
- Object loadResult = yaml.load(yamlFullFileName);
- return loadResult != null;
- } catch (Exception exception) {
- return false;
- }
- }
-
-
- private class CustomRepresenter extends Representer {
- @Override
- protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
- //remove the bean type from the output yaml (!! ...)
- if (!classTags.containsKey(javaBean.getClass())) {
- addClassTag(javaBean.getClass(), Tag.MAP);
- }
-
- return super.representJavaBean(properties, javaBean);
- }
-
- @Override
- protected NodeTuple representJavaBeanProperty(Object javaBean, Property property,
- Object propertyValue, Tag customTag) {
- if (propertyValue == null) {
- return null;
- } else {
- NodeTuple defaultNode =
- super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
-
- return DEFAULT_STR.equals(property.getName())
- ? new NodeTuple(representData(DEFAULT), defaultNode.getValueNode())
- : defaultNode;
- }
- }
- }
-
-
- /**
- * The type My property utils.
- */
- public class MyPropertyUtils extends PropertyUtils {
- //Unsorted properties
- @Override
- protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bnAccess)
- throws IntrospectionException {
- return new LinkedHashSet<>(getPropertiesMap(type,
- BeanAccess.FIELD).values());
+ return new Yaml().load(yamlFileInputStream);
}
- @Override
- public Property getProperty(Class<?> type, String name) throws IntrospectionException {
- String updatedName = name;
- if (DEFAULT.equals(updatedName)) {
- updatedName = DEFAULT_STR;
- }
- return super.getProperty(type, updatedName);
+ /**
+ * Object to yaml string.
+ *
+ * @param obj the obj
+ * @return the string
+ */
+ public String objectToYaml(Object obj) {
+ DumperOptions options = new DumperOptions();
+ options.setPrettyFlow(true);
+ options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
+ Representer representer = new CustomRepresenter();
+ representer.addClassTag(obj.getClass(), Tag.MAP);
+ representer.setPropertyUtils(new MyPropertyUtils());
+
+ Yaml yaml = new Yaml(representer, options);
+ return yaml.dump(obj);
}
- }
-
- /**
- * The type Strict map appender constructor.
- */
- protected class StrictMapAppenderConstructor extends Constructor {
-
/**
- * Instantiates a new Strict map appender constructor.
+ * Is yaml file content valid boolean.
*
- * @param theRoot the the root
+ * @param yamlFullFileName the yaml full file name
+ * @return the boolean
*/
- public StrictMapAppenderConstructor(Class<?> theRoot) {
- super(theRoot);
+ public boolean isYamlFileContentValid(String yamlFullFileName) {
+ try {
+ return new Yaml().load(yamlFullFileName) != null;
+ } catch (Exception exception) {
+ return false;
+ }
}
- @Override
- protected Map<Object, Object> createDefaultMap() {
- final Map<Object, Object> delegate = super.createDefaultMap();
- return new AbstractMap<Object, Object>() {
+
+ private class CustomRepresenter extends Representer {
@Override
- public Object put(Object key, Object value) {
- if (delegate.containsKey(key)) {
- throw new IllegalStateException("duplicate key: " + key);
- }
- return delegate.put(key, value);
+ protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
+ //remove the bean type from the output yaml (!! ...)
+ if (!classTags.containsKey(javaBean.getClass())) {
+ addClassTag(javaBean.getClass(), Tag.MAP);
+ }
+
+ return super.representJavaBean(properties, javaBean);
}
@Override
- public Set<Entry<Object, Object>> entrySet() {
- return delegate.entrySet();
+ protected NodeTuple representJavaBeanProperty(Object javaBean, Property property,
+ Object propertyValue, Tag customTag) {
+ if (propertyValue == null) {
+ return null;
+ } else {
+ NodeTuple defaultNode =
+ super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
+
+ return DEFAULT_STR.equals(property.getName())
+ ? new NodeTuple(representData(DEFAULT), defaultNode.getValueNode())
+ : defaultNode;
+ }
}
- };
- }
-
- @Override
- protected Map<Object, Object> constructMapping(MappingNode node) {
- try {
- return super.constructMapping(node);
- } catch (IllegalStateException exception) {
- throw new ParserException("while parsing MappingNode",
- node.getStartMark(), exception.getMessage(),
- node.getEndMark());
- }
}
- }
}
<org.reflections.version>0.9.10</org.reflections.version>
<servlet.version>2.5</servlet.version>
<slf4j.version>1.7.21</slf4j.version>
- <snakeyaml.version>1.17</snakeyaml.version>
<spring.framework.version>4.3.18.RELEASE</spring.framework.version>
<swagger.version>2.0.8</swagger.version>
<woodstox.version>4.4.1</woodstox.version>
<groupId>org.openecomp.sdc.onboarding</groupId>
<artifactId>action-library-rest</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../</relativePath>
</parent>
<dependencies>
<groupId>org.openecomp.sdc</groupId>
<artifactId>openecomp-sdc-rest-webapp</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../</relativePath>
</parent>
<modules>
<module>/action-library-rest-services</module>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc</artifactId>
- <relativePath>../../..</relativePath>
+ <artifactId>openecomp-sdc-rest-webapp</artifactId>
<version>1.8.1-SNAPSHOT</version>
</parent>
</parent>
<modules>
- <module>/openecomp-sdc-common-rest</module>
- <module>/vendor-license-rest</module>
- <module>/onboarding-rest-war</module>
- <module>/vendor-software-products-rest</module>
- <module>/validation-rest</module>
- <module>/action-library-rest</module>
- <module>/application-config-rest</module>
- <module>/healthcheck-rest</module>
+ <module>openecomp-sdc-common-rest</module>
+ <module>vendor-license-rest</module>
+ <module>onboarding-rest-war</module>
+ <module>vendor-software-products-rest</module>
+ <module>validation-rest</module>
+ <module>action-library-rest</module>
+ <module>application-config-rest</module>
+ <module>healthcheck-rest</module>
<module>conflict-rest</module>
<module>item-permissions-rest</module>
<module>item-rest</module>
<groupId>org.openecomp.sdc.onboarding</groupId>
<artifactId>validation-rest</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../</relativePath>
</parent>
<dependencies>
<groupId>org.openecomp.sdc</groupId>
<artifactId>openecomp-sdc-rest-webapp</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../</relativePath>
</parent>
<modules>
<groupId>org.openecomp.sdc.onboarding</groupId>
<artifactId>vendor-license-rest</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../</relativePath>
</parent>
<properties>
<groupId>org.openecomp.sdc.onboarding</groupId>
<artifactId>vendor-license-rest</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../</relativePath>
</parent>
<dependencies>
<groupId>org.openecomp.sdc.onboarding</groupId>
<artifactId>vendor-software-products-rest</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../</relativePath>
</parent>
<dependencies>
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anEmptyMap;
-import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.collections.CollectionUtils;
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
- , Messages.INVALID_YAML_FORMAT_1.formatMessage(nonManoPmEventsSource, "while scanning a simple key\n"
- + " in 'reader', line 2, column 1:\n"
- + " key {}\n"
- + " ^\n"
- + "could not find expected ':'\n"
- + " in 'reader', line 2, column 7:\n"
- + " {}\n"
- + " ^\n"))
+ , Messages.INVALID_YAML_FORMAT_1.formatMessage(nonManoPmEventsSource, "while scanning a simple key in 'reader', line 2, column 1: key {} ^could not find expected ':' in 'reader', line 2, column 7: key {} ^"))
);
- expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, "while scanning a simple key\n" +
- " in 'reader', line 2, column 1:\n" +
- " key {}\n" +
- " ^\n" +
- "could not find expected ':'\n" +
- " in 'reader', line 2, column 7:\n" +
- " {}\n" +
- " ^\n")
+ expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, "while scanning a simple key in 'reader', line 2, column 1: key {} ^could not find expected ':' in 'reader', line 2, column 7: key {} ^")
);
- final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
- .validateContent(handler);
+ final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler);
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
}
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
}
- protected void assertExpectedErrors(List<ErrorMessage> actualErrorList, final List<ErrorMessage> expectedErrorList) {
- if (actualErrorList == null) {
- actualErrorList = new ArrayList<>();
- }
-
- printErrorMessages(actualErrorList);
-
- assertThat("The actual error list should have the same size as the expected error list " + actualErrorList.toString()
- , actualErrorList, hasSize(expectedErrorList.size())
- );
-
- assertThat("The actual error and expected error lists should be the same"
- , actualErrorList, containsInAnyOrder(expectedErrorList.toArray(new ErrorMessage[0]))
- );
- }
-
protected void assertExpectedErrors(final String testCase, final Map<String, List<ErrorMessage>> errors, final int expectedErrors){
final List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
printErrorMessages(errorMessages);
}
}
+ private void assertExpectedErrors(List<ErrorMessage> actualErrorList, final List<ErrorMessage> expectedErrorList) {
+ if (actualErrorList == null) {
+ actualErrorList = new ArrayList<>();
+ }
+
+ printErrorMessages(actualErrorList);
+
+ assertThat("The actual error list should have the same size as the expected error list"
+ , actualErrorList, hasSize(expectedErrorList.size())
+ );
+
+ actualErrorList.forEach(error -> {
+ Predicate<ErrorMessage> matching = e -> e.getLevel() == error.getLevel() && sanitize(e.getMessage()).equalsIgnoreCase(sanitize(error.getMessage()));
+ assertTrue("The actual error and expected error lists should be the same", expectedErrorList.stream().anyMatch(matching));
+ });
+ }
+
+ private static String sanitize(String s) {
+ return s.trim().replaceAll("\n", "").replaceAll("\r", "").replaceAll("\\s{2,}", " ").trim();
+ }
+
}
<name>openecomp-facade-api</name>
<artifactId>openecomp-facade-api</artifactId>
- <groupId>org.openecomp.sdc.core</groupId>
<parent>
- <groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <groupId>org.openecomp.sdc.core</groupId>
+ <artifactId>openecomp-facade-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../../../</relativePath>
</parent>
<dependencies>
-
<dependency>
<groupId>org.openecomp.sdc.core</groupId>
<artifactId>openecomp-utilities-lib</artifactId>
<artifactId>openecomp-facade-core</artifactId>
<name>openecomp-facade-core</name>
- <groupId>org.openecomp.sdc.core</groupId>
<parent>
- <artifactId>openecomp-sdc-lib</artifactId>
- <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-facade-lib</artifactId>
+ <groupId>org.openecomp.sdc.core</groupId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../../..</relativePath>
</parent>
<name>openecomp-facade-lib</name>
<artifactId>openecomp-facade-lib</artifactId>
-
<packaging>pom</packaging>
+
<parent>
<artifactId>openecomp-core-lib</artifactId>
<groupId>org.openecomp.sdc.core</groupId>
<module>openecomp-facade-core</module>
</modules>
- <dependencies>
- <dependency>
- <groupId>org.openecomp.sdc.core</groupId>
- <artifactId>openecomp-facade-api</artifactId>
- <version>${project.version}</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.openecomp.sdc.core</groupId>
- <artifactId>openecomp-facade-core</artifactId>
- <version>${project.version}</version>
- <scope>runtime</scope>
- </dependency>
- </dependencies>
</project>
\ No newline at end of file
<module>openecomp-nosqldb-api</module>
<module>openecomp-nosqldb-core</module>
</modules>
-
</project>
\ No newline at end of file
</parent>
<modules>
- <module>/openecomp-facade-lib</module>
- <module>/openecomp-nosqldb-lib</module>
- <module>/openecomp-utilities-lib</module>
- <module>/openecomp-config-lib</module>
- <module>/openecomp-zusammen-lib</module>
- <module>/openecomp-session-lib</module>
+ <module>openecomp-facade-lib</module>
+ <module>openecomp-nosqldb-lib</module>
+ <module>openecomp-utilities-lib</module>
+ <module>openecomp-config-lib</module>
+ <module>openecomp-zusammen-lib</module>
+ <module>openecomp-session-lib</module>
</modules>
</project>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-enrichment-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-enrichment-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-enrichment-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
name = entry.getName()
.substring(entry.getName().lastIndexOf(File.separator) + 1, entry.getName().length());
if (expectedResultFileNameSet.contains(name)) {
- expected = new String(expectedResultMap.get(name)).trim().replace("\r", "");
- actual = new String(FileUtils.toByteArray(zis)).trim().replace("\r", "");
+ expected = sanitize(new String(expectedResultMap.get(name)));
+ actual = sanitize(new String(FileUtils.toByteArray(zis)));
assertEquals("difference in file: " + name, expected, actual);
expectedResultFileNameSet.remove(name);
}
assertEquals(0, expectedResultFileNameSet.size());
}
+
+ private static String sanitize(String s) {
+ return s.trim().replaceAll("\n", "").replaceAll("\r", "").replaceAll("\\s{2,}", " ").trim();
+ }
}
<module>openecomp-sdc-enrichment-core</module>
<module>openecomp-sdc-enrichment-impl</module>
</modules>
-
- <dependencies>
- <dependency>
- <groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-enrichment-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-enrichment-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-vendor-software-product-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- <!--dependency>
- <groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-validation-impl</artifactId>
- <version>${project.version}</version>
- </dependency-->
- </dependencies>
</project>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-externaltesting-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-externaltesting-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<name>openecomp-sdc-model-api</name>
<artifactId>openecomp-sdc-model-api</artifactId>
-
- <parent>
+ <parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-model-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<artifactId>openecomp-facade-core</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-validation-api</artifactId>
- <version>${project.version}</version>
- </dependency>
<dependency>
<groupId>org.openecomp.sdc</groupId>
<artifactId>openecomp-sdc-versioning-core</artifactId>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-model-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<module>openecomp-sdc-model-api</module>
<module>openecomp-sdc-model-impl</module>
</modules>
-
- <dependencies>
- <dependency>
- <groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-model-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-model-impl</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
</project>
<artifactId>openecomp-sdc-notification-api</artifactId>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-notification-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-notification-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<dependency>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-notification-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-notification-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-tosca-generator-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-tosca-generator-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-translator-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-translator-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
while ((entry = zis.getNextEntry()) != null) {
name = entry.getName()
- .substring(entry.getName().lastIndexOf(File.separator) + 1, entry.getName().length());
+ .substring(entry.getName().lastIndexOf(File.separator) + 1);
if (expectedResultFileNameSet.contains(name)) {
- expected = new String(expectedResultMap.get(name)).trim().replace("\r", "");
- actual = new String(FileUtils.toByteArray(zis)).trim().replace("\r", "");
+ expected = sanitize(new String(expectedResultMap.get(name)));
+ actual = sanitize(new String(FileUtils.toByteArray(zis)));
assertEquals("difference in file: " + name, expected, actual);
expectedResultFileNameSet.remove(name);
}
}
+ private static String sanitize(String s) {
+ return s.trim().replaceAll("\n", "").replaceAll("\r", "").replaceAll("\\s{2,}", " ").trim();
+ }
+
public static String getErrorAsString(Map<String, List<ErrorMessage>> errorMessages) {
StringBuilder sb = new StringBuilder();
errorMessages.forEach((file, errorList) -> sb.append("File:").append(file).append(System.lineSeparator())
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
- 107.250.172.217
entry_schema:
type: string
- default: 169.254.1.4
ps_server_names:
label: PS server names
hidden: false
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-validation-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-validation-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
import org.openecomp.core.validation.types.GlobalValidationContext;
import org.openecomp.core.validation.types.MessageContainer;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.validation.Validator;
import org.openecomp.sdc.validation.services.ValidationFactory;
public class ValidationManagerImpl implements ValidationManager {
- private static Logger logger = (Logger) LoggerFactory.getLogger(ValidationManagerImpl.class);
-
private GlobalValidationContext globalContext;
private List<Validator> validators;
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-validation-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
package org.openecomp.sdc.validation.impl.validators;
-import org.onap.sdc.tosca.services.YamlUtil;
+import org.onap.sdc.tosca.services.MyPropertyUtils;
+import org.onap.sdc.tosca.services.StrictMapAppenderConstructor;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
import org.openecomp.core.validation.types.GlobalValidationContext;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.validation.Validator;
import org.openecomp.sdc.validation.impl.util.YamlValidatorUtil;
+import org.yaml.snakeyaml.DumperOptions;
+import org.yaml.snakeyaml.LoaderOptions;
+import org.yaml.snakeyaml.TypeDescription;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.Constructor;
+import org.yaml.snakeyaml.representer.Representer;
import java.io.InputStream;
import java.util.Collection;
import java.util.Set;
public class YamlValidator implements Validator {
- private static final ErrorMessageCode ERROR_CODE_YML_1 = new ErrorMessageCode("YML1");
- private static final ErrorMessageCode ERROR_CODE_YML_2 = new ErrorMessageCode("YML2");
+ private static final ErrorMessageCode ERROR_CODE_YML_1 = new ErrorMessageCode("YML1");
+ private static final ErrorMessageCode ERROR_CODE_YML_2 = new ErrorMessageCode("YML2");
- @Override
- public void validate(GlobalValidationContext globalContext) {
- Set<String> pmDictionaryFiles = GlobalContextUtil.findPmDictionaryFiles(globalContext);
+ @Override
+ public void validate(GlobalValidationContext globalContext) {
+ Set<String> pmDictionaryFiles = GlobalContextUtil.findPmDictionaryFiles(globalContext);
- Collection<String> files = globalContext.files(
- (fileName, globalValidationContext) -> FileExtensionUtils.isYaml(fileName)
- && !pmDictionaryFiles.contains(fileName));
+ Collection<String> files = globalContext.files(
+ (fileName, globalValidationContext) -> FileExtensionUtils.isYaml(fileName)
+ && !pmDictionaryFiles.contains(fileName));
- files.forEach(fileName -> validate(fileName, globalContext));
- }
-
- private void validate(String fileName, GlobalValidationContext globalContext) {
- Optional<InputStream> rowContent = globalContext.getFileContent(fileName);
- if (rowContent.isEmpty()) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_YML_1, Messages
- .INVALID_YAML_FORMAT_REASON.getErrorMessage(),
- Messages.EMPTY_YAML_FILE.getErrorMessage()));
- return; /* no need to continue validation */
+ files.forEach(fileName -> validate(fileName, globalContext));
}
- try {
- convert(rowContent.get(), Map.class);
- } catch (Exception exception) {
+ private void validate(String fileName, GlobalValidationContext globalContext) {
+ Optional<InputStream> rowContent = globalContext.getFileContent(fileName);
+ if (rowContent.isEmpty()) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_YML_1, Messages
+ .INVALID_YAML_FORMAT_REASON.getErrorMessage(),
+ Messages.EMPTY_YAML_FILE.getErrorMessage()));
+ return; /* no need to continue validation */
+ }
+
+ try (var yamlContent = rowContent.get()) {
+ Constructor constructor = new StrictMapAppenderConstructor(Map.class);
+ constructor.setAllowDuplicateKeys(false);
+ constructor.setPropertyUtils(new MyPropertyUtils());
+ TypeDescription yamlFileDescription = new TypeDescription(Map.class);
+ constructor.addTypeDescription(yamlFileDescription);
+ LoaderOptions options = new LoaderOptions();
+ options.setAllowDuplicateKeys(false);
+ //No Yaml Constructor takes only Constructor and LoaderOptions, that is why I had to pass anonymous Representer and DumperOptions objects
+ Object yamlObj = new Yaml(constructor, new Representer(), new DumperOptions(), options).load(yamlContent);
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_YML_2, Messages
- .INVALID_YAML_FORMAT_REASON.getErrorMessage(),
- YamlValidatorUtil.getParserExceptionReason(exception)));
+ if (yamlObj == null) {
+ throw new Exception();
+ }
+ } catch (Exception exception) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_YML_2, Messages
+ .INVALID_YAML_FORMAT_REASON.getErrorMessage(),
+ YamlValidatorUtil.getParserExceptionReason(exception)));
+ }
}
- }
- private <T> T convert(InputStream content, Class<T> type) {
- return new YamlUtil().yamlToObject(content, type);
- }
}
import org.openecomp.sdc.validation.type.NamingConventionValidationContext;
import org.openecomp.sdc.validation.util.ValidationUtil;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static java.util.Objects.nonNull;
public class NeutronPortNamingConventionValidator implements ResourceValidator {
- private static final ErrorMessageCode ERROR_CODE_NNP1 = new ErrorMessageCode("NNP1");
- private static final ErrorMessageCode ERROR_CODE_NNP2 = new ErrorMessageCode("NNP2");
- private static final ErrorMessageCode ERROR_CODE_NNP3 = new ErrorMessageCode("NNP3");
-
- @Override
- public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext, ValidationContext validationContext) {
-
- NamingConventionValidationContext namingConventionValidationContext =
- (NamingConventionValidationContext)validationContext;
- validatePortNetworkNamingConvention(fileName, namingConventionValidationContext.getHeatOrchestrationTemplate(),
- globalContext);
- validateFixedIpsNamingConvention(fileName, namingConventionValidationContext.getHeatOrchestrationTemplate(),
- globalContext);
- }
-
- private void validatePortNetworkNamingConvention(String fileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
- return;
+ private static final ErrorMessageCode ERROR_CODE_NNP1 = new ErrorMessageCode("NNP1");
+ private static final ErrorMessageCode ERROR_CODE_NNP2 = new ErrorMessageCode("NNP2");
+ private static final ErrorMessageCode ERROR_CODE_NNP3 = new ErrorMessageCode("NNP3");
+
+ @Override
+ public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext, ValidationContext validationContext) {
+ NamingConventionValidationContext namingConventionValidationContext = (NamingConventionValidationContext) validationContext;
+ validatePortNetworkNamingConvention(fileName, namingConventionValidationContext.getHeatOrchestrationTemplate(), globalContext);
+ validateFixedIpsNamingConvention(fileName, namingConventionValidationContext.getHeatOrchestrationTemplate(), globalContext);
}
- String[] regexList = {".*_net_id", ".*_net_name", ".*_net_fqdn"};
-
- heatOrchestrationTemplate
- .getResources()
- .entrySet()
- .stream()
- .filter(entry -> entry.getValue().getType()
- .equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource()))
- .forEach(entry -> entry.getValue()
- .getProperties()
- .entrySet()
- .stream()
- .filter(propertyEntry ->
- ("network").equalsIgnoreCase(propertyEntry.getKey())
- || ("network_id").equals(propertyEntry.getKey()))
- .forEach(propertyEntry -> validateParamNamingConvention(fileName, entry.getKey(),
- propertyEntry.getValue(), regexList,
- Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES, globalContext)));
- }
- private void validateFixedIpsNamingConvention(String fileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- GlobalValidationContext globalContext) {
- if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
- return;
+ private void validatePortNetworkNamingConvention(String fileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
+ return;
+ }
+ String[] regexList = {".*_net_id", ".*_net_name", ".*_net_fqdn"};
+
+ heatOrchestrationTemplate
+ .getResources()
+ .entrySet()
+ .stream()
+ .filter(entry -> entry.getValue().getType().equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource()))
+ .forEach(entry -> entry.getValue()
+ .getProperties()
+ .entrySet()
+ .stream()
+ .filter(propertyEntry -> ("network").equalsIgnoreCase(propertyEntry.getKey()) || ("network_id").equals(propertyEntry.getKey()))
+ .forEach(propertyEntry -> validateParamNamingConvention(fileName, entry.getKey(),
+ propertyEntry.getValue(), regexList,
+ Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES, globalContext)));
}
- heatOrchestrationTemplate.getResources()
- .entrySet()
- .stream()
- .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType()) != null)
- .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType())
- .equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE))
- .forEach(entry -> checkNeutronPortFixedIpsName(fileName, entry, globalContext));
- }
-
- private void checkNeutronPortFixedIpsName(String fileName,
- Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext) {
- String[] regexList = {"[^_]+_[^_]+_ips", "[^_]+_[^_]+_v6_ips", "[^_]+_[^_]+_ip_(\\d+)",
- "[^_]+_[^_]+_v6_ip_(\\d+)", "[^_]+_[^_]+_[^_]+_ips", "[^_]+_[^_]+_[^_]+_v6_ips",
- "[^_]+_[^_]+_[^_]+_ip_(\\d+)", "[^_]+_[^_]+_[^_]+_v6_ip_(\\d+)"};
+ private void validateFixedIpsNamingConvention(String fileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ GlobalValidationContext globalContext) {
+ if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) {
+ return;
+ }
- if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
- return;
+ heatOrchestrationTemplate.getResources()
+ .entrySet()
+ .stream()
+ .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType()) != null)
+ .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType())
+ .equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE))
+ .forEach(entry -> checkNeutronPortFixedIpsName(fileName, entry, globalContext));
}
- Map<String, Object> propertiesMap = resourceEntry.getValue().getProperties();
- Object fixedIps = propertiesMap.get("fixed_ips");
- if (nonNull(fixedIps) && fixedIps instanceof List) {
- List<Object> fixedIpsList = (List<Object>) fixedIps;
- for (Object fixedIpsObject : fixedIpsList) {
- Map.Entry<String, Object> fixedIpsEntry =
- ((Map<String, Object>) fixedIpsObject).entrySet().iterator().next();
-
- validateFixedIpsName(fileName, resourceEntry, globalContext, regexList, fixedIpsEntry);
+ private void checkNeutronPortFixedIpsName(String fileName,
+ Map.Entry<String, Resource> resourceEntry,
+ GlobalValidationContext globalContext) {
+ String[] regexList = {"[^_]+_[^_]+_ips", "[^_]+_[^_]+_v6_ips", "[^_]+_[^_]+_ip_(\\d+)",
+ "[^_]+_[^_]+_v6_ip_(\\d+)", "[^_]+_[^_]+_[^_]+_ips", "[^_]+_[^_]+_[^_]+_v6_ips",
+ "[^_]+_[^_]+_[^_]+_ip_(\\d+)", "[^_]+_[^_]+_[^_]+_v6_ip_(\\d+)"};
+ if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
+ return;
+ }
- }
+ Map<String, Object> propertiesMap = resourceEntry.getValue().getProperties();
+ Object fixedIps = propertiesMap.get("fixed_ips");
+ if (nonNull(fixedIps) && fixedIps instanceof List) {
+ List<Object> fixedIpsList = (List<Object>) fixedIps;
+ for (Object fixedIpsObject : fixedIpsList) {
+ Map.Entry<String, Object> fixedIpsEntry = ((Map<String, Object>) fixedIpsObject).entrySet().iterator().next();
+ validateFixedIpsName(fileName, resourceEntry, globalContext, regexList, fixedIpsEntry);
+ }
+ }
}
- }
-
- private void validateFixedIpsName(String fileName, Map.Entry<String, Resource> resourceEntry,
- GlobalValidationContext globalContext,
- String[] regexList, Map.Entry<String, Object> fixedIpsEntry) {
- if (nonNull(fixedIpsEntry)) {
- if (fixedIpsEntry.getValue() instanceof Map) {
-
- String fixedIpsName = ValidationUtil
- .getWantedNameFromPropertyValueGetParam(fixedIpsEntry.getValue());
- if (nonNull(fixedIpsName) && !ValidationUtil.evalPattern(fixedIpsName, regexList)) {
- globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_NNP1, Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
- "Port", "Fixed_IPS", fixedIpsName, resourceEntry.getKey()));
- }
-
-
- } else {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_NNP2, Messages.MISSING_GET_PARAM.getErrorMessage(),
- "fixed_ips", resourceEntry.getKey()));
- }
+ private void validateFixedIpsName(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext,
+ String[] regexList, Map.Entry<String, Object> fixedIpsEntry) {
+ if (nonNull(fixedIpsEntry)) {
+ if (fixedIpsEntry.getValue() instanceof Map) {
+ String fixedIpsName = ValidationUtil.getWantedNameFromPropertyValueGetParam(fixedIpsEntry.getValue());
+ if (nonNull(fixedIpsName) && !ValidationUtil.evalPattern(fixedIpsName, regexList)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNP1, Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
+ "Port", "Fixed_IPS", fixedIpsName, resourceEntry.getKey()));
+ }
+ } else {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder.
+ getErrorWithParameters(ERROR_CODE_NNP2, Messages.MISSING_GET_PARAM.getErrorMessage(), "fixed_ips", resourceEntry.getKey()));
+ }
+ }
}
- }
- private void validateParamNamingConvention(String fileName, String resourceId,
- Object propertyValue,
- String[] regexList,
- Messages message,
- GlobalValidationContext globalContext) {
- Object paramName;
- if (propertyValue instanceof Map) {
- paramName = ((Map) propertyValue).get("get_param");
- if (paramName instanceof String && !ValidationUtil.evalPattern(paramName, regexList)) {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_NNP3, message.getErrorMessage(), "Port",
- "Network", (String) paramName, resourceId));
+ private void validateParamNamingConvention(String fileName, String resourceId, Object propertyValue, String[] regexList,
+ Messages message, GlobalValidationContext globalContext) {
+ if (propertyValue instanceof Map) {
+ Object paramName = ((Map) propertyValue).get("get_param");
+ if (paramName instanceof String && !ValidationUtil.evalPattern(paramName, regexList)) {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNP3, message.getErrorMessage(), "Port", "Network", (String) paramName, resourceId));
+ }
+ } else {
+ globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNP2, Messages.MISSING_GET_PARAM.getErrorMessage(), "network or network_id", resourceId));
}
-
- } else {
- globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(
- ERROR_CODE_NNP2, Messages.MISSING_GET_PARAM.getErrorMessage(),
- "network or network_id", resourceId));
}
- }
}
@Test
public void testWarningMessageExistWhenConrailV1AndV2ResourcesCollidesInSameHeatFile() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/collidesinsameheatfile/");
validateMessage(messages,
"WARNING: [CTL2]: HEAT Package includes both Contrail 2 and Contrail 3 " +
@Test
public void testParseException(){
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/parseException/");
validateMessage(messages,
"ERROR: [CTL4]: Invalid HEAT format problem - [while scanning for the next " +
@Test
public void testWarningMessageExistWhenConrailV1AndV2ResourcesCollidesInDifferentHeatFiles() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/collidesindifferentheatfiles/");
validateMessage(messages,
"WARNING: [CTL2]: HEAT Package includes both Contrail 2 and Contrail 3 " +
@Test
public void testWarningMessageNotExistWhenConrailV1AndV2ResourcesCollidesInNonHeatFile() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/collidesinnontheatfiles/");
validateMessage(messages,
"WARNING: [CTL2]: HEAT Package includes both Contrail 2 and Contrail 3 " +
@Test
public void testWarningMessageNotExistWhenOnlyConrailV1Resources() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/notcollides/");
validateMessage(messages,
"WARNING: [CTL3]: Contrail 2.x deprecated resource is in use, " +
@Test
public void testWarningMessageOnResourceWithContrailType() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/validatenocontrailresource/");
validateMessage(messages,
"WARNING: [CTL3]: Contrail 2.x deprecated resource is in use, " +
@Test
public void testInvalidHeatStructure(){
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/invalidHeatStructure/");
validateMessage(messages,
"ERROR: [CTL1]: Invalid HEAT format problem - [The file 'first.yaml' " +
@Test
public void testInvalidHeatStructuredueToParsingError(){
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/invalidHeatStructure/");
validateMessage(messages,
"ERROR: [CTL1]: Invalid HEAT format problem - [The file 'first.yaml' " +
@BeforeClass
public static void init() throws IOException {
- Map<String, Object> resourcesMap = ValidationTestUtil.getResourceMap(mockConfigFileName);
+ Map<String, Object> resourcesMap = new ValidationTestUtil().getResourceMap(mockConfigFileName);
Map<String, Object> resourceBaseValidatorMap =
(Map<String, Object>) resourcesMap.get("forbiddenResourceGuideLineValidator");
@Test
public void testFloatingIpResourceType() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(
forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/positive");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(forbiddenResourceGuideLineValidator,
+ messages = new ValidationTestUtil().testValidator(forbiddenResourceGuideLineValidator,
RESOURCE_PATH + "/negative");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
}
@Test
public void testParseException(){
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(
forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/parseException");
Assert.assertEquals(messages.size(), 1);
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
@Test
public void testInvalidResourceType(){
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(
forbiddenResourceGuideLineValidator, RESOURCE_PATH + "/TestInvalidResourceType");
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
"WARNING: [FRG1]: A resource has an invalid or unsupported type - null, " +
@Test
void shouldReturnOnlyFilesWithPmDictionaryType() {
// given
- GlobalValidationContext globalContext = ValidationTestUtil.createGlobalContextFromPath(TEST_MANIFEST_PATH);
+ GlobalValidationContext globalContext = new ValidationTestUtil().createGlobalContextFromPath(TEST_MANIFEST_PATH);
// when
Set<String> pmDictionaryFiles = GlobalContextUtil.findPmDictionaryFiles(globalContext);
@Test
public void testParseException(){
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
"/org/openecomp/validation/validators/guideLineValidator/baseHeatDoesNotExposeNetwork/parseException/");
Assert.assertEquals(messages.size(), 1);
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
@Test
public void testInvalidHeatFormat() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/invalid_heat_format/negative_test/input");
Assert.assertNotNull(messages);
@Test
public void testDependsOn() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/depends_on_points_to_existing_resource/input");
Assert.assertNotNull(messages);
@Test
public void testResourcesReferencesExistInHeat() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new HeatValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new HeatValidator(),
RESOURCE_PATH + "/resource_references_exist_in_heat/negative_test/input");
Assert.assertNotNull(messages);
@Test
public void testGetResourceValueIsValid() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new HeatValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new HeatValidator(),
RESOURCE_PATH + "/get_resource_value_valid/negative_test/input");
Assert.assertNotNull(messages);
@Test
public void testTwoResourcesDoesNotHoldSameId() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new HeatValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new HeatValidator(),
RESOURCE_PATH + "/two_resources_does_not_hold_same_id/positive_test/input");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
@Test
public void testWithWrongFileExtension(){
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new HeatValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new HeatValidator(),
RESOURCE_PATH + "/wrongFileExtension");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.get("single.aad").getErrorMessageList().get(0).getMessage(),
@Test
public void testWithMissingManifestContent(){
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new HeatValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new HeatValidator(),
RESOURCE_PATH + "/missingManifestContent");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.get("single.yaml").getErrorMessageList().get(0).getMessage(),
@Test
public void testWithInvalidHeatContent(){
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new HeatValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new HeatValidator(),
RESOURCE_PATH + "/invalidHeatContent");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.get("single.yaml").getErrorMessageList().get(0).getMessage(),
@Test
public void testGeneratedArtifactExistInHeat() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new HeatValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new HeatValidator(),
RESOURCE_PATH + "/generated_artifact_exist/negative_test/input");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 3);
@Test
public void negativeTestGetParamPointToExistingParameter() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new HeatValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new HeatValidator(),
RESOURCE_PATH + "/get_param_points_to_existing_parameter/negative_test/input");
Assert.assertNotNull(messages);
@Test
public void testGetAttrFromNested() throws IOException {
- Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(new HeatValidator(),
+ Map<String, MessageContainer> messages =new ValidationTestUtil().testValidator(new HeatValidator(),
RESOURCE_PATH + "/get_attr_from_nested/negative_test/input");
Assert.assertNotNull(messages);
@Test
public void testDefaultValueAlignWithType() throws IOException {
- Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(new HeatValidator(),
+ Map<String, MessageContainer> messages =new ValidationTestUtil().testValidator(new HeatValidator(),
RESOURCE_PATH + "/default_value_align_with_type/negative_test/input");
Assert.assertNotNull(messages);
@Test
public void testEnvParametersMatchDefinedHeatParameterTypes() throws IOException {
- Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(new HeatValidator(),
+ Map<String, MessageContainer> messages =new ValidationTestUtil().testValidator(new HeatValidator(),
RESOURCE_PATH + "/env_parameters_match_defined_types/negative_test/input");
Assert.assertNotNull(messages);
@Test
public void testReferencedArtifactsExist() throws IOException {
- Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(new HeatValidator(),
+ Map<String, MessageContainer> messages =new ValidationTestUtil().testValidator(new HeatValidator(),
RESOURCE_PATH + "/referenced_artifacts_exist/negative_test/input");
Assert.assertNotNull(messages);
@Test
public void testEnvContentIsSubSetOfHeatParameters() throws IOException {
- Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages =new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/env_content_is_subset_of_heat/negative_test/input");
Assert.assertNotNull(messages);
@Test
public void testGetParamPseudoParameters() {
- Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(new HeatValidator(),
+ Map<String, MessageContainer> messages =new ValidationTestUtil().testValidator(new HeatValidator(),
RESOURCE_PATH + "/pseudo_parameters/input");
Assert.assertNotNull(messages);
}
@Test
public void testNoErrorWhenEmptyValueForParameterInEnv() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/env_empty_value/input");
Assert.assertNotNull(messages);
@Test
public void testValidManifest() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/validFiles");
Assert.assertNotNull(messages);
Assert.assertNotNull(messages);
@Test
public void testManifestMissingFileInZip() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new ManifestValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new ManifestValidator(),
RESOURCE_PATH + "/missingFileInZip");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
Assert.assertTrue(messages.containsKey("singleVol.yaml"));
- ValidationTestUtil.validateErrorMessage(messages.get("singleVol.yaml").getErrorMessageList()
+ new ValidationTestUtil().validateErrorMessage(messages.get("singleVol.yaml").getErrorMessageList()
.get(0).getMessage(),
"ERROR: " + "[MNF4]: " + Messages.MISSING_FILE_IN_ZIP.getErrorMessage());
}
@Test
public void testInvalidManifest() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new ManifestValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new ManifestValidator(),
RESOURCE_PATH + "/invalidManifest");
Assert.assertNotNull(messages);
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
Assert.assertTrue(messages.containsKey(SdcCommon.MANIFEST_NAME));
- ValidationTestUtil.validateErrorMessage(
+ new ValidationTestUtil().validateErrorMessage(
messages.get(SdcCommon.MANIFEST_NAME).getErrorMessageList().get(0).getMessage(),
"ERROR: " +"[MNF6]: " + Messages.INVALID_MANIFEST_FILE.getErrorMessage());
@Test
public void testMissingFileInManifest() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new ManifestValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new ManifestValidator(),
RESOURCE_PATH + "/missingFileInManifest");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
Assert.assertTrue(messages.containsKey("extraFile.env"));
- ValidationTestUtil.validateErrorMessage(messages.get("extraFile.env").getErrorMessageList()
+ new ValidationTestUtil().validateErrorMessage(messages.get("extraFile.env").getErrorMessageList()
.get(0).getMessage(),
"WARNING: " + "[MNF5]: " + Messages.MISSING_FILE_IN_MANIFEST.getErrorMessage());
}
@Test
public void testMissingFileTypeInManifest() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new ManifestValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new ManifestValidator(),
RESOURCE_PATH + "/missingFileTypeInManifest");
- ValidationTestUtil.validateErrorMessage(
+ new ValidationTestUtil().validateErrorMessage(
messages.get("MANIFEST.json").getErrorMessageList().get(0).getMessage(),
"ERROR: " + "[MNF7]: Missing file name in manifest");
}
@Test
public void testInvalidFileTypeInManifest() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new ManifestValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new ManifestValidator(),
RESOURCE_PATH + "/invalidFileTypeInManifest");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 4);
Assert.assertTrue(messages.containsKey("illegalTypeFile.yaml"));
Assert.assertTrue(messages.containsKey("single.yaml.illegalSuffix"));
Assert.assertTrue(messages.containsKey("singleVol.yaml.illegalSuffix"));
- ValidationTestUtil.validateErrorMessage(
+ new ValidationTestUtil().validateErrorMessage(
messages.get("single.env.illegalSuffix").getErrorMessageList().get(0).getMessage(),
"ERROR: "+"[MNF3]: " + Messages.WRONG_ENV_FILE_EXTENSION.getErrorMessage(),
"single.env.illegalSuffix");
- ValidationTestUtil.validateErrorMessage(
+ new ValidationTestUtil().validateErrorMessage(
messages.get("illegalTypeFile.yaml").getErrorMessageList().get(0).getMessage(),
"ERROR: "+"[MNF8]: " + Messages.INVALID_FILE_TYPE.getErrorMessage(),
"illegalTypeFile.yaml");
- ValidationTestUtil.validateErrorMessage(
+ new ValidationTestUtil().validateErrorMessage(
messages.get("single.yaml.illegalSuffix").getErrorMessageList().get(0).getMessage(),
"ERROR: "+"[MNF2]: " + Messages.WRONG_HEAT_FILE_EXTENSION.getErrorMessage(),
"single.yaml.illegalSuffix");
- ValidationTestUtil.validateErrorMessage(
+ new ValidationTestUtil().validateErrorMessage(
messages.get("singleVol.yaml.illegalSuffix").getErrorMessageList().get(0).getMessage(),
"ERROR: "+"[MNF2]: " + Messages.WRONG_HEAT_FILE_EXTENSION.getErrorMessage(),
"singleVol.yaml.illegalSuffix");
@Test
public void testMissingFileInManifestAndInZip() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new ManifestValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new ManifestValidator(),
RESOURCE_PATH + "/missingFileInManifestAndInZip");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 2);
Assert.assertTrue(messages.containsKey("extraFile.env"));
Assert.assertTrue(messages.containsKey("singleVol.yaml"));
- ValidationTestUtil.validateErrorMessage(messages.get("extraFile.env").getErrorMessageList()
+ new ValidationTestUtil().validateErrorMessage(messages.get("extraFile.env").getErrorMessageList()
.get(0).getMessage(), "WARNING: " + "[MNF5]: "+ Messages.MISSING_FILE_IN_MANIFEST
.getErrorMessage());
- ValidationTestUtil.validateErrorMessage(messages.get("singleVol.yaml").getErrorMessageList()
+ new ValidationTestUtil().validateErrorMessage(messages.get("singleVol.yaml").getErrorMessageList()
.get(0).getMessage(), "ERROR: " + "[MNF4]: " + Messages.MISSING_FILE_IN_ZIP
.getErrorMessage());
@Test
public void testEnvInRoot() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new ManifestValidator(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new ManifestValidator(),
RESOURCE_PATH + "/envInRoot");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
Assert.assertTrue(messages.containsKey("second.env"));
- ValidationTestUtil.validateErrorMessage(messages.get("second.env").getErrorMessageList()
+ new ValidationTestUtil().validateErrorMessage(messages.get("second.env").getErrorMessageList()
.get(0).getMessage(),
"ERROR: [MNF1]: ENV file must be associated to a HEAT file");
}
private Map<String, MessageContainer> runValidation(String path) {
PmDictionaryValidator validator = new PmDictionaryValidator();
- return ValidationTestUtil.testValidator(validator, path);
+ return new ValidationTestUtil().testValidator(validator, path);
}
}
@Test
public void testBaseHeatExposeNetwork() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/baseHeatDoesNotExposeNetwork/positive/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(validator,
+ messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/baseHeatDoesNotExposeNetwork/negative/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
@Test
public void testParseException(){
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/baseHeatDoesNotExposeNetwork/parseException/");
Assert.assertEquals(messages.size(), 1);
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
@Test
public void testInvalidGetResource(){
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/" +
"baseHeatDoesNotExposeNetworkInvalidGetResource");
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
@Test
public void testBaseHeatExposeNetworkAndVolume() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/baseHeatDoesNotExposeNetworkAndVolume/positive/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(validator,
+ messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/baseHeatDoesNotExposeNetworkAndVolume/negative/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
@Test
public void testBaseHeatExposeServerGroup() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/baseHeatDoesNotExposeServerGroup/positive/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(validator,
+ messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/baseHeatDoesNotExposeServerGroup/negative/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
@Test
public void testBaseHeatExposeSecurityGroup() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/baseHeatDoesNotExposeSecurityGroup/positive/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(validator,
+ messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/baseHeatDoesNotExposeSecurityGroup/negative/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
@Test
public void testBaseHeatExposeVolume() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/baseHeatDoesNotExposeVolume/positive/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(validator,
+ messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/baseHeatDoesNotExposeVolume/negative/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
@Test
public void testHeatVolumeExpose() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/heatVolumeExpose/positive/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(validator,
+ messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/heatVolumeExpose/negative/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
@Test
public void testResourceIsExposedByCallingGetResourceNotFromOutput() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/baseHeatExposeResourceUsingGetResource/positive");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(validator,
+ messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/baseHeatExposeResourceUsingGetResource/negative");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
@Test
public void testMissingBaseHeat() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/missingBaseHeat/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
@Test
public void testMultiBaseHeat() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(validator,
RESOURCE_PATH + "/multiBaseHeat/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
public class YamlValidatorTest {
- private static final String RESOURCE_PATH = "/org/openecomp/validation/validators/yaml_validator";
-
- public Map<String, MessageContainer> runValidation(String path) {
- YamlValidator validator = new YamlValidator();
- return ValidationTestUtil.testValidator(validator, path);
-
- }
-
- @Test
- public void testValidYaml() {
-
- Map<String, MessageContainer> messages = runValidation(
- RESOURCE_PATH + "/valid_yaml/input/validHeat.yaml");
- Assert.assertNotNull(messages);
- Assert.assertEquals(messages.size(), 0);
- }
-
- @Test
- public void testInvalidTabYaml() {
-
- Map<String, MessageContainer> messages = runValidation(
- RESOURCE_PATH + "/invalid_valid_yaml_structure/input/invalidYamlTab.yaml");
- Assert.assertNotNull(messages);
- Assert.assertEquals(messages.size(), 1);
- ValidationTestUtil.validateErrorMessage(
- messages.get("invalidYamlTab.yaml").getErrorMessageList().get(0).getMessage(),
- "ERROR: " +"[YML2]: "+ Messages.INVALID_YAML_FORMAT_REASON.getErrorMessage(),
- "while scanning for the next tokenfound character '\\t(TAB)' that cannot start " +
- "any token. (Do not use \\t(TAB) for indentation) in 'reader', line 14, " +
- "column 5: \tadmin_state_up: true ^");
- }
-
- @Test
- public void testDuplicateKeyInYaml() {
-
- Map<String, MessageContainer> messages =
- runValidation(RESOURCE_PATH + "/duplicateKey.yaml");
- Assert.assertNotNull(messages);
- Assert.assertEquals(messages.size(), 1);
- Assert.assertTrue(messages.containsKey("duplicateKey.yaml"));
- ValidationTestUtil.validateErrorMessage(
- messages.get("duplicateKey.yaml").getErrorMessageList().get(0).getMessage(),
- "ERROR: " +"[YML2]: "+ Messages.INVALID_YAML_FORMAT_REASON.getErrorMessage(),
- "while parsing MappingNode in 'reader', line 6, column 3: " +
- "Key_1_unique: ^duplicate key: Key_2_not_unique in 'reader', line 31, " +
- "column 1: ^");
- }
-
- @Test
- public void testInvalidYamlStructure() {
-
- Map<String, MessageContainer> messages = runValidation(
- RESOURCE_PATH + "/invalidYamlStructure.yaml");
- Assert.assertNotNull(messages);
- Assert.assertEquals(messages.size(), 1);
- Assert.assertTrue(messages.containsKey("invalidYamlStructure.yaml"));
- ValidationTestUtil.validateErrorMessage(
- messages.get("invalidYamlStructure.yaml").getErrorMessageList().get(0).getMessage(),
- "ERROR: " +"[YML2]: "+ Messages.INVALID_YAML_FORMAT_REASON.getErrorMessage(),
- "while parsing a block mapping in 'reader', line 8, column 7: " +
- "admin_state_up: true ^expected <block end>, but found BlockEntry in 'reader', " +
- "line 10, column 7: - shared: true ^");
- }
-
- @Test
- public void testEmptyYaml() {
-
- Map<String, MessageContainer> messages =
- runValidation(RESOURCE_PATH + "/emptyYaml.yaml");
- Assert.assertNotNull(messages);
- Assert.assertEquals(messages.size(), 1);
- Assert.assertTrue(messages.containsKey("emptyYaml.yaml"));
- ValidationTestUtil.validateErrorMessage(messages.get("emptyYaml.yaml").getErrorMessageList()
- .get(0).getMessage(),
- "ERROR: " +"[YML1]: "+ Messages.INVALID_YAML_FORMAT_REASON.getErrorMessage(),
- Messages.EMPTY_YAML_FILE.getErrorMessage());
- }
+ private static final String RESOURCE_PATH = "/org/openecomp/validation/validators/yaml_validator";
+
+ public Map<String, MessageContainer> runValidation(String path) {
+ return new ValidationTestUtil().testValidator(new YamlValidator(), path);
+ }
+
+ @Test
+ public void testValidYaml() {
+ Map<String, MessageContainer> messages = runValidation(RESOURCE_PATH + "/valid_yaml/input/validHeat.yaml");
+ Assert.assertNotNull(messages);
+ Assert.assertEquals(0, messages.size());
+ }
+
+ @Test
+ public void testInvalidTabYaml() {
+
+ Map<String, MessageContainer> messages = runValidation(
+ RESOURCE_PATH + "/invalid_valid_yaml_structure/input/invalidYamlTab.yaml");
+ Assert.assertNotNull(messages);
+ Assert.assertEquals(1, messages.size());
+ new ValidationTestUtil().validateErrorMessage(
+ messages.get("invalidYamlTab.yaml").getErrorMessageList().get(0).getMessage(),
+ "ERROR: " + "[YML2]: " + Messages.INVALID_YAML_FORMAT_REASON.getErrorMessage(),
+ "while scanning for the next tokenfound character '\\t(TAB)' that cannot start " +
+ "any token. (Do not use \\t(TAB) for indentation) in 'reader', line 14, " +
+ "column 5: \tadmin_state_up: true ^");
+ }
+
+ @Test
+ public void testDuplicateKeyInYaml() {
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new YamlValidator(), RESOURCE_PATH + "/duplicateKey.yaml");
+ Assert.assertNotNull(messages);
+ Assert.assertEquals(1, messages.size());
+ Assert.assertTrue(messages.containsKey("duplicateKey.yaml"));
+ Assert.assertTrue(messages.get("duplicateKey.yaml").getErrorMessageList().get(0).getMessage().contains("Key_2_not_unique"));
+ }
+
+ @Test
+ public void testInvalidYamlStructure() {
+ Map<String, MessageContainer> messages = runValidation(RESOURCE_PATH + "/invalidYamlStructure.yaml");
+ Assert.assertNotNull(messages);
+ Assert.assertEquals(1, messages.size());
+ Assert.assertTrue(messages.containsKey("invalidYamlStructure.yaml"));
+ new ValidationTestUtil().validateErrorMessage(
+ messages.get("invalidYamlStructure.yaml").getErrorMessageList().get(0).getMessage(),
+ "ERROR: " + "[YML2]: " + Messages.INVALID_YAML_FORMAT_REASON.getErrorMessage(),
+ "while parsing a block mapping in 'reader', line 8, column 7: " +
+ "admin_state_up: true ^expected <block end>, but found '-' in 'reader', " +
+ "line 10, column 7: - shared: true ^");
+ }
+
+ @Test
+ public void testEmptyYaml() {
+ Map<String, MessageContainer> messages = runValidation(RESOURCE_PATH + "/emptyYaml.yaml");
+ Assert.assertNotNull(messages);
+ Assert.assertEquals(1, messages.size());
+ Assert.assertTrue(messages.containsKey("emptyYaml.yaml"));
+ new ValidationTestUtil().validateErrorMessage(messages.get("emptyYaml.yaml").getErrorMessageList()
+ .get(0).getMessage(),
+ "ERROR: " + "[YML1]: " + Messages.INVALID_YAML_FORMAT_REASON.getErrorMessage(),
+ Messages.EMPTY_YAML_FILE.getErrorMessage());
+ }
}
private static final String PATH = "/org/openecomp/validation/validators/heat_validator/network_policy_associated_with_attach_policy/";
@Test
public void testNetworkPolicyAssociatedWithAttachPolicy() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator, resourceValidator
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator, resourceValidator
, HeatResourcesTypes.CONTRAIL_NETWORK_RULE_RESOURCE_TYPE.getHeatResource(),
PATH + "positive");
@Test
public void testNonNetworkPolicyResource() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator, resourceValidator
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator, resourceValidator
, HeatResourcesTypes.CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource(),
PATH + "negative");
@Test
public void testNoLoopsNesting() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, null,
PATH + "no_loops_nesting/negative_test/input");
@Test
public void testPropertiesMatchNestedParameters() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, null,
PATH + "properties_match_nested_parameters/negative_test/input");
@Test
public void testWrongValueTypeAssigned() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, null,
PATH + "properties_match_nested_parameters/wrong_value_type_assigned/input");
final Resource resource = new Resource();
resource.setType("nested-pps_v1.0.yaml");
- final GlobalValidationContext globalValidationContext = ValidationTestUtil.createGlobalContextFromPath(PATH + "missing_nested_file/input");
+ final GlobalValidationContext globalValidationContext = new ValidationTestUtil().createGlobalContextFromPath(PATH + "missing_nested_file/input");
NestedResourceValidator.validateAllPropertiesMatchNestedParameters(null, null, resource, Optional.empty(), globalValidationContext);
private static final String PATH = "/org/openecomp/validation/validators/heat_validator/";
@Test
public void testMoreThanOneBindFromNovaToPort() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
PATH + "one_nova_points_to_one_port/negative_test/input");
@Test
public void testPortNotBindToAnyNovaServerHPR1() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "no_neutron_port/input");
@Test
public void testPortNotBindToAnyNovaServerHPR3() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "port_no_bind_to_any_nova_server/input");
@Test
public void testSecurityGroupBaseFileNoPorts() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator,
HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource(),
PATH + "security_group_base_file_no_ports/input");
@Test
public void testSecurityGroupsCalledByPort() throws IOException {
- Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages =new ValidationTestUtil().testValidator(baseValidator,
resourceValidator,
HeatResourcesTypes.NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource(),
PATH + "security_group_called_by_port/input");
private static final String PATH = "/org/openecomp/validation/validators/heat_validator/";
@Test
public void testPolicyIsAffinityOrAntiAffinity() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource(),
PATH + "policy_is_affinity_or_anti_affinity/negative_test/input");
@Test
public void testServerGroupCalledByServer() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource(),
PATH + "server_group_called_by_nova_server/input");
@Test
public void testNonServerGroup() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "server_group_called_by_nova_server_negative/input");
private static final String PATH = "/org/openecomp/validation/validators/heat_validator/";
@Test
public void testNovaPropertiesHasAssignedValue() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "nova_properties_has_assigned_value/negative_test/input");
@Test
public void testServerGroupsPointedByServersDefinedCorrectly() throws IOException {
- Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages =new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "server_groups_defined_correctly/negative_test/input");
private static final String PATH = "/org/openecomp/validation/validators/heat_validator/";
@Test
public void testResourceGroupWithInvalidIndexVar() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource(),
PATH + "resource_group_invalid_indexvar/negative_test/input");
@Test
public void testResourceGroupWithInvalidType() {
- Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages =new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource(),
PATH + "resource_group_invalid_type/negative_test/input");
@Test
public void testResourcesGroupWithNested() {
- Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages =new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource(),
PATH + "resources_group_with_nested/negative_test/input");
package org.openecomp.sdc.validation.impl.validators.heatresource;
import java.util.Map;
+
import org.junit.Assert;
import org.junit.Test;
import org.openecomp.core.validation.types.MessageContainer;
*/
public class VirtualMachineInterfaceValidatorTest {
- private static final String PATH =
- "/org/openecomp/validation/validators/heat_validator/vlan_resource_validation/";
-
-
- @Test
- public void hasSingleParentPortNegative() {
- HeatResourceValidator baseValidator = new HeatResourceValidator();
- VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator,
- HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
- PATH + "vlan_multiple_parent_ports/negative_test/input");
-
- Assert.assertNotNull(messages);
- Assert.assertEquals(messages.size(), 1);
-
- Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
- Assert.assertEquals(
- messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
- "ERROR: [VLAN1]: More than one parent port found, " +
- "there should be only one parent port for a VLAN sub-interface ID [template_Vlan_2]");
- }
-
- @Test
- public void hasSingleParentPortNegativeWithGetResource() {
- HeatResourceValidator baseValidator = new HeatResourceValidator();
- VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator,
- HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
- PATH + "vlan_multiple_parent_ports/negative_get_resource/input");
-
- Assert.assertNotNull(messages);
- Assert.assertEquals(messages.size(), 0);
- }
-
-
- @Test
- public void hasSingleParentPortPositive() {
- HeatResourceValidator baseValidator = new HeatResourceValidator();
- VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator,
- HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
- PATH + "vlan_multiple_parent_ports/positive_test/input");
-
- Assert.assertNotNull(messages);
- Assert.assertEquals(messages.size(), 0);
-
-
- }
-
-
- @Test
- public void hasBothPropertiesNegativeMissingVlanTag() {
- HeatResourceValidator baseValidator = new HeatResourceValidator();
- VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator,
- HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
- PATH + "vlan_has_two_properties/negative_tag_missing/input");
-
- Assert.assertNotNull(messages);
- Assert.assertEquals(messages.size(), 1);
-
- Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
- Assert.assertEquals(
- messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
- "WARNING: [VLAN2]: VLAN Tag property " +
- "virtual_machine_interface_properties_sub_interface_vlan_tag " +
- "is missing in VLAN Resource ID [template_Vlan_2]");
- }
-
- @Test
- public void hasBothPropertiesNegativeMissingRefs() {
- HeatResourceValidator baseValidator = new HeatResourceValidator();
- VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator,
- HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
- PATH + "vlan_has_two_properties/negative_refs_missing/input");
-
- Assert.assertNotNull(messages);
- Assert.assertEquals(messages.size(), 1);
-
- Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
- Assert.assertEquals(
- messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
- "WARNING: [VLAN2]: Parent port property virtual_machine_interface_refs is " +
- "missing in VLAN Resource ID [template_Vlan_2]");
- }
-
- @Test
- public void hasBothPropertiesBothMissingWhichMeansPositive() {
- HeatResourceValidator baseValidator = new HeatResourceValidator();
- VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator,
- HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
- PATH + "vlan_has_two_properties/negative_both_missing/input");
-
- Assert.assertNotNull(messages);
- Assert.assertEquals(messages.size(), 0);
-
- }
-
-
- @Test
- public void hasBothPropertiesPositive() {
- HeatResourceValidator baseValidator = new HeatResourceValidator();
- VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator,
- HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
- PATH + "vlan_has_two_properties/positive_test/input");
-
- Assert.assertNotNull(messages);
- Assert.assertEquals(messages.size(), 0);
-
-
- }
-
-
-
+ private static final String PATH =
+ "/org/openecomp/validation/validators/heat_validator/vlan_resource_validation/";
+
+
+ @Test
+ public void hasSingleParentPortNegative() {
+ HeatResourceValidator baseValidator = new HeatResourceValidator();
+ VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
+ resourceValidator,
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
+ PATH + "vlan_multiple_parent_ports/negative_test/input");
+
+ Assert.assertNotNull(messages);
+ Assert.assertEquals(1, messages.size());
+
+ Assert.assertEquals(1, messages.get("nested.yml").getErrorMessageList().size());
+ Assert.assertEquals(
+ messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
+ "ERROR: [VLAN1]: More than one parent port found, " +
+ "there should be only one parent port for a VLAN sub-interface ID [template_Vlan_2]");
+ }
+
+ @Test
+ public void hasSingleParentPortNegativeWithGetResource() {
+ HeatResourceValidator baseValidator = new HeatResourceValidator();
+ VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
+ resourceValidator,
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
+ PATH + "vlan_multiple_parent_ports/negative_get_resource/input");
+
+ Assert.assertNotNull(messages);
+ Assert.assertEquals(messages.size(), 0);
+ }
+
+
+ @Test
+ public void hasSingleParentPortPositive() {
+ HeatResourceValidator baseValidator = new HeatResourceValidator();
+ VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
+ resourceValidator,
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
+ PATH + "vlan_multiple_parent_ports/positive_test/input");
+
+ Assert.assertNotNull(messages);
+ Assert.assertEquals(0, messages.size());
+ }
+
+
+ @Test
+ public void hasBothPropertiesNegativeMissingVlanTag() {
+ HeatResourceValidator baseValidator = new HeatResourceValidator();
+ VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
+ resourceValidator,
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
+ PATH + "vlan_has_two_properties/negative_tag_missing/input");
+
+ Assert.assertNotNull(messages);
+ Assert.assertEquals(messages.size(), 1);
+
+ Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
+ Assert.assertEquals(
+ messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
+ "WARNING: [VLAN2]: VLAN Tag property " +
+ "virtual_machine_interface_properties_sub_interface_vlan_tag " +
+ "is missing in VLAN Resource ID [template_Vlan_2]");
+ }
+
+ @Test
+ public void hasBothPropertiesNegativeMissingRefs() {
+ HeatResourceValidator baseValidator = new HeatResourceValidator();
+ VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
+ resourceValidator,
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
+ PATH + "vlan_has_two_properties/negative_refs_missing/input");
+
+ Assert.assertNotNull(messages);
+ Assert.assertEquals(messages.size(), 1);
+
+ Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
+ Assert.assertEquals(
+ messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
+ "WARNING: [VLAN2]: Parent port property virtual_machine_interface_refs is " +
+ "missing in VLAN Resource ID [template_Vlan_2]");
+ }
+
+ @Test
+ public void hasBothPropertiesBothMissingWhichMeansPositive() {
+ HeatResourceValidator baseValidator = new HeatResourceValidator();
+ VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
+ resourceValidator,
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
+ PATH + "vlan_has_two_properties/negative_both_missing/input");
+
+ Assert.assertNotNull(messages);
+ Assert.assertEquals(messages.size(), 0);
+
+ }
+
+
+ @Test
+ public void hasBothPropertiesPositive() {
+ HeatResourceValidator baseValidator = new HeatResourceValidator();
+ VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
+ resourceValidator,
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
+ PATH + "vlan_has_two_properties/positive_test/input");
+
+ Assert.assertNotNull(messages);
+ Assert.assertEquals(messages.size(), 0);
+ }
}
\ No newline at end of file
@Test
public void testContrailServiceInstanceAvailabilityZoneNotAlignedWithNamingConvention() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE.getHeatResource(),
PATH + "notaligned");
Assert.assertNotNull(messages);
@Test
public void testContrailServiceInstanceAvailabilityZoneAlignedWithNamingConvention() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE.getHeatResource(),
PATH + "aligned");
Assert.assertNotNull(messages);
}
@Test
public void testContrailServiceInstanceAvailabilityZoneNotAlignedWithNamingConventionMissingParam() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_INSTANCE.getHeatResource(),
PATH + "missingparam");
Assert.assertNotNull(messages);
@Test
public void testContrailServiceTemplateImageAndFlavorNamesAlignedWithNamingConventionButDifferentVmType() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(),
PATH + "imageandflavordifferentvmtype");
Assert.assertNotNull(messages);
@Test
public void testContrailServiceTemplateImageAndFlavorNamesNotAlignedWithNamingConvention() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(),
PATH + "/notaligned");
Assert.assertNotNull(messages);
@Test
public void testContrailServiceTemplateImageAndFlavorNamesAlignedWithNamingConvention() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(),
PATH + "aligned");
Assert.assertNotNull(messages);
@Test
public void testContrailServiceTemplateMissingParam() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(),
PATH + "missingparam");
Assert.assertNotNull(messages);
public class NeutronPortNamingConventionValidatorTest {
NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
- NeutronPortNamingConventionValidator resourceValidator = new
- NeutronPortNamingConventionValidator();
- private static final String PATH = "/org/openecomp/validation/validators/guideLineValidator/heatPortNetworkNamingConvention/";
+ NeutronPortNamingConventionValidator resourceValidator = new NeutronPortNamingConventionValidator();
+ private static final String PATH = "/org/openecomp/validation/validators/guideLineValidator/heatPortNetworkNamingConvention/";
@Test
public void testHeatPortNetworkNamingConvention() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
PATH + "positive/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(baseValidator,
+ messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
PATH + "negative/");
Assert.assertNotNull(messages);
@Test
public void testNeutronFixedIpName() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
PATH + "positiveFixedIP");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(baseValidator,
+ messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
PATH + "negativeFixedIP/");
Assert.assertNotNull(messages);
@Test
public void testMissingParam() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new NamingConventionGuideLineValidator(),
+ new NeutronPortNamingConventionValidator(), HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
PATH + "missingparam/");
Assert.assertNotNull(messages);
- Assert.assertEquals(messages.size(), 1);
- Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
- Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
- "WARNING: [NNP2]: Missing get_param in network or network_id, Resource Id [port_resource_2]");
+ Assert.assertEquals(1, messages.size());
+ Assert.assertEquals(1, messages.get("first.yaml").getErrorMessageList().size());
+ Assert.assertEquals("WARNING: [NNP2]: Missing get_param in network or network_id, Resource Id [port_resource_2]",
+ messages.get("first.yaml").getErrorMessageList().get(0).getMessage());
}
}
private static final String PATH = "/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/";
@Test
public void testHeatNovaServerMetaDataValidation() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaServerMetaDataValidation/positive/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(baseValidator,
+ messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaServerMetaDataValidation/negative/");
Assert.assertNotNull(messages);
@Test
public void testNovaServerAvailabilityZoneName() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaServerAvailabilityZoneName/positive");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(baseValidator,
+ messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaServerAvailabilityZoneName/negative");
Assert.assertNotNull(messages);
@Test
public void testNovaImageAndFlavorNamesEmptyProperties() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaServerImageAndFlavor/negativeEmptyProperties");
Assert.assertNotNull(messages);
@Test
public void testNovaImageAndFlavorNames() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaServerImageAndFlavor/positive");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(baseValidator,
+ messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaServerImageAndFlavor/negative");
Assert.assertNotNull(messages);
@Test
public void testNovaResourceNetworkUniqueRole() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaNetworkUniqueRoleConvention/positive/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(baseValidator,
+ messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaNetworkUniqueRoleConvention/negative/");
Assert.assertNotNull(messages);
@Test
public void testNovaServerName() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaServerNameValidation/positive");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
- messages = ValidationTestUtil.testValidator(baseValidator,
+ messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaServerNameValidation/negative/");
Assert.assertNotNull(messages);
@Test
public void testVMNameSyncInNova() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "input");
@Test
public void testAvailabilityZoneName() throws IOException {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "availability_zone_name/input");
@Test
public void testHeatNovaServerVnfIDValidation() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
"/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/heatNovaServerMetaDataValidation/negativemissingvnfid/");
Assert.assertNotNull(messages);
@Test
public void testHeatNovaServerVfModuleValidation() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
"/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/heatNovaServerMetaDataValidation/negativemisningvfmodule/");
Assert.assertNotNull(messages);
@Test
public void testMissingParam() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaNetworkUniqueRoleConvention/missingportNetwork/");
Assert.assertNotNull(messages);
@Test
public void testNovaResource() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaNetworkUniqueRoleConvention/invalidresource/");
Assert.assertNotNull(messages);
@Test
public void testEnvFileContent() {
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
PATH + "heatNovaNetworkUniqueRoleConvention/input/");
Assert.assertNotNull(messages);
NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
VirtualMachineInterfaceGuidelineValidator resourceValidator = new
VirtualMachineInterfaceGuidelineValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator,
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
PATH + "modeled_through_resource_group/positive_test/input");
NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
VirtualMachineInterfaceGuidelineValidator resourceValidator = new
VirtualMachineInterfaceGuidelineValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator,
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
PATH + "modeled_through_resource_group/negative_test/input");
NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
VirtualMachineInterfaceGuidelineValidator resourceValidator = new
VirtualMachineInterfaceGuidelineValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator,
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
PATH + "modeled_through_resource_group/negative_test_non_string/input");
NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
VirtualMachineInterfaceGuidelineValidator resourceValidator = new
VirtualMachineInterfaceGuidelineValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator,
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
PATH + "modeled_through_resource_group/negative_get_resource/input");
NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
VirtualMachineInterfaceGuidelineValidator resourceValidator = new
VirtualMachineInterfaceGuidelineValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator,
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
PATH + "single_vlan_resource/positive_test/input");
NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
VirtualMachineInterfaceGuidelineValidator resourceValidator = new
VirtualMachineInterfaceGuidelineValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator,
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
PATH + "single_vlan_resource/negative_test/two_vlans");
NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
VirtualMachineInterfaceGuidelineValidator resourceValidator = new
VirtualMachineInterfaceGuidelineValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator,
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
PATH + "single_vlan_resource/negative_test/vlan_and_nova");
NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
VirtualMachineInterfaceGuidelineValidator resourceValidator = new
VirtualMachineInterfaceGuidelineValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator,
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
PATH + "naming_convention/negative_test/input");
NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
VirtualMachineInterfaceGuidelineValidator resourceValidator = new
VirtualMachineInterfaceGuidelineValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
resourceValidator,
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
PATH + "naming_convention/positive_test/input");
*/
public class ValidationTestUtil {
- private ValidationTestUtil(){}
+ public ValidationTestUtil(){}
- public static GlobalValidationContext createGlobalContextFromPath(String path) {
+ public GlobalValidationContext createGlobalContextFromPath(String path) {
GlobalValidationContext globalValidationContext = new GlobalValidationContext();
Map<String, byte[]> contentMap = getContentMapByPath(path);
if (contentMap == null) {
return globalValidationContext;
}
- private static Map<String, byte[]> getContentMapByPath(String path) {
+ private Map<String, byte[]> getContentMapByPath(String path) {
Map<String, byte[]> contentMap = new HashMap<>();
URL url = ValidationTestUtil.class.getResource(path);
File pathFile = new File(url.getFile());
return contentMap;
}
- public static Map<String, MessageContainer> testValidator(Validator validator, String path) {
-
+ public Map<String, MessageContainer> testValidator(Validator validator, String path) {
GlobalValidationContext globalValidationContext = createGlobalContextFromPath(path);
validator.validate(globalValidationContext);
}
- public static Map<String, MessageContainer> testValidator(ResourceBaseValidator baseValidator,
+ public Map<String, MessageContainer> testValidator(ResourceBaseValidator baseValidator,
ResourceValidator resourceValidator,
String resourceTypeToValidate, String path) {
return globalContext.getContextMessageContainers();
}
- private static void validateFiles(ResourceBaseValidator baseValidator,
+ private void validateFiles(ResourceBaseValidator baseValidator,
ResourceValidator resourceValidator,
GlobalValidationContext globalContext,
Map<String, FileData> fileEnvMap,
}
}
- private static void validateResources(String fileName, ResourceValidator resourceValidator,
+ private void validateResources(String fileName, ResourceValidator resourceValidator,
String resourceTypeToValidate, ValidationContext validationContext,
GlobalValidationContext globalValidationContext){
(fileName, resourceEntry, globalValidationContext, validationContext));
}
- private static boolean isResourceNeedToBeTested(String currResource, String resourceToTest){
+ private boolean isResourceNeedToBeTested(String currResource, String resourceToTest){
if(Objects.isNull(resourceToTest)){
return HeatStructureUtil.isNestedResource(currResource);
}
return currResource.equals(resourceToTest);
}
- public static void validateErrorMessage(String actualMessage, String expected, String... params) {
-
+ public void validateErrorMessage(String actualMessage, String expected, String... params) {
Assert.assertEquals(actualMessage.replace("\n", "").replace("\r", ""),
ErrorMessagesFormatBuilder.getErrorWithParameters(expected, params).replace("\n", "")
.replace("\r", ""));
}
- public static Map<String, Object> getResourceMap(String configFileName) throws IOException {
+ public Map<String, Object> getResourceMap(String configFileName) throws IOException {
URL mockResource = ValidationTestUtil.class.getResource(configFileName);
String json = IOUtils.toString(mockResource.openStream(), "UTF-8");
return JsonUtil.json2Object(json, Map.class);
description: heat expose volume resource
-resources:
- port_resource_0:
- type: OS::Neutron::Port
- properties:
- network_id: { get_param: Internal1_net_id }
-resources:
- port_resource_1:
- type: OS::Neutron::Port
- properties:
- network_id: { get_param: Internal1_net_name }
resources:
port_resource_2:
type: OS::Neutron::Port
properties:
+ # required to be 'not a map' to trigger error NNP2
network_id: Internal1_net_fqdn
type: OS::Neutron::Port
properties:
network_id: { get_param: Internal1_net_id }
-resources:
- port_resource_1:
- type: OS::Neutron::Port
- properties:
- network_id: { get_param: Internal1_net_name }
-resources:
- port_resource_2:
- type: OS::Neutron::Port
- properties:
- network_id: { get_param: Internal1_net_fqdn }
-
outputs:
expose_resource_port_output_0:
- port: { get_resource: template_VMInt_OAM_lb_1 }
- port: { get_resource: cmaui_port_2 }
-
- type: OS::ContrailV2::VirtualMachineInterface
- properties:
- virtual_machine_interface_properties:
- {
- virtual_machine_interface_properties_service_interface_type: { get_param: lb_st_interface_type_oam },
- }
- virtual_network_refs: [{ get_resource: test_net1 }]
- port_tuple_refs: [{ get_param: template_PortTuple_LB1 }]
- security_group_refs: [{ get_param: oam_sec_group_name}]
-
cmaui_port_2:
type: OS::Neutron::Port
properties:
- port: { get_resource: template_VMInt_OAM_lb_1 }
- port: { get_resource: cmaui_port_2 }
-
- type: OS::ContrailV2::VirtualMachineInterface
- properties:
- virtual_machine_interface_properties:
- {
- virtual_machine_interface_properties_service_interface_type: { get_param: lb_st_interface_type_oam },
- }
- virtual_network_refs: [{ get_resource: test_net1 }]
- port_tuple_refs: [{ get_param: template_PortTuple_LB1 }]
- security_group_refs: [{ get_param: oam_sec_group_name}]
-
cmaui_port_2:
type: OS::Neutron::Port
properties:
- port: { get_resource: template_VMInt_OAM_lb_1 }
- port: { get_resource: cmaui_port_2 }
-
- type: OS::ContrailV2::VirtualMachineInterface
- properties:
- virtual_machine_interface_properties:
- {
- virtual_machine_interface_properties_service_interface_type: { get_param: lb_st_interface_type_oam },
- }
- virtual_network_refs: [{ get_resource: test_net1 }]
- port_tuple_refs: [{ get_param: template_PortTuple_LB1 }]
- security_group_refs: [{ get_param: oam_sec_group_name}]
-
cmaui_port_2:
type: OS::Neutron::Port
properties:
- port: { get_resource: template_VMInt_OAM_lb_1 }
- port: { get_resource: cmaui_port_2 }
-
- type: OS::ContrailV2::VirtualMachineInterface
- properties:
- virtual_machine_interface_properties:
- {
- virtual_machine_interface_properties_service_interface_type: { get_param: lb_st_interface_type_oam },
- }
- virtual_network_refs: [{ get_resource: test_net1 }]
- port_tuple_refs: [{ get_param: template_PortTuple_LB1 }]
- security_group_refs: [{ get_param: oam_sec_group_name}]
-
cmaui_port_2:
type: OS::Neutron::Port
properties:
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-validation-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
return MapUtils.unmodifiableMap(this.resourceTypeToImpl);
}
-@Override
+ @Override
public void init(Map<String, Object> properties) {
if (MapUtils.isEmpty(properties)) {
return;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
+import org.openecomp.core.validation.types.GlobalValidationContext;
import org.openecomp.core.validation.types.MessageContainer;
import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.heat.services.HeatStructureUtil;
+import org.openecomp.sdc.heat.services.manifest.ManifestUtil;
+import org.openecomp.sdc.validation.ResourceValidator;
+import org.openecomp.sdc.validation.ValidationContext;
+import org.openecomp.sdc.validation.Validator;
import org.openecomp.sdc.validation.type.ConfigConstants;
-import org.openecomp.sdc.validation.util.ValidationTestUtil;
+import org.openecomp.sdc.validation.util.ValidationUtil;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.*;
public class ResourceBaseValidatorTest {
-private String testValidator = "testValidator";
-
- @Test
- public void testInvalidResourceType(){
- ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(
- resourceBaseValidator, "/InvalidResourceType");
- assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
- "WARNING: [RBV1]: A resource has an invalid or unsupported type - null, " +
- "Resource ID [FSB2]");
- }
-
- @Test
- public void testInvalidHeatStructure(){
- ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
- Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(resourceBaseValidator,
- "/InvalidHeatStructure");
- assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
- "ERROR: [RBV2]: Invalid HEAT format problem - [while scanning for the next " +
- "token\n" + "found character '\\t(TAB)' that cannot start any token. " +
- "(Do not use \\t(TAB) for indentation)\n" +
- " in 'reader', line 10, column 1:\n" +
- " \t\t\tresources:\n" +
- " ^\n" +
- "]");
- }
-
- @Test
- public void testInitWithEmptyPropertiesMap() {
- ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
- Map<String, Object> properties = new HashMap<>();
- resourceBaseValidator.init(properties);
-
- assertTrue(MapUtils.isEmpty(resourceBaseValidator.getResourceTypeToImpl()));
- }
-
- @Test
- public void testInitPropertiesMap() {
- ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
- initProperties(resourceBaseValidator, getValidImplementationConfiguration());
-
- Map<String, ImplementationConfiguration> resourceTypeToImpl =
- resourceBaseValidator.getResourceTypeToImpl();
- assertTrue(MapUtils.isNotEmpty(resourceTypeToImpl));
- assertTrue(resourceTypeToImpl.containsKey(testValidator));
- }
-
- @Test
- public void testInitPropertiesWithString() {
- ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
- Map<String, Object> properties = new HashMap<>();
- properties.put(testValidator, "invalidValue");
-
- resourceBaseValidator.init(properties);
-
- assertTrue(MapUtils.isEmpty(resourceBaseValidator.getResourceTypeToImpl()));
- }
-
- @Test
- public void testInitPropertiesWithoutImplClass() {
- ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
- initProperties(resourceBaseValidator, new HashMap<>());
-
- assertTrue(MapUtils.isEmpty(resourceBaseValidator.getResourceTypeToImpl()));
- }
-
- public Map<String, Object> getValidImplementationConfiguration() {
- Map<String, Object> implConfiguration = new HashMap<>();
- implConfiguration.put(
- ConfigConstants.Impl_Class, "org.openecomp.sdc.validation.impl.validators.ForbiddenResourceGuideLineValidator");
- implConfiguration.put(ConfigConstants.Enable, true);
-
- return implConfiguration;
- }
-
- private void initProperties(ResourceBaseValidator resourceBaseValidator,
- Map<String, Object> implementationConfiguration) {
- Map<String, Object> properties =
- Collections.singletonMap(testValidator, implementationConfiguration);
-
- resourceBaseValidator.init(properties);
- }
+ private String testValidator = "testValidator";
+
+ @Test
+ public void testInvalidResourceType() {
+ ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
+ Map<String, MessageContainer> messages = testValidator(resourceBaseValidator, "/InvalidResourceType");
+ assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
+ "WARNING: [RBV1]: A resource has an invalid or unsupported type - null, Resource ID [FSB2]");
+ }
+
+ @Test
+ public void testInvalidHeatStructure() {
+ ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
+ Map<String, MessageContainer> messages = testValidator(resourceBaseValidator, "/InvalidHeatStructure");
+ assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
+ "ERROR: [RBV2]: Invalid HEAT format problem - [while scanning for the next " +
+ "token\n" + "found character '\\t(TAB)' that cannot start any token. " +
+ "(Do not use \\t(TAB) for indentation)\n" +
+ " in 'reader', line 10, column 1:\n" +
+ " \t\t\tresources:\n" +
+ " ^\n" +
+ "]");
+ }
+
+ @Test
+ public void testInitWithEmptyPropertiesMap() {
+ ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
+ Map<String, Object> properties = new HashMap<>();
+ resourceBaseValidator.init(properties);
+ assertTrue(MapUtils.isEmpty(resourceBaseValidator.getResourceTypeToImpl()));
+ }
+
+ @Test
+ public void testInitPropertiesMap() {
+ ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
+ initProperties(resourceBaseValidator, getValidImplementationConfiguration());
+
+ Map<String, ImplementationConfiguration> resourceTypeToImpl = resourceBaseValidator.getResourceTypeToImpl();
+ assertTrue(MapUtils.isNotEmpty(resourceTypeToImpl));
+ assertTrue(resourceTypeToImpl.containsKey(testValidator));
+ }
+
+ @Test
+ public void testInitPropertiesWithString() {
+ ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
+ Map<String, Object> properties = new HashMap<>();
+ properties.put(testValidator, "invalidValue");
+ resourceBaseValidator.init(properties);
+ assertTrue(MapUtils.isEmpty(resourceBaseValidator.getResourceTypeToImpl()));
+ }
+
+ @Test
+ public void testInitPropertiesWithoutImplClass() {
+ ResourceBaseValidator resourceBaseValidator = new ResourceBaseValidator();
+ initProperties(resourceBaseValidator, new HashMap<>());
+ assertTrue(MapUtils.isEmpty(resourceBaseValidator.getResourceTypeToImpl()));
+ }
+
+ public Map<String, Object> getValidImplementationConfiguration() {
+ Map<String, Object> implConfiguration = new HashMap<>();
+ implConfiguration.put(ConfigConstants.Impl_Class, "org.openecomp.sdc.validation.impl.validators.ForbiddenResourceGuideLineValidator");
+ implConfiguration.put(ConfigConstants.Enable, true);
+
+ return implConfiguration;
+ }
+
+ private void initProperties(ResourceBaseValidator resourceBaseValidator, Map<String, Object> implementationConfiguration) {
+ Map<String, Object> properties = Collections.singletonMap(testValidator, implementationConfiguration);
+ resourceBaseValidator.init(properties);
+ }
+
+ public GlobalValidationContext createGlobalContextFromPath(String path) {
+ GlobalValidationContext globalValidationContext = new GlobalValidationContext();
+ Map<String, byte[]> contentMap = getContentMapByPath(path);
+ if (contentMap == null) {
+ return null;
+ }
+ contentMap.forEach(globalValidationContext::addFileContext);
+
+ return globalValidationContext;
+ }
+
+ private Map<String, byte[]> getContentMapByPath(String path) {
+ Map<String, byte[]> contentMap = new HashMap<>();
+ URL url = ResourceBaseValidator.class.getResource(path);
+ File pathFile = new File(url.getFile());
+ File[] files;
+ if (pathFile.isDirectory()) {
+ files = pathFile.listFiles();
+ } else {
+ files = new File[]{pathFile};
+ }
+
+ if (files == null || files.length == 0) {
+ return null;
+ }
+
+ for (File file : files) {
+
+ try (FileInputStream fis = new FileInputStream(file)) {
+ contentMap.put(file.getName(), FileUtils.toByteArray(fis));
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to read file: " + file, e);
+ }
+
+ }
+ return contentMap;
+ }
+
+ public Map<String, MessageContainer> testValidator(Validator validator, String path) {
+ GlobalValidationContext globalValidationContext = createGlobalContextFromPath(path);
+ validator.validate(globalValidationContext);
+
+ assert globalValidationContext != null;
+ return globalValidationContext.getContextMessageContainers();
+ }
+
+ public Map<String, MessageContainer> testValidator(ResourceBaseValidator baseValidator,
+ ResourceValidator resourceValidator,
+ String resourceTypeToValidate, String path) {
+
+ GlobalValidationContext globalContext = Objects.requireNonNull(
+ createGlobalContextFromPath(path), "Global validation context cannot be null");
+
+ ManifestContent manifestContent = ValidationUtil.validateManifest(globalContext);
+ Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent);
+ Map<String, FileData> fileEnvMap = ManifestUtil.getFileAndItsEnv(manifestContent);
+
+ validateFiles(baseValidator, resourceValidator, globalContext, fileEnvMap, fileTypeMap,
+ resourceTypeToValidate);
+
+ return globalContext.getContextMessageContainers();
+ }
+
+ private void validateFiles(ResourceBaseValidator baseValidator,
+ ResourceValidator resourceValidator,
+ GlobalValidationContext globalContext,
+ Map<String, FileData> fileEnvMap,
+ Map<String, FileData.Type> fileTypeMap,
+ String resourceTypeToValidate) {
+
+ Collection<String> files = globalContext.getFiles();
+ for (String fileName : files) {
+ if (FileData.isHeatFile(fileTypeMap.get(fileName))) {
+ HeatOrchestrationTemplate heatOrchestrationTemplate =
+ ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext);
+
+ if (Objects.isNull(heatOrchestrationTemplate)) {
+ continue;
+ }
+
+ ValidationContext validationContext = baseValidator.createValidationContext(fileName,
+ fileEnvMap.get(fileName) == null ? null : fileEnvMap.get(fileName).getFile(),
+ heatOrchestrationTemplate, globalContext);
+
+ validateResources(fileName, resourceValidator, resourceTypeToValidate, validationContext,
+ globalContext);
+ }
+ }
+ }
+
+ private void validateResources(String fileName, ResourceValidator resourceValidator,
+ String resourceTypeToValidate, ValidationContext validationContext,
+ GlobalValidationContext globalValidationContext) {
+
+ HeatOrchestrationTemplate heatOrchestrationTemplate =
+ ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalValidationContext);
+
+ Map<String, Resource> resourcesMap =
+ Objects.requireNonNull(heatOrchestrationTemplate, "Orchestration template cannot be null").getResources();
+
+ if (MapUtils.isEmpty(resourcesMap)) {
+ return;
+ }
+
+ resourcesMap.entrySet()
+ .stream()
+ .filter(resourceEntry -> isResourceNeedToBeTested(resourceEntry.getValue().getType(), resourceTypeToValidate))
+ .forEach(resourceEntry ->
+ resourceValidator.validate
+ (fileName, resourceEntry, globalValidationContext, validationContext));
+ }
+
+ private boolean isResourceNeedToBeTested(String currResource, String resourceToTest) {
+ if (Objects.isNull(resourceToTest)) {
+ return HeatStructureUtil.isNestedResource(currResource);
+ }
+
+ return currResource.equals(resourceToTest);
+ }
+
+ public void validateErrorMessage(String actualMessage, String expected, String... params) {
+ assertEquals(actualMessage.replace("\n", "").replace("\r", ""),
+ ErrorMessagesFormatBuilder.getErrorWithParameters(expected, params).replace("\n", "")
+ .replace("\r", ""));
+ }
+
}
<artifactId>openecomp-sdc-vendor-license-api</artifactId>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-vendor-license-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-vendor-license-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<version>1.8.1-SNAPSHOT</version>
</parent>
-
<modules>
<module>openecomp-sdc-vendor-software-product-api</module>
<module>openecomp-sdc-vendor-software-product-core</module>
</modules>
-
</project>
<artifactId>openecomp-sdc-versioning-api</artifactId>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-versioning-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<parent>
<groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-lib</artifactId>
+ <artifactId>openecomp-sdc-versioning-lib</artifactId>
<version>1.8.1-SNAPSHOT</version>
- <relativePath>../..</relativePath>
</parent>
<dependencies>
<artifactId>onap-tosca-datatype</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.openecomp.sdc.core</groupId>
- <artifactId>openecomp-tosca-lib</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.openecomp.sdc.core</groupId>
- <artifactId>openecomp-facade-core</artifactId>
- <version>${project.version}</version>
- </dependency>
</dependencies>
<parent>
<artifactId>openecomp-tosca-converter-api</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.openecomp.sdc.core</groupId>
- <artifactId>openecomp-tosca-lib</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.openecomp.sdc.core</groupId>
- <artifactId>openecomp-facade-core</artifactId>
- <version>${project.version}</version>
- </dependency>
<dependency>
<groupId>org.openecomp.sdc</groupId>
<artifactId>openecomp-sdc-translator-core</artifactId>
package org.openecomp.core.converter.impl.pnfd;
-import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
+import org.onap.sdc.tosca.services.YamlUtil;
+import org.openecomp.core.converter.ServiceTemplateReaderService;
+import org.openecomp.core.converter.pnfd.PnfdTransformationEngine;
+import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
-import org.onap.sdc.tosca.services.YamlUtil;
-import org.openecomp.core.converter.ServiceTemplateReaderService;
-import org.openecomp.core.converter.pnfd.PnfdTransformationEngine;
-import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl;
-@RunWith(Parameterized.class)
+import static org.junit.Assert.assertEquals;
+
public class PnfTransformationEngineParameterizedTest {
private static final String TEST_CASES_PATH = "transformation/pnfParseEngine";
private static final String OUTPUT_FOLDER = "expectedOutput";
private static final String DEFAULT_OUTPUT_FILE_NAME = "defaultOutput.yaml";
- private final String inputFileName;
- private final Path inputFilePath;
- private final String outputFileName;
- private final Path outputFilePath;
- private final String transformationDescriptorFileName;
- private final Path transformationDescriptorFilePath;
private final YamlUtil yamlUtil = new YamlUtil();
private final ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
- public PnfTransformationEngineParameterizedTest(final String inputFileName, final Path inputFilePath,
- final String outputFileName, final Path outputFilePath,
- final String transformationDescriptorFileName, final Path transformationDescriptorFilePath) {
- this.inputFileName = inputFileName;
- this.inputFilePath = inputFilePath;
- this.outputFileName = outputFileName;
- this.outputFilePath = outputFilePath;
- this.transformationDescriptorFileName = transformationDescriptorFileName;
- this.transformationDescriptorFilePath = transformationDescriptorFilePath;
- }
-
-
- @Parameterized.Parameters(name = "{index}: input: {0}, descriptor: {4}, output: {2}")
- public static Collection<Object> input() throws IOException, URISyntaxException {
- return Files.list(getPathFromClasspath(TEST_CASES_PATH)).map(path -> {
- try {
- return buildTestCase(path);
- } catch (final IOException e) {
- return null;
- }
- }).filter(Objects::nonNull).flatMap(Collection::stream).collect(Collectors.toList());
- }
-
private static Collection<Object[]> buildTestCase(final Path testCasePath) throws IOException {
final Path inputFilePath = Files.list(testCasePath)
.filter(path -> path.toFile().getName().endsWith("yaml"))
}
final List<Path> transformationDescriptorList;
try (final Stream<Path> files = Files.walk(testCasePath.resolve(TRANSFORMATION_DESCRIPTOR_FOLDER))) {
- transformationDescriptorList = files.filter(path -> Files.isRegularFile(path))
+ transformationDescriptorList = files.filter(Files::isRegularFile)
.map(path -> Paths.get(TEST_CASES_PATH, testCasePath.getFileName().toString()
, TRANSFORMATION_DESCRIPTOR_FOLDER, path.getFileName().toString()))
.collect(Collectors.toList());
final List<Path> outputList;
try (final Stream<Path> files = Files.walk(testCasePath.resolve(OUTPUT_FOLDER))) {
- outputList = files.filter(path -> Files.isRegularFile(path)).collect(Collectors.toList());
+ outputList = files.filter(Files::isRegularFile).collect(Collectors.toList());
}
final Path defaultOutput = outputList.stream()
.filter(path -> path.toFile().getName().equals(DEFAULT_OUTPUT_FILE_NAME))
.filter(path -> path.toFile().getName().equals(transformationDescriptorPath.toFile().getName()))
.findFirst().orElse(defaultOutput);
if (outputPath != null) {
- testCaseList.add(new Object[] {inputFilePath.toFile().getName(), inputFilePath,
- outputPath.toFile().getName(), outputPath,
- transformationDescriptorPath.toFile().getName(), transformationDescriptorPath});
+ testCaseList.add(new Object[]{ inputFilePath, outputPath, transformationDescriptorPath});
}
}
-
return testCaseList;
-
}
@Test
- public void testTopologyTemplateConversions() throws IOException {
- final byte[] descriptor = Files.readAllBytes(inputFilePath);
- final ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor);
- final ServiceTemplate serviceTemplate = new ServiceTemplate();
-
- final PnfdTransformationEngine pnfdTransformationEngine = new PnfdNodeTemplateTransformationEngine(
- serviceTemplateReaderService, serviceTemplate, transformationDescriptorFilePath.toString());
- pnfdTransformationEngine.transform();
-
- final String result = yamlUtil.objectToYaml(serviceTemplate);
- final String expectedResult = parseToYaml(outputFilePath);
- assertEquals(expectedResult, result);
+ public void testTopologyTemplateConversions() throws IOException, URISyntaxException {
+ Files.list(getPathFromClasspath()).forEach(testCasePath -> {
+ try {
+ var paths = buildTestCase(testCasePath);
+ paths.forEach(p -> {
+ try {
+ final ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(Files.readAllBytes((Path) p[0]));
+ final ServiceTemplate serviceTemplate = new ServiceTemplate();
+
+ final PnfdTransformationEngine pnfdTransformationEngine = new PnfdNodeTemplateTransformationEngine(
+ serviceTemplateReaderService, serviceTemplate, p[2].toString());
+ pnfdTransformationEngine.transform();
+
+ final String result = yamlUtil.objectToYaml(serviceTemplate);
+ final String expectedResult = parseToYaml((Path) p[1]);
+ assertEquals(expectedResult, result);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ );
}
private String parseToYaml(final Path filePath) throws IOException {
}
}
- private static Path getPathFromClasspath(final String location) throws URISyntaxException {
- return Paths.get(PnfTransformationEngineParameterizedTest.class.getClassLoader().getResource(location).toURI());
+ private static Path getPathFromClasspath() throws URISyntaxException {
+ return Paths.get(PnfTransformationEngineParameterizedTest.class.getClassLoader().getResource(PnfTransformationEngineParameterizedTest.TEST_CASES_PATH).toURI());
}
}
\ No newline at end of file
<module>openecomp-tosca-converter-core</module>
</modules>
-
+ <dependencies>
+ <dependency>
+ <groupId>org.openecomp.sdc.core</groupId>
+ <artifactId>openecomp-tosca-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc.core</groupId>
+ <artifactId>openecomp-facade-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file
<skipYamlJsonValidator>false</skipYamlJsonValidator>
<!-- Yaml for properties -->
- <snakeyaml.version>1.14</snakeyaml.version>
+ <snakeyaml.version>1.26</snakeyaml.version>
<functionaljava.version>4.7</functionaljava.version>
<httpclient.version>4.5.3</httpclient.version>
<httpcore.version>4.4.1</httpcore.version>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
- <version>1.18</version>
+ <version>${snakeyaml.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>