aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2019-03-06 13:18:43 +0000
committermark.j.leonard <mark.j.leonard@gmail.com>2019-03-06 13:18:43 +0000
commitff0718120f36e14b065047f0b3f29665f2191e53 (patch)
tree85551b2aefc3bcac93cfaf418ada59058aff5974 /src/test/java/org/onap
parent4e828f7f2037735de2253a0dcc2b557c88c15cd3 (diff)
Add JUnit test for invalid TOSCA mappings JSON
Add a test to improve code coverage. Also tidy up some out of date test code comments and unnecessary structural code. Change-Id: Ib38a3d602bc5ae46d16f3067d1d3e0ba0838c446 Issue-ID: AAI-2212 Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r--src/test/java/org/onap/aai/babel/MicroServiceAuthTest.java8
-rw-r--r--src/test/java/org/onap/aai/babel/parser/TestToscaParser.java45
-rw-r--r--src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java13
-rw-r--r--src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java9
-rw-r--r--src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java11
-rw-r--r--src/test/java/org/onap/aai/babel/util/Resources.java5
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestGeneratorUtil.java5
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java12
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java16
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java12
10 files changed, 63 insertions, 73 deletions
diff --git a/src/test/java/org/onap/aai/babel/MicroServiceAuthTest.java b/src/test/java/org/onap/aai/babel/MicroServiceAuthTest.java
index aae7846..b9a8ff9 100644
--- a/src/test/java/org/onap/aai/babel/MicroServiceAuthTest.java
+++ b/src/test/java/org/onap/aai/babel/MicroServiceAuthTest.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 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.
@@ -47,11 +47,11 @@ public class MicroServiceAuthTest {
private static final String authPolicyFile = "auth_policy.json";
static {
- System.setProperty("CONFIG_HOME", System.getProperty("user.dir") + File.separator + "src/test/resources");
+ System.setProperty("CONFIG_HOME", "src/test/resources");
}
/**
- * Temporarily invalidate the default policy file and then try to initialise the authorisation class using the name
+ * Temporarily invalidate the default policy file and then try to initialize the authorization class using the name
* of a policy file that does not exist.
*
* @throws AAIAuthException
diff --git a/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java b/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java
index f94328b..f300f7b 100644
--- a/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java
+++ b/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 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.
@@ -27,16 +27,15 @@ import static org.junit.Assert.assertThat;
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.onap.aai.babel.csar.extractor.InvalidArchiveException;
import org.onap.aai.babel.testdata.CsarTest;
import org.onap.aai.babel.util.ArtifactTestUtils;
+import org.onap.aai.babel.util.Resources;
import org.onap.aai.babel.xml.generator.api.AaiArtifactGenerator;
import org.onap.aai.babel.xml.generator.data.AdditionalParams;
-import org.onap.aai.babel.xml.generator.data.Artifact;
import org.onap.aai.babel.xml.generator.data.GenerationData;
/**
@@ -44,29 +43,41 @@ import org.onap.aai.babel.xml.generator.data.GenerationData;
*/
public class TestToscaParser {
- static {
- if (System.getProperty("APP_HOME") == null) {
- System.setProperty("APP_HOME", ".");
- }
- }
-
@Before
public void setup() {
new ArtifactTestUtils().setGeneratorSystemProperties();
}
@Test
- public void testParserWithCsarFile() throws IOException, InvalidArchiveException {
- List<Artifact> ymlFiles = CsarTest.VNF_VENDOR_CSAR.extractArtifacts();
- Map<String, String> additionalParams = new HashMap<>();
- additionalParams.put(AdditionalParams.SERVICE_VERSION.getName(), "1.0");
+ public void testParserWithInvalidMappings() throws IOException, InvalidArchiveException {
+ System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE,
+ new ArtifactTestUtils().getResourcePath(Resources.INVALID_TOSCA_MAPPING_CONFIG));
- AaiArtifactGenerator generator = new AaiArtifactGenerator();
- GenerationData data =
- generator.generateArtifact(CsarTest.VNF_VENDOR_CSAR.getContent(), ymlFiles, additionalParams);
+ GenerationData data = generateArtifactsFromCsarFile();
+ assertThat("Number of errors produced " + data.getErrorData(), data.getErrorData().size(), is(equalTo(1)));
+ assertThat("Number of resources generated", data.getResultData().size(), is(equalTo(0)));
+ }
+ @Test
+ public void testParserWithCsarFile() throws IOException, InvalidArchiveException {
+ GenerationData data = generateArtifactsFromCsarFile();
assertThat("Number of errors produced " + data.getErrorData(), data.getErrorData().size(), is(equalTo(0)));
assertThat("Number of resources generated", data.getResultData().size(), is(equalTo(2)));
}
+ /**
+ * Invoke the generator with a sample CSAR file.
+ *
+ * @return the generated AAI Artifacts
+ * @throws InvalidArchiveException
+ * if the test CSAR file is invalid
+ * @throws IOException
+ * if there are I/O errors reading the CSAR content
+ */
+ private GenerationData generateArtifactsFromCsarFile() throws InvalidArchiveException, IOException {
+ Map<String, String> additionalParams = new HashMap<>();
+ additionalParams.put(AdditionalParams.SERVICE_VERSION.getName(), "1.0");
+ return new AaiArtifactGenerator().generateArtifact(CsarTest.VNF_VENDOR_CSAR.getContent(),
+ CsarTest.VNF_VENDOR_CSAR.extractArtifacts(), additionalParams);
+ }
}
diff --git a/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java b/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java
index fe30be4..5001a09 100644
--- a/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java
+++ b/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 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.
@@ -57,12 +57,6 @@ public class CsarToXmlConverterTest {
private static final String INCORRECT_CSAR_NAME = "the_name_of_the_csar_file.csar";
private static final String SERVICE_VERSION = "1.0";
- static {
- if (System.getProperty("APP_HOME") == null) {
- System.setProperty("APP_HOME", ".");
- }
- }
-
// The class to be tested.
private CsarToXmlConverter converter;
@@ -117,7 +111,8 @@ public class CsarToXmlConverterTest {
@Test
public void testArtifactGeneratorConfigMissing() throws CsarConverterException, IOException {
exception.expect(IllegalArgumentException.class);
- exception.expectMessage("Cannot generate artifacts. System property artifactgenerator.config not configured");
+ exception.expectMessage("Cannot generate artifacts. System property "
+ + ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE + " not configured");
// Unset the required system property
System.clearProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE);
diff --git a/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java b/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java
index a38686f..be02e17 100644
--- a/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java
+++ b/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 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.
@@ -59,20 +59,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class TestGenerateArtifactsServiceImpl {
static {
- if (System.getProperty("APP_HOME") == null) {
- System.setProperty("APP_HOME", ".");
- }
System.setProperty("CONFIG_HOME", "src/test/resources");
}
-
@Inject
private AAIMicroServiceAuth auth;
@BeforeClass
public static void setup() {
new ArtifactTestUtils().setGeneratorSystemProperties();
-
}
@Test
diff --git a/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java b/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java
index f5a5a94..df27c22 100644
--- a/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java
+++ b/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 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.
@@ -57,7 +57,7 @@ public class ArtifactTestUtils {
private static final String CSAR_INPUTS_FOLDER = "compressedArtifacts/";
/**
- * Initialise System Properties for test configuration files.
+ * Initialize System Properties for test configuration files.
*/
public void setGeneratorSystemProperties() {
System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
@@ -78,16 +78,15 @@ public class ArtifactTestUtils {
}
/**
- * Load the Widget to UUID mappings from the Artifact Generator Properties (resource).
+ * Load the Widget type mappings (resource).
*
* @throws IOException
- * if the properties file is not loaded
+ * if the configuration file is not loaded
*/
public void loadWidgetMappings() throws IOException {
ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(getResourcePath(Resources.TOSCA_MAPPING_CONFIG));
}
-
/**
* Specific test method for the YAML Extractor test.
*
diff --git a/src/test/java/org/onap/aai/babel/util/Resources.java b/src/test/java/org/onap/aai/babel/util/Resources.java
index a8cffdb..72b0d1a 100644
--- a/src/test/java/org/onap/aai/babel/util/Resources.java
+++ b/src/test/java/org/onap/aai/babel/util/Resources.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 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.util;
/**
diff --git a/src/test/java/org/onap/aai/babel/xml/generator/model/TestGeneratorUtil.java b/src/test/java/org/onap/aai/babel/xml/generator/model/TestGeneratorUtil.java
index 60bcc7e..9b5d05f 100644
--- a/src/test/java/org/onap/aai/babel/xml/generator/model/TestGeneratorUtil.java
+++ b/src/test/java/org/onap/aai/babel/xml/generator/model/TestGeneratorUtil.java
@@ -2,13 +2,14 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2018 Nokia Networks Intellectual Property. All rights reserved.
+ * Copyright (c) 2017-2018 Nokia Networks Intellectual Property. All rights reserved.
+ * Copyright (c) 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.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
diff --git a/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java b/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java
index 4c5ff20..c564a93 100644
--- a/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java
+++ b/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 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.
@@ -49,16 +49,12 @@ public class TestModel {
private Widget widgetModel = new Widget(Type.OAM_NETWORK, "oam-network", true);
private Model anonymousModel;
- static {
- System.setProperty("APP_HOME", ".");
- }
-
/**
- * Initialize the Artifact Generator with filtering and mapping configuration. Also Load the Widget to UUID mappings
+ * Initialize the Artifact Generator with filtering and mapping configuration. Also load the Widget to UUID mappings
* from the Artifact Generator properties.
*
* @throws IOException
- * if the Artifact Generator properties file is not loaded
+ * if the mappings configuration cannot be loaded
*/
@Before
public void setup() throws IOException {
diff --git a/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java b/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java
index cc6d968..f712ba5 100644
--- a/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java
+++ b/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 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.
@@ -37,19 +37,15 @@ import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
/**
- * Direct tests of the VfModule Model class to improve code coverage.
+ * Direct tests of the VFMODULE Resource and Widget functionality to improve code coverage.
*/
public class TestVfModule {
- static {
- System.setProperty("APP_HOME", ".");
- }
-
/**
- * Initialize the Widget mappings.
- *
+ * Load the Widget Configuration, including the type mappings and the UUID mappings.
+ *
* @throws IOException
- * if a properties file is not loaded
+ * if the mappings configuration cannot be loaded
*/
@BeforeClass
public static void setup() throws IOException {
diff --git a/src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java b/src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java
index 00694b2..8c2338c 100644
--- a/src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java
+++ b/src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 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.
@@ -38,15 +38,11 @@ import org.onap.aai.babel.xml.generator.types.ModelType;
*/
public class TestWidget {
- static {
- System.setProperty("APP_HOME", ".");
- }
-
/**
- * Load the Widget to UUID mappings from the Artifact Generator properties.
+ * Load the Widget Configuration, including the type mappings and the UUID mappings.
*
* @throws IOException
- * if the properties file is not loaded
+ * if the mappings configuration cannot be loaded
*/
@BeforeClass
public static void setup() throws IOException {