aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/aai/babel/MicroServiceAuthTest.java119
-rw-r--r--src/test/java/org/onap/aai/babel/TestApplication.java117
-rw-r--r--src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java107
-rw-r--r--src/test/java/org/onap/aai/babel/parser/TestToscaParser.java47
-rw-r--r--src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java15
-rw-r--r--src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java11
-rw-r--r--src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java16
-rw-r--r--src/test/java/org/onap/aai/babel/util/Resources.java7
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java55
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestGeneratorUtil.java22
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java132
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java110
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java174
13 files changed, 670 insertions, 262 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..ef9504b 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.
@@ -27,9 +27,11 @@ import static org.junit.Assert.assertThat;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.util.concurrent.TimeUnit;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import org.junit.Before;
import org.junit.Test;
import org.onap.aai.auth.AAIAuthException;
import org.onap.aai.auth.AAIMicroServiceAuth;
@@ -46,12 +48,27 @@ public class MicroServiceAuthTest {
private static final String VALID_ADMIN_USER = "cn=common-name, ou=org-unit, o=org, l=location, st=state, c=us";
private static final String authPolicyFile = "auth_policy.json";
- static {
- System.setProperty("CONFIG_HOME", System.getProperty("user.dir") + File.separator + "src/test/resources");
+ @Before
+ public void setup() {
+ System.setProperty("CONFIG_HOME", "src/test/resources");
}
/**
- * Temporarily invalidate the default policy file and then try to initialise the authorisation class using the name
+ * Test authorization of a request when authentication is disabled.
+ *
+ * @throws AAIAuthException
+ * if the test creates invalid Auth Policy roles
+ */
+ @Test
+ public void testAuthenticationDisabled() throws AAIAuthException {
+ BabelAuthConfig babelAuthConfig = new BabelAuthConfig();
+ babelAuthConfig.setAuthenticationDisable(true);
+ AAIMicroServiceAuth auth = new AAIMicroServiceAuth(babelAuthConfig);
+ assertThat(auth.validateRequest(null, new MockHttpServletRequest(), null, "any/uri"), is(true));
+ }
+
+ /**
+ * 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
@@ -71,6 +88,26 @@ public class MicroServiceAuthTest {
}
/**
+ * Temporarily invalidate the default policy file and then try to initialize the authorization class using a null
+ * policy file name.
+ *
+ * @throws AAIAuthException
+ * if the Auth policy file cannot be loaded
+ */
+ @Test(expected = AAIAuthException.class)
+ public void testNullPolicyFile() throws AAIAuthException {
+ String defaultFile = AAIMicroServiceAuthCore.getDefaultAuthFileName();
+ try {
+ AAIMicroServiceAuthCore.setDefaultAuthFileName("invalid.default.file");
+ BabelAuthConfig babelServiceAuthConfig = new BabelAuthConfig();
+ babelServiceAuthConfig.setAuthPolicyFile(null);
+ new AAIMicroServiceAuth(babelServiceAuthConfig);
+ } finally {
+ AAIMicroServiceAuthCore.setDefaultAuthFileName(defaultFile);
+ }
+ }
+
+ /**
* Test loading of a temporary file created with the specified roles.
*
* @throws AAIAuthException
@@ -89,6 +126,40 @@ public class MicroServiceAuthTest {
}
/**
+ * Test re-loading of users by changing the contents of a temporary file.
+ *
+ * @throws JSONException
+ * if this test creates an invalid JSON object
+ * @throws AAIAuthException
+ * if the test creates invalid Auth Policy roles
+ * @throws IOException
+ * for I/O failures
+ * @throws InterruptedException
+ * if interrupted while sleeping
+ */
+ @Test
+ public void createLocalAuthFileOnChange()
+ throws JSONException, AAIAuthException, IOException, InterruptedException {
+ JSONObject roles = createRoleObject("role", createUserObject("user"), createFunctionObject("func"));
+ File file = createTempPolicyFile(roles);
+
+ BabelAuthConfig babelAuthConfig = new BabelAuthConfig();
+ babelAuthConfig.setAuthPolicyFile(file.getAbsolutePath());
+ new AAIMicroServiceAuth(babelAuthConfig);
+
+ // Make changes to the temp file
+ FileWriter fileWriter = new FileWriter(file);
+ fileWriter.write("");
+ fileWriter.flush();
+ fileWriter.close();
+
+ // Wait for the file to be reloaded
+ TimeUnit.SECONDS.sleep(3);
+
+ AAIMicroServiceAuthCore.cleanup();
+ }
+
+ /**
* Test that the default policy file is loaded when a non-existent file is passed to the authorisation class.
*
* @throws AAIAuthException
@@ -104,6 +175,23 @@ public class MicroServiceAuthTest {
}
/**
+ * Test that the default policy file is loaded when a non-existent file is passed to the authorisation class and
+ * CONFIG_HOME is not set.
+ *
+ * @throws AAIAuthException
+ * if the Auth Policy cannot be loaded
+ */
+ @Test
+ public void createAuthFromDefaultFileAppHome() throws AAIAuthException {
+ System.clearProperty("CONFIG_HOME");
+ System.setProperty("APP_HOME", "src/test/resources");
+ BabelAuthConfig babelServiceAuthConfig = new BabelAuthConfig();
+ babelServiceAuthConfig.setAuthPolicyFile("non-existent-file");
+ new AAIMicroServiceAuth(babelServiceAuthConfig);
+ // The default policy will have been loaded from APP_HOME/appconfig
+ }
+
+ /**
* Test loading of the policy file relative to CONFIG_HOME.
*
* @throws AAIAuthException
@@ -146,16 +234,29 @@ public class MicroServiceAuthTest {
* if the auth policy file cannot be loaded
*/
private AAIMicroServiceAuth createAuthService(JSONObject roles) throws AAIAuthException, IOException {
+ File file = createTempPolicyFile(roles);
+ BabelAuthConfig babelAuthConfig = new BabelAuthConfig();
+ babelAuthConfig.setAuthPolicyFile(file.getAbsolutePath());
+ return new AAIMicroServiceAuth(babelAuthConfig);
+ }
+
+ /**
+ * Create a temporary JSON file using the supplied roles.
+ *
+ * @param roles
+ * the roles to use to populate the new file
+ * @return the new temporary file
+ * @throws IOException
+ * for I/O errors
+ */
+ private File createTempPolicyFile(JSONObject roles) throws IOException {
File file = File.createTempFile("auth-policy", "json");
file.deleteOnExit();
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(roles.toString());
fileWriter.flush();
fileWriter.close();
-
- BabelAuthConfig babelAuthConfig = new BabelAuthConfig();
- babelAuthConfig.setAuthPolicyFile(file.getAbsolutePath());
- return new AAIMicroServiceAuth(babelAuthConfig);
+ return file;
}
/**
diff --git a/src/test/java/org/onap/aai/babel/TestApplication.java b/src/test/java/org/onap/aai/babel/TestApplication.java
new file mode 100644
index 0000000..8c9ca5e
--- /dev/null
+++ b/src/test/java/org/onap/aai/babel/TestApplication.java
@@ -0,0 +1,117 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * 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.
+ * 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.onap.aai.babel;
+
+import java.io.IOException;
+import org.eclipse.jetty.util.security.Password;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeMatcher;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest(classes = BabelApplication.class)
+public class TestApplication {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ /**
+ * Initialize System Properties.
+ */
+ @Before
+ public void init() {
+ System.setProperty("APP_HOME", ".");
+ System.setProperty("CONFIG_HOME", "src/test/resources");
+ System.setProperty("server.ssl.key-store", "src/test/resources/auth/keystore.jks");
+ }
+
+ @Test
+ public void testApplicationStarts() {
+ System.setProperty("KEY_STORE_PASSWORD", "password");
+ BabelApplication.main(new String[] {});
+ BabelApplication.exit();
+ }
+
+ @Test
+ public void testApplicationStartsWithObfuscatedPassword() {
+ System.setProperty("KEY_STORE_PASSWORD", Password.obfuscate("password"));
+ BabelApplication.main(new String[] {});
+ BabelApplication.exit();
+ }
+
+ @Test
+ public void testApplicationWithNullArgs() {
+ System.setProperty("KEY_STORE_PASSWORD", "test");
+ expectedEx.expect(IllegalArgumentException.class);
+ expectedEx.expectMessage("Args must not be null");
+ BabelApplication.main(null);
+ }
+
+ @Test
+ public void testApplicationWithEmptyKeyStorePassword() {
+ System.setProperty("KEY_STORE_PASSWORD", "");
+ expectedEx.expect(IllegalArgumentException.class);
+ expectedEx.expectMessage("roperty KEY_STORE_PASSWORD not set");
+ BabelApplication.main(new String[] {});
+ }
+
+ @Test
+ public void testApplicationWithNullKeyStorePassword() {
+ System.clearProperty("KEY_STORE_PASSWORD");
+ expectedEx.expect(IllegalArgumentException.class);
+ expectedEx.expectMessage("roperty KEY_STORE_PASSWORD not set");
+ BabelApplication.main(new String[] {});
+ }
+
+ @Test
+ public void testApplicationWithIncorrectKeyStorePassword() {
+ System.setProperty("KEY_STORE_PASSWORD", "test");
+ final CauseMatcher expectedCause = new CauseMatcher(IOException.class, "password was incorrect");
+ expectedEx.expectCause(expectedCause);
+ BabelApplication.main(new String[] {});
+ }
+
+ private static class CauseMatcher extends TypeSafeMatcher<Throwable> {
+
+ private final Class<? extends Throwable> type;
+ private final String expectedMessage;
+
+ public CauseMatcher(Class<? extends Throwable> type, String expectedMessage) {
+ this.type = type;
+ this.expectedMessage = expectedMessage;
+ }
+
+ @Override
+ protected boolean matchesSafely(Throwable item) {
+ return item.getClass().isAssignableFrom(type) && item.getMessage().contains(expectedMessage);
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendValue(type).appendText(" and message ").appendValue(expectedMessage);
+ }
+ }
+
+}
diff --git a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
index a538373..50f0aa9 100644
--- a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
+++ b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.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.
@@ -25,16 +25,20 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import org.junit.Test;
import org.mockito.Mockito;
+import org.onap.aai.babel.util.ArtifactTestUtils;
+import org.onap.aai.babel.util.Resources;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
import org.onap.aai.babel.xml.generator.data.WidgetMapping;
import org.onap.aai.babel.xml.generator.model.Resource;
-import org.onap.aai.babel.xml.generator.model.Widget.Type;
+import org.onap.aai.babel.xml.generator.model.WidgetType;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.toscaparser.api.Group;
import org.onap.sdc.toscaparser.api.NodeTemplate;
@@ -50,13 +54,60 @@ public class TestArtifactGeneratorToscaParser {
private static final String TEST_UUID = "1234";
/**
+ * Initialize the Generator with an invalid artifact generator properties file path.
+ *
+ * @throws IOException
+ * if an error occurs reading the configuration properties
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testMissingPropertiesFile() throws IOException {
+ System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE, "non-existent.file");
+ ArtifactGeneratorToscaParser.initWidgetConfiguration();
+ }
+
+ /**
+ * Initialize the Generator with an invalid mappings file path.
+ *
+ * @throws IOException
+ * if the file content could not be read successfully
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testMissingMappingsFile() throws IOException {
+ ArtifactGeneratorToscaParser.initToscaMappingsConfiguration("non-existent.file");
+ }
+
+ /**
+ * Initialize the Generator with no Widget Mappings content.
+ *
+ * @throws IOException
+ * if the file content could not be read successfully
+ */
+ @Test(expected = IOException.class)
+ public void testMissingMappingsContent() throws IOException {
+ String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.EMPTY_TOSCA_MAPPING_CONFIG);
+ ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson);
+ }
+
+ /**
+ * Initialize the Generator with invalid Widget Mappings content.
+ *
+ * @throws IOException
+ * if the file content could not be read successfully
+ */
+ @Test(expected = IOException.class)
+ public void testInvalidMappingsContent() throws IOException {
+ String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.INVALID_TOSCA_MAPPING_CONFIG);
+ ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson);
+ }
+
+ /**
* Process an Allotted Resource that does not have a Providing Service.
*/
@Test(expected = IllegalArgumentException.class)
public void testMissingProvidingService() {
List<NodeTemplate> nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage"));
- new ArtifactGeneratorToscaParser(null).processResourceModels(new Resource(Type.ALLOTTED_RESOURCE, true),
- nodeTemplateList);
+ new ArtifactGeneratorToscaParser(null)
+ .processResourceModels(new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true), nodeTemplateList);
}
/**
@@ -66,25 +117,44 @@ public class TestArtifactGeneratorToscaParser {
public void testAddResourceNotProvidingService() {
List<NodeTemplate> nodeTemplateList = Collections.singletonList(buildNodeTemplate("testCR", "CR"));
// Create any Resource to which the CR can be added
- final Resource dummyResource = new Resource(Type.ALLOTTED_RESOURCE, true);
+ final Resource dummyResource = new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true);
new ArtifactGeneratorToscaParser(null).processResourceModels(dummyResource, nodeTemplateList);
}
/**
- * Initialise the Artifact Generator Widget Mapping config with incomplete data.
+ * Initialize the Artifact Generator Widget Mapping config with incomplete data (no type).
+ *
+ * @throws IOException
+ * if a WidgetMapping is invalid
*/
- @Test(expected = IllegalArgumentException.class)
- public void testToscaMappingWithoutType() {
+ @Test(expected = IOException.class)
+ public void testToscaMappingWithoutType() throws IOException {
WidgetMapping invalidMapping = new WidgetMapping();
invalidMapping.setType(null);
WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
}
/**
- * Initialise the Artifact Generator Widget Mapping config with incomplete data.
+ * Initialize the Artifact Generator Widget Mapping config with invalid data (type value).
+ *
+ * @throws IOException
+ * if a WidgetMapping is invalid
*/
- @Test(expected = IllegalArgumentException.class)
- public void testToscaMappingWithoutWidget() {
+ @Test(expected = IOException.class)
+ public void testToscaMappingWithInvalidType() throws IOException {
+ WidgetMapping invalidMapping = new WidgetMapping();
+ invalidMapping.setType("invalid");
+ WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
+ }
+
+ /**
+ * Initialize the Artifact Generator Widget Mapping config with incomplete data (no widget name).
+ *
+ * @throws IOException
+ * if a WidgetMapping is invalid
+ */
+ @Test(expected = IOException.class)
+ public void testToscaMappingWithoutWidget() throws IOException {
WidgetMapping invalidMapping = new WidgetMapping();
invalidMapping.setWidget(null);
WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
@@ -92,9 +162,16 @@ public class TestArtifactGeneratorToscaParser {
/**
* Process a dummy Group object for a Service Resource.
+ *
+ * @throws XmlArtifactGenerationException
+ * if there is no configuration defined for a member Widget of an instance group
+ * @throws IOException
+ * if the widget mappings cannot be loaded
*/
@Test
- public void testInstanceGroups() {
+ public void testInstanceGroups() throws XmlArtifactGenerationException, IOException {
+ new ArtifactTestUtils().loadWidgetMappings();
+
final String instanceGroupType = "org.openecomp.groups.ResourceInstanceGroup";
WidgetConfigurationUtil.setSupportedInstanceGroups(Collections.singletonList(instanceGroupType));
@@ -111,8 +188,8 @@ public class TestArtifactGeneratorToscaParser {
Mockito.when(helper.getGroupsOfOriginOfNodeTemplate(serviceNodeTemplate)).thenReturn(groups);
ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(helper);
- List<Resource> resources =
- parser.processInstanceGroups(new Resource(Type.INSTANCE_GROUP, true), serviceNodeTemplate);
+ Resource groupResource = new Resource(WidgetType.valueOf("INSTANCE_GROUP"), true);
+ List<Resource> resources = parser.processInstanceGroups(groupResource, serviceNodeTemplate);
assertThat(resources.size(), is(1));
Resource resource = resources.get(0);
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 348e1a1..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)));
+ }
- assertThat("Number of errors produced", data.getErrorData().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 4921490..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;
@@ -116,8 +110,9 @@ public class CsarToXmlConverterTest {
*/
@Test
public void testArtifactGeneratorConfigMissing() throws CsarConverterException, IOException {
- exception.expect(CsarConverterException.class);
- exception.expectMessage("Cannot generate artifacts. System property artifactgenerator.config not configured");
+ exception.expect(IllegalArgumentException.class);
+ 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..0673d04 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,26 +59,21 @@ 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
public void testGenerateArtifacts() throws Exception {
Response response = processJsonRequest(CsarTest.VNF_VENDOR_CSAR);
- assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ assertThat(response.toString(), response.getStatus(), is(Response.Status.OK.getStatusCode()));
assertThat(response.getEntity(), is(getResponseJson("response.json")));
}
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 01f62cf..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,6 +78,16 @@ public class ArtifactTestUtils {
}
/**
+ * Load the Widget type mappings (resource).
+ *
+ * @throws IOException
+ * 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.
*
* @param toscaFiles
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 bbd663d..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;
/**
@@ -27,5 +28,7 @@ public class Resources {
public static final String ARTIFACT_GENERATOR_CONFIG = "artifact-generator.properties";
public static final String TOSCA_MAPPING_CONFIG = "tosca-mappings.json";
+ public static final String EMPTY_TOSCA_MAPPING_CONFIG = "empty-tosca-mappings.json";
+ public static final String INVALID_TOSCA_MAPPING_CONFIG = "invalid-tosca-mappings.json";
}
diff --git a/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java b/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java
new file mode 100644
index 0000000..404fb19
--- /dev/null
+++ b/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java
@@ -0,0 +1,55 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * 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.
+ * 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.onap.aai.babel.xml.generator;
+
+import java.io.IOException;
+import java.util.Collections;
+import org.junit.Before;
+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;
+
+/**
+ * Direct tests of the @{link ModelGenerator} implementation class (to improve code coverage). Not all methods are
+ * tested here. Most use cases are covered by direct tests of @{link CsarToXmlConverter}.
+ */
+public class TestModelGenerator {
+
+ static {
+ System.setProperty("APP_HOME", ".");
+ }
+
+ @Before
+ public void setup() {
+ new ArtifactTestUtils().setGeneratorSystemProperties();
+ }
+
+ @Test
+ public void testDefaultServiceVersion() throws XmlArtifactGenerationException, IOException {
+ Artifact ymlFile = new Artifact(null, null, null, null);
+ new ModelGenerator().generateArtifacts(CsarTest.SD_WAN_CSAR_FILE.getContent(),
+ Collections.singletonList(ymlFile));
+ }
+
+
+}
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..1fc5d13 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,
@@ -49,23 +50,6 @@ public class TestGeneratorUtil {
}
@Test
- public void shouldDecodeUsingBase64() {
- byte[] input = Base64.getEncoder().encode(TEST_BYTES);
- byte[] expected = Base64.getDecoder().decode(input);
-
- byte[] result = GeneratorUtil.decode(input);
-
- assertThat(result, is(expected));
- }
-
- @Test
- public void shouldReturnEmptyByteArrayWhenNullPassedToDecode() {
- byte[] result = GeneratorUtil.decode(null);
-
- assertThat(result, is(EMPTY_BYTE_ARRAY));
- }
-
- @Test
public void shouldReturnNullWhenNullPassedToCheckSum() {
assertNull(GeneratorUtil.checkSum(null));
}
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 92b548a..ed4f5c1 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.
@@ -26,16 +26,9 @@ import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
import org.onap.aai.babel.util.ArtifactTestUtils;
-import org.onap.aai.babel.xml.generator.model.Widget.Type;
-import org.onap.aai.babel.xml.generator.types.ModelType;
/**
* Direct tests of the Model abstract class (to improve code coverage). Not all methods are tested here. Some are
@@ -43,64 +36,17 @@ import org.onap.aai.babel.xml.generator.types.ModelType;
*/
public class TestModel {
- private Service serviceModel = new Service();
- private List<Resource> resourceModels =
- Arrays.asList(new Resource(Type.CR, true), new Resource(Type.INSTANCE_GROUP, true));
- private Widget widgetModel = new OamNetwork();
- private Model anonymousModel;
-
- static {
- System.setProperty("APP_HOME", ".");
- }
-
/**
- * Initialise the Artifact Generator with filtering and mapping configuration. Also 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 Artifact Generator properties file is not loaded
+ * if the mappings configuration cannot be loaded
*/
- @Before
- public void setup() throws IOException {
- ArtifactTestUtils utils = new ArtifactTestUtils();
- utils.setGeneratorSystemProperties();
-
- String configLocation = System.getProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE);
- if (configLocation == null) {
- throw new IllegalArgumentException(
- String.format(ArtifactGeneratorToscaParser.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND,
- ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE));
- }
-
- ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation);
- utils.loadWidgetToUuidMappings();
-
- anonymousModel = new Model() {
- @Override
- public boolean addResource(Resource resource) {
- return false;
- }
-
- @Override
- public boolean addWidget(Widget resource) {
- return false;
- }
-
- @Override
- public Type getWidgetType() {
- return null;
- }
-
- @Override
- public Map<String, Object> getProperties() {
- return Collections.emptyMap();
- }
-
- @Override
- public boolean isResource() {
- return false;
- }
- };
+ @BeforeClass
+ public static void setup() throws IOException {
+ ArtifactTestUtils util = new ArtifactTestUtils();
+ util.loadWidgetToUuidMappings();
+ util.loadWidgetMappings();
}
@Test
@@ -109,21 +55,22 @@ public class TestModel {
assertThat(Model.getModelFor(""), is(nullValue()));
assertThat(Model.getModelFor("any.unknown.type"), is(nullValue()));
- assertMapping("org.openecomp.resource.vfc", Type.VSERVER);
- assertMapping("org.openecomp.resource.cp", Type.LINT);
- assertMapping("org.openecomp.cp", Type.LINT);
- assertMapping("org.openecomp.cp.some.suffix", Type.LINT);
- assertMapping("org.openecomp.resource.vl", Type.L3_NET);
- assertMapping("org.openecomp.resource.vf", Type.VF);
- assertMapping("org.openecomp.groups.vfmodule", Type.VFMODULE);
- assertMapping("org.openecomp.groups.VfModule", Type.VFMODULE);
- assertMapping("org.openecomp.resource.vfc.nodes.heat.cinder", Type.VOLUME);
- assertMapping("org.openecomp.nodes.PortMirroringConfiguration", "Configuration", Type.CONFIGURATION);
- assertMapping("any.string", "Configuration", Type.CONFIGURATION);
- assertMapping("org.openecomp.resource.cr.Kk1806Cr1", "CR", Type.CR);
- assertMapping("any.string", "CR", Type.CR);
-
- assertMapping("org.openecomp.resource.vfc", "an.unknown.type", Type.VSERVER);
+ assertMapping("org.openecomp.resource.vfc", WidgetType.valueOf("VSERVER"));
+ assertMapping("org.openecomp.resource.cp", WidgetType.valueOf("LINT"));
+ assertMapping("org.openecomp.cp", WidgetType.valueOf("LINT"));
+ assertMapping("org.openecomp.cp.some.suffix", WidgetType.valueOf("LINT"));
+ assertMapping("org.openecomp.resource.vl", WidgetType.valueOf("L3_NET"));
+ assertMapping("org.openecomp.resource.vf", WidgetType.valueOf("VF"));
+ assertMapping("org.openecomp.groups.vfmodule", WidgetType.valueOf("VFMODULE"));
+ assertMapping("org.openecomp.groups.VfModule", WidgetType.valueOf("VFMODULE"));
+ assertMapping("org.openecomp.resource.vfc.nodes.heat.cinder", WidgetType.valueOf("VOLUME"));
+ assertMapping("org.openecomp.nodes.PortMirroringConfiguration", "Configuration",
+ WidgetType.valueOf("CONFIGURATION"));
+ assertMapping("any.string", "Configuration", WidgetType.valueOf("CONFIGURATION"));
+ assertMapping("org.openecomp.resource.cr.Kk1806Cr1", "CR", WidgetType.valueOf("CR"));
+ assertMapping("any.string", "CR", WidgetType.valueOf("CR"));
+
+ assertMapping("org.openecomp.resource.vfc", "an.unknown.type", WidgetType.valueOf("VSERVER"));
}
/**
@@ -134,7 +81,7 @@ public class TestModel {
* @param widgetType
* the type of Widget expected from the mappings
*/
- private void assertMapping(String toscaType, Type widgetType) {
+ private void assertMapping(String toscaType, WidgetType widgetType) {
assertThat(Model.getModelFor(toscaType).getWidgetType(), is(widgetType));
}
@@ -148,31 +95,8 @@ public class TestModel {
* @param widgetType
* the type of Widget expected from the mappings
*/
- private void assertMapping(String toscaType, String metadataType, Type widgetType) {
+ private void assertMapping(String toscaType, String metadataType, WidgetType widgetType) {
assertThat(Model.getModelFor(toscaType, metadataType).getWidgetType(), is(widgetType));
}
- @Test
- public void testGetModelType() {
- assertThat(serviceModel.getModelType(), is(ModelType.SERVICE));
- for (Resource resourceModel : resourceModels) {
- assertThat(resourceModel.getModelType(), is(ModelType.RESOURCE));
- }
- assertThat(widgetModel.getModelType(), is(ModelType.WIDGET));
- assertThat(anonymousModel.getModelType(), is(nullValue()));
- }
-
- @Test
- public void testGetModelNameVersionId() {
- assertThat(anonymousModel.getModelNameVersionId(), is(nullValue()));
- }
-
- @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
- public void testGetModelNameVersionIdIsUnsupported() {
- assertThat(widgetModel.getModelNameVersionId(), is(nullValue()));
- assertThat(resourceModels.get(0).getModelType(), is(ModelType.RESOURCE));
- assertThat(widgetModel.getModelType(), is(ModelType.WIDGET));
- assertThat(anonymousModel.getModelType(), is(nullValue()));
- }
-
}
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 451d2bb..14f3798 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.
@@ -33,20 +33,24 @@ import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.aai.babel.util.ArtifactTestUtils;
-import org.onap.aai.babel.xml.generator.model.Widget.Type;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
/**
- * 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", ".");
- }
-
+ /**
+ * Load the Widget Configuration, including the type mappings and the UUID mappings.
+ *
+ * @throws IOException
+ * if the mappings configuration cannot be loaded
+ */
@BeforeClass
public static void setup() throws IOException {
- new ArtifactTestUtils().loadWidgetToUuidMappings();
+ ArtifactTestUtils util = new ArtifactTestUtils();
+ util.loadWidgetToUuidMappings();
+ util.loadWidgetMappings();
}
/**
@@ -80,33 +84,39 @@ public class TestVfModule {
}
@Test
- public void testAddVServerWidgetToVf() {
- assertAddWidget(createNewVfModule(), Type.VSERVER);
+ public void testAddVServerWidgetToVf() throws XmlArtifactGenerationException {
+ assertAddWidget(createNewVfModule(), WidgetType.valueOf("VSERVER"));
}
@Test
- public void testAddServiceWidgetToVf() {
- assertAddWidget(createNewVfModule(), Type.SERVICE);
+ public void testAddServiceWidgetToVf() throws XmlArtifactGenerationException {
+ assertAddWidget(createNewVfModule(), WidgetType.valueOf("SERVICE"));
}
/**
* Add a new Widget to a VF Module, where the Widget is NOT set as a member. N.B. For the current VF Module
* implementation the actual Widget type is not important.
+ *
+ * @throws XmlArtifactGenerationException
+ * if the Widget mapping configuration is missing
*/
@Test
- public void testNonMemberWidgetToVf() {
+ public void testNonMemberWidgetToVf() throws XmlArtifactGenerationException {
Resource vfModule = createNewVfModule();
- assertThat(vfModule.addWidget(createNewWidget(Type.SERVICE)), is(false));
+ assertThat(vfModule.addWidget(createNewWidget(WidgetType.valueOf("SERVICE"))), is(false));
assertNumberOfWidgets(vfModule, 0);
}
/**
* OAM Network is specifically excluded from a VF Module.
+ *
+ * @throws XmlArtifactGenerationException
+ * if the Widget mapping configuration is missing
*/
@Test
- public void testAddOamNetworkWidgetToVf() {
+ public void testAddOamNetworkWidgetToVf() throws XmlArtifactGenerationException {
Resource vfModule = createNewVfModule();
- assertThat(createNewWidgetForModule(vfModule, Type.OAM_NETWORK), is(false));
+ assertThat(createNewWidgetForModule(vfModule, WidgetType.valueOf("OAM_NETWORK")), is(false));
assertNumberOfWidgets(vfModule, 0);
}
@@ -117,13 +127,16 @@ public class TestVfModule {
* <li>Add a Volume Widget</li>
* <li>Add a vserver Widget</li>
* <li>Check that the Volume Widget appears under the vserver</li>
+ *
+ * @throws XmlArtifactGenerationException
+ * if the Widget mapping configuration is missing
*/
@Test
- public void testAddVolumeWidgetToVf() {
+ public void testAddVolumeWidgetToVf() throws XmlArtifactGenerationException {
Resource vfModule = createNewVfModule();
// Adding a Volume widget has no effect until a vserver widget is added.
- assertAddWidget(vfModule, Type.VOLUME);
+ assertAddWidget(vfModule, WidgetType.valueOf("VOLUME"));
assertNumberOfWidgets(vfModule, 0);
final int vserverBaseWidgetCount = createVserverForVf(vfModule);
@@ -132,11 +145,11 @@ public class TestVfModule {
assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 1);
// Adding another instance of a vserver widget fails.
- assertFailToAddWidget(vfModule, Type.VSERVER);
+ assertFailToAddWidget(vfModule, WidgetType.valueOf("VSERVER"));
assertNumberOfWidgets(vfModule, 1);
// Adding another Volume widget is always treated as successful.
- assertAddWidget(vfModule, Type.VOLUME);
+ assertAddWidget(vfModule, WidgetType.valueOf("VOLUME"));
// Assert that no additional Widgets are actually present.
assertNumberOfWidgets(vfModule, 1);
assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 1);
@@ -149,13 +162,16 @@ public class TestVfModule {
* <li>Add an L-Interface Widget</li>
* <li>Add a vserver Widget</li>
* <li>Check that the L-Interface Widget appears under the vserver</li>
+ *
+ * @throws XmlArtifactGenerationException
+ * if the Widget mapping configuration is missing
*/
@Test
- public void testAddLinterfaceWidgetToVf() {
+ public void testAddLinterfaceWidgetToVf() throws XmlArtifactGenerationException {
Resource vfModule = createNewVfModule();
// Adding an L-Interface widget has no effect until a vserver widget is added.
- assertFailToAddWidget(vfModule, Type.LINT);
+ assertFailToAddWidget(vfModule, WidgetType.valueOf("LINT"));
assertNumberOfWidgets(vfModule, 0);
final int vserverBaseWidgetCount = createVserverForVf(vfModule);
@@ -164,11 +180,11 @@ public class TestVfModule {
assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 1);
// Adding another instance of a vserver widget fails.
- assertFailToAddWidget(vfModule, Type.VSERVER);
+ assertFailToAddWidget(vfModule, WidgetType.valueOf("VSERVER"));
assertNumberOfWidgets(vfModule, 1);
// Adding an L-Interface widget is always treated as successful when a vserver exists.
- assertAddWidget(vfModule, Type.LINT);
+ assertAddWidget(vfModule, WidgetType.valueOf("LINT"));
// Assert that no additional Widgets are actually present.
assertNumberOfWidgets(vfModule, 1);
assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 1);
@@ -182,17 +198,20 @@ public class TestVfModule {
* <li>Add an L-Interface Widget</li>
* <li>Add a vserver Widget</li>
* <li>Check that both Widgets appear under the vserver</li>
+ *
+ * @throws XmlArtifactGenerationException
+ * if the Widget mapping configuration is missing
*/
@Test
- public void testAddVolumeAndLinterfaceWidgetToVf() {
+ public void testAddVolumeAndLinterfaceWidgetToVf() throws XmlArtifactGenerationException {
Resource vfModule = createNewVfModule();
// Adding a Volume widget has no effect until a vserver widget is added.
- assertAddWidget(vfModule, Type.VOLUME);
+ assertAddWidget(vfModule, WidgetType.valueOf("VOLUME"));
assertNumberOfWidgets(vfModule, 0);
// Adding an L-Interface widget has no effect until a vserver widget is added.
- assertFailToAddWidget(vfModule, Type.LINT);
+ assertFailToAddWidget(vfModule, WidgetType.valueOf("LINT"));
assertNumberOfWidgets(vfModule, 0);
final int vserverBaseWidgetCount = createVserverForVf(vfModule);
@@ -201,12 +220,12 @@ public class TestVfModule {
assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 2);
// Adding another instance of a vserver widget fails.
- assertFailToAddWidget(vfModule, Type.VSERVER);
+ assertFailToAddWidget(vfModule, WidgetType.valueOf("VSERVER"));
assertNumberOfWidgets(vfModule, 1);
// Add new instances (with no effect).
- assertAddWidget(vfModule, Type.VOLUME);
- assertAddWidget(vfModule, Type.LINT);
+ assertAddWidget(vfModule, WidgetType.valueOf("VOLUME"));
+ assertAddWidget(vfModule, WidgetType.valueOf("LINT"));
// Assert that no additional Widgets are in fact present.
assertNumberOfWidgets(vfModule, 1);
assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 2);
@@ -222,8 +241,10 @@ public class TestVfModule {
* @param widgetType
* type of Widget to create
* @return a new Widget
+ * @throws XmlArtifactGenerationException
+ * if the Widget mapping configuration is missing
*/
- private Widget createNewWidget(Type widgetType) {
+ private Widget createNewWidget(WidgetType widgetType) throws XmlArtifactGenerationException {
return Widget.getWidget(widgetType);
}
@@ -233,7 +254,7 @@ public class TestVfModule {
* @return new VF Module resource
*/
private Resource createNewVfModule() {
- Resource vfModule = new Resource(Type.VFMODULE, true);
+ Resource vfModule = new Resource(WidgetType.valueOf("VFMODULE"), true);
assertNumberOfWidgets(vfModule, 0);
return vfModule;
}
@@ -257,8 +278,10 @@ public class TestVfModule {
* the VF Module to update
* @param widgetType
* the type of Widget to create and add
+ * @throws XmlArtifactGenerationException
+ * if the Widget mapping configuration is missing
*/
- private void assertAddWidget(Resource vfModule, Type widgetType) {
+ private void assertAddWidget(Resource vfModule, WidgetType widgetType) throws XmlArtifactGenerationException {
assertThat(createNewWidgetForModule(vfModule, widgetType), is(true));
}
@@ -269,8 +292,10 @@ public class TestVfModule {
* the VF Module
* @param widgetType
* the type of Widget to create and attempt to add
+ * @throws XmlArtifactGenerationException
+ * if the Widget mapping configuration is missing
*/
- private void assertFailToAddWidget(Resource vfModule, Type widgetType) {
+ private void assertFailToAddWidget(Resource vfModule, WidgetType widgetType) throws XmlArtifactGenerationException {
assertThat(createNewWidgetForModule(vfModule, widgetType), is(false));
}
@@ -282,8 +307,11 @@ public class TestVfModule {
* @param widgetType
* the type of Widget to create and attempt to add
* @return whether or not the Widget was added to the module
+ * @throws XmlArtifactGenerationException
+ * if the Widget mapping configuration is missing
*/
- private boolean createNewWidgetForModule(Resource vfModule, Type widgetType) {
+ private boolean createNewWidgetForModule(Resource vfModule, WidgetType widgetType)
+ throws XmlArtifactGenerationException {
Widget widget = createNewWidget(widgetType);
setWidgetAsMember(vfModule, widget);
return vfModule.addWidget(widget);
@@ -311,9 +339,11 @@ public class TestVfModule {
* @param vfModule
* the VF Module to update
* @return the number of Widgets present in the vserver on creation
+ * @throws XmlArtifactGenerationException
+ * if the Widget mapping configuration is missing
*/
- private int createVserverForVf(Resource vfModule) {
- VServerWidget vserverWidget = (VServerWidget) createNewWidget(Type.VSERVER);
+ private int createVserverForVf(Resource vfModule) throws XmlArtifactGenerationException {
+ Widget vserverWidget = createNewWidget(WidgetType.valueOf("VSERVER"));
assertNumberOfWidgets(vfModule, 0);
final int initialWidgetCount = addVserverToVf(vfModule, vserverWidget);
assertNumberOfWidgets(vfModule, 1);
@@ -328,8 +358,10 @@ public class TestVfModule {
* @param vserverWidget
* the Widget to add
* @return initial widget count for the vserver Widget
+ * @throws XmlArtifactGenerationException
+ * if the Widget mapping configuration is missing
*/
- private int addVserverToVf(Resource vfModule, VServerWidget vserverWidget) {
+ private int addVserverToVf(Resource vfModule, Widget vserverWidget) throws XmlArtifactGenerationException {
// A vserver (initially) has Flavor, Image, Tenant and Vfc.
final int initialWidgetCount = 4;
assertNumberOfWidgets(vserverWidget, initialWidgetCount);
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 d7fe4af..4f28131 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.
@@ -21,7 +21,6 @@
package org.onap.aai.babel.xml.generator.model;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
@@ -31,7 +30,7 @@ import java.util.Collections;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.aai.babel.util.ArtifactTestUtils;
-import org.onap.aai.babel.xml.generator.model.Widget.Type;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.types.ModelType;
/**
@@ -39,56 +38,161 @@ 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 {
- new ArtifactTestUtils().loadWidgetToUuidMappings();
+ ArtifactTestUtils util = new ArtifactTestUtils();
+ util.loadWidgetToUuidMappings();
+ util.loadWidgetMappings();
}
@Test
- public void testGetWidgets() {
- assertThat(Widget.getWidget(Type.SERVICE), instanceOf(ServiceWidget.class));
- assertThat(Widget.getWidget(Type.VF), instanceOf(VfWidget.class));
- assertThat(Widget.getWidget(Type.VFC), instanceOf(VfcWidget.class));
- assertThat(Widget.getWidget(Type.VSERVER), instanceOf(VServerWidget.class));
- assertThat(Widget.getWidget(Type.VOLUME), instanceOf(VolumeWidget.class));
- assertThat(Widget.getWidget(Type.FLAVOR), instanceOf(FlavorWidget.class));
- assertThat(Widget.getWidget(Type.TENANT), instanceOf(TenantWidget.class));
- assertThat(Widget.getWidget(Type.VOLUME_GROUP), instanceOf(VolumeGroupWidget.class));
- assertThat(Widget.getWidget(Type.LINT), instanceOf(LIntfWidget.class));
- assertThat(Widget.getWidget(Type.L3_NET), instanceOf(L3NetworkWidget.class));
- assertThat(Widget.getWidget(Type.VFMODULE), instanceOf(VfModuleWidget.class));
- assertThat(Widget.getWidget(Type.IMAGE), instanceOf(ImageWidget.class));
- assertThat(Widget.getWidget(Type.OAM_NETWORK), instanceOf(OamNetwork.class));
- assertThat(Widget.getWidget(Type.ALLOTTED_RESOURCE), instanceOf(AllotedResourceWidget.class));
- assertThat(Widget.getWidget(Type.TUNNEL_XCONNECT), instanceOf(TunnelXconnectWidget.class));
- assertThat(Widget.getWidget(Type.CONFIGURATION), instanceOf(ConfigurationWidget.class));
+ public void testGetWidgets() throws XmlArtifactGenerationException {
+ Widget widget = Widget.getWidget(WidgetType.valueOf("SERVICE"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("service-instance"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(WidgetType.valueOf("VF"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("generic-vnf"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.getWidget(WidgetType.valueOf("VFC"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("vnfc"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(WidgetType.valueOf("VSERVER"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("vserver"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(WidgetType.valueOf("VOLUME"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("volume"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(WidgetType.valueOf("FLAVOR"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("flavor"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.getWidget(WidgetType.valueOf("TENANT"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("tenant"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.getWidget(WidgetType.valueOf("VOLUME_GROUP"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("volume-group"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(WidgetType.valueOf("LINT"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("l-interface"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(WidgetType.valueOf("L3_NET"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("l3-network"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(WidgetType.valueOf("VFMODULE"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("vf-module"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(WidgetType.valueOf("IMAGE"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("image"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.getWidget(WidgetType.valueOf("OAM_NETWORK"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("oam-network"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(WidgetType.valueOf("ALLOTTED_RESOURCE"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("allotted-resource"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(WidgetType.valueOf("TUNNEL_XCONNECT"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("tunnel-xconnect"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(WidgetType.valueOf("CONFIGURATION"));
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("configuration"));
+ assertThat(widget.getDeleteFlag(), is(true));
}
@Test
- public void testWidgetMethods() {
- Widget widget = new ServiceWidget();
+ public void testWidgetMethods() throws XmlArtifactGenerationException {
+ Widget widget = new Widget(WidgetType.valueOf("SERVICE"), "service-instance", true);
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getWidgetId(), is("service-instance-invariant-id"));
- assertThat(widget.addWidget(new TenantWidget()), is(true));
+ assertThat(widget.addWidget(Widget.getWidget(WidgetType.valueOf("TENANT"))), is(true));
assertThat(widget.memberOf(null), is(false));
assertThat(widget.memberOf(Collections.emptyList()), is(false));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetUnknownWidget() throws XmlArtifactGenerationException {
+ WidgetType.valueOf("invalid-widget-name");
+ }
+
+ /**
+ * Try to get the Widget object for an unsupported (non-configured) type.
+ *
+ * @throws XmlArtifactGenerationException
+ * if there is no configuration defined for the specified Widget type
+ */
+ @Test(expected = XmlArtifactGenerationException.class)
+ public void testGetDynamicWidget() throws XmlArtifactGenerationException {
+ Widget.getWidget(new WidgetType(null));
+ }
+
+ @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
+ public void testAddResourceIsUnsupported() throws XmlArtifactGenerationException {
+ Widget.getWidget(WidgetType.valueOf("OAM_NETWORK")).addResource(null);
+ }
- widget = new VolumeGroupWidget(); // just for variety
- assertThat(widget.getWidgetType(), is(nullValue()));
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetVersionIdForUknownWidget() {
+ new Widget(new WidgetType("test"), null, false).getId();
}
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetInvariantIdForUknownWidget() {
+ new Widget(new WidgetType("test"), null, false).getWidgetId();
+ }
+
+ // Call Widget methods which are not supported, purely for code coverage.
+
@Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
- public void testAddResourceIsUnsupported() {
- new OamNetwork().addResource(null);
+ public void testGetModelNameVersionIdIsUnsupported() {
+ Widget widgetModel = new Widget(WidgetType.valueOf("OAM_NETWORK"), "oam-network", true);
+ assertThat(widgetModel.getModelNameVersionId(), is(nullValue()));
}
+
+ @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
+ public void testGetModelTypeNameIsUnsupported() {
+ Widget widgetModel = new Widget(WidgetType.valueOf("OAM_NETWORK"), "oam-network", true);
+ assertThat(widgetModel.getModelTypeName(), is(nullValue()));
+ }
+
+ @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
+ public void testGetModelIdIsUnsupported() {
+ Widget widgetModel = new Widget(WidgetType.valueOf("OAM_NETWORK"), "oam-network", true);
+ assertThat(widgetModel.getModelId(), is(nullValue()));
+ }
+
}