* @return the generated Artifacts (containing XML models)
* @throws XmlArtifactGenerationException
*/
- private GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper)
+ public GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper)
throws XmlArtifactGenerationException {
List<NodeTemplate> serviceNodeTemplates = csarHelper.getServiceNodeTemplates();
if (serviceNodeTemplates == null) {
* ============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.
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.xml.generator.types;
public enum ModelType {
- SERVICE,
- RESOURCE,
- WIDGET;
+ SERVICE, // top-level model from the CSAR file
+ RESOURCE, // model type for which we generate XML and which may have children
+ WIDGET; // leaf-level type, pre-defined in A&AI
}
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.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.WidgetType;
+import org.onap.aai.babel.xml.generator.types.ModelType;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.toscaparser.api.Group;
import org.onap.sdc.toscaparser.api.NodeTemplate;
/**
* Initialize the Generator with an invalid artifact generator properties file path.
- *
+ *
* @throws IOException
* if an error occurs reading the configuration properties
*/
/**
* Initialize the Generator with an invalid mappings file path.
- *
+ *
* @throws IOException
* if the file content could not be read successfully
*/
/**
* Initialize the Generator with no Widget Mappings content.
- *
+ *
* @throws IOException
* if the file content could not be read successfully
*/
/**
* Initialize the Generator with invalid Widget Mappings content.
- *
+ *
* @throws IOException
* if the file content could not be read successfully
*/
/**
* Initialize the Artifact Generator Widget Mapping config with incomplete data (no type).
- *
+ *
* @throws IOException
* if a WidgetMapping is invalid
*/
/**
* Initialize the Artifact Generator Widget Mapping config with invalid data (type value).
- *
+ *
* @throws IOException
* if a WidgetMapping is invalid
*/
/**
* Initialize the Artifact Generator Widget Mapping config with incomplete data (no widget name).
- *
+ *
* @throws IOException
* if a WidgetMapping is invalid
*/
WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
}
+ /**
+ * Create a Resource with a Widget model type and add this to a Service. Note that there are no test CSAR files
+ * which require this functionality, but the code path exists to support it.
+ *
+ * @throws IOException
+ * if the widget mappings are not loaded
+ * @throws XmlArtifactGenerationException
+ * if there is no configuration defined for the test resource's widget type
+ */
+ @Test
+ public void testAddWidgetToService() throws IOException, XmlArtifactGenerationException {
+ ArtifactTestUtils testUtils = new ArtifactTestUtils();
+ testUtils.loadWidgetMappings();
+ testUtils.loadWidgetToUuidMappings();
+
+ Model serviceModel = new Service();
+ Resource resourceModel = new Resource(WidgetType.valueOf("VF"), false);
+ resourceModel.setModelType(ModelType.WIDGET);
+
+ ISdcCsarHelper helper = Mockito.mock(ISdcCsarHelper.class);
+ ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(helper);
+ parser.addRelatedModel(serviceModel, resourceModel);
+ }
+
/**
* 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
/**
* Tests {@link CsarToXmlConverter}.
*/
-public class CsarToXmlConverterTest {
+public class TestCsarToXmlConverter {
private static final String INCORRECT_CSAR_NAME = "the_name_of_the_csar_file.csar";
private static final String SERVICE_VERSION = "1.0";
/**
* A Matcher for comparing generated XML Strings with expected XML content.
- *
+ *
* @param expected
* the expected XML String
* @return a new Matcher for comparing XML Strings
*/
public class ArtifactTestUtils {
+ public static final String CSAR_INPUTS_FOLDER = "compressedArtifacts/";
private static final String JSON_REQUESTS_FOLDER = "jsonFiles/";
private static final String JSON_RESPONSES_FOLDER = "response/";
- private static final String CSAR_INPUTS_FOLDER = "compressedArtifacts/";
/**
* Initialize System Properties for test configuration files.
/**
* Load the Widget to UUID mappings from the Artifact Generator Properties (resource).
- *
+ *
* @throws IOException
* if the properties file is not loaded
*/
/**
* Load the Widget type mappings (resource).
- *
+ *
* @throws IOException
* if the configuration file is not loaded
*/
/**
* Create Properties from the content of the named resource (e.g. a file on the classpath).
- *
+ *
* @param resourceName
* the resource name
* @return Properties loaded from the named resource
* ============LICENSE_END=========================================================
*/
-package org.onap.aai.babel.parser;
+package org.onap.aai.babel.xml.generator;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.babel.csar.extractor.InvalidArchiveException;
+import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
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.GenerationData;
+import org.onap.aai.babel.xml.generator.model.WidgetType;
+import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
/**
* Direct tests of the {@link AaiArtifactGenerator} to improve code coverage.
*/
-public class TestToscaParser {
+public class TestAaiArtifactGenerator {
+
+ private ArtifactTestUtils testUtils;
@Before
public void setup() {
- new ArtifactTestUtils().setGeneratorSystemProperties();
+ testUtils = new ArtifactTestUtils();
+ testUtils.setGeneratorSystemProperties();
}
@Test
assertThat("Number of resources generated", data.getResultData().size(), is(equalTo(2)));
}
+ /**
+ * Test that an Exception is thrown when a Widget Type (such as ALLOTTED_RESOURCE) required by Babel is not present
+ * in the WidgetType dynamic enumeration.
+ *
+ * @throws SdcToscaParserException
+ * @throws IOException
+ * @throws XmlArtifactGenerationException
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testParserWithIncompleteMappings()
+ throws SdcToscaParserException, IOException, XmlArtifactGenerationException {
+ testUtils.loadWidgetMappings();
+ testUtils.loadWidgetToUuidMappings();
+
+ AaiArtifactGenerator artifactGenerator = new AaiArtifactGenerator();
+ WidgetType.clearElements(); // Remove all WidgetTypes so that the generator fails
+
+ ISdcCsarHelper csarHelper = SdcToscaParserFactory.getInstance()
+ .getSdcCsarHelper(TestAaiArtifactGenerator.class.getClassLoader()
+ .getResource(ArtifactTestUtils.CSAR_INPUTS_FOLDER + CsarTest.VNF_VENDOR_CSAR.getName())
+ .getFile().toString());
+ artifactGenerator.generateAllArtifacts("1.0", csarHelper);
+ }
+
/**
* Invoke the generator with a sample CSAR file.
- *
+ *
* @return the generated AAI Artifacts
* @throws InvalidArchiveException
* if the test CSAR file is invalid
assertMapping("org.openecomp.resource.vfc", "an.unknown.type", WidgetType.valueOf("VSERVER"));
}
+ /**
+ * Test that there is no exception if processing a Model that has no metadata properties.
+ */
+ @Test
+ public void testNullIdentProperties() {
+ createTestModel().populateModelIdentificationInformation(null);
+ }
+
+ /**
+ * Test that an exception occurs if calling code passes an unsupported Widget Type value to the base implementation
+ * of the hasWidgetType() method.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testUnknownWidgetType() {
+ createTestModel().hasWidgetType(null);
+ }
+
+ /**
+ * Create any Model with a valid WidgetType, for method testing.
+ *
+ * @return a valid Model for testing purposes
+ */
+ private Model createTestModel() {
+ return new Resource(WidgetType.valueOf("VSERVER"), false);
+ }
+
/**
* Assert that the TOSCA type String is mapped to the expected Widget Type.
- *
+ *
* @param toscaType
* the TOSCA type or prefix
* @param widgetType
/**
* Assert that the TOSCA metadata type is mapped to the expected Widget Type.
- *
+ *
* @param toscaType
* the name (or name prefix) of the TOSCA type
* @param metadataType