diff options
author | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-02-05 15:47:47 +0000 |
---|---|---|
committer | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-02-05 16:25:22 +0000 |
commit | 4217e6f7018d08b11291490b3ad5c54064cdc031 (patch) | |
tree | 8d783b6a34582eba9c58776358fec5c8e4ae7b82 /src/test/java/org | |
parent | 1954294aed95c2db4eb2659dcef91248535de079 (diff) |
Fix checkstyle issues including javadoc
Minor code tidy-ups: mostly formatting and Javadoc comments
Change-Id: I8a9ab692428fa09c73bd1fb542100610a86f6eca
Issue-ID: AAI-2121
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/test/java/org')
7 files changed, 86 insertions, 35 deletions
diff --git a/src/test/java/org/onap/aai/babel/MicroServiceAuthTest.java b/src/test/java/org/onap/aai/babel/MicroServiceAuthTest.java index a8f1f92..aae7846 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-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; import static org.hamcrest.CoreMatchers.is; @@ -37,7 +38,7 @@ import org.onap.aai.babel.config.BabelAuthConfig; import org.springframework.mock.web.MockHttpServletRequest; /** - * Tests @{link AAIMicroServiceAuth} + * Tests @{link AAIMicroServiceAuth}. */ public class MicroServiceAuthTest { @@ -54,10 +55,10 @@ 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"); @@ -70,14 +71,17 @@ public class MicroServiceAuthTest { } /** - * 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)); @@ -85,9 +89,10 @@ public class MicroServiceAuthTest { } /** - * 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 { @@ -99,9 +104,10 @@ public class MicroServiceAuthTest { } /** - * 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 { @@ -129,12 +135,17 @@ public class MicroServiceAuthTest { } /** - * @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); @@ -148,11 +159,14 @@ public class MicroServiceAuthTest { } /** - * 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)); diff --git a/src/test/java/org/onap/aai/babel/csar/vnfcatalog/SdcToscaHelper.java b/src/test/java/org/onap/aai/babel/csar/vnfcatalog/SdcToscaHelper.java index 9fcc5a4..6fbb1f1 100644 --- a/src/test/java/org/onap/aai/babel/csar/vnfcatalog/SdcToscaHelper.java +++ b/src/test/java/org/onap/aai/babel/csar/vnfcatalog/SdcToscaHelper.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. @@ -31,7 +31,9 @@ public class SdcToscaHelper { private ArrayList<NodeTemplate> smnodetemplates = new ArrayList<>(); /** - * @return + * Create the test SubstitutionMappings. + * + * @return the new Substitution Mappings */ public SubstitutionMappings buildMappings() { LinkedHashMap<String, Object> defProps = getImagesDefProps(); @@ -78,7 +80,7 @@ public class SdcToscaHelper { } /** - * + * Create a new NodeTemplate and add it to the list (for populating the Substitution Mappings). */ public void addNodeTemplate() { String name = "node name"; @@ -98,7 +100,11 @@ public class SdcToscaHelper { } /** + * 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<>(); 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 f8d8478..348e1a1 100644 --- a/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java +++ b/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.babel.parser; import static org.hamcrest.CoreMatchers.equalTo; @@ -64,8 +65,8 @@ public class TestToscaParser { 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))); } } 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 1ead8e6..bcd1e8a 100644 --- a/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java +++ b/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java @@ -113,9 +113,6 @@ public class CsarToXmlConverterTest { * 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 { @@ -131,13 +128,13 @@ public class CsarToXmlConverterTest { /** * 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"); @@ -195,6 +192,13 @@ public class CsarToXmlConverterTest { 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; 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 d87f3c3..a38686f 100644 --- a/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java +++ b/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java @@ -84,11 +84,14 @@ public class TestGenerateArtifactsServiceImpl { /** * 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"))); @@ -146,6 +149,7 @@ public class TestGenerateArtifactsServiceImpl { * 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 diff --git a/src/test/java/org/onap/aai/babel/testdata/CsarTest.java b/src/test/java/org/onap/aai/babel/testdata/CsarTest.java index 4f4c8ad..8b28551 100644 --- a/src/test/java/org/onap/aai/babel/testdata/CsarTest.java +++ b/src/test/java/org/onap/aai/babel/testdata/CsarTest.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. @@ -66,8 +66,10 @@ public enum CsarTest { * 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"); @@ -77,14 +79,22 @@ public enum CsarTest { * 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()); 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 6608c00..445dd84 100644 --- a/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java +++ b/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java @@ -56,6 +56,9 @@ public class ArtifactTestUtils { 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)); @@ -143,6 +146,15 @@ public class ArtifactTestUtils { 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); |