* ============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.
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.auth;
import java.security.cert.X509Certificate;
/**
* @param babelAuthConfig
* @throws AAIAuthException
+ * if the Auth Policy cannot be loaded
*/
@Inject
public AAIMicroServiceAuth(final BabelAuthConfig babelAuthConfig) throws AAIAuthException {
* ============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.
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.logging;
import com.att.eelf.i18n.EELFResourceManager;
public enum ApplicationMsgs implements LogMessageEnum {
- DISTRIBUTION_EVENT,
- MESSAGE_AUDIT,
- MESSAGE_METRIC,
- MISSING_REQUEST_ID,
- PROCESS_REQUEST_ERROR,
- INVALID_CSAR_FILE,
- INVALID_REQUEST_JSON,
- BABEL_REQUEST_PAYLOAD,
- BABEL_RESPONSE_PAYLOAD,
- LOAD_PROPERTIES,
- PROCESSING_VNF_CATALOG_ERROR,
- TEMP_FILE_ERROR,
+ DISTRIBUTION_EVENT, //
+ MESSAGE_AUDIT, //
+ MESSAGE_METRIC, //
+ MISSING_REQUEST_ID, //
+ PROCESS_REQUEST_ERROR, //
+ INVALID_CSAR_FILE, //
+ INVALID_REQUEST_JSON, //
+ BABEL_REQUEST_PAYLOAD, //
+ BABEL_RESPONSE_PAYLOAD, //
+ LOAD_PROPERTIES, //
+ PROCESSING_VNF_CATALOG_ERROR, //
+ TEMP_FILE_ERROR, //
MISSING_SERVICE_METADATA;
static {
* ============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.
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.xml.generator;
import java.util.Base64;
*/
public class ModelGenerator implements ArtifactGenerator {
+
private static final Logger logger = LogHelper.INSTANCE;
private static final String VERSION_DELIMITER = ".";
* Invokes the TOSCA artifact generator API with the input artifacts.
*
* @param csarArchive
- * @param csarArtifacts the input artifacts
+ * @param csarArtifacts
+ * the input artifacts
* @return {@link List} of output artifacts
- * @throws XmlArtifactGenerationException if there is an error trying to generate XML artifacts
+ * @throws XmlArtifactGenerationException
+ * if there is an error trying to generate XML artifacts
*/
@Override
public List<BabelArtifact> generateArtifacts(byte[] csarArchive, List<Artifact> csarArtifacts)
/**
* Creates an instance of an input artifact for the generator.
*
- * @param payload the payload downloaded from SDC
- * @param artifactName name of the artifact to create
- * @param artifactVersion version of the artifact to create
+ * @param payload
+ * the payload downloaded from SDC
+ * @param artifactName
+ * name of the artifact to create
+ * @param artifactVersion
+ * version of the artifact to create
* @return an {@link Artifact} object constructed from the payload and artifactInfo
*/
public static Artifact createArtifact(byte[] payload, String artifactName, String artifactVersion) {
* ============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.
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.xml.generator.api;
import java.io.StringWriter;
/**
* Method to generate the AAI model for a Service.
*
- * @param service Java object model representing an AAI {@link Service} model
+ * @param service
+ * Java object model representing an AAI {@link Service} model
* @return XML representation of the service model in String format
*/
@Override
/**
* Method to generate the AAI model for a Resource.
*
- * @param resource Java object model representing an AAI {@link Resource} model
+ * @param resource
+ * Java object model representing an AAI {@link Resource} model
* @return XML representation of the resource model in String format
*/
@Override
/**
* 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
+ * @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,
* 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
+ * @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) {
/**
* Converts the data delete flag value from boolean to String as per AAI model.
*
- * @param delFlag Boolean value as true/false from the annotation
+ * @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) {
- if (delFlag) {
- return "T";
- } else {
- return "F";
- }
+ 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
+ * @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) {
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.xml.generator.model;
import java.util.Collections;
private Type type;
private boolean deleteFlag;
- private boolean isResource = true;
+ private boolean isResource = true;
private Map<String, Object> properties = Collections.emptyMap();
Widget vserver = null;
public boolean addWidget(Widget widget) {
if (type == Type.VFMODULE) {
if (widget.memberOf(members)) {
- if (vserver == null && widget.getId().equals(new VServerWidget().getId())) {
+ if (vserver == null && widget instanceof VServerWidget) {
addVserverWidget(widget);
- } else if (widget.getId().equals(new LIntfWidget().getId())) {
+ } else if (widget instanceof LIntfWidget) {
return addLIntfWidget(widget);
- } else if (widget.getId().equals(new VolumeWidget().getId())) {
+ } else if (widget instanceof VolumeWidget) {
addVolumeWidget(widget);
return true;
}
- if (widget.getId().equals(new OamNetwork().getId())) {
- return false;
+ if (!(widget instanceof OamNetwork)) {
+ return widgets.add(widget);
}
- return widgets.add(widget);
}
return false;
} else {
}
public String getName() {
- ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
- return widgetModel.name();
+ return this.getClass().getAnnotation(ModelWidget.class).name();
}
/**
* ============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.
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel;
import static org.hamcrest.CoreMatchers.is;
import org.springframework.mock.web.MockHttpServletRequest;
/**
- * Tests @{link AAIMicroServiceAuth}
+ * Tests @{link AAIMicroServiceAuth}.
*/
public class MicroServiceAuthTest {
* of a policy file that does not exist.
*
* @throws AAIAuthException
- * @throws IOException
+ * if the Auth policy file cannot be loaded
*/
@Test(expected = AAIAuthException.class)
- public void missingPolicyFile() throws AAIAuthException, IOException {
+ public void missingPolicyFile() throws AAIAuthException {
String defaultFile = AAIMicroServiceAuthCore.getDefaultAuthFileName();
try {
AAIMicroServiceAuthCore.setDefaultAuthFileName("invalid.default.file");
}
/**
- * Test loading of a temporary file created with the specified roles
+ * Test loading of a temporary file created with the specified roles.
*
* @throws AAIAuthException
+ * if the test creates invalid Auth Policy roles
* @throws IOException
+ * for I/O failures
* @throws JSONException
+ * if this test creates an invalid JSON object
*/
@Test
- public void createLocalAuthFile() throws AAIAuthException, IOException, JSONException {
+ public void createLocalAuthFile() throws JSONException, AAIAuthException, IOException {
JSONObject roles = createRoleObject("role", createUserObject("user"), createFunctionObject("func"));
createAuthService(roles);
assertThat(AAIMicroServiceAuthCore.authorize("nosuchuser", "method:func"), is(false));
}
/**
- * Test that the default policy file is loaded when a non-existent file is passed to the authorisation clas.
+ * Test that the default policy file is loaded when a non-existent file is passed to the authorisation class.
*
* @throws AAIAuthException
+ * if the Auth Policy cannot be loaded
*/
@Test
public void createAuthFromDefaultFile() throws AAIAuthException {
}
/**
- * Test loading of the policy file relative to CONFIG_HOME
+ * Test loading of the policy file relative to CONFIG_HOME.
*
* @throws AAIAuthException
+ * if the Auth Policy cannot be loaded
*/
@Test
public void createAuth() throws AAIAuthException {
}
/**
- * @param rolesJson
- * @return
+ * Create a test Auth policy JSON file and pass this to the Auth Service.
+ *
+ * @param roles
+ * the Auth policy JSON content
+ * @return a new Auth Service configured with the supplied roles
* @throws IOException
+ * for I/O failures
* @throws AAIAuthException
+ * if the auth policy file cannot be loaded
*/
- private AAIMicroServiceAuth createAuthService(JSONObject roles) throws IOException, AAIAuthException {
+ private AAIMicroServiceAuth createAuthService(JSONObject roles) throws AAIAuthException, IOException {
File file = File.createTempFile("auth-policy", "json");
file.deleteOnExit();
FileWriter fileWriter = new FileWriter(file);
}
/**
- * Assert authorisation results for an admin user based on the test policy file
+ * Assert authorisation results for an admin user based on the test policy file.
*
* @param auth
+ * the Auth Service to test
* @param adminUser
+ * admin username
* @throws AAIAuthException
+ * if the Auth Service is not initialized
*/
private void assertAdminUserAuthorisation(AAIMicroServiceAuth auth, String adminUser) throws AAIAuthException {
assertThat(AAIMicroServiceAuthCore.authorize(adminUser, "GET:actions"), is(true));
* ============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.
private ArrayList<NodeTemplate> smnodetemplates = new ArrayList<>();
/**
- * @return
+ * Create the test SubstitutionMappings.
+ *
+ * @return the new Substitution Mappings
*/
public SubstitutionMappings buildMappings() {
LinkedHashMap<String, Object> defProps = getImagesDefProps();
}
/**
- *
+ * Create a new NodeTemplate and add it to the list (for populating the Substitution Mappings).
*/
public void addNodeTemplate() {
String name = "node name";
}
/**
+ * Simulate the creation of a NodeTemplate by the SDC TOSCA parser. Populate the properties of the NodeTemplate with
+ * the supplied images.
+ *
* @param images
+ * the value of the images property
*/
public void addNodeTemplate(Object images) {
LinkedHashMap<String, Object> properties = new LinkedHashMap<>();
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.parser;
import static org.hamcrest.CoreMatchers.equalTo;
GenerationData data =
generator.generateArtifact(CsarTest.VNF_VENDOR_CSAR.getContent(), ymlFiles, additionalParams);
- assertThat(data.getErrorData().size(), is(equalTo(0)));
- assertThat(data.getResultData().size(), is(equalTo(2)));
+ assertThat("Number of errors produced", data.getErrorData().size(), is(equalTo(0)));
+ assertThat("Number of resources generated", data.getResultData().size(), is(equalTo(2)));
}
}
* if there is an error either extracting the YAML files or generating XML artifacts
* @throws IOException
* if an I/O exception occurs loading the test CSAR file
- * @throws IOException
- * @throws XmlArtifactGenerationException
- * @throws CsarConverterException
*/
@Test
public void testArtifactGeneratorConfigMissing() throws CsarConverterException, IOException {
/**
* Test that an Exception is thrown when the Artifact Generator's Group Filter properties are not present.
*
- * @throws IOException
- * @throws XmlArtifactGenerationException
* @throws CsarConverterException
+ * if there is an error either extracting the YAML files or generating XML artifacts
+ * @throws IOException
+ * if an I/O exception occurs
*/
@Test
- public void generateXmlFromCsarFilterTypesSystemPropertyNotSet()
- throws IOException, XmlArtifactGenerationException, CsarConverterException {
+ public void generateXmlFromCsarFilterTypesSystemPropertyNotSet() throws CsarConverterException, IOException {
exception.expect(CsarConverterException.class);
exception.expectMessage("Cannot generate artifacts. System property "
+ ArtifactGeneratorToscaParser.PROPERTY_GROUP_FILTERS_CONFIG_FILE + " not configured");
assertThatGeneratedFilesMatchExpected(createExpectedXmlFiles(filesToLoad), CsarTest.SERVICE_PROXY_CSAR_FILE);
}
+ /**
+ * 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 Matcher<String> matches(final String expected) {
return new BaseMatcher<String>() {
protected String theExpected = expected;
/**
* No VNF Configuration exists.
- *
- * @throws Exception
+ *
+ * @throws URISyntaxException
+ * if the URI cannot be created
+ * @throws IOException
+ * if the resource cannot be loaded
*/
@Test
- public void testGenerateArtifactsWithoutVnfConfiguration() throws Exception {
+ public void testGenerateArtifactsWithoutVnfConfiguration() throws IOException, URISyntaxException {
Response response = processJsonRequest(CsarTest.NO_VNF_CONFIG_CSAR);
assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
assertThat(response.getEntity(), is(getResponseJson("validNoVnfConfigurationResponse.json")));
* Create a (mocked) HTTPS request and invoke the Babel generate artifacts API.
*
* @param csar
+ * test CSAR file
* @return the Response from the HTTP API
* @throws URISyntaxException
* if the URI cannot be created
* ============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.
* Extract YAML Artifacts.
*
* @return the extracted artifacts
- * @throws InvalidArchiveException if the CSAR is invalid
- * @throws IOException for I/O errors
+ * @throws InvalidArchiveException
+ * if the CSAR is invalid
+ * @throws IOException
+ * for I/O errors
*/
public List<Artifact> extractArtifacts() throws InvalidArchiveException, IOException {
return new YamlExtractor().extract(getContent(), getName(), "v1");
* Extract VNF Vendor Image Artifacts.
*
* @return the extracted artifacts
- * @throws IOException
* @throws ToscaToCatalogException
- *
+ * if the CSAR content is not valid
+ * @throws IOException
+ * if an I/O exception occursSince:
*/
public BabelArtifact extractVnfVendorImages() throws ToscaToCatalogException, IOException {
return new VnfVendorImageExtractor().extract(getContent());
}
+ /**
+ * Create a BabelRequest containing the encoded CSAR content.
+ *
+ * @return a new Babel request for this CSAR
+ * @throws IOException
+ * if an I/O exception occurs
+ */
public String getJsonRequest() throws IOException {
BabelRequest request = new BabelRequest();
request.setArtifactName(getName());
private static final String JSON_RESPONSES_FOLDER = "response/";
private static final String CSAR_INPUTS_FOLDER = "compressedArtifacts/";
+ /**
+ * Initialise System Properties for test configuration files.
+ */
public void setGeneratorSystemProperties() {
System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
getResourcePath(Resources.ARTIFACT_GENERATOR_CONFIG));
return Files.lines(Paths.get(getResource(resourceFile).toURI())).collect(Collectors.joining());
}
+ /**
+ * 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
+ * @throws IOException
+ * if an error occurred when reading from the named resource
+ */
public Properties getResourceAsProperties(String resourceName) throws IOException {
final Properties properties = new Properties();
InputStream in = ArtifactTestUtils.class.getClassLoader().getResourceAsStream(resourceName);