Remove the Generator Constants class 71/55471/1
authormark.j.leonard <mark.j.leonard@gmail.com>
Wed, 27 Jun 2018 10:46:19 +0000 (11:46 +0100)
committermark.j.leonard <mark.j.leonard@gmail.com>
Wed, 27 Jun 2018 10:46:37 +0000 (11:46 +0100)
Move the String constants out of a common class and into the individual
classes where they are used. This eliminates a set of Sonar code smells
relating to non-standard ordering of declarations. It simplifies the
code by removing the need for an empty private constructor in the static
class (i.e. containing static methods only).

Additionally, simplify the AaiModelGenerator interface by removing the
static factory method (which is not currently required). If multiple
implementations are needed we can use Spring annotations in the future.

Issue-ID: AAI-1242
Change-Id: Ica03b66ae2fd899977093d11d3e23dc3f3c8f194
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java
src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorConstants.java [deleted file]
src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java
src/test/java/org/onap/aai/babel/csar/extractor/YamlExtractorTest.java
src/test/java/org/onap/aai/babel/parser/TestToscaParser.java
src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java
src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java

index 70e78ec..c769e9a 100644 (file)
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
-package org.onap.aai.babel.parser;
 
-import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGFILE_NOT_FOUND;
-import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND;
-import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING;
-import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_MISSING;
+package org.onap.aai.babel.parser;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -33,9 +29,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.stream.Collectors;
-
 import org.onap.aai.babel.logging.LogHelper;
-import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
 import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
 import org.onap.aai.babel.xml.generator.model.AllotedResource;
 import org.onap.aai.babel.xml.generator.model.L3NetworkWidget;
@@ -55,11 +49,26 @@ import org.onap.sdc.toscaparser.api.Property;
 
 public class ArtifactGeneratorToscaParser {
 
-    public static final String GENERATOR_AAI_ERROR_INVALID_ID =
-            "Invalid value for mandatory attribute <%s> in Artifact: <%s>";
+    private static Logger log = LogHelper.INSTANCE;
+
+    public static final String PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE = "artifactgenerator.config";
+
+    private static final String GENERATOR_AAI_CONFIGFILE_NOT_FOUND =
+            "Cannot generate artifacts. Artifact Generator Configuration file not found at %s";
+    private static final String GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND =
+            "Cannot generate artifacts. artifactgenerator.config system property not configured";
+    private static final String GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING =
+            "Cannot generate artifacts. Providing Service Metadata is missing for allotted resource %s";
+    private static final String GENERATOR_AAI_PROVIDING_SERVICE_MISSING =
+            "Cannot generate artifacts. Providing Service is missing for allotted resource %s";
+
+    // Metadata properties
+    private static final String CATEGORY = "category";
     private static final String ALLOTTED_RESOURCE = "Allotted Resource";
+    private static final String SUBCATEGORY = "subcategory";
     private static final String TUNNEL_XCONNECT = "Tunnel XConnect";
-    private static Logger log = LogHelper.INSTANCE;
+
+    private static final String VERSION = "version";
 
     private ISdcCsarHelper csarHelper;
 
@@ -95,7 +104,7 @@ public class ArtifactGeneratorToscaParser {
      */
     public static void initWidgetConfiguration() throws IOException {
         log.debug("Getting Widget Configuration");
-        String configLocation = System.getProperty(GeneratorConstants.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE);
+        String configLocation = System.getProperty(PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE);
         if (configLocation != null) {
             File file = new File(configLocation);
             if (file.exists()) {
@@ -111,7 +120,7 @@ public class ArtifactGeneratorToscaParser {
     }
 
     /**
-     * Generates a Resource List using input Service Node Templates
+     * Generates a Resource List using input Service Node Templates.
      *
      * @param serviceNodes input Service Node Templates
      * @param idTypeStore ID->Type mapping
@@ -254,11 +263,11 @@ public class ArtifactGeneratorToscaParser {
     }
 
     private boolean hasAllottedResource(Map<String, String> metadata) {
-        return ALLOTTED_RESOURCE.equals(metadata.get(GeneratorConstants.CATEGORY));
+        return ALLOTTED_RESOURCE.equals(metadata.get(CATEGORY));
     }
 
     private boolean hasSubCategoryTunnelXConnect(Map<String, String> metadata) {
-        return TUNNEL_XCONNECT.equals(metadata.get(GeneratorConstants.SUBCATEGORY));
+        return TUNNEL_XCONNECT.equals(metadata.get(SUBCATEGORY));
     }
 
     /**
@@ -286,7 +295,7 @@ public class ArtifactGeneratorToscaParser {
                             String.format(GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING, model.getModelId()));
                 }
                 Map<String, String> properties = populateStringProperties(nodeProperties);
-                properties.put(GeneratorConstants.VERSION, "1.0");
+                properties.put(VERSION, "1.0");
                 resourceNode.populateModelIdentificationInformation(properties);
                 model.addResource((Resource) resourceNode);
             } else if (resourceNode instanceof Resource && !(resourceNode.getWidgetType().equals(Widget.Type.L3_NET))) {
index c6ca460..79c7492 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
@@ -26,7 +26,6 @@ import java.nio.file.Path;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import org.apache.commons.io.FileUtils;
 import org.onap.aai.babel.logging.ApplicationMsgs;
 import org.onap.aai.babel.logging.LogHelper;
@@ -35,7 +34,6 @@ 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;
 import org.onap.aai.babel.xml.generator.data.GenerationData;
-import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
 import org.onap.aai.babel.xml.generator.data.GeneratorUtil;
 import org.onap.aai.babel.xml.generator.data.GroupType;
 import org.onap.aai.babel.xml.generator.model.Model;
@@ -49,10 +47,16 @@ import org.slf4j.MDC;
 
 public class AaiArtifactGenerator implements ArtifactGenerator {
 
-    private static final String ARTIFACT_MODEL_INFO = "ARTIFACT_MODEL_INFO";
-
     private static Logger log = LogHelper.INSTANCE;
 
+    private static final String MDC_PARAM_MODEL_INFO = "ARTIFACT_MODEL_INFO";
+    private static final String GENERATOR_AAI_GENERATED_ARTIFACT_EXTENSION = "xml";
+    private static final String GENERATOR_AAI_ERROR_MISSING_SERVICE_TOSCA = "Service tosca missing from list of input artifacts";
+    private static final String GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION = "Cannot generate artifacts. Service version is not specified";
+    private static final String GENERATOR_AAI_INVALID_SERVICE_VERSION = "Cannot generate artifacts. Service version is incorrect";
+
+    private AaiModelGenerator modelGenerator = new AaiModelGeneratorImpl();
+
     @Override
     public GenerationData generateArtifact(byte[] csarArchive, List<Artifact> input,
             Map<String, String> additionalParams) {
@@ -65,15 +69,14 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
 
             path = createTempFile(csarArchive);
             if (path != null) {
-                ISdcCsarHelper csarHelper =
-                        SdcToscaParserFactory.getInstance().getSdcCsarHelper(path.toAbsolutePath().toString());
+                ISdcCsarHelper csarHelper = SdcToscaParserFactory.getInstance()
+                        .getSdcCsarHelper(path.toAbsolutePath().toString());
 
-                List<NodeTemplate> serviceNodes =
-                        csarHelper.getServiceNodeTemplates();
+                List<NodeTemplate> serviceNodes = csarHelper.getServiceNodeTemplates();
                 Map<String, String> serviceMetaData = csarHelper.getServiceMetadataAllProperties();
 
                 if (serviceNodes == null) {
-                    throw new IllegalArgumentException(GeneratorConstants.GENERATOR_AAI_ERROR_MISSING_SERVICE_TOSCA);
+                    throw new IllegalArgumentException(GENERATOR_AAI_ERROR_MISSING_SERVICE_TOSCA);
                 }
 
                 // Populate basic service model metadata
@@ -91,15 +94,13 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
                 // Process the resource TOSCA files
                 List<Resource> resources = parser.processResourceToscas(serviceNodes, idTypeStore);
 
-                // Generate AAI XML service model
-                AaiModelGenerator modelGenerator = AaiModelGenerator.getInstance();
-                MDC.put(ARTIFACT_MODEL_INFO, serviceModel.getModelName() + "," + getArtifactLabel(serviceModel));
+                MDC.put(MDC_PARAM_MODEL_INFO, serviceModel.getModelName() + "," + getArtifactLabel(serviceModel));
                 String aaiServiceModel = modelGenerator.generateModelFor(serviceModel);
                 generationData.add(getServiceArtifact(serviceModel, aaiServiceModel));
 
                 // Generate AAI XML resource model
                 for (Resource res : resources) {
-                    MDC.put(ARTIFACT_MODEL_INFO, res.getModelName() + "," + getArtifactLabel(res));
+                    MDC.put(MDC_PARAM_MODEL_INFO, res.getModelName() + "," + getArtifactLabel(res));
                     String aaiResourceModel = modelGenerator.generateModelFor(res);
                     generationData.add(getResourceArtifact(res, aaiResourceModel));
 
@@ -149,7 +150,8 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
     /**
      * Method to generate the artifact name for an AAI model.
      *
-     * @param model AAI artifact model
+     * @param model
+     *            AAI artifact model
      * @return Model artifact name
      */
     private String getArtifactName(Model model) {
@@ -165,15 +167,17 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
         artifactName.append(model.getModelVersion());
 
         artifactName.append(".");
-        artifactName.append(GeneratorConstants.GENERATOR_AAI_GENERATED_ARTIFACT_EXTENSION);
+        artifactName.append(GENERATOR_AAI_GENERATED_ARTIFACT_EXTENSION);
         return artifactName.toString();
     }
 
     /**
      * Create Resource artifact model from the AAI xml model string.
      *
-     * @param resourceModel Model of the resource artifact
-     * @param aaiResourceModel AAI model as string
+     * @param resourceModel
+     *            Model of the resource artifact
+     * @param aaiResourceModel
+     *            AAI model as string
      * @return Generated {@link Artifact} model for the resource
      */
     private Artifact getResourceArtifact(Model resourceModel, String aaiResourceModel) {
@@ -191,8 +195,10 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
     /**
      * Create Service artifact model from the AAI xml model string.
      *
-     * @param serviceModel Model of the service artifact
-     * @param aaiServiceModel AAI model as string
+     * @param serviceModel
+     *            Model of the service artifact
+     * @param aaiServiceModel
+     *            AAI model as string
      * @return Generated {@link Artifact} model for the service
      */
     private Artifact getServiceArtifact(Service serviceModel, String aaiServiceModel) {
@@ -227,12 +233,12 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
         String serviceVersion;
         serviceVersion = additionalParams.get(AdditionalParams.SERVICE_VERSION.getName());
         if (serviceVersion == null) {
-            throw new IllegalArgumentException(GeneratorConstants.GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION);
+            throw new IllegalArgumentException(GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION);
         } else {
             String versionRegex = "^[1-9]\\d*(\\.0)$";
             if (!(serviceVersion.matches(versionRegex))) {
                 throw new IllegalArgumentException(
-                        String.format(GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION));
+                        String.format(GENERATOR_AAI_INVALID_SERVICE_VERSION));
             }
         }
         return serviceVersion;
index 409dbc2..daf9d36 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
  */
 package org.onap.aai.babel.xml.generator.api;
 
-import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.ERROR_CATEGORY;
-import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.ERROR_CODE;
-import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.ERROR_DESCRIPTION;
-import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_ERROR_CODE;
-import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_ERROR_SERVICE_INSTANTIATION_FAILED;
-import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_PARTNER_NAME;
-import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.PARTNER_NAME;
-
-import org.onap.aai.babel.logging.ApplicationMsgs;
-import org.onap.aai.babel.logging.LogHelper;
-import org.onap.aai.babel.xml.generator.logging.CategoryLogLevel;
 import org.onap.aai.babel.xml.generator.model.Resource;
 import org.onap.aai.babel.xml.generator.model.Service;
-import org.onap.aai.cl.api.Logger;
-import org.slf4j.MDC;
 
 public interface AaiModelGenerator {
 
-    /**
-     * Gets instance.
-     *
-     * @return the instance
-     */
-    public static AaiModelGenerator getInstance() {
-        Logger log = LogHelper.INSTANCE;
-        try {
-            return AaiModelGenerator.class
-                    .cast(Class.forName("org.onap.aai.babel.xml.generator.api.AaiModelGeneratorImpl").newInstance());
-        } catch (Exception exception) {
-            MDC.put(PARTNER_NAME, GENERATOR_PARTNER_NAME);
-            MDC.put(ERROR_CATEGORY, CategoryLogLevel.ERROR.name());
-            MDC.put(ERROR_CODE, GENERATOR_ERROR_CODE);
-            MDC.put(ERROR_DESCRIPTION, GENERATOR_ERROR_SERVICE_INSTANTIATION_FAILED);
-            log.error(ApplicationMsgs.PROCESS_REQUEST_ERROR, exception);
-        }
-        return null;
-    }
-
     public String generateModelFor(Service service);
 
     public String generateModelFor(Resource resource);
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorConstants.java b/src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorConstants.java
deleted file mode 100644 (file)
index b9d8cb2..0000000
+++ /dev/null
@@ -1,92 +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.data;
-
-public class GeneratorConstants {
-
-    /*
-     * Private constructor to prevent instantiation
-     */
-    private GeneratorConstants() {
-        throw new UnsupportedOperationException("This static class should not be instantiated!");
-    }
-
-    public static final String PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE = "artifactgenerator.config";
-
-    public static final String VERSION = "version";
-    public static final String CATEGORY = "category";
-    public static final String SUBCATEGORY = "subcategory";
-    public static final int ID_LENGTH = 36;
-
-    public static final String GENERATOR_AAI_GENERATED_ARTIFACT_EXTENSION = "xml";
-
-    // Error codes
-    public static final String GENERATOR_INVOCATION_ERROR_CODE = "ARTIFACT_GENERATOR_INVOCATION_ERROR";
-
-    // Error Constants
-    public static final String GENERATOR_ERROR_INVALID_CLIENT_CONFIGURATION = "Invalid Client Configuration";
-    public static final String GENERATOR_ERROR_ARTIFACT_GENERATION_FAILED =
-            "Unable to generate artifacts for the provided input";
-    public static final String GENERATOR_ERROR_SERVICE_INSTANTIATION_FAILED =
-            "Artifact Generation Service Instantiation failed";
-
-    // AAI Generator Error Messages
-    public static final String GENERATOR_AAI_ERROR_CHECKSUM_MISMATCH = "Checksum Mismatch for file : %s";
-    public static final String GENERATOR_AAI_ERROR_INVALID_TOSCA = "Invalid format for Tosca YML  : %s";
-    public static final String GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION = "Operation Not Supported for Widgets";
-    public static final String GENERATOR_AAI_ERROR_MISSING_SERVICE_TOSCA =
-            "Service tosca missing from list of input artifacts";
-    public static final String GENERATOR_AAI_ERROR_NULL_RESOURCE_VERSION_IN_SERVICE_TOSCA =
-            "Invalid Service definition mandatory attribute version missing for resource with UUID: <%s>";
-
-    public static final String GENERATOR_AAI_ERROR_INVALID_RESOURCE_VERSION_IN_SERVICE_TOSCA =
-            "Cannot generate artifacts. Invalid Resource version in Service tosca for resource with " + "UUID: "
-                    + "<%s>";
-    public static final String GENERATOR_AAI_ERROR_MISSING_RESOURCE_TOSCA =
-            "Cannot generate artifacts. Resource Tosca missing for resource with UUID: <%s>";
-
-    public static final String GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION =
-            "Cannot generate artifacts. Service version is not specified";
-
-    public static final String GENERATOR_AAI_INVALID_SERVICE_VERSION =
-            "Cannot generate artifacts. Service version is incorrect";
-
-    // Logging constants
-    public static final String PARTNER_NAME = "userId";
-    public static final String ERROR_CATEGORY = "ErrorCategory";
-    public static final String ERROR_CODE = "ErrorCode";
-    public static final String ERROR_DESCRIPTION = "ErrorDescription";
-
-    public static final String GENERATOR_ERROR_CODE = "300F";
-    public static final String GENERATOR_PARTNER_NAME = "SDC Catalog";
-
-    // AAI Generator Error Messages for Logging
-    public static final String GENERATOR_AAI_CONFIGFILE_NOT_FOUND =
-            "Cannot generate artifacts. Artifact Generator Configuration file not found at %s";
-    public static final String GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND =
-            "Cannot generate artifacts. artifactgenerator.config system property not configured";
-    public static final String GENERATOR_AAI_CONFIGLPROP_NOT_FOUND =
-            "Cannot generate artifacts. Widget configuration not found for %s";
-    public static final String GENERATOR_AAI_PROVIDING_SERVICE_MISSING =
-            "Cannot generate artifacts. Providing Service is missing for allotted resource %s";
-    public static final String GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING =
-            "Cannot generate artifacts. Providing Service Metadata is missing for allotted resource %s";
-}
index 0a8f0b1..0ee0838 100644 (file)
@@ -24,12 +24,12 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
 import org.onap.aai.babel.xml.generator.error.IllegalAccessException;
 import org.onap.aai.babel.xml.generator.types.Cardinality;
 import org.onap.aai.babel.xml.generator.types.ModelType;
 
 public abstract class Model {
+    public static final String GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION = "Operation Not Supported for Widgets";
 
     protected Set<Resource> resources = new HashSet<>();
     protected Set<Widget> widgets = new HashSet<>();
@@ -242,7 +242,7 @@ public abstract class Model {
 
     private void checkSupported() {
         if (this instanceof Widget) {
-            throw new IllegalAccessException(GeneratorConstants.GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
+            throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
         }
     }
 }
index 2a85e27..be58844 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
  */
 package org.onap.aai.babel.xml.generator.model;
 
-import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGLPROP_NOT_FOUND;
-
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Properties;
 import java.util.Set;
 import org.onap.aai.babel.xml.generator.data.ArtifactType;
-import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
 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;
@@ -36,16 +33,22 @@ import org.onap.aai.babel.xml.generator.types.ModelWidget;
 
 public abstract 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;
+    }
+
     private Set<String> keys = new HashSet<>();
 
     /**
      * Gets widget.
      *
-     * @param type the type
+     * @param type
+     *            the type
      * @return the widget
      */
     public static Widget getWidget(Type type) {
-
         switch (type) {
             case SERVICE:
                 return new ServiceWidget();
@@ -82,11 +85,6 @@ public abstract class Widget extends Model {
         }
     }
 
-    /**
-     * Gets id.
-     *
-     * @return the id
-     */
     public String getId() {
         Properties properties = WidgetConfigurationUtil.getConfig();
         String id = properties.getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
@@ -136,7 +134,8 @@ public abstract class Widget extends Model {
     /**
      * Equals.
      *
-     * @param obj Object
+     * @param obj
+     *            Object
      * @return the boolean
      */
     @Override
@@ -159,7 +158,8 @@ public abstract class Widget extends Model {
     /**
      * Member of boolean.
      *
-     * @param keys the keys
+     * @param keys
+     *            the keys
      * @return the boolean
      */
     public boolean memberOf(List<String> keys) {
@@ -172,7 +172,8 @@ public abstract class Widget extends Model {
     /**
      * All instances used boolean.
      *
-     * @param collection the collection
+     * @param collection
+     *            the collection
      * @return the boolean
      */
     public boolean allInstancesUsed(Set<String> collection) {
@@ -183,7 +184,7 @@ public abstract class Widget extends Model {
 
     @Override
     public boolean addResource(Resource resource) {
-        throw new IllegalAccessException(GeneratorConstants.GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
+        throw new IllegalAccessException(Model.GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
     }
 
     @Override
@@ -191,21 +192,4 @@ public abstract class Widget extends Model {
         return true;
     }
 
-    public enum Type {
-        SERVICE,
-        VF,
-        VFC,
-        VSERVER,
-        VOLUME,
-        FLAVOR,
-        TENANT,
-        VOLUME_GROUP,
-        LINT,
-        L3_NET,
-        VFMODULE,
-        IMAGE,
-        OAM_NETWORK,
-        ALLOTTED_RESOURCE,
-        TUNNEL_XCONNECT
-    }
 }
index b53f38d..f783e7c 100644 (file)
@@ -129,7 +129,7 @@ public class YamlExtractorTest {
         try {
             new YamlExtractor().extract(archive, name, version);
             fail("An instance of InvalidArchiveException should have been thrown");
-        } catch (Exception ex) {
+        } catch (InvalidArchiveException ex) {
             assertTrue(ex instanceof InvalidArchiveException);
             assertEquals(expectedErrorMessage, ex.getLocalizedMessage());
         }
index d27396d..a73e64c 100644 (file)
@@ -40,7 +40,6 @@ 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;
-import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
 import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
 
 /**
@@ -54,10 +53,12 @@ public class TestToscaParser {
         }
     }
 
+    private static final String ARTIFACT_GENERATOR_CONFIG = "artifact-generator.properties";
+
     @Before
     public void setup() throws FileNotFoundException, IOException {
-        System.setProperty(GeneratorConstants.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
-                new ArtifactTestUtils().getResourcePath("artifact-generator.properties"));
+        System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
+                new ArtifactTestUtils().getResourcePath(ARTIFACT_GENERATOR_CONFIG));
         InputStream in = TestToscaParser.class.getClassLoader().getResourceAsStream("artifact-generator.properties");
         Properties properties = new Properties();
         properties.load(in);
index 0bc7c31..0d6c7b3 100644 (file)
@@ -37,10 +37,10 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.onap.aai.babel.csar.CsarConverterException;
 import org.onap.aai.babel.csar.CsarToXmlConverter;
+import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
 import org.onap.aai.babel.service.data.BabelArtifact;
 import org.onap.aai.babel.util.ArtifactTestUtils;
 import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
-import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
 
 /**
  * Tests {@link CsarToXmlConverter}
@@ -84,7 +84,7 @@ public class CsarToXmlConverterTest {
 
     @Before
     public void setup() {
-        System.setProperty(GeneratorConstants.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
+        System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
                 new ArtifactTestUtils().getResourcePath(ARTIFACT_GENERATOR_CONFIG));
         converter = new CsarToXmlConverter();
     }
@@ -126,7 +126,7 @@ public class CsarToXmlConverterTest {
         exception.expectMessage("Cannot generate artifacts. artifactgenerator.config system property not configured");
 
         // Unset the required system property
-        System.clearProperty(GeneratorConstants.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE);
+        System.clearProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE);
         converter.generateXmlFromCsar(CsarTest.VALID_CSAR_FILE.getContent(), CsarTest.VALID_CSAR_FILE.getName(),
                 SERVICE_VERSION);
     }
index 4cc8c8c..b5063dd 100644 (file)
@@ -41,8 +41,8 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mockito;
 import org.onap.aai.auth.AAIMicroServiceAuth;
+import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
 import org.onap.aai.babel.util.ArtifactTestUtils;
-import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -52,7 +52,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  *
  */
 @RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { "classpath:/babel-beans.xml" })
+@ContextConfiguration(locations = {"classpath:/babel-beans.xml"})
 public class TestGenerateArtifactsServiceImpl {
 
     static {
@@ -62,13 +62,14 @@ public class TestGenerateArtifactsServiceImpl {
         System.setProperty("CONFIG_HOME", "src/test/resources");
     }
 
+    private static final String ARTIFACT_GENERATOR_CONFIG = "artifact-generator.properties";
     @Inject
     private AAIMicroServiceAuth auth;
 
     @BeforeClass
     public static void setup() {
-        System.setProperty(GeneratorConstants.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
-                new ArtifactTestUtils().getResourcePath("artifact-generator.properties"));
+        System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
+                new ArtifactTestUtils().getResourcePath(ARTIFACT_GENERATOR_CONFIG));
     }
 
     @Test
@@ -109,8 +110,7 @@ public class TestGenerateArtifactsServiceImpl {
     /**
      * Create a (mocked) HTTPS request and invoke the Babel generate artifacts API
      *
-     * @param resource
-     *            path to the incoming JSON request
+     * @param resource path to the incoming JSON request
      * @return the Response from the HTTP API
      * @throws URISyntaxException
      * @throws IOException
@@ -144,7 +144,7 @@ public class TestGenerateArtifactsServiceImpl {
         Mockito.when(mockCertificate.getSubjectX500Principal())
                 .thenReturn(new X500Principal("CN=test, OU=qa, O=Test Ltd, L=London, ST=London, C=GB"));
 
-        servletRequest.setAttribute("javax.servlet.request.X509Certificate", new X509Certificate[] { mockCertificate });
+        servletRequest.setAttribute("javax.servlet.request.X509Certificate", new X509Certificate[] {mockCertificate});
         servletRequest.setAttribute("javax.servlet.request.cipher_suite", "");
 
         GenerateArtifactsServiceImpl service = new GenerateArtifactsServiceImpl(auth);
@@ -156,10 +156,6 @@ public class TestGenerateArtifactsServiceImpl {
         return new ArtifactTestUtils().getRequestJson(resource);
     }
 
-    private String getResponseJson(String jsonResponse) throws IOException, URISyntaxException {
-        return new ArtifactTestUtils().getResponseJson(jsonResponse);
-    }
-
     private List<String> createSingletonList(String listItem) {
         return Collections.<String>singletonList(listItem);
     }