aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--INFO.yaml49
-rw-r--r--License.txt4
-rw-r--r--src/main/java/org/onap/aai/auth/AAIAuthException.java7
-rw-r--r--src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java107
-rw-r--r--src/main/java/org/onap/aai/auth/FileWatcher.java5
-rw-r--r--src/main/java/org/onap/aai/babel/BabelApplication.java23
-rw-r--r--src/main/java/org/onap/aai/babel/config/BabelAuthConfig.java5
-rw-r--r--src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java7
-rw-r--r--src/main/java/org/onap/aai/babel/csar/vnfcatalog/VendorImageConfiguration.java29
-rw-r--r--src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java146
-rw-r--r--src/main/java/org/onap/aai/babel/service/GenerateArtifactsServiceImpl.java9
-rw-r--r--src/main/java/org/onap/aai/babel/service/data/BabelArtifact.java20
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java85
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java248
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java264
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/Artifact.java25
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/GenerationData.java17
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorUtil.java17
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java14
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java51
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java9
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetTypeConfig.java (renamed from src/main/java/org/onap/aai/babel/xml/generator/model/ResourceWidget.java)18
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResourceWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/CRWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/ConfigurationWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/FlavorWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/ImageWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/InstanceGroupWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/L3NetworkWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/LIntfWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Model.java83
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/OamNetwork.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java69
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Service.java30
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/ServiceWidget.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/TenantWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/TunnelXconnectWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VServerWidget.java44
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VfModuleWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VfWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VfcWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VolumeGroupWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VolumeWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java127
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/WidgetType.java73
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/types/Cardinality.java25
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/types/Model.java53
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/types/ModelWidget.java45
-rw-r--r--src/main/resources/babel-logging-resources.properties38
-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
-rw-r--r--src/test/resources/appconfig/auth/auth_policy.json12
-rw-r--r--src/test/resources/auth/keystore.jksbin0 -> 2206 bytes
-rw-r--r--src/test/resources/empty-tosca-mappings.json0
-rw-r--r--src/test/resources/invalid-tosca-mappings.json1
-rw-r--r--src/test/resources/tosca-mappings.json92
67 files changed, 1596 insertions, 1711 deletions
diff --git a/INFO.yaml b/INFO.yaml
index c2dfdb7..c5aaa2f 100644
--- a/INFO.yaml
+++ b/INFO.yaml
@@ -1,18 +1,24 @@
---
project: 'aai-babel'
project_creation_date: '2017-07-14'
+project_category: ''
lifecycle_state: 'Incubation'
-project_lead: &onap_releng_ptl
+project_lead: &onap_aai_ptl
name: 'James Forsyth'
email: 'jf2512@att.com'
id: 'jimmydot'
company: 'ATT'
timezone: 'America/Detroit'
-primary_contact: *onap_releng_ptl
+primary_contact: *onap_aai_ptl
issue_tracking:
type: 'jira'
url: 'https://jira.onap.org/projects/AAI'
key: 'AAI'
+mailing_list:
+ type: 'groups.io'
+ url: 'lists.onap.org'
+ tag: '<[sub-project_name]>'
+realtime_discussion: ''
meetings:
- type: 'zoom'
agenda: 'https://wiki.onap.org/display/DW/AAI+Meeting+Notes'
@@ -21,13 +27,46 @@ meetings:
channel: 'n/a'
repeats: 'weekly'
time: '14:00 UTC'
+repositories:
+ - 'aai-aai-common'
+ - 'aai-aai-config'
+ - 'aai-aai-data'
+ - 'aai-aai-service'
+ - 'aai-babel'
+ - 'aai-cacher'
+ - 'aai-chameleon'
+ - 'aai-champ'
+ - 'aai-data-router'
+ - 'aai-eis'
+ - 'aai-enricher'
+ - 'aai-event-client'
+ - 'aai-gallifrey'
+ - 'aai-gap'
+ - 'aai-gizmo'
+ - 'aai-graphadmin'
+ - 'aai-graphgraph'
+ - 'aai-logging-service'
+ - 'aai-model-loader'
+ - 'aai-oom'
+ - 'aai-resources'
+ - 'aai-rest-client'
+ - 'aai-router-core'
+ - 'aai-schema-service'
+ - 'aai-search-data-service'
+ - 'aai-sparky-be'
+ - 'aai-sparky-fe'
+ - 'aai-spike'
+ - 'aai-tabular-data-service'
+ - 'aai-test-config'
+ - 'aai-traversal'
+ - 'aai-validation'
committers:
- - <<: *onap_releng_ptl
+ - <<: *onap_aai_ptl
- name: 'Manisha Aggarwal'
email: 'ma9181@att.com'
company: 'ATT'
id: 'ma9181'
- timezone: 'America/New York'
+ timezone: 'America/New_York'
- name: 'Steven Blimkie'
email: 'Steven.Blimkie@amdocs.com'
company: 'Amdocs'
@@ -42,7 +81,7 @@ committers:
email: 'vk250x@att.com'
company: 'ATT'
id: 'vk250x'
- timezone: 'America/New York'
+ timezone: 'America/New_York'
tsc:
approval: 'https://lists.onap.org/pipermail/onap-tsc'
changes:
diff --git a/License.txt b/License.txt
index 5ce31aa..50054e3 100644
--- a/License.txt
+++ b/License.txt
@@ -1,8 +1,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.
diff --git a/src/main/java/org/onap/aai/auth/AAIAuthException.java b/src/main/java/org/onap/aai/auth/AAIAuthException.java
index a29ee98..35adb5a 100644
--- a/src/main/java/org/onap/aai/auth/AAIAuthException.java
+++ b/src/main/java/org/onap/aai/auth/AAIAuthException.java
@@ -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,10 +18,11 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.auth;
public class AAIAuthException extends Exception {
- /** */
+
private static final long serialVersionUID = 1L;
public AAIAuthException(String string) {
diff --git a/src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java b/src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java
index ee5fb26..0eec7e1 100644
--- a/src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java
+++ b/src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java
@@ -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 (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.auth;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -26,12 +27,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
@@ -43,15 +46,15 @@ public class AAIMicroServiceAuthCore {
private static LogHelper applicationLogger = LogHelper.INSTANCE;
- private static final String CONFIG_HOME = System.getProperty("CONFIG_HOME");
-
- public static final String FILESEP =
- (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
- public static final String APPCONFIG_DIR =
- (CONFIG_HOME == null) ? System.getProperty("APP_HOME") + FILESEP + "appconfig" : CONFIG_HOME;
-
- private static String appConfigAuthDir = APPCONFIG_DIR + FILESEP + "auth";
- private static String defaultAuthFileName = appConfigAuthDir + FILESEP + "auth_policy.json";
+ /**
+ * The default policy file is expected to be located in either one of
+ * <ul>
+ * <li><code>$CONFIG_HOME/auth_policy.json</code></li>
+ * <li><code>$CONFIG_HOME/auth/auth_policy.json</code></li>
+ * <p>
+ * Note that if <code>CONFIG_HOME</code> is not set then assume it has a value of <code>$APP_HOME/appconfig</code>
+ */
+ private static String defaultAuthFileName = "auth_policy.json";
private static boolean usersInitialized = false;
private static HashMap<String, AAIAuthUser> users;
@@ -60,11 +63,7 @@ public class AAIMicroServiceAuthCore {
private static String policyAuthFileName;
public enum HTTP_METHODS {
- GET,
- PUT,
- DELETE,
- HEAD,
- POST
+ GET, PUT, DELETE, HEAD, POST
}
// Don't instantiate
@@ -86,8 +85,9 @@ public class AAIMicroServiceAuthCore {
applicationLogger.error(ApplicationMsgs.PROCESS_REQUEST_ERROR, e);
throw new AAIAuthException(e.getMessage());
}
+
if (policyAuthFileName == null) {
- throw new AAIAuthException("Auth policy file could not be found" + CONFIG_HOME + APPCONFIG_DIR);
+ throw new AAIAuthException("Auth policy file could not be found");
}
AAIMicroServiceAuthCore.reloadUsers();
@@ -119,21 +119,46 @@ public class AAIMicroServiceAuthCore {
}
public static String getConfigFile(String authPolicyFile) throws IOException {
- File authFile = new File(authPolicyFile);
- if (authFile.exists()) {
- return authFile.getCanonicalPath();
- }
- authFile = new File(appConfigAuthDir + FILESEP + authPolicyFile);
- if (authFile.exists()) {
- return authFile.getCanonicalPath();
- }
- if (defaultAuthFileName != null) {
- authFile = new File(defaultAuthFileName);
- if (authFile.exists()) {
- return defaultAuthFileName;
+ return locateConfigFile(authPolicyFile).orElse(locateConfigFile(defaultAuthFileName).orElse(null));
+ }
+
+ /**
+ * Locate the auth policy file by its name or path.
+ * <ul>
+ * <li>First try to use the absolute path to the file (if provided), or instead locate the path relative to the
+ * current (or user) dir.</li>
+ * <li>If this fails, try resolving the path relative to the configuration home location (either
+ * <code>$CONFIG_HOME</code> or <code>$APP_HOME/appconfig</code>).</li>
+ * <li>If this fails try resolving relative to the <code>auth</code> folder under configuration home.</li>
+ *
+ * @param authPolicyFile
+ * filename or path
+ * @return the Optional canonical path to the located policy file
+ * @throws IOException
+ * if the construction of the canonical pathname requires filesystem queries which cause I/O error(s)
+ */
+ private static Optional<String> locateConfigFile(String authPolicyFile) throws IOException {
+ if (authPolicyFile != null) {
+ List<Path> paths = new ArrayList<>();
+ paths.add(Paths.get("."));
+
+ String configHome = System.getProperty("CONFIG_HOME");
+ if (configHome == null) {
+ configHome = System.getProperty("APP_HOME") + "/appconfig";
+ }
+
+ paths.add(Paths.get(configHome));
+ paths.add(Paths.get(configHome).resolve("auth"));
+
+ for (Path path : paths) {
+ File authFile = path.resolve(authPolicyFile).toFile();
+ if (authFile.exists()) {
+ return Optional.of(authFile.getCanonicalPath());
+ }
}
}
- return null;
+
+ return Optional.empty();
}
public static synchronized void reloadUsers() throws AAIAuthException {
@@ -193,28 +218,18 @@ public class AAIMicroServiceAuthCore {
user = new AAIAuthUser();
}
applicationLogger.debug("Assigning " + roleName + " to user " + name);
- user.setUser(name);
user.addRole(roleName, r);
users.put(name, user);
}
}
public static class AAIAuthUser {
- private String username;
private HashMap<String, AAIAuthRole> roles;
public AAIAuthUser() {
this.roles = new HashMap<>();
}
- public String getUser() {
- return this.username;
- }
-
- public Map<String, AAIAuthRole> getRoles() {
- return this.roles;
- }
-
public void addRole(String roleName, AAIAuthRole r) {
this.roles.put(roleName, r);
}
@@ -228,10 +243,6 @@ public class AAIMicroServiceAuthCore {
}
return false;
}
-
- public void setUser(String myuser) {
- this.username = myuser;
- }
}
public static class AAIAuthRole {
@@ -246,12 +257,6 @@ public class AAIMicroServiceAuthCore {
this.allowedFunctions.add(func);
}
- public void delAllowedFunction(String delFunc) {
- if (this.allowedFunctions.contains(delFunc)) {
- this.allowedFunctions.remove(delFunc);
- }
- }
-
public boolean hasAllowedFunction(String afunc) {
return this.allowedFunctions.contains(afunc);
}
diff --git a/src/main/java/org/onap/aai/auth/FileWatcher.java b/src/main/java/org/onap/aai/auth/FileWatcher.java
index d974e66..9c4e04e 100644
--- a/src/main/java/org/onap/aai/auth/FileWatcher.java
+++ b/src/main/java/org/onap/aai/auth/FileWatcher.java
@@ -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.auth;
import java.io.File;
diff --git a/src/main/java/org/onap/aai/babel/BabelApplication.java b/src/main/java/org/onap/aai/babel/BabelApplication.java
index 0b0285b..9eaa0ce 100644
--- a/src/main/java/org/onap/aai/babel/BabelApplication.java
+++ b/src/main/java/org/onap/aai/babel/BabelApplication.java
@@ -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 (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,25 +18,29 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel;
import java.util.HashMap;
import org.eclipse.jetty.util.security.Password;
+import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ImportResource;
@SpringBootApplication
@ImportResource("classpath:babel-beans.xml")
public class BabelApplication extends SpringBootServletInitializer {
- private static final String OBFS_PATTERN = "OBF:";
+ private static ConfigurableApplicationContext context;
/**
* Spring Boot Initialization.
*
- * @param args main args
+ * @param args
+ * main args
*/
public static void main(String[] args) {
String keyStorePassword = System.getProperty("KEY_STORE_PASSWORD");
@@ -44,14 +48,19 @@ public class BabelApplication extends SpringBootServletInitializer {
throw new IllegalArgumentException("Env property KEY_STORE_PASSWORD not set");
}
HashMap<String, Object> props = new HashMap<>();
- String decryptedValue = keyStorePassword.startsWith(OBFS_PATTERN)? Password.deobfuscate(keyStorePassword) : keyStorePassword;
+ String decryptedValue = keyStorePassword.startsWith(Password.__OBFUSCATE) ? //
+ Password.deobfuscate(keyStorePassword) : keyStorePassword;
props.put("server.ssl.key-store-password", decryptedValue);
String requireClientAuth = System.getenv("REQUIRE_CLIENT_AUTH");
props.put("server.ssl.client-auth",
Boolean.FALSE.toString().equalsIgnoreCase(requireClientAuth) ? "want" : "need");
- new BabelApplication().configure(new SpringApplicationBuilder(BabelApplication.class).properties(props))
- .run(args);
+ context = new BabelApplication()
+ .configure(new SpringApplicationBuilder(BabelApplication.class).properties(props)).run(args);
+ }
+
+ public static void exit() {
+ SpringApplication.exit(context);
}
}
diff --git a/src/main/java/org/onap/aai/babel/config/BabelAuthConfig.java b/src/main/java/org/onap/aai/babel/config/BabelAuthConfig.java
index 21525a1..cae71de 100644
--- a/src/main/java/org/onap/aai/babel/config/BabelAuthConfig.java
+++ b/src/main/java/org/onap/aai/babel/config/BabelAuthConfig.java
@@ -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 (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2017-2018 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.config;
import org.springframework.beans.factory.annotation.Value;
diff --git a/src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java b/src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java
index 98db8ae..9e1ff6e 100644
--- a/src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java
+++ b/src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java
@@ -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;
import java.util.List;
@@ -53,7 +54,7 @@ public class CsarToXmlConverter {
* the name of the archive file
* @param version
* the version of the archive file
- * @return List<org.onap.sdc.generator.data.Artifact> a list of generated XML artifacts
+ * @return a list of generated XML artifacts
* @throws CsarConverterException
* if there is an error either extracting the YAML files or generating XML artifacts
*/
diff --git a/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VendorImageConfiguration.java b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VendorImageConfiguration.java
index 6142aac..bb4476a 100644
--- a/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VendorImageConfiguration.java
+++ b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VendorImageConfiguration.java
@@ -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 (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.csar.vnfcatalog;
import com.google.gson.annotations.SerializedName;
@@ -79,30 +80,6 @@ class VendorImageConfiguration {
this.applicationVersion = applicationVersion;
}
- public String getApplication() {
- return application;
- }
-
- public void setApplication(String application) {
- this.application = application;
- }
-
- public String getApplicationVendor() {
- return applicationVendor;
- }
-
- public void setApplicationVendor(String applicationVendor) {
- this.applicationVendor = applicationVendor;
- }
-
- public String getApplicationVersion() {
- return applicationVersion;
- }
-
- public void setApplicationVersion(String applicationVersion) {
- this.applicationVersion = applicationVersion;
- }
-
@Override
public String toString() {
return "VendorImage [" + application + ", " + applicationVendor + ", " + applicationVersion + "]";
diff --git a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
index 3fb77be..3f2e670 100644
--- a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
+++ b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.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.
@@ -22,10 +22,10 @@
package org.onap.aai.babel.parser;
import com.google.gson.Gson;
+import com.google.gson.JsonSyntaxException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
@@ -37,12 +37,14 @@ import java.util.Properties;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.data.GroupConfiguration;
import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
import org.onap.aai.babel.xml.generator.model.Model;
import org.onap.aai.babel.xml.generator.model.Resource;
import org.onap.aai.babel.xml.generator.model.Widget;
-import org.onap.aai.babel.xml.generator.model.Widget.Type;
+import org.onap.aai.babel.xml.generator.model.WidgetType;
+import org.onap.aai.babel.xml.generator.types.ModelType;
import org.onap.aai.cl.api.Logger;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.toscaparser.api.Group;
@@ -85,34 +87,17 @@ public class ArtifactGeneratorToscaParser {
* Constructs using csarHelper
*
* @param csarHelper
- * The csar helper
+ * The csar helper
*/
public ArtifactGeneratorToscaParser(ISdcCsarHelper csarHelper) {
this.csarHelper = csarHelper;
}
/**
- * Get or create the artifact description.
- *
- * @param model
- * the artifact model
- * @return the artifact model's description
- */
- public static String getArtifactDescription(Model model) {
- switch (model.getModelType()) {
- case SERVICE:
- return "AAI Service Model";
- case RESOURCE:
- return "AAI Resource Model";
- default:
- return model.getModelDescription();
- }
- }
-
- /**
- * Initialises the widget configuration.
- *
+ * Initializes the Widget to UUID mapping configuration.
+ *
* @throws IOException
+ * if an error occurs reading the configuration properties
*/
public static void initWidgetConfiguration() throws IOException {
log.debug("Getting Widget Configuration");
@@ -133,26 +118,35 @@ public class ArtifactGeneratorToscaParser {
}
/**
- * Initialises the group filtering and TOSCA mapping configuration.
+ * Initializes the group filtering and TOSCA to Widget mapping configuration.
*
* @param configLocation
- * the pathname to the JSON config file
- * @throws FileNotFoundException
- * if the file cannot be opened for reading
+ * the pathname to the JSON mappings file
+ * @throws IOException
+ * if the file content could not be read successfully
*/
- public static void initToscaMappingsConfiguration(String configLocation) throws FileNotFoundException {
+ public static void initToscaMappingsConfiguration(String configLocation) throws IOException {
log.debug("Getting TOSCA Mappings Configuration");
File file = new File(configLocation);
if (!file.exists()) {
throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGFILE_NOT_FOUND, configLocation));
}
- BufferedReader bufferedReader = new BufferedReader(new FileReader(configLocation));
- GroupConfiguration config = new Gson().fromJson(bufferedReader, GroupConfiguration.class);
- if (config != null) {
- WidgetConfigurationUtil.setSupportedInstanceGroups(config.getInstanceGroupTypes());
- WidgetConfigurationUtil.setWidgetMappings(config.getWidgetMappings());
+ GroupConfiguration config;
+
+ try (BufferedReader bufferedReader = new BufferedReader(new FileReader(configLocation))) {
+ config = new Gson().fromJson(bufferedReader, GroupConfiguration.class);
+ } catch (JsonSyntaxException e) {
+ throw new IOException("Invalid Mappings Configuration " + configLocation, e);
}
+
+ if (config == null) {
+ throw new IOException("There is no content for the Mappings Configuration " + configLocation);
+ }
+
+ WidgetConfigurationUtil.setSupportedInstanceGroups(config.getInstanceGroupTypes());
+ WidgetConfigurationUtil.setWidgetTypes(config.getWidgetTypes());
+ WidgetConfigurationUtil.setWidgetMappings(config.getWidgetMappings());
}
/**
@@ -161,8 +155,11 @@ public class ArtifactGeneratorToscaParser {
* @param resourceModel
* @param serviceNodeTemplate
* @return resources for which XML Models should be generated
+ * @throws XmlArtifactGenerationException
+ * if there is no configuration defined for a member Widget of an instance group
*/
- public List<Resource> processInstanceGroups(Model resourceModel, NodeTemplate serviceNodeTemplate) {
+ public List<Resource> processInstanceGroups(Model resourceModel, NodeTemplate serviceNodeTemplate)
+ throws XmlArtifactGenerationException {
List<Resource> resources = new ArrayList<>();
if (serviceNodeTemplate.getSubMappingToscaTemplate() != null) {
List<Group> serviceGroups = csarHelper.getGroupsOfOriginOfNodeTemplate(serviceNodeTemplate);
@@ -181,9 +178,9 @@ public class ArtifactGeneratorToscaParser {
* duplicate keys then the TOSCA Property value takes precedence.
*
* @param stringProps
- * initial Map of String property values (e.g. from the TOSCA YAML metadata section)
+ * initial Map of String property values (e.g. from the TOSCA YAML metadata section)
* @param toscaProps
- * Map of TOSCA Property Type Object values to merge in (or overwrite)
+ * Map of TOSCA Property Type Object values to merge in (or overwrite)
* @return a Map of the property values converted to String
*/
public Map<String, String> mergeProperties(Map<String, String> stringProps, Map<String, Property> toscaProps) {
@@ -194,17 +191,22 @@ public class ArtifactGeneratorToscaParser {
}
public Resource createInstanceGroupModel(Map<String, String> properties) {
- Resource groupModel = new Resource(Type.INSTANCE_GROUP, true);
+ Resource groupModel = new Resource(WidgetType.valueOf("INSTANCE_GROUP"), true);
groupModel.populateModelIdentificationInformation(properties);
return groupModel;
}
/**
+ * Add the resource/widget to the specified model.
+ *
* @param model
* @param relation
+ * resource or widget model to add
+ * @throws XmlArtifactGenerationException
+ * if the relation is a widget and there is no configuration defined for the relation's widget type
*/
- public void addRelatedModel(final Model model, final Resource relation) {
- if (relation.isResource()) {
+ public void addRelatedModel(final Model model, final Resource relation) throws XmlArtifactGenerationException {
+ if (relation.getModelType() == ModelType.RESOURCE) {
model.addResource(relation);
} else {
model.addWidget(Widget.getWidget(relation.getWidgetType()));
@@ -225,8 +227,10 @@ public class ArtifactGeneratorToscaParser {
* @param resources
* @param model
* @param serviceNode
+ * @throws XmlArtifactGenerationException
*/
- public void processVfModules(List<Resource> resources, Model resourceModel, NodeTemplate serviceNode) {
+ public void processVfModules(List<Resource> resources, Model resourceModel, NodeTemplate serviceNode)
+ throws XmlArtifactGenerationException {
// Get the customisation UUID for each VF node and use it to get its Groups
String uuid = csarHelper.getNodeTemplateCustomizationUuid(serviceNode);
List<Group> serviceGroups = csarHelper.getVfModulesByVf(uuid);
@@ -234,7 +238,7 @@ public class ArtifactGeneratorToscaParser {
// Process each VF Group
for (Group serviceGroup : serviceGroups) {
Model groupModel = Model.getModelFor(serviceGroup.getType());
- if (groupModel.getWidgetType() == Type.VFMODULE) {
+ if (groupModel.getWidgetType() == WidgetType.valueOf("VFMODULE")) {
processVfModule(resources, resourceModel, serviceGroup, serviceNode, (Resource) groupModel);
}
}
@@ -254,8 +258,8 @@ public class ArtifactGeneratorToscaParser {
Resource model = Model.getModelFor(nodeTypeName, metaDataType);
if (metadata != null && hasAllottedResource(metadata.getAllProperties())
- && model.getWidgetType() == Type.VSERVER) {
- model = new Resource(Type.ALLOTTED_RESOURCE, false);
+ && model.getWidgetType() == WidgetType.valueOf("VSERVER")) {
+ model = new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), false);
Map<String, Object> props = new HashMap<>();
props.put("providingService", true);
model.setProperties(props);
@@ -264,7 +268,7 @@ public class ArtifactGeneratorToscaParser {
foundProvidingService |= processModel(resourceModel, metadata, model, resourceNodeTemplate.getProperties());
}
- if (resourceModel.getWidgetType() == Type.ALLOTTED_RESOURCE && !foundProvidingService) {
+ if (resourceModel.getWidgetType() == WidgetType.valueOf("ALLOTTED_RESOURCE") && !foundProvidingService) {
final String modelInvariantId = resourceModel.getModelId();
throw new IllegalArgumentException(String.format(GENERATOR_AAI_PROVIDING_SERVICE_MISSING,
modelInvariantId == null ? "<null ID>" : modelInvariantId));
@@ -275,17 +279,20 @@ public class ArtifactGeneratorToscaParser {
* Create an Instance Group Model and populate it with the supplied data.
*
* @param resourceModel
- * the Resource node template Model
+ * the Resource node template Model
* @param memberNodes
- * the Resources and Widgets belonging to the Group
+ * the Resources and Widgets belonging to the Group
* @param metaProperties
- * the metadata of the Group
+ * the metadata of the Group
* @param properties
- * the properties of the Group
+ * the properties of the Group
* @return the Instance Group and Member resource models
+ * @throws XmlArtifactGenerationException
+ * if there is no configuration defined for one of the member Widgets
*/
private List<Resource> processInstanceGroup(Model resourceModel, ArrayList<NodeTemplate> memberNodes,
- Map<String, String> metaProperties, Map<String, Property> properties) {
+ Map<String, String> metaProperties, Map<String, Property> properties)
+ throws XmlArtifactGenerationException {
Resource groupModel = createInstanceGroupModel(mergeProperties(metaProperties, properties));
resourceModel.addResource(groupModel);
List<Resource> resources = Stream.of(groupModel).collect(Collectors.toList());
@@ -300,10 +307,13 @@ public class ArtifactGeneratorToscaParser {
/**
* @param memberNodes
* @param groupModel
- * @return
+ * @return a list of Resources
+ * @throws XmlArtifactGenerationException
+ * if a member node template is a widget and there is no configuration defined for that relation's
+ * widget type
*/
private List<Resource> generateResourcesAndWidgets(final ArrayList<NodeTemplate> memberNodes,
- final Resource groupModel) {
+ final Resource groupModel) throws XmlArtifactGenerationException {
log.debug(String.format("Processing member nodes for Group %s (invariant UUID %s)", //
groupModel.getModelName(), groupModel.getModelId()));
@@ -323,7 +333,7 @@ public class ArtifactGeneratorToscaParser {
memberModel.getClass().getSuperclass().getSimpleName(), memberModel.getClass(), nodeTypeName));
addRelatedModel(groupModel, memberModel);
- if (memberModel.isResource()) {
+ if (memberModel.getModelType() == ModelType.RESOURCE) {
resources.add(memberModel);
}
}
@@ -332,7 +342,7 @@ public class ArtifactGeneratorToscaParser {
}
private void processVfModule(List<Resource> resources, Model vfModel, Group groupDefinition,
- NodeTemplate serviceNode, Resource groupModel) {
+ NodeTemplate serviceNode, Resource groupModel) throws XmlArtifactGenerationException {
groupModel.populateModelIdentificationInformation(
mergeProperties(groupDefinition.getMetadata().getAllProperties(), groupDefinition.getProperties()));
@@ -345,7 +355,8 @@ public class ArtifactGeneratorToscaParser {
}
}
- private void processVfModuleGroup(Resource groupModel, List<NodeTemplate> members) {
+ private void processVfModuleGroup(Resource groupModel, List<NodeTemplate> members)
+ throws XmlArtifactGenerationException {
if (members != null && !members.isEmpty()) {
// Get names of the members of the service group
List<String> memberNames = members.stream().map(NodeTemplate::getName).collect(Collectors.toList());
@@ -361,18 +372,19 @@ public class ArtifactGeneratorToscaParser {
*
* @param group
* @param member
+ * @throws XmlArtifactGenerationException
*/
- private void processGroupMembers(Resource group, NodeTemplate member) {
+ private void processGroupMembers(Resource group, NodeTemplate member) throws XmlArtifactGenerationException {
Resource resource = Model.getModelFor(member.getType());
log.debug(member.getType() + " mapped to " + resource);
- if (resource.getWidgetType() == Type.L3_NET) {
+ if (resource.getWidgetType() == WidgetType.valueOf("L3_NET")) {
// An l3-network inside a vf-module is treated as a Widget
- resource.setIsResource(false);
+ resource.setModelType(ModelType.WIDGET);
}
- if (!resource.isResource()) {
+ if (resource.getModelType() == ModelType.WIDGET) {
Widget widget = Widget.getWidget(resource.getWidgetType());
widget.addKey(member.getName());
// Add the widget element encountered to the Group model
@@ -384,7 +396,7 @@ public class ArtifactGeneratorToscaParser {
* Create a Map of property name against String property value from the input Map
*
* @param inputMap
- * The input Map
+ * The input Map
* @return Map of property name against String property value
*/
private Map<String, String> populateStringProperties(Map<String, Property> inputMap) {
@@ -397,13 +409,13 @@ public class ArtifactGeneratorToscaParser {
* is ProvidingService then return true, otherwise return false.
*
* @param resourceModel
- * parent Resource
+ * parent Resource
* @param metaData
- * for populating the Resource IDs
+ * for populating the Resource IDs
* @param resourceNode
- * any Model (will be ignored if not a Resource)
+ * any Model (will be ignored if not a Resource)
* @param nodeProperties
- * the node properties
+ * the node properties
* @return whether or not a ProvidingService was processed
*/
private boolean processModel(Model resourceModel, Metadata metaData, Resource resourceNode,
@@ -413,8 +425,8 @@ public class ArtifactGeneratorToscaParser {
if (foundProvidingService) {
processProvidingService(resourceModel, resourceNode, nodeProperties);
- } else if (resourceNode != null && resourceNode.isResource()
- && resourceNode.getWidgetType() != Widget.Type.L3_NET) {
+ } else if (resourceNode != null && resourceNode.getModelType() == ModelType.RESOURCE
+ && resourceNode.getWidgetType() != WidgetType.valueOf("L3_NET")) {
if (metaData != null) {
resourceNode.populateModelIdentificationInformation(metaData.getAllProperties());
}
diff --git a/src/main/java/org/onap/aai/babel/service/GenerateArtifactsServiceImpl.java b/src/main/java/org/onap/aai/babel/service/GenerateArtifactsServiceImpl.java
index 72d8ae2..8d89db9 100644
--- a/src/main/java/org/onap/aai/babel/service/GenerateArtifactsServiceImpl.java
+++ b/src/main/java/org/onap/aai/babel/service/GenerateArtifactsServiceImpl.java
@@ -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.service;
import com.google.gson.Gson;
@@ -59,7 +60,9 @@ public class GenerateArtifactsServiceImpl implements GenerateArtifactsService {
private AAIMicroServiceAuth aaiMicroServiceAuth;
- /** @param authorization */
+ /**
+ * @param authorization
+ */
@Inject
public GenerateArtifactsServiceImpl(final AAIMicroServiceAuth authorization) {
this.aaiMicroServiceAuth = authorization;
diff --git a/src/main/java/org/onap/aai/babel/service/data/BabelArtifact.java b/src/main/java/org/onap/aai/babel/service/data/BabelArtifact.java
index 81c237e..86bf0cc 100644
--- a/src/main/java/org/onap/aai/babel/service/data/BabelArtifact.java
+++ b/src/main/java/org/onap/aai/babel/service/data/BabelArtifact.java
@@ -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 (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,14 +18,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.service.data;
/** Bean representing the return artifacts of the Babel microservice. */
public class BabelArtifact {
public enum ArtifactType {
- MODEL,
- VNFCATALOG;
+ MODEL, VNFCATALOG;
}
String name;
@@ -42,23 +42,11 @@ public class BabelArtifact {
return name;
}
- public void setName(String name) {
- this.name = name;
- }
-
public ArtifactType getType() {
return type;
}
- public void setType(String type) {
- this.type = ArtifactType.valueOf(type);
- }
-
public String getPayload() {
return payload;
}
-
- public void setPayload(String payload) {
- this.payload = payload;
- }
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
index 57e8a67..741c194 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.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,6 +33,7 @@ import org.apache.commons.lang3.StringUtils;
import org.onap.aai.babel.logging.ApplicationMsgs;
import org.onap.aai.babel.logging.LogHelper;
import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
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.ArtifactType;
@@ -43,10 +44,12 @@ import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
import org.onap.aai.babel.xml.generator.model.Model;
import org.onap.aai.babel.xml.generator.model.Resource;
import org.onap.aai.babel.xml.generator.model.Service;
-import org.onap.aai.babel.xml.generator.model.TunnelXconnectWidget;
-import org.onap.aai.babel.xml.generator.model.Widget.Type;
+import org.onap.aai.babel.xml.generator.model.WidgetType;
+import org.onap.aai.babel.xml.generator.model.Widget;
+import org.onap.aai.babel.xml.generator.types.ModelType;
import org.onap.aai.cl.api.Logger;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
import org.onap.sdc.toscaparser.api.Group;
import org.onap.sdc.toscaparser.api.NodeTemplate;
@@ -66,20 +69,11 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
private static final String GENERATOR_AAI_INVALID_SERVICE_VERSION =
"Cannot generate artifacts. Service version is incorrect";
- private AaiModelGenerator modelGenerator = new AaiModelGeneratorImpl();
+ private AaiModelGenerator modelGenerator = new AaiModelGenerator();
@Override
public GenerationData generateArtifact(byte[] csarArchive, List<Artifact> input,
Map<String, String> additionalParams) {
- Path csarPath;
-
- try {
- csarPath = createTempFile(csarArchive);
- } catch (IOException e) {
- log.error(ApplicationMsgs.TEMP_FILE_ERROR, e);
- return createErrorData(e);
- }
-
String configLocation = System.getProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE);
if (configLocation == null) {
throw new IllegalArgumentException(
@@ -90,10 +84,25 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
try {
ArtifactGeneratorToscaParser.initWidgetConfiguration();
ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation);
+ } catch (IOException e) {
+ log.error(ApplicationMsgs.LOAD_PROPERTIES, e, configLocation);
+ return createErrorData(e);
+ }
+
+ Path csarPath;
+
+ try {
+ csarPath = createTempFile(csarArchive);
+ } catch (IOException e) {
+ log.error(ApplicationMsgs.TEMP_FILE_ERROR, e);
+ return createErrorData(e);
+ }
+
+ try {
ISdcCsarHelper csarHelper =
SdcToscaParserFactory.getInstance().getSdcCsarHelper(csarPath.toAbsolutePath().toString());
return generateAllArtifacts(validateServiceVersion(additionalParams), csarHelper);
- } catch (Exception e) {
+ } catch (SdcToscaParserException | XmlArtifactGenerationException e) {
log.error(ApplicationMsgs.INVALID_CSAR_FILE, e);
return createErrorData(e);
} finally {
@@ -112,10 +121,12 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
*
* @param serviceVersion
* @param csarHelper
- * interface to the TOSCA parser
+ * interface to the TOSCA parser
* @return the generated Artifacts (containing XML models)
+ * @throws XmlArtifactGenerationException
*/
- private GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper) {
+ private GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper)
+ throws XmlArtifactGenerationException {
List<NodeTemplate> serviceNodeTemplates = csarHelper.getServiceNodeTemplates();
if (serviceNodeTemplates == null) {
throw new IllegalArgumentException(GENERATOR_AAI_ERROR_MISSING_SERVICE_TOSCA);
@@ -170,9 +181,10 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* @param serviceNodeTemplates
* @param serviceModel
* @return the generated Models
+ * @throws XmlArtifactGenerationException
*/
private List<Resource> generateResourceModels(ISdcCsarHelper csarHelper, List<NodeTemplate> serviceNodeTemplates,
- Service serviceModel) {
+ Service serviceModel) throws XmlArtifactGenerationException {
final List<Group> serviceGroups = csarHelper.getGroupsOfTopologyTemplate();
final ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(csarHelper);
@@ -191,7 +203,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
private void generateModelFromNodeTemplate(ISdcCsarHelper csarHelper, Service serviceModel,
List<Resource> resources, final List<Group> serviceGroups, ArtifactGeneratorToscaParser parser,
- NodeTemplate nodeTemplate) {
+ NodeTemplate nodeTemplate) throws XmlArtifactGenerationException {
Resource model = getModelFor(parser, nodeTemplate);
if (model != null) {
@@ -200,7 +212,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
}
parser.addRelatedModel(serviceModel, model);
- if (model.isResource()) {
+ if (model.getModelType() == ModelType.RESOURCE) {
generateResourceModel(csarHelper, resources, parser, nodeTemplate);
}
} else {
@@ -230,8 +242,8 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
if (model != null) {
Metadata metadata = nodeTemplate.getMetaData();
if (metadata != null && parser.hasAllottedResource(metadata.getAllProperties())
- && model.getWidgetType() == Type.VF) {
- model = new Resource(Type.ALLOTTED_RESOURCE, true);
+ && model.getWidgetType() == WidgetType.valueOf("VF")) {
+ model = new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true);
}
}
@@ -239,7 +251,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
}
private void generateResourceModel(ISdcCsarHelper csarHelper, List<Resource> resources,
- ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) {
+ ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) throws XmlArtifactGenerationException {
Resource resourceModel = getModelFor(parser, nodeTemplate);
if (resourceModel == null) {
log.info(ApplicationMsgs.DISTRIBUTION_EVENT, "Could not generate resource model");
@@ -256,7 +268,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
}
if (parser.hasSubCategoryTunnelXConnect(serviceMetadata) && parser.hasAllottedResource(serviceMetadata)) {
- resourceModel.addWidget(new TunnelXconnectWidget());
+ resourceModel.addWidget(Widget.getWidget(WidgetType.valueOf("TUNNEL_XCONNECT")));
}
resources.addAll(parser.processInstanceGroups(resourceModel, nodeTemplate));
@@ -266,8 +278,10 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
/**
* @param generationData
* @param resource
+ * @throws XmlArtifactGenerationException
*/
- private void generateResourceArtifact(GenerationData generationData, Resource resource) {
+ private void generateResourceArtifact(GenerationData generationData, Resource resource)
+ throws XmlArtifactGenerationException {
if (!isContained(generationData, getArtifactName(resource))) {
log.info(ApplicationMsgs.DISTRIBUTION_EVENT, "Generating resource model");
generationData.add(getResourceArtifact(resource, modelGenerator.generateModelFor(resource)));
@@ -290,7 +304,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
private String getArtifactLabel(Model model) {
StringBuilder artifactName = new StringBuilder(ArtifactType.AAI.name());
artifactName.append("-");
- artifactName.append(model.getModelType().name().toLowerCase());
+ artifactName.append(model.getModelTypeName());
artifactName.append("-");
artifactName.append(hashCodeUuId(model.getModelNameVersionId()));
return (artifactName.toString()).replaceAll("[^a-zA-Z0-9 +]+", "-");
@@ -300,7 +314,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* Method to generate the artifact name for an AAI model.
*
* @param model
- * AAI artifact model
+ * AAI artifact model
* @return Model artifact name
*/
private String getArtifactName(Model model) {
@@ -311,7 +325,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
artifactName.append(truncatedArtifactName);
artifactName.append("-");
- artifactName.append(model.getModelType().name().toLowerCase());
+ artifactName.append(model.getModelTypeName());
artifactName.append("-");
artifactName.append(model.getModelVersion());
@@ -324,12 +338,12 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* Create Resource artifact model from the AAI xml model string.
*
* @param resourceModel
- * Model of the resource artifact
+ * Model of the resource artifact
* @param aaiResourceModel
- * AAI model as string
+ * AAI model as string
* @return Generated {@link Artifact} model for the resource
*/
- private Artifact getResourceArtifact(Model resourceModel, String aaiResourceModel) {
+ private Artifact getResourceArtifact(Resource resourceModel, String aaiResourceModel) {
final String resourceArtifactLabel = getArtifactLabel(resourceModel);
MDC.put(MDC_PARAM_MODEL_INFO, resourceModel.getModelName() + "," + resourceArtifactLabel);
final byte[] bytes = aaiResourceModel.getBytes();
@@ -338,7 +352,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
GeneratorUtil.checkSum(bytes), GeneratorUtil.encode(bytes));
artifact.setName(getArtifactName(resourceModel));
artifact.setLabel(resourceArtifactLabel);
- artifact.setDescription(ArtifactGeneratorToscaParser.getArtifactDescription(resourceModel));
+ artifact.setDescription("AAI Resource Model");
return artifact;
}
@@ -356,9 +370,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* Create Service artifact model from the AAI XML model.
*
* @param serviceModel
- * Model of the service artifact
+ * Model of the service artifact
* @param aaiServiceModel
- * AAI model as string
+ * AAI model as string
* @return Generated {@link Artifact} model for the service
*/
private Artifact getServiceArtifact(Service serviceModel, String aaiServiceModel) {
@@ -368,8 +382,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
String serviceArtifactLabel = getArtifactLabel(serviceModel);
artifact.setName(serviceArtifactName);
artifact.setLabel(serviceArtifactLabel);
- String description = ArtifactGeneratorToscaParser.getArtifactDescription(serviceModel);
- artifact.setDescription(description);
+ artifact.setDescription("AAI Service Model");
return artifact;
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java
index daf9d36..91eb6a4 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java
@@ -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 (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,14 +18,252 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.xml.generator.api;
+import java.io.StringWriter;
+import java.util.Collection;
+import java.util.List;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import org.onap.aai.babel.logging.ApplicationMsgs;
+import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
+import org.onap.aai.babel.xml.generator.model.Model;
import org.onap.aai.babel.xml.generator.model.Resource;
import org.onap.aai.babel.xml.generator.model.Service;
+import org.onap.aai.babel.xml.generator.model.Widget;
+import org.onap.aai.babel.xml.generator.xsd.ModelElement;
+import org.onap.aai.babel.xml.generator.xsd.ModelElements;
+import org.onap.aai.babel.xml.generator.xsd.ModelVer;
+import org.onap.aai.babel.xml.generator.xsd.ModelVers;
+import org.onap.aai.babel.xml.generator.xsd.Relationship;
+import org.onap.aai.babel.xml.generator.xsd.RelationshipData;
+import org.onap.aai.babel.xml.generator.xsd.RelationshipList;
+import org.onap.aai.cl.api.Logger;
+import org.w3c.dom.DOMException;
+
+/**
+ * Generates the A&AI XML models from the Service/Resource/Widget Java models.
+ */
+public class AaiModelGenerator {
+
+ private static Logger log = LogHelper.INSTANCE;
+
+ /**
+ * Method to generate the AAI model for a Service or Resource.
+ *
+ * @param model
+ * Java object model representing an AAI {@link Service} or {@link Resource} model
+ * @return XML representation of the model in String format
+ * @throws XmlArtifactGenerationException
+ */
+ public String generateModelFor(Model model) throws XmlArtifactGenerationException {
+ org.onap.aai.babel.xml.generator.xsd.Model aaiModel = createJaxbModel(model);
+ ModelElement baseWidget = addBaseWidgetRelation(model, aaiModel);
+ generateWidgetChildren(baseWidget, model.getWidgets());
+ return getModelAsString(aaiModel);
+ }
+
+ /**
+ * Create a JAXB Model from the supplied Service or Resource.
+ *
+ * @param model
+ * the Service or Resource containing the model details
+ * @return a new Model object based on the A&AI schema
+ */
+ private org.onap.aai.babel.xml.generator.xsd.Model createJaxbModel(Model model) {
+ log.debug(model.toString());
+
+ org.onap.aai.babel.xml.generator.xsd.Model aaiModel = new org.onap.aai.babel.xml.generator.xsd.Model();
+ aaiModel.setModelInvariantId(model.getModelId());
+ aaiModel.setModelType(model.getModelTypeName());
+
+ aaiModel.setModelVers(new ModelVers());
+ aaiModel.getModelVers().getModelVer().add(createModelVersion(model));
+
+ return aaiModel;
+ }
+
+ /**
+ * Create a new JAXB object representing the model-ver complex type, and populate this with the Model Version
+ * information.
+ *
+ * @param model
+ * the Service or Resource containing the version details
+ * @return a new ModelVer object
+ */
+ private ModelVer createModelVersion(Model model) {
+ ModelVer modelVer = new ModelVer();
+ modelVer.setModelDescription(model.getModelDescription());
+ modelVer.setModelName(model.getModelName());
+ modelVer.setModelVersion(model.getModelVersion());
+ modelVer.setModelVersionId(model.getModelNameVersionId());
+ modelVer.setModelElements(new ModelElements());
+ return modelVer;
+ }
+
+ /**
+ * Add base widget model element for the Service or Resource.
+ *
+ * @param model
+ * the Service or Resource containing the Model and child resources
+ * @param aaiModel
+ * the JAXB Model to populate
+ * @return a new ModelElement for the relationship to the base Widget
+ * @throws XmlArtifactGenerationException
+ */
+ private ModelElement addBaseWidgetRelation(Model model, org.onap.aai.babel.xml.generator.xsd.Model aaiModel)
+ throws XmlArtifactGenerationException {
+ ModelElement widgetElement = createWidgetRelationshipModelElement(model);
+ ModelVer modelVer = aaiModel.getModelVers().getModelVer().get(0);
+ modelVer.getModelElements().getModelElement().add(widgetElement);
+
+ // Add the child resources to the base widget model element list
+ List<ModelElement> modelElements = widgetElement.getModelElements().getModelElement();
+ for (Resource resource : model.getResources()) {
+ modelElements.add(createRelationshipModelElement(resource));
+ }
+
+ return widgetElement;
+ }
+
+ /**
+ * Create a model-element complex type storing the relationship to a Service or Resource model's base Widget.
+ *
+ * @param model
+ * the Service or Resource model storing the widget's relationship data
+ * @return a new Java object for the model-element type storing the Widget relationship
+ * @throws XmlArtifactGenerationException
+ */
+ private ModelElement createWidgetRelationshipModelElement(Model model) throws XmlArtifactGenerationException {
+ return createRelationshipModelElement(model.getDeleteFlag(), model.getWidgetId(),
+ model.getWidgetInvariantId());
+ }
+
+ /**
+ * Create a model-element complex type storing the relationship to a Resource model.
+ *
+ * @param resource
+ * the Resource model storing the relationship data
+ * @return a new Java object for the model-element type storing the relationship
+ * @throws XmlArtifactGenerationException
+ */
+ private ModelElement createRelationshipModelElement(Resource resource) {
+ return createRelationshipModelElement(resource.getDeleteFlag(), resource.getModelNameVersionId(),
+ resource.getModelId());
+ }
+
+ /**
+ * Create a model-element complex type storing the relationship to a Widget model.
+ *
+ * @param widget
+ * the Widget model storing the relationship data
+ * @return a new Java object for the model-element type storing the Widget relationship
+ */
+ private ModelElement createRelationshipModelElement(Widget widget) {
+ return createRelationshipModelElement(widget.getDeleteFlag(), widget.getId(), widget.getWidgetId());
+ }
+
+ /**
+ * Method to create the <model-element></model-element> holding the relationship value for a resource/widget model.
+ *
+ * @param newDataDelFlag
+ * new-data-del-flag (mapped from boolean to the string T or F)
+ * @param modelVersionId
+ * model-version-id
+ * @param modelInvariantId
+ * model-invariant-id
+ * @return a new Java object for the model-element type storing the relationship
+ */
+ private ModelElement createRelationshipModelElement(boolean newDataDelFlag, String modelVersionId,
+ String modelInvariantId) {
+ ModelElement relationshipModelElement = new ModelElement();
+ relationshipModelElement.setNewDataDelFlag(newDataDelFlag ? "T" : "F");
+ relationshipModelElement.setCardinality("unbounded");
+ relationshipModelElement.setModelElements(new ModelElements());
+ relationshipModelElement.setRelationshipList(createModelRelationship(modelVersionId, modelInvariantId));
+ return relationshipModelElement;
+ }
+
+ /**
+ * Create the Model Version relationship data.
+ *
+ * @param modelVersionId
+ * model-version-id
+ * @param modelInvariantId
+ * model-invariant-id
+ * @return a new RelationshipList object containing the model-ver relationships
+ */
+ private RelationshipList createModelRelationship(String modelVersionId, String modelInvariantId) {
+ Relationship relationship = new Relationship();
+ relationship.setRelatedTo("model-ver");
+ List<RelationshipData> relationshipDataList = relationship.getRelationshipData();
+ relationshipDataList.add(createRelationshipData("model-ver.model-version-id", modelVersionId));
+ relationshipDataList.add(createRelationshipData("model.model-invariant-id", modelInvariantId));
+
+ RelationshipList relationShipList = new RelationshipList();
+ relationShipList.getRelationship().add(relationship);
+ return relationShipList;
+ }
+
+ /**
+ * Create a new RelationshipData element for the given key/value pair.
+ *
+ * @param key
+ * relationship key
+ * @param value
+ * relationship value
+ * @return a new Java object representing the relationship-data complex type
+ */
+ private RelationshipData createRelationshipData(String key, String value) {
+ RelationshipData data = new RelationshipData();
+ data.setRelationshipKey(key);
+ data.setRelationshipValue(value);
+ return data;
+ }
-public interface AaiModelGenerator {
+ /**
+ * Method to create the child model elements of the widget. Handles the generation of recursive child widget
+ * elements (if any).
+ *
+ * @param parent
+ * Reference to the parent widget model element
+ * @param widgets
+ * Set of child widgets obtained from the tosca/widget definition
+ */
+ private void generateWidgetChildren(ModelElement parent, Collection<Widget> widgets) {
+ for (Widget widget : widgets) {
+ ModelElement childRelation = createRelationshipModelElement(widget);
+ parent.getModelElements().getModelElement().add(childRelation);
+ // Recursive call to create any child widgets.
+ generateWidgetChildren(childRelation, widget.getWidgets());
+ }
+ }
- public String generateModelFor(Service service);
+ /**
+ * JAXB marshalling helper method to convert the Java object model to XML String.
+ *
+ * @param model
+ * Java Object model of a service/widget/resource
+ * @return XML representation of the Java model in String format
+ */
+ private String getModelAsString(org.onap.aai.babel.xml.generator.xsd.Model model) {
+ JAXBContext jaxbContext;
+ StringWriter modelStringWriter = new StringWriter();
+ try {
+ jaxbContext = JAXBContext.newInstance(org.onap.aai.babel.xml.generator.xsd.Model.class);
+ Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
+ jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "US-ASCII");
+ jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
+ jaxbMarshaller.marshal(model, modelStringWriter);
+ } catch (JAXBException jaxbException) {
+ log.error(ApplicationMsgs.INVALID_CSAR_FILE, jaxbException);
+ throw new DOMException(DOMException.SYNTAX_ERR, jaxbException.getMessage());
+ }
- public String generateModelFor(Resource resource);
+ return modelStringWriter.toString();
+ }
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java
deleted file mode 100644
index 3bff7e7..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * 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.
- * 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.api;
-
-import java.io.StringWriter;
-import java.util.List;
-import java.util.Set;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import org.onap.aai.babel.logging.ApplicationMsgs;
-import org.onap.aai.babel.logging.LogHelper;
-import org.onap.aai.babel.xml.generator.model.Resource;
-import org.onap.aai.babel.xml.generator.model.Service;
-import org.onap.aai.babel.xml.generator.model.Widget;
-import org.onap.aai.babel.xml.generator.xsd.Model;
-import org.onap.aai.babel.xml.generator.xsd.ModelElement;
-import org.onap.aai.babel.xml.generator.xsd.ModelElements;
-import org.onap.aai.babel.xml.generator.xsd.ModelVer;
-import org.onap.aai.babel.xml.generator.xsd.ModelVers;
-import org.onap.aai.babel.xml.generator.xsd.Relationship;
-import org.onap.aai.babel.xml.generator.xsd.RelationshipData;
-import org.onap.aai.babel.xml.generator.xsd.RelationshipList;
-import org.onap.aai.cl.api.Logger;
-import org.w3c.dom.DOMException;
-
-/**
- * Implementation of the {@link AaiModelGenerator} which generates the XML models from the Service/Resource/Widget java
- * models.
- */
-public class AaiModelGeneratorImpl implements AaiModelGenerator {
- private static Logger log = LogHelper.INSTANCE;
-
- /**
- * Method to generate the AAI model for a Service.
- *
- * @param service
- * Java object model representing an AAI {@link Service} model
- * @return XML representation of the service model in String format
- */
- @Override
- public String generateModelFor(Service service) {
- // Create a JAXB Model for AAI service model
- Model aaiServiceModel = new Model();
- log.debug("Generating Model for Service with ModelName: " + service.getModelName());
- // after new model
- aaiServiceModel.setModelInvariantId(service.getModelId());
- aaiServiceModel.setModelVers(new ModelVers());
- ModelVer modelVer = new ModelVer();
- modelVer.setModelDescription(service.getModelDescription());
- modelVer.setModelName(service.getModelName());
- modelVer.setModelVersion(service.getModelVersion());
- modelVer.setModelVersionId(service.getModelNameVersionId());
- modelVer.setModelElements(new ModelElements());
- ModelElements modelElements = modelVer.getModelElements();
- // Populate basic model details
- aaiServiceModel.setModelType(service.getModelType().name().toLowerCase()); // Using enum name as model type
- List<ModelElement> modelElementList = modelElements.getModelElement();
-
- // Add service base widget model element
- ModelElement serviceWidgetModelRelationshipElement = createRelationshipModelElement(
- getNewDataDelFlagValue(service.getDeleteFlag()), service.getWidgetId(), service.getWidgetInvariantId());
- modelElementList.add(serviceWidgetModelRelationshipElement);
-
- // Add the resource model elements
- ModelElements serviceModelElements = serviceWidgetModelRelationshipElement.getModelElements();
- List<ModelElement> serviceModelElementList = serviceModelElements.getModelElement();
- Set<Resource> serviceResources = service.getResources();
- if (serviceResources != null && !serviceResources.isEmpty()) {
- for (Resource resourceModel : serviceResources) {
- ModelElement aaiResourceModelElement =
- createRelationshipModelElement(getNewDataDelFlagValue(resourceModel.getDeleteFlag()),
- resourceModel.getModelNameVersionId(), resourceModel.getModelId());
- serviceModelElementList.add(aaiResourceModelElement);
- }
- }
-
- // Add the widget model elements
- Set<Widget> serviceWidgets = service.getWidgets();
- if (serviceWidgets != null && !serviceWidgets.isEmpty()) {
- for (Widget widgetModel : serviceWidgets) {
- ModelElement widgetModelElement =
- createRelationshipModelElement(getNewDataDelFlagValue(widgetModel.getDeleteFlag()),
- widgetModel.getId(), widgetModel.getWidgetId());
- serviceModelElementList.add(widgetModelElement);
- }
- }
- ModelVers modelVers = aaiServiceModel.getModelVers();
- List<ModelVer> modelVerList = modelVers.getModelVer();
- modelVerList.add(modelVer);
- return getModelAsString(aaiServiceModel);
- }
-
- /**
- * Method to generate the AAI model for a Resource.
- *
- * @param resource
- * Java object model representing an AAI {@link Resource} model
- * @return XML representation of the resource model in String format
- */
- @Override
- public String generateModelFor(Resource resource) {
- // Create a JAXB Model for AAI Resource model
- Model aaiResourceModel = new Model();
- log.debug("Generating Model for Resource with ModelName: " + resource.getModelName());
- aaiResourceModel.setModelInvariantId(resource.getModelId());
- aaiResourceModel.setModelVers(new ModelVers());
- ModelVer modelVer = new ModelVer();
- modelVer.setModelDescription(resource.getModelDescription());
- modelVer.setModelName(resource.getModelName());
- modelVer.setModelVersion(resource.getModelVersion());
- modelVer.setModelVersionId(resource.getModelNameVersionId());
- modelVer.setModelElements(new ModelElements());
- ModelElements modelElements = modelVer.getModelElements();
- aaiResourceModel.setModelType(resource.getModelType().name().toLowerCase()); // Using enum name as model type
- List<ModelElement> modelElementList = modelElements.getModelElement();
-
- // Add resource base widget model element
- ModelElement resourceWidgetModelRelationshipElement =
- createRelationshipModelElement(getNewDataDelFlagValue(resource.getDeleteFlag()), resource.getWidgetId(),
- resource.getWidgetInvariantId());
- modelElementList.add(resourceWidgetModelRelationshipElement);
-
- // Add the child resources to the base widget model element list
- ModelElements baseResourceWidgetModelElements = resourceWidgetModelRelationshipElement.getModelElements();
- List<ModelElement> baseResourceWidgetModelElementList = baseResourceWidgetModelElements.getModelElement();
- Set<Resource> childResources = resource.getResources();
- if (childResources != null && !childResources.isEmpty()) {
- for (Resource childResourceModel : childResources) {
- ModelElement aaiChildResourceModelElement =
- createRelationshipModelElement(getNewDataDelFlagValue(childResourceModel.getDeleteFlag()),
- childResourceModel.getModelNameVersionId(), childResourceModel.getModelId());
- baseResourceWidgetModelElementList.add(aaiChildResourceModelElement);
- }
- }
- // Add resource widgets/resources to the resource widget model relationship element
- Set<Widget> resourceWidgets = resource.getWidgets();
- if (resourceWidgets != null && !resourceWidgets.isEmpty()) {
- generateWidgetChildren(resourceWidgetModelRelationshipElement, resourceWidgets);
- }
-
- ModelVers modelVers = aaiResourceModel.getModelVers();
- List<ModelVer> modelVerList = modelVers.getModelVer();
- modelVerList.add(modelVer);
- return getModelAsString(aaiResourceModel);
- }
-
- /**
- * Method to create the <model-element></model-element> holding the relationship value for a resource/widget model.
- *
- * @param newDataDelFlag
- * Value of the <new-data-del-flag></new-data-del-flag> attribute for a widget/resource in the model xml
- * @param relationshipValue
- * Value of the <relationship-value></relationship-value> attribute for the widget/resource in the model
- * xml
- * @return Java object representation for the <model-element></model-element> holding the relationship
- */
- private ModelElement createRelationshipModelElement(String newDataDelFlag, String modelVersionId,
- String modelInvariantId) {
- ModelElement relationshipModelElement = new ModelElement();
- relationshipModelElement.setNewDataDelFlag(newDataDelFlag); // Set new-data-del-flag value
- relationshipModelElement.setCardinality("unbounded");
- RelationshipList relationShipList = new RelationshipList();
- final List<Relationship> relationships = relationShipList.getRelationship();
- Relationship relationship = new Relationship();
- relationship.setRelatedTo("model-ver");
- List<RelationshipData> relationshipDataList = relationship.getRelationshipData();
-
- RelationshipData modelVersionRelationshipData = new RelationshipData();
- modelVersionRelationshipData.setRelationshipKey("model-ver.model-version-id");
- modelVersionRelationshipData.setRelationshipValue(modelVersionId); // Set the widget/resource name-version-uuid
- // as value
- relationshipDataList.add(modelVersionRelationshipData);
- RelationshipData modelInvariantRelationshipData = new RelationshipData();
- modelInvariantRelationshipData.setRelationshipKey("model.model-invariant-id");
- modelInvariantRelationshipData.setRelationshipValue(modelInvariantId);
- relationshipDataList.add(modelInvariantRelationshipData);
- relationships.add(relationship);
- relationshipModelElement.setRelationshipList(relationShipList);
- relationshipModelElement.setModelElements(new ModelElements());
- return relationshipModelElement;
- }
-
- /**
- * Method to create the child model elements of the widget. Handles the generation of recursive child widget
- * elements (if any)
- *
- * @param parent
- * Reference to the parent widget model element
- * @param widgetChildrenSet
- * Set of children obtained from the tosca/widget definition
- */
- private void generateWidgetChildren(ModelElement parent, Set<Widget> widgetChildrenSet) {
- for (Widget widget : widgetChildrenSet) {
- Set<Widget> widgetSubChildren = widget.getWidgets();
- if (widgetSubChildren != null && !widgetSubChildren.isEmpty()) {
- ModelElement widgetChildRelationshipElement = createRelationshipModelElement(
- getNewDataDelFlagValue(widget.getDeleteFlag()), widget.getId(), widget.getWidgetId());
- // Recursive call for getting the children of widgets (if any)
- generateWidgetChildren(widgetChildRelationshipElement, widgetSubChildren);
- parent.getModelElements().getModelElement().add(widgetChildRelationshipElement);
- } else {
- ModelElement widgetChildRelationshipElement = createRelationshipModelElement(
- getNewDataDelFlagValue(widget.getDeleteFlag()), widget.getId(), widget.getWidgetId());
- parent.getModelElements().getModelElement().add(widgetChildRelationshipElement);
- }
- }
- }
-
- /**
- * Converts the data delete flag value from boolean to String as per AAI model.
- *
- * @param delFlag
- * Boolean value as true/false from the annotation
- * @return Converted value to a flag as per AAI model
- */
- private String getNewDataDelFlagValue(boolean delFlag) {
- return delFlag ? "T" : "F";
- }
-
- /**
- * JAXB marshalling helper method to convert the Java object model to XML String.
- *
- * @param model
- * Java Object model of a service/widget/resource
- * @return XML representation of the Java model in String format
- */
- private String getModelAsString(Model model) {
- JAXBContext jaxbContext;
- StringWriter modelStringWriter = new StringWriter();
- try {
- jaxbContext = JAXBContext.newInstance(Model.class);
- Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
- jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "US-ASCII");
- jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
- jaxbMarshaller.marshal(model, modelStringWriter);
- } catch (JAXBException jaxbException) {
- log.error(ApplicationMsgs.INVALID_CSAR_FILE, jaxbException);
- throw new DOMException(DOMException.SYNTAX_ERR, jaxbException.getMessage());
- }
-
- return modelStringWriter.toString();
- }
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/Artifact.java b/src/main/java/org/onap/aai/babel/xml/generator/data/Artifact.java
index 50dfc89..2a2e32c 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/data/Artifact.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/Artifact.java
@@ -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 (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.xml.generator.data;
public class Artifact {
@@ -50,18 +51,6 @@ public class Artifact {
return payload;
}
- public String getChecksum() {
- return checksum;
- }
-
- public String getType() {
- return type;
- }
-
- public String getGroupType() {
- return groupType;
- }
-
public String getName() {
return name;
}
@@ -70,18 +59,10 @@ public class Artifact {
this.name = name;
}
- public String getLabel() {
- return label;
- }
-
public void setLabel(String label) {
this.label = label;
}
- public String getDescription() {
- return description;
- }
-
public void setDescription(String description) {
this.description = description;
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/GenerationData.java b/src/main/java/org/onap/aai/babel/xml/generator/data/GenerationData.java
index f59cb66..8ca8b6b 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/data/GenerationData.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/GenerationData.java
@@ -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 (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.xml.generator.data;
import java.util.ArrayList;
@@ -30,17 +31,12 @@ public class GenerationData {
List<Artifact> resultData = new ArrayList<>();
Map<String, List<String>> errorData = new HashMap<>();
- public void add(List<Artifact> resultData, Map<String, List<String>> errorData) {
- this.resultData.addAll(resultData);
- this.errorData.putAll(errorData);
- }
-
public void add(Artifact generatedArtifact) {
resultData.add(generatedArtifact);
}
/**
- * Add the error code to the list of error codes for the given ID
+ * Add the error code to the list of error codes for the given ID.
*
* @param generatorId the generator id
* @param errorCode the error code
@@ -50,11 +46,6 @@ public class GenerationData {
errorData.get(generatorId).add(errorCode);
}
- public void add(GenerationData generationData) {
- this.resultData.addAll(generationData.resultData);
- this.errorData.putAll(generationData.errorData);
- }
-
public List<Artifact> getResultData() {
return resultData;
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorUtil.java b/src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorUtil.java
index 42c8893..16f6b13 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorUtil.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorUtil.java
@@ -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 (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.xml.generator.data;
import java.util.Base64;
@@ -27,21 +28,11 @@ import org.apache.commons.codec.digest.DigestUtils;
public final class GeneratorUtil {
/*
- * Private constructor to prevent instantiation
+ * Private constructor to prevent instantiation.
*/
private GeneratorUtil() {}
/**
- * Decodes Base64 encode byte array input.
- *
- * @param input Base64 encoded byte array
- * @return Decoded byte array
- */
- public static byte[] decode(byte[] input) {
- return input != null ? Base64.getDecoder().decode(input) : new byte[0];
- }
-
- /**
* Encode a byte array input using Base64 encoding.
*
* @param input Input byte array to be encoded
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java b/src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java
index bbc7164..7ecd3f2 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.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.
@@ -31,6 +31,11 @@ public class GroupConfiguration {
private List<String> instanceGroupTypes;
/**
+ * Set of Widget Types.
+ */
+ private List<WidgetTypeConfig> widgetTypes;
+
+ /**
* Mapping from TOSCA type to Widget directly.
*/
private List<WidgetMapping> widgetMappings;
@@ -39,7 +44,12 @@ public class GroupConfiguration {
return instanceGroupTypes;
}
+ public List<WidgetTypeConfig> getWidgetTypes() {
+ return widgetTypes;
+ }
+
public List<WidgetMapping> getWidgetMappings() {
return widgetMappings;
}
+
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java
index 5298f08..7683f7c 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.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,23 +21,29 @@
package org.onap.aai.babel.xml.generator.data;
+import com.google.common.base.Enums;
+import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.model.Resource;
+import org.onap.aai.babel.xml.generator.model.WidgetType;
import org.onap.aai.babel.xml.generator.model.Widget;
+import org.onap.aai.babel.xml.generator.types.ModelType;
public class WidgetConfigurationUtil {
private static Properties config;
private static List<String> instanceGroups = Collections.emptyList();
- private static Map<String, Resource> typeToWidget = new HashMap<>();
+ private static Map<String, Resource> typeToResource = new HashMap<>();
+ private static Map<String, Widget> typeToWidget = new HashMap<>();
/*
- * Private constructor to prevent instantiation
+ * Private constructor to prevent instantiation.
*/
private WidgetConfigurationUtil() {
throw new UnsupportedOperationException("This static class should not be instantiated!");
@@ -60,17 +66,40 @@ public class WidgetConfigurationUtil {
}
public static Optional<Resource> createModelFromType(String typePrefix) {
- return Optional.ofNullable(typeToWidget.get(typePrefix));
+ return Optional.ofNullable(typeToResource.get(typePrefix));
}
- public static void setWidgetMappings(List<WidgetMapping> mappings) {
+ public static Widget createWidgetFromType(String widgetType) throws XmlArtifactGenerationException {
+ Optional<Widget> widget = Optional.ofNullable(typeToWidget.get(widgetType));
+ if (widget.isPresent()) {
+ // Make a copy of the Widget found in the mappings table.
+ return new Widget(widget.get());
+ }
+ return null;
+ }
+
+ public static void setWidgetTypes(List<WidgetTypeConfig> types) {
+ for (WidgetTypeConfig type : types) {
+ if (type.type == null || type.name == null) {
+ throw new IllegalArgumentException("Incomplete widget type specified: " + type);
+ }
+ WidgetType widgetType = new WidgetType(type.type);
+ Widget widget = new Widget(widgetType, type.name, type.deleteFlag);
+ typeToWidget.put(type.type, widget);
+ }
+ WidgetType.validateElements();
+ }
+
+ public static void setWidgetMappings(List<WidgetMapping> mappings) throws IOException {
for (WidgetMapping mapping : mappings) {
- if (mapping.prefix == null || mapping.widget == null) {
- throw new IllegalArgumentException("Incomplete widget mapping specified: " + mapping);
+ ModelType modelType = Optional.ofNullable(mapping.type).map(String::toUpperCase)
+ .map(s -> Enums.getIfPresent(ModelType.class, s).orNull()).orElse(null);
+ if (mapping.prefix == null || mapping.widget == null || modelType == null) {
+ throw new IOException("Invalid widget mapping specified: " + mapping);
}
- Resource resource = new Resource(Widget.Type.valueOf(mapping.widget), mapping.deleteFlag);
- resource.setIsResource(mapping.type.equalsIgnoreCase("resource"));
- typeToWidget.put(mapping.prefix, resource);
+ Resource resource = new Resource(WidgetType.valueOf(mapping.widget), mapping.deleteFlag);
+ resource.setModelType(modelType);
+ typeToResource.put(mapping.prefix, resource);
}
}
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java
index dd46626..2b298da 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java
@@ -21,15 +21,12 @@
package org.onap.aai.babel.xml.generator.data;
-import java.util.Map;
-
public class WidgetMapping {
- String prefix = null;
+ String prefix;
String type = "resource"; // Default type is Resource (not Widget)
- String widget = null;
+ String widget;
boolean deleteFlag = true;
- Map<String, Object> properties;
public void setType(String type) {
this.type = type;
@@ -42,6 +39,6 @@ public class WidgetMapping {
@Override
public String toString() {
return "WidgetMapping [prefix=" + prefix + ", type=" + type + ", widget=" + widget + ", deleteFlag="
- + deleteFlag + ", properties=" + properties + "]";
+ + deleteFlag + "]";
}
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/ResourceWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetTypeConfig.java
index a0f84c7..0d0fe6b 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/ResourceWidget.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetTypeConfig.java
@@ -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 (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,7 +18,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.aai.babel.xml.generator.model;
-public class ResourceWidget extends Widget {
+package org.onap.aai.babel.xml.generator.data;
+
+/**
+ * Widget Type as configured in the TOSCA Mappings.
+ *
+ */
+public class WidgetTypeConfig {
+
+ String type;
+ String name;
+ boolean deleteFlag = false;
+
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResourceWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResourceWidget.java
deleted file mode 100644
index 740ca62..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResourceWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.ALLOTTED_RESOURCE,
- cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "allotted-resource")
-public class AllotedResourceWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/CRWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/CRWidget.java
deleted file mode 100644
index f0962ad..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/CRWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.CR, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "cr")
-public class CRWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/ConfigurationWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/ConfigurationWidget.java
deleted file mode 100644
index 7822926..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/ConfigurationWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.CONFIGURATION, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "configuration")
-public class ConfigurationWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/FlavorWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/FlavorWidget.java
deleted file mode 100644
index 26dde9b..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/FlavorWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.FLAVOR, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = false)
-@ModelWidget(type = ModelType.WIDGET, name = "flavor")
-public class FlavorWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/ImageWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/ImageWidget.java
deleted file mode 100644
index 60656b2..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/ImageWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.IMAGE, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = false)
-@ModelWidget(type = ModelType.WIDGET, name = "image")
-public class ImageWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/InstanceGroupWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/InstanceGroupWidget.java
deleted file mode 100644
index dabce34..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/InstanceGroupWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.INSTANCE_GROUP, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "instance-group")
-public class InstanceGroupWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/L3NetworkWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/L3NetworkWidget.java
deleted file mode 100644
index f737b82..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/L3NetworkWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.L3_NET, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "l3-network")
-public class L3NetworkWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/LIntfWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/LIntfWidget.java
deleted file mode 100644
index fb07ef6..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/LIntfWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.LINT, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "l-interface")
-public class LIntfWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
index d4da6df..ea1d478 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.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.xml.generator.model;
import java.util.Collections;
@@ -27,10 +28,8 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
-import org.onap.aai.babel.xml.generator.error.IllegalAccessException;
-import org.onap.aai.babel.xml.generator.model.Widget.Type;
-import org.onap.aai.babel.xml.generator.types.ModelType;
public abstract class Model {
@@ -99,9 +98,9 @@ public abstract class Model {
public abstract void populate(Model model, String value);
}
- private String modelId;
+ private String modelId; // model-invariant-id
private String modelName;
- private String modelNameVersionId;
+ private String modelNameVersionId; // model-version-id
private String modelVersion;
private String modelDescription;
@@ -109,10 +108,10 @@ public abstract class Model {
protected Set<Widget> widgets = new HashSet<>();
/**
- * Gets the object (model) corresponding to the supplied TOSCA type.
+ * Gets the Resource Model corresponding to the supplied TOSCA type.
*
* @param toscaType
- * the tosca type
+ * the tosca type
* @return the model for the type, or null
*/
public static Resource getModelFor(String toscaType) {
@@ -141,30 +140,30 @@ public abstract class Model {
* information.
*
* @param toscaType
- * the TOSCA type
+ * the TOSCA type
* @param metaDataType
- * the type from the TOSCA metadata
+ * the type from the TOSCA metadata
* @return the model for the type, or null
*/
public static Resource getModelFor(String toscaType, String metaDataType) {
if ("Configuration".equals(metaDataType)) {
- return new Resource(Type.CONFIGURATION, true);
+ return new Resource(WidgetType.valueOf("CONFIGURATION"), true);
} else if ("CR".equals(metaDataType)) {
- return new Resource(Type.CR, true);
+ return new Resource(WidgetType.valueOf("CR"), true);
} else {
return getModelFor(toscaType);
}
}
- public abstract boolean addResource(Resource resource);
-
- public abstract boolean addWidget(Widget resource);
+ public abstract boolean addWidget(Widget resource) throws XmlArtifactGenerationException;
- public abstract Widget.Type getWidgetType();
+ public abstract WidgetType getWidgetType();
- public abstract Map<String, Object> getProperties();
+ public abstract String getModelTypeName();
- public abstract boolean isResource();
+ public boolean addResource(Resource resource) {
+ return resources.add(resource);
+ }
/**
* Gets delete flag.
@@ -172,9 +171,7 @@ public abstract class Model {
* @return the delete flag
*/
public boolean getDeleteFlag() {
- org.onap.aai.babel.xml.generator.types.Model model =
- this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
- return model.dataDeleteFlag();
+ return true;
}
public String getModelDescription() {
@@ -182,7 +179,6 @@ public abstract class Model {
}
public String getModelId() {
- checkSupported();
return modelId;
}
@@ -195,54 +191,34 @@ public abstract class Model {
}
public String getModelNameVersionId() {
- checkSupported();
return modelNameVersionId;
}
/**
- * Gets model type.
- *
- * @return the model type
- */
- public ModelType getModelType() {
- if (this instanceof Service) {
- return ModelType.SERVICE;
- } else if (this instanceof Resource) {
- return ModelType.RESOURCE;
- } else if (this instanceof Widget) {
- return ModelType.WIDGET;
- } else {
- return null;
- }
- }
-
- /**
* Gets widget version id.
*
* @return the widget version id
+ * @throws XmlArtifactGenerationException
*/
- public String getWidgetId() {
- org.onap.aai.babel.xml.generator.types.Model model =
- this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
- return Widget.getWidget(model.widget()).getId();
+ public String getWidgetId() throws XmlArtifactGenerationException {
+ return Widget.getWidget(getWidgetType()).getId();
}
/**
* Gets invariant id.
*
* @return the invariant id
+ * @throws XmlArtifactGenerationException
*/
- public String getWidgetInvariantId() {
- org.onap.aai.babel.xml.generator.types.Model model =
- this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
- return Widget.getWidget(model.widget()).getWidgetId();
+ public String getWidgetInvariantId() throws XmlArtifactGenerationException {
+ return Widget.getWidget(getWidgetType()).getWidgetId();
}
/**
* Populate model identification information.
*
* @param modelIdentInfo
- * the model ident info
+ * the model ident info
*/
public void populateModelIdentificationInformation(Map<String, String> modelIdentInfo) {
Iterator<String> iter = modelIdentInfo.keySet().iterator();
@@ -268,10 +244,9 @@ public abstract class Model {
return widgets;
}
- private void checkSupported() {
- if (this instanceof Widget) {
- throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
- }
+ @Override
+ public String toString() {
+ return "Model [type=" + getModelTypeName() + ", name=" + getModelName() + "]";
}
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/OamNetwork.java b/src/main/java/org/onap/aai/babel/xml/generator/model/OamNetwork.java
deleted file mode 100644
index e9076a9..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/OamNetwork.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.L3_NET, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "oam-network")
-public class OamNetwork extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java
index d655ca6..f5f7c50 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.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.
@@ -24,13 +24,14 @@ package org.onap.aai.babel.xml.generator.model;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-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;
public class Resource extends Model {
- private Type type;
+ private WidgetType type;
private boolean deleteFlag;
- private boolean isResource = true;
+ private ModelType modelType = ModelType.RESOURCE;
private Map<String, Object> properties = Collections.emptyMap();
Widget vserver = null;
@@ -38,7 +39,7 @@ public class Resource extends Model {
boolean addvolume = false;
List<String> members;
- public Resource(Type type, boolean deleteFlag) {
+ public Resource(WidgetType type, boolean deleteFlag) {
this.type = type;
this.deleteFlag = deleteFlag;
}
@@ -62,63 +63,47 @@ public class Resource extends Model {
return deleteFlag;
}
- @Override
- public String getWidgetInvariantId() {
- return Widget.getWidget(getWidgetType()).getWidgetId();
- }
-
- @Override
- public String getWidgetId() {
- return Widget.getWidget(getWidgetType()).getId();
- }
-
public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}
- @Override
public Map<String, Object> getProperties() {
return properties;
}
- public void setIsResource(boolean isResource) {
- this.isResource = isResource;
+ public void setModelType(ModelType type) {
+ this.modelType = type;
}
- @Override
- public boolean isResource() {
- return isResource;
+ public ModelType getModelType() {
+ return modelType;
}
public void setMembers(List<String> members) {
this.members = members;
}
- @Override
- public boolean addResource(Resource resource) {
- return resources.add(resource);
- }
-
/**
* Adds a Widget.
*
* @param widget
- * the widget
+ * the widget
* @return the boolean
+ * @throws XmlArtifactGenerationException
*/
@Override
- public boolean addWidget(Widget widget) {
- if (type == Type.VFMODULE) {
+ public boolean addWidget(Widget widget) throws XmlArtifactGenerationException {
+ if (type == WidgetType.valueOf("VFMODULE")) {
if (widget.memberOf(members)) {
- if (vserver == null && widget instanceof VServerWidget) {
+ if (vserver == null && widget.getWidgetType() == WidgetType.valueOf("VSERVER")) {
addVserverWidget(widget);
- } else if (widget instanceof LIntfWidget) {
+ } else if (widget.getWidgetType() == WidgetType.valueOf("LINT")) {
return addLIntfWidget(widget);
- } else if (widget instanceof VolumeWidget) {
+ } else if (widget.getWidgetType() == WidgetType.valueOf("VOLUME")) {
addVolumeWidget(widget);
return true;
}
- if (!(widget instanceof OamNetwork)) {
+ if (widget.getWidgetType() != WidgetType.valueOf("OAM_NETWORK")) {
return widgets.add(widget);
}
}
@@ -128,13 +113,19 @@ public class Resource extends Model {
}
}
- public Type getWidgetType() {
+ public WidgetType getWidgetType() {
return type;
}
+ public String getModelTypeName() {
+ return "resource";
+ }
+
@Override
public String toString() {
- return "Widget type " + getWidgetType() + ", isResource=" + isResource() + ", deleteFlag=" + deleteFlag;
+ return "Resource [widget type=" + getWidgetType() + ", deleteFlag=" + deleteFlag + ", modelType=" + modelType
+ + ", properties=" + properties + ", vserver=" + vserver + ", addlintf=" + addlintf + ", addvolume="
+ + addvolume + ", members=" + members + "]";
}
private void addVolumeWidget(Widget widget) {
@@ -159,13 +150,13 @@ public class Resource extends Model {
}
}
- private void addVserverWidget(Widget widget) {
+ private void addVserverWidget(Widget widget) throws XmlArtifactGenerationException {
vserver = widget;
if (addlintf) {
- vserver.addWidget(new LIntfWidget());
+ vserver.addWidget(Widget.getWidget(WidgetType.valueOf("LINT")));
}
if (addvolume) {
- vserver.addWidget(new VolumeWidget());
+ vserver.addWidget(Widget.getWidget(WidgetType.valueOf("VOLUME")));
}
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java
index 0815a61..0d20c2d 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java
@@ -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 (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,38 +18,22 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.aai.babel.xml.generator.model;
-import java.util.Collections;
-import java.util.Map;
-import org.onap.aai.babel.xml.generator.types.Cardinality;
+package org.onap.aai.babel.xml.generator.model;
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.SERVICE, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
public class Service extends Model {
@Override
- public boolean addResource(Resource resource) {
- return resources.add(resource);
- }
-
- @Override
public boolean addWidget(Widget widget) {
return widgets.add(widget);
}
@Override
- public Widget.Type getWidgetType() {
- return null;
- }
-
- @Override
- public Map<String, Object> getProperties() {
- return Collections.emptyMap();
+ public WidgetType getWidgetType() {
+ return WidgetType.valueOf("SERVICE");
}
- @Override
- public boolean isResource() {
- return false;
+ public String getModelTypeName() {
+ return "service";
}
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/ServiceWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/ServiceWidget.java
deleted file mode 100644
index 7c2229d..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/ServiceWidget.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@ModelWidget(type = ModelType.WIDGET, name = "service-instance")
-public class ServiceWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/TenantWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/TenantWidget.java
deleted file mode 100644
index a0a4392..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/TenantWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.TENANT, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = false)
-@ModelWidget(type = ModelType.WIDGET, name = "tenant")
-public class TenantWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/TunnelXconnectWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/TunnelXconnectWidget.java
deleted file mode 100644
index 548cd6f..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/TunnelXconnectWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.TUNNEL_XCONNECT, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "tunnel-xconnect")
-public class TunnelXconnectWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VServerWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VServerWidget.java
deleted file mode 100644
index dabeecd..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/VServerWidget.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.VSERVER, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "vserver")
-public class VServerWidget extends Widget {
-
- /** Instantiates a new vserver widget. */
- public VServerWidget() {
- addWidget(new FlavorWidget());
- addWidget(new ImageWidget());
- addWidget(new TenantWidget());
- addWidget(new VfcWidget());
- }
-
- @Override
- public boolean addWidget(Widget widget) {
- return widgets.add(widget);
- }
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VfModuleWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VfModuleWidget.java
deleted file mode 100644
index cc27ca9..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/VfModuleWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.VFMODULE, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "vf-module")
-public class VfModuleWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VfWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VfWidget.java
deleted file mode 100644
index 614244e..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/VfWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.VF, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "generic-vnf")
-public class VfWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VfcWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VfcWidget.java
deleted file mode 100644
index abfa49f..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/VfcWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.VFC, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "vnfc")
-public class VfcWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeGroupWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeGroupWidget.java
deleted file mode 100644
index 3a0aa37..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeGroupWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.VOLUME_GROUP, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "volume-group")
-public class VolumeGroupWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeWidget.java
deleted file mode 100644
index d18a723..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.VOLUME, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "volume")
-public class VolumeWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java
index be84526..732ec4d 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.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,86 +18,70 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.xml.generator.model;
-import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Collections;
-import java.util.EnumMap;
import java.util.HashSet;
-import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import org.onap.aai.babel.logging.ApplicationMsgs;
-import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.data.ArtifactType;
import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
import org.onap.aai.babel.xml.generator.error.IllegalAccessException;
import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-import org.onap.aai.cl.api.Logger;
-public abstract class Widget extends Model {
+public class Widget extends Model {
public static final String GENERATOR_AAI_CONFIGLPROP_NOT_FOUND =
"Cannot generate artifacts. Widget configuration not found for %s";
- public enum Type {
- SERVICE, VF, VFC, VSERVER, VOLUME, FLAVOR, TENANT, VOLUME_GROUP, LINT, L3_NET, VFMODULE, IMAGE, OAM_NETWORK, ALLOTTED_RESOURCE, TUNNEL_XCONNECT, CONFIGURATION, CR, INSTANCE_GROUP;
- }
+ private Set<String> keys = new HashSet<>();
- private static Logger log = LogHelper.INSTANCE;
+ protected String name;
+ protected WidgetType type;
+ protected boolean deleteFlag = false;
- private Set<String> keys = new HashSet<>();
+ public Widget(WidgetType widgetType, String name, boolean deleteFlag) {
+ type = widgetType;
+ this.name = name;
+ this.deleteFlag = deleteFlag;
+ }
- private static EnumMap<Widget.Type, Class<? extends Widget>> typeToWidget = new EnumMap<>(Widget.Type.class);
- static {
- typeToWidget.put(Type.SERVICE, ServiceWidget.class);
- typeToWidget.put(Type.VF, VfWidget.class);
- typeToWidget.put(Type.VFC, VfcWidget.class);
- typeToWidget.put(Type.VSERVER, VServerWidget.class);
- typeToWidget.put(Type.VOLUME, VolumeWidget.class);
- typeToWidget.put(Type.FLAVOR, FlavorWidget.class);
- typeToWidget.put(Type.TENANT, TenantWidget.class);
- typeToWidget.put(Type.VOLUME_GROUP, VolumeGroupWidget.class);
- typeToWidget.put(Type.LINT, LIntfWidget.class);
- typeToWidget.put(Type.L3_NET, L3NetworkWidget.class);
- typeToWidget.put(Type.VFMODULE, VfModuleWidget.class);
- typeToWidget.put(Type.IMAGE, ImageWidget.class);
- typeToWidget.put(Type.OAM_NETWORK, OamNetwork.class);
- typeToWidget.put(Type.ALLOTTED_RESOURCE, AllotedResourceWidget.class);
- typeToWidget.put(Type.TUNNEL_XCONNECT, TunnelXconnectWidget.class);
- typeToWidget.put(Type.CONFIGURATION, ConfigurationWidget.class);
- typeToWidget.put(Type.CR, CRWidget.class);
- typeToWidget.put(Type.INSTANCE_GROUP, InstanceGroupWidget.class);
+ /**
+ * Copy Constructor.
+ *
+ * @param baseWidget
+ * @throws XmlArtifactGenerationException
+ */
+ public Widget(Widget baseWidget) throws XmlArtifactGenerationException {
+ this(baseWidget.getWidgetType(), baseWidget.getName(), baseWidget.getDeleteFlag());
+ if (type == WidgetType.valueOf("VSERVER")) {
+ widgets.add(getWidget(WidgetType.valueOf("FLAVOR")));
+ widgets.add(getWidget(WidgetType.valueOf("IMAGE")));
+ widgets.add(getWidget(WidgetType.valueOf("TENANT")));
+ widgets.add(getWidget(WidgetType.valueOf("VFC")));
+ }
}
/**
* Gets widget.
*
- * @param type
- * the type
- * @return the widget
+ * @param typeString
+ *
+ * @return a new widget of the specified type
+ * @throws XmlArtifactGenerationException
+ * if there is no configuration defined for the specified type
*/
- public static Widget getWidget(Type type) {
- Widget widget = null;
- Class<? extends Widget> clazz = typeToWidget.get(type);
- if (clazz != null) {
- try {
- widget = clazz.getConstructor().newInstance();
- } catch (InstantiationException | java.lang.IllegalAccessException | IllegalArgumentException
- | InvocationTargetException | NoSuchMethodException | SecurityException e) {
- log.error(ApplicationMsgs.INVALID_CSAR_FILE, e);
- }
+ public static Widget getWidget(WidgetType type) throws XmlArtifactGenerationException {
+ Widget widget = WidgetConfigurationUtil.createWidgetFromType(type.toString());
+ if (widget == null) {
+ throw new XmlArtifactGenerationException("No widget type is defined for " + type);
}
return widget;
}
- @Override
- public boolean isResource() {
- return false;
- }
-
public String getId() {
String id = WidgetConfigurationUtil.getConfig()
.getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
@@ -109,12 +93,11 @@ public abstract class Widget extends Model {
}
public ModelType getType() {
- ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
- return widgetModel.type();
+ return ModelType.WIDGET;
}
public String getName() {
- return this.getClass().getAnnotation(ModelWidget.class).name();
+ return name;
}
/**
@@ -139,8 +122,8 @@ public abstract class Widget extends Model {
}
@Override
- public Type getWidgetType() {
- return null;
+ public WidgetType getWidgetType() {
+ return type;
}
/**
@@ -188,11 +171,35 @@ public abstract class Widget extends Model {
@Override
public boolean addWidget(Widget widget) {
+ if (getWidgetType() == WidgetType.valueOf("VSERVER")) {
+ return widgets.add(widget);
+ }
return true;
}
@Override
- public Map<String, Object> getProperties() {
- return Collections.emptyMap();
+ public String toString() {
+ return getName() + " Widget keys=" + keys + ", resources=" + resources + ", widgets=" + widgets;
}
+
+ @Override
+ public boolean getDeleteFlag() {
+ return deleteFlag;
+ }
+
+ @Override
+ public String getModelTypeName() {
+ throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
+ }
+
+ @Override
+ public String getModelId() {
+ throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
+ }
+
+ @Override
+ public String getModelNameVersionId() {
+ throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
+ }
+
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/WidgetType.java b/src/main/java/org/onap/aai/babel/xml/generator/model/WidgetType.java
new file mode 100644
index 0000000..2cab6ae
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/WidgetType.java
@@ -0,0 +1,73 @@
+/**
+ * ============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.model;
+
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Widget Type Enumeration.
+ *
+ */
+public class WidgetType {
+
+ /**
+ * Dynamically created set of Widget Types.
+ */
+ private static Map<String, WidgetType> elements = new LinkedHashMap<>();
+
+ /**
+ * Types that must be present for Model generation to function correctly.
+ */
+ private static final List<String> mandatoryElements = Arrays.asList( //
+ "SERVICE", "VF", "VFC", "VSERVER", "VOLUME", "FLAVOR", "TENANT", "VOLUME_GROUP", "LINT", "L3_NET",
+ "VFMODULE", "IMAGE", "OAM_NETWORK", "ALLOTTED_RESOURCE", "TUNNEL_XCONNECT", "CONFIGURATION", "CR",
+ "INSTANCE_GROUP");
+
+ private final String name;
+
+ public WidgetType(String name) {
+ this.name = name;
+ elements.put(name, this);
+ }
+
+ public static void validateElements() {
+ mandatoryElements.forEach(WidgetType::valueOf);
+ }
+
+ public static WidgetType valueOf(String typeName) {
+ WidgetType type = elements.get(typeName);
+ if (type == null) {
+ throw new IllegalArgumentException("Unknown type " + typeName);
+ }
+ return type;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+}
+
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/types/Cardinality.java b/src/main/java/org/onap/aai/babel/xml/generator/types/Cardinality.java
deleted file mode 100644
index 9cdb93b..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/types/Cardinality.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.types;
-
-public enum Cardinality {
- UNBOUNDED
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/types/Model.java b/src/main/java/org/onap/aai/babel/xml/generator/types/Model.java
deleted file mode 100644
index f69c3ea..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/types/Model.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.types;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import org.onap.aai.babel.xml.generator.model.Widget;
-
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface Model {
-
- /**
- * Widget widget . type.
- *
- * @return the widget . type
- */
- public Widget.Type widget();
-
- /**
- * Data delete flag boolean.
- *
- * @return the boolean
- */
- public boolean dataDeleteFlag();
-
- /**
- * Cardinality cardinality.
- *
- * @return the cardinality
- */
- public Cardinality cardinality();
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/types/ModelWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/types/ModelWidget.java
deleted file mode 100644
index 307524e..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/types/ModelWidget.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.types;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface ModelWidget {
-
- /**
- * Type model type.
- *
- * @return the model type
- */
- public ModelType type();
-
- /**
- * Name string.
- *
- * @return the string
- */
- public String name();
-}
diff --git a/src/main/resources/babel-logging-resources.properties b/src/main/resources/babel-logging-resources.properties
index 167c369..d749cd0 100644
--- a/src/main/resources/babel-logging-resources.properties
+++ b/src/main/resources/babel-logging-resources.properties
@@ -1,8 +1,8 @@
# ============LICENSE_START=======================================================
# org.onap.aai
# ================================================================================
-# Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
-# Copyright © 2017-2018 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.
@@ -17,27 +17,23 @@
# limitations under the License.
# ============LICENSE_END=========================================================
-#Resource key=Error Code|Message text|Resolution text |Description text
-#######
-#Newlines can be utilized to add some clarity ensuring continuing line
-#has at least one leading space
-#ResourceKey=\
+# Resource key=Error Code|Message text|Resolution text |Description text
+#
+# For example:
+# ResourceKey=\
# ERR0000E\
# Sample error msg txt\
# Sample resolution msg\
# Sample description txt
#
-######
-#Error code classification category
-#000 Info/Debug
-#100 Permission errors
-#200 Availability errors/Timeouts
-#300 Data errors
-#400 Schema Interface type/validation errors
-#500 Business process errors
-#900 Unknown errors
-#
-########################################################################
+# Error code classification category
+# 000 Info/Debug
+# 100 Permission errors
+# 200 Availability errors/Timeouts
+# 300 Data errors
+# 400 Schema Interface type/validation errors
+# 500 Business process errors
+# 900 Unknown errors
DISTRIBUTION_EVENT=\
BABEL0001I|\
@@ -89,4 +85,8 @@ MISSING_SERVICE_METADATA=\
TEMP_FILE_ERROR=\
BABEL0012E|\
Error creating temporary CSAR file.|\
- \ No newline at end of file
+
+LOAD_PROPERTIES=\
+ BABEL0013E|\
+ Error loading properties: {0}|\
+ Correct the file contents|\
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()));
+ }
+
}
diff --git a/src/test/resources/appconfig/auth/auth_policy.json b/src/test/resources/appconfig/auth/auth_policy.json
new file mode 100644
index 0000000..dc966e0
--- /dev/null
+++ b/src/test/resources/appconfig/auth/auth_policy.json
@@ -0,0 +1,12 @@
+{"roles": [
+ {
+ "name": "nofuncauth",
+ "functions": [{
+ "name": "nofuncutil"
+ }],
+ "users": [{
+ "user": "aai",
+ "pass": "OBF:1u2a1t2v1vgb1s3g1s3m1vgj1t3b1u30"
+ }]
+ }
+]}
diff --git a/src/test/resources/auth/keystore.jks b/src/test/resources/auth/keystore.jks
new file mode 100644
index 0000000..037769b
--- /dev/null
+++ b/src/test/resources/auth/keystore.jks
Binary files differ
diff --git a/src/test/resources/empty-tosca-mappings.json b/src/test/resources/empty-tosca-mappings.json
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/test/resources/empty-tosca-mappings.json
diff --git a/src/test/resources/invalid-tosca-mappings.json b/src/test/resources/invalid-tosca-mappings.json
new file mode 100644
index 0000000..bbd27bd
--- /dev/null
+++ b/src/test/resources/invalid-tosca-mappings.json
@@ -0,0 +1 @@
+test file that does not contain valid JSON content \ No newline at end of file
diff --git a/src/test/resources/tosca-mappings.json b/src/test/resources/tosca-mappings.json
index 0d306ea..c67b3e2 100644
--- a/src/test/resources/tosca-mappings.json
+++ b/src/test/resources/tosca-mappings.json
@@ -4,6 +4,98 @@
"org.openecomp.groups.VfcInstanceGroup",
"org.openecomp.groups.ResourceInstanceGroup"
],
+ "widgetTypes": [
+ {
+ "type": "SERVICE",
+ "name": "service-instance",
+ "deleteFlag": true
+ },
+ {
+ "type": "VF",
+ "name": "generic-vnf",
+ "deleteFlag": false
+ },
+ {
+ "type": "VFC",
+ "name": "vnfc",
+ "deleteFlag": true
+ },
+ {
+ "type": "VSERVER",
+ "name": "vserver",
+ "deleteFlag": true
+ },
+ {
+ "type": "VOLUME",
+ "name": "volume",
+ "deleteFlag": true
+ },
+ {
+ "type": "FLAVOR",
+ "name": "flavor",
+ "deleteFlag": false
+ },
+ {
+ "type": "TENANT",
+ "name": "tenant",
+ "deleteFlag": false
+ },
+ {
+ "type": "VOLUME_GROUP",
+ "name": "volume-group",
+ "deleteFlag": true
+ },
+ {
+ "type": "LINT",
+ "name": "l-interface",
+ "deleteFlag": true
+ },
+ {
+ "type": "L3_NET",
+ "name": "l3-network",
+ "deleteFlag": true
+ },
+ {
+ "type": "VFMODULE",
+ "name": "vf-module",
+ "deleteFlag": true
+ },
+ {
+ "type": "IMAGE",
+ "name": "image",
+ "deleteFlag": false
+ },
+ {
+ "type": "OAM_NETWORK",
+ "name": "oam-network",
+ "deleteFlag": true
+ },
+ {
+ "type": "ALLOTTED_RESOURCE",
+ "name": "allotted-resource",
+ "deleteFlag": true
+ },
+ {
+ "type": "TUNNEL_XCONNECT",
+ "name": "tunnel-xconnect",
+ "deleteFlag": true
+ },
+ {
+ "type": "CONFIGURATION",
+ "name": "configuration",
+ "deleteFlag": true
+ },
+ {
+ "type": "CR",
+ "name": "cr",
+ "deleteFlag": true
+ },
+ {
+ "type": "INSTANCE_GROUP",
+ "name": "instance-group",
+ "deleteFlag": true
+ }
+ ],
"widgetMappings": [
{
"prefix": "org.openecomp.resource.vfc",