* ============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 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;
@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());
}
}
@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");
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 {
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");
- }
}