Unit tests - openecomp-sdc-validation-manager 55/93955/2
authorTomasz Golabek <tomasz.golabek@nokia.com>
Tue, 20 Aug 2019 12:06:08 +0000 (14:06 +0200)
committerPiotr Darosz <piotr.darosz@nokia.com>
Thu, 22 Aug 2019 06:36:05 +0000 (06:36 +0000)
Tests for org.openecomp.sdc.validation

Change-Id: If0acdb2f453b5cd60d0ec49870f1467cdd212492
Issue-ID: SDC-2326
Signed-off-by: Tomasz Golabek <tomasz.golabek@nokia.com>
15 files changed:
openecomp-be/backend/openecomp-sdc-validation-manager/pom.xml
openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/types/ValidationFileStatus.java
openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImplTest.java [new file with mode: 0644]
openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/ContrailValidator.java [new file with mode: 0644]
openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidator.java [new file with mode: 0644]
openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/HeatResourceValidator.java [new file with mode: 0644]
openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java [new file with mode: 0644]
openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/ManifestValidator.java [new file with mode: 0644]
openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/NamingConventionGuideLineValidator.java [new file with mode: 0644]
openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/SharedResourceGuideLineValidator.java [new file with mode: 0644]
openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/YamlValidator.java [new file with mode: 0644]
openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/types/ValidationFileResponseTest.java [new file with mode: 0644]
openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/util/ValidationManagerUtilTest.java [new file with mode: 0644]
openecomp-be/backend/openecomp-sdc-validation-manager/src/test/resources/MANIFEST.json [new file with mode: 0644]
openecomp-be/backend/openecomp-sdc-validation-manager/src/test/resources/vfw.zip [new file with mode: 0644]

index 6c53ce6..91289a2 100644 (file)
             <artifactId>openecomp-common-lib</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>com.google.code.bean-matchers</groupId>
+            <artifactId>bean-matchers</artifactId>
+            <version>${bean-matchers.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
-
 </project>
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImplTest.java
new file mode 100644 (file)
index 0000000..aae9b3c
--- /dev/null
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.validation.impl;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import org.junit.Test;
+import org.openecomp.sdc.validation.types.ValidationFileResponse;
+
+public class UploadValidationManagerImplTest {
+
+    @Test
+    public void shouldValidateHeatFile() throws IOException {
+        UploadValidationManagerImpl uploadValidationManager = new UploadValidationManagerImpl();
+        ValidationFileResponse validationFileResponse = uploadValidationManager
+            .validateFile("heat", this.getClass().getClassLoader().getResourceAsStream("vfw.zip"));
+        assertNotNull(validationFileResponse.getValidationData());
+    }
+
+    @Test(expected = RuntimeException.class)
+    public void shouldNotValidateNonHeatFile() throws IOException {
+        UploadValidationManagerImpl uploadValidationManager = new UploadValidationManagerImpl();
+        uploadValidationManager.validateFile("txt", new ByteArrayInputStream( "test".getBytes() ));
+    }
+}
\ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/ContrailValidator.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/ContrailValidator.java
new file mode 100644 (file)
index 0000000..d3146e2
--- /dev/null
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.validation.impl.validators;
+
+import org.openecomp.core.validation.types.GlobalValidationContext;
+import org.openecomp.sdc.validation.Validator;
+
+/**
+ * Stub required for class creation in test scope
+ */
+public class ContrailValidator implements Validator {
+
+    @Override
+    public void validate(GlobalValidationContext globalContext) {
+    }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidator.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/ForbiddenResourceGuideLineValidator.java
new file mode 100644 (file)
index 0000000..e9b2d9a
--- /dev/null
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.validation.impl.validators;
+
+import org.openecomp.core.validation.types.GlobalValidationContext;
+import org.openecomp.sdc.validation.Validator;
+
+/**
+ * Stub required for class creation in test scope
+ */
+public class ForbiddenResourceGuideLineValidator implements Validator {
+
+    @Override
+    public void validate(GlobalValidationContext globalContext) {
+    }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/HeatResourceValidator.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/HeatResourceValidator.java
new file mode 100644 (file)
index 0000000..cbff792
--- /dev/null
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.validation.impl.validators;
+
+import org.openecomp.core.validation.types.GlobalValidationContext;
+import org.openecomp.sdc.validation.Validator;
+
+/**
+ * Stub required for class creation in test scope
+ */
+public class HeatResourceValidator implements Validator {
+
+    @Override
+    public void validate(GlobalValidationContext globalContext) {
+    }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java
new file mode 100644 (file)
index 0000000..1dcb047
--- /dev/null
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.validation.impl.validators;
+
+import org.openecomp.core.validation.types.GlobalValidationContext;
+import org.openecomp.sdc.validation.Validator;
+
+/**
+ * Stub required for class creation in test scope
+ */
+public class HeatValidator implements Validator {
+
+    @Override
+    public void validate(GlobalValidationContext globalContext) {
+    }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/ManifestValidator.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/ManifestValidator.java
new file mode 100644 (file)
index 0000000..292f0cd
--- /dev/null
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.validation.impl.validators;
+
+import org.openecomp.core.validation.types.GlobalValidationContext;
+import org.openecomp.sdc.validation.Validator;
+
+/**
+ * Stub required for class creation in test scope
+ */
+public class ManifestValidator implements Validator {
+
+    @Override
+    public void validate(GlobalValidationContext globalContext) {
+    }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/NamingConventionGuideLineValidator.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/NamingConventionGuideLineValidator.java
new file mode 100644 (file)
index 0000000..eac0006
--- /dev/null
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.validation.impl.validators;
+
+import org.openecomp.core.validation.types.GlobalValidationContext;
+import org.openecomp.sdc.validation.Validator;
+
+/**
+ * Stub required for class creation in test scope
+ */
+public class NamingConventionGuideLineValidator implements Validator{
+
+    @Override
+    public void validate(GlobalValidationContext globalContext) {
+    }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/SharedResourceGuideLineValidator.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/SharedResourceGuideLineValidator.java
new file mode 100644 (file)
index 0000000..fc7bf51
--- /dev/null
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.validation.impl.validators;
+
+import org.openecomp.core.validation.types.GlobalValidationContext;
+import org.openecomp.sdc.validation.Validator;
+
+/**
+ * Stub required for class creation in test scope
+ */
+public class SharedResourceGuideLineValidator implements Validator{
+
+    @Override
+    public void validate(GlobalValidationContext globalContext) {
+
+    }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/YamlValidator.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/impl/validators/YamlValidator.java
new file mode 100644 (file)
index 0000000..1e01c34
--- /dev/null
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.validation.impl.validators;
+
+import org.openecomp.core.validation.types.GlobalValidationContext;
+import org.openecomp.sdc.validation.Validator;
+
+/**
+ * Stub required for class creation in test scope
+ */
+public class YamlValidator implements Validator {
+
+    @Override
+    public void validate(GlobalValidationContext globalContext) {
+    }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/types/ValidationFileResponseTest.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/types/ValidationFileResponseTest.java
new file mode 100644 (file)
index 0000000..3532b76
--- /dev/null
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.validation.types;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class ValidationFileResponseTest {
+    @Test
+    public void shouldHaveValidGettersAndSetters() {
+        assertThat(ValidationFileResponse.class, hasValidGettersAndSetters());
+    }
+}
\ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/util/ValidationManagerUtilTest.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/java/org/openecomp/sdc/validation/util/ValidationManagerUtilTest.java
new file mode 100644 (file)
index 0000000..b151ea2
--- /dev/null
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.validation.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.sdc.common.utils.SdcCommon;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+
+public class ValidationManagerUtilTest {
+
+    private FileContentHandler fileContentMap;
+    private Map<String, List<ErrorMessage>> errors;
+
+    @Before
+    public void setUp() throws Exception {
+        fileContentMap = new FileContentHandler();
+        errors = new HashMap<>();
+    }
+
+    @Test
+    public void shouldHandleNonMissingManifest() throws IOException {
+        fileContentMap.addFile(SdcCommon.MANIFEST_NAME, this.getClass().getClassLoader().getResourceAsStream("MANIFEST.json"));
+        ValidationManagerUtil.handleMissingManifest(fileContentMap, errors);
+        assertTrue(errors.isEmpty());
+    }
+
+    @Test
+    public void shouldHandleMissingManifest() throws IOException {
+        fileContentMap.addFile("ANY", this.getClass().getClassLoader().getResourceAsStream("vfw.zip"));
+        ValidationManagerUtil.handleMissingManifest(fileContentMap, errors);
+        assertEquals(errors.get(SdcCommon.MANIFEST_NAME).size(), 1);
+        assertEquals(errors.get(SdcCommon.MANIFEST_NAME).get(0).getMessage(), "Manifest doesn't exist");
+    }
+
+}
\ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/resources/MANIFEST.json b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/resources/MANIFEST.json
new file mode 100644 (file)
index 0000000..a4e5cfd
--- /dev/null
@@ -0,0 +1,17 @@
+{
+    "name": "virtualFireWall", 
+    "description": "robot ete manifest", 
+    "data": [
+        {
+            "file": "base_vfw.yaml", 
+            "type": "HEAT", 
+            "isBase": "true", 
+            "data": [
+                {
+                    "file": "base_vfw.env", 
+                    "type": "HEAT_ENV"
+                }
+            ]
+        }
+    ]
+}
\ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/resources/vfw.zip b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/resources/vfw.zip
new file mode 100644 (file)
index 0000000..b8273de
Binary files /dev/null and b/openecomp-be/backend/openecomp-sdc-validation-manager/src/test/resources/vfw.zip differ