Additional null checks and comments
[aai/babel.git] / src / test / java / org / onap / aai / babel / csar / extractor / YamlExtractorTest.java
index e01a8f0..20c3434 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.
@@ -18,6 +18,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.babel.csar.extractor;
 
 import static org.junit.Assert.assertEquals;
@@ -28,6 +29,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import org.junit.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,18 +91,18 @@ 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.",
+            assertEquals("Incorrect message was returned", "No valid YAML files were found in the CSAR file.",
                     e.getMessage());
         }
     }
@@ -108,7 +110,7 @@ public class YamlExtractorTest {
     @Test
     public void testArchiveContainsOnlyTheExpectedYmlFilesFromSdWanService()
             throws IOException, InvalidArchiveException {
-        final List<Artifact> ymlFiles = extractArchive("service-SdWanServiceTest-csar.csar");
+        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");
@@ -131,9 +133,13 @@ public class YamlExtractorTest {
      * 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 {
@@ -144,19 +150,4 @@ public class YamlExtractorTest {
             assertEquals(expectedErrorMessage, ex.getLocalizedMessage());
         }
     }
-
-    /**
-     * Extract Artifacts from the specified CSAR resource.
-     *
-     * @param resourceName
-     *            the CSAR file
-     * @return the extracted artifacts
-     * @throws InvalidArchiveException
-     * @throws IOException
-     *             for I/O errors
-     */
-    private List<Artifact> extractArchive(String resourceName) throws InvalidArchiveException, IOException {
-        byte[] csar = new ArtifactTestUtils().getCompressedArtifact(resourceName);
-        return new YamlExtractor().extract(csar, resourceName, "v1");
-    }
 }