Update aai-parent in babel to 1.13.3
[aai/babel.git] / src / test / java / org / onap / aai / babel / csar / extractor / YamlExtractorTest.java
index b53f38d..68414a8 100644 (file)
@@ -2,8 +2,8 @@
  * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 European Software Marketing Ltd.
+ * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2019 European Software Marketing Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.babel.csar.extractor;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.onap.aai.babel.testdata.CsarTest;
 import org.onap.aai.babel.util.ArtifactTestUtils;
 import org.onap.aai.babel.xml.generator.data.Artifact;
 
@@ -89,59 +92,66 @@ public class YamlExtractorTest {
     @Test
     public void testInvalidContentSupplied() {
         invalidArgumentsTest("This is a piece of nonsense and not a zip file".getBytes(), FOO, FOO,
-                "An error occurred trying to create a ZipFile. Is the content being converted really a csar file?");
+                "An error occurred trying to create a ZipFile. Is the content being converted really a CSAR file?");
     }
 
     @Test
     public void testArchiveContainsNoYmlFiles() throws IOException {
         try {
-            extractArchive("noYmlFilesArchive.zip");
+            CsarTest.NO_YAML_FILES.extractArtifacts();
             fail("An instance of InvalidArchiveException should have been thrown.");
         } catch (Exception e) {
-            assertTrue("An instance of InvalidArchiveException should have been thrown.",
-                    e instanceof InvalidArchiveException);
-            assertEquals("Incorrect message was returned", "No valid YAML files were found in the csar file.",
-                    e.getMessage());
+            assertTrue(e instanceof InvalidArchiveException,
+                    "An instance of InvalidArchiveException should have been thrown.");
+            assertEquals("No valid YAML files were found in the CSAR file.",
+                    e.getMessage(),
+                    "Incorrect message was returned");
         }
     }
 
     @Test
     public void testArchiveContainsOnlyTheExpectedYmlFilesFromSdWanService()
             throws IOException, InvalidArchiveException {
-        final List<Artifact> ymlFiles = extractArchive("service-SdWanServiceTest-csar.csar");
-        List<String> payloads = new ArrayList<>();
-        payloads.add("ymlFiles/resource-SdWanTestVsp-template.yml");
-        payloads.add("ymlFiles/resource-TunnelXconntest-template.yml");
-        payloads.add("ymlFiles/service-SdWanServiceTest-template.yml");
-        payloads.add("ymlFiles/artifacts.yml");
-        payloads.add("ymlFiles/data.yml");
-
-        new ArtifactTestUtils().performYmlAsserts(ymlFiles, payloads);
+        assertDoesNotThrow(() -> {
+            final List<Artifact> ymlFiles = CsarTest.SD_WAN_CSAR_FILE.extractArtifacts();
+            List<String> payloads = new ArrayList<>();
+            payloads.add("ymlFiles/resource-SdWanTestVsp-template.yml");
+            payloads.add("ymlFiles/resource-SdWanTestVsp-template-interface.yml");
+            payloads.add("ymlFiles/resource-TunnelXconntest-template.yml");
+            payloads.add("ymlFiles/resource-TunnelXconntest-template-interface.yml");
+            payloads.add("ymlFiles/service-SdWanServiceTest-template.yml");
+            payloads.add("ymlFiles/service-SdWanServiceTest-template-interface.yml");
+            payloads.add("ymlFiles/resource-Allotedresource-template.yml");
+            payloads.add("ymlFiles/resource-SdwantestvspNodesDummyServer-template.yml");
+            payloads.add("ymlFiles/nodes.yml");
+            payloads.add("ymlFiles/capabilities.yml");
+            payloads.add("ymlFiles/artifacts.yml");
+            payloads.add("ymlFiles/data.yml");
+            payloads.add("ymlFiles/groups.yml");
+
+            new ArtifactTestUtils().performYmlAsserts(ymlFiles, payloads);
+        });
     }
 
     /**
+     * Call the extractor with the specified arguments and assert that an exception is thrown.
+     *
      * @param archive
+     *            the compressed archive in the form of a byte array, expected to contain one or more YAML files
      * @param name
+     *            the name of the archive
      * @param version
+     *            the version of the archive
      * @param expectedErrorMessage
+     *            the text of the InvalidArchiveException thrown by the extractor
      */
     private void invalidArgumentsTest(byte[] archive, String name, String version, String expectedErrorMessage) {
         try {
             new YamlExtractor().extract(archive, name, version);
             fail("An instance of InvalidArchiveException should have been thrown");
-        } catch (Exception ex) {
+        } catch (InvalidArchiveException ex) {
             assertTrue(ex instanceof InvalidArchiveException);
             assertEquals(expectedErrorMessage, ex.getLocalizedMessage());
         }
     }
-
-    /**
-     * @param resourceName
-     * @return
-     * @throws InvalidArchiveException
-     * @throws IOException
-     */
-    private List<Artifact> extractArchive(String resourceName) throws InvalidArchiveException, IOException {
-        return new YamlExtractor().extract(new ArtifactTestUtils().getCompressedArtifact(resourceName), resourceName, "v1");
-    }
 }