summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Hansen <tony@att.com>2020-08-05 12:44:31 +0000
committerGerrit Code Review <gerrit@onap.org>2020-08-05 12:44:31 +0000
commit6f07a03be43f84bf251ff8376551d744ac2e646e (patch)
treefa9f2fa5dad89318f384f64361174a5f9c07880f
parent639ba4a3f0bb4fa5334eabc11c3b5e35f19398a2 (diff)
parentf97b7705fa00109530b4e0dfb6c8c52136b6562a (diff)
Merge "Fixed sonar issues"
-rw-r--r--services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceMapper.java3
-rw-r--r--services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidator.java4
-rw-r--r--services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/UrlMapper.java2
-rw-r--r--services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/ValidatorCache.java7
-rw-r--r--services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/FileReaderTest.java8
-rw-r--r--services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/JsonFragmentRetrieverTest.java4
-rw-r--r--services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceJsonGeneratorTest.java4
-rw-r--r--services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceMapperTest.java4
-rw-r--r--services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidatorBuilderTest.java14
-rw-r--r--services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidatorTest.java2
-rw-r--r--services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/UrlMapperTest.java12
11 files changed, 33 insertions, 31 deletions
diff --git a/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceMapper.java b/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceMapper.java
index 79108f01..7963b7cc 100644
--- a/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceMapper.java
+++ b/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceMapper.java
@@ -20,6 +20,7 @@
package org.onap.dcaegen2.services.sdk.services.external.schema.manager.service;
+import org.onap.dcaegen2.services.sdk.services.external.schema.manager.exception.NoLocalReferenceException;
import org.onap.dcaegen2.services.sdk.services.external.schema.manager.model.SchemaReference;
import java.io.File;
@@ -38,7 +39,7 @@ class SchemaReferenceMapper {
return urlMapper;
}
- SchemaReference mapToLocalSchema(SchemaReference schemaReference) {
+ SchemaReference mapToLocalSchema(SchemaReference schemaReference) throws NoLocalReferenceException {
String publicUrl = schemaReference.getUrl();
String localUrl = urlMapper.mapToLocalUrl(publicUrl);
return createLocalSchemaReference(localUrl, schemaReference.getInternalReference());
diff --git a/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidator.java b/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidator.java
index 0b343394..95bb575f 100644
--- a/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidator.java
+++ b/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidator.java
@@ -53,7 +53,7 @@ public class StndDefinedValidator {
* @param event as JsonNode
* @return validation result
* @throws IncorrectInternalFileReferenceException when reference to part of openApi yaml file with schemas is incorrect.
- * @throws NoLocalReferenceException when mapping for public url is not present in schema mapping file.
+ * @throws NoLocalReferenceException when mapping for public url is not present in schema mapping file.
*/
public boolean validate(JsonNode event) throws IncorrectInternalFileReferenceException, NoLocalReferenceException {
boolean validationResult = false;
@@ -65,7 +65,7 @@ public class StndDefinedValidator {
validationResult = true;
} catch (ValidationException ex) {
logger.error(String.valueOf(ex.results()));
- } catch (IOException ex){
+ } catch (IOException ex) {
logger.error("Schema reference has invalid characters", ex);
}
return validationResult;
diff --git a/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/UrlMapper.java b/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/UrlMapper.java
index 06864b31..5edaf460 100644
--- a/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/UrlMapper.java
+++ b/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/UrlMapper.java
@@ -36,7 +36,7 @@ final class UrlMapper {
return Map.copyOf(mappingsCache);
}
- String mapToLocalUrl(String publicUrl) {
+ String mapToLocalUrl(String publicUrl) throws NoLocalReferenceException {
String externalUrl = mappingsCache.get(publicUrl);
if (externalUrl == null) {
throw new NoLocalReferenceException("Couldn't find mapping for public url. PublicURL: " + publicUrl);
diff --git a/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/ValidatorCache.java b/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/ValidatorCache.java
index e67f0ebc..b19768cb 100644
--- a/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/ValidatorCache.java
+++ b/services/external-schema-manager/src/main/java/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/ValidatorCache.java
@@ -21,6 +21,7 @@
package org.onap.dcaegen2.services.sdk.services.external.schema.manager.service;
import com.fasterxml.jackson.databind.JsonNode;
+import org.onap.dcaegen2.services.sdk.services.external.schema.manager.exception.NoLocalReferenceException;
import org.onap.dcaegen2.services.sdk.services.external.schema.manager.model.SchemaReference;
import org.onap.dcaegen2.services.sdk.services.external.schema.manager.exception.IncorrectInternalFileReferenceException;
import org.openapi4j.core.exception.ResolutionException;
@@ -47,7 +48,7 @@ class ValidatorCache {
return schemaReferenceMapper;
}
- synchronized SchemaValidator resolveValidator(JsonNode event, String schemaRefPath) throws IOException {
+ synchronized SchemaValidator resolveValidator(JsonNode event, String schemaRefPath) throws IOException, IncorrectInternalFileReferenceException, NoLocalReferenceException {
SchemaReference schemaReference = resolveSchemaReference(event, schemaRefPath);
schemaReference = schemaReferenceMapper.mapToLocalSchema(schemaReference);
SchemaValidator validator = cache.get(schemaReference.getUrl());
@@ -67,7 +68,7 @@ class ValidatorCache {
return validator != null;
}
- private SchemaValidator createNewValidator(SchemaReference schemaReference) throws IOException {
+ private SchemaValidator createNewValidator(SchemaReference schemaReference) throws IOException, IncorrectInternalFileReferenceException {
logger.info("Creating new stndDefined schema validator");
JsonNode schemaRefNode = SchemaReferenceJsonGenerator.getSchemaReferenceJson(schemaReference);
SchemaValidator schemaValidator = handleValidatorCreation(schemaRefNode);
@@ -75,7 +76,7 @@ class ValidatorCache {
return schemaValidator;
}
- private SchemaValidator handleValidatorCreation(JsonNode schemaNode) {
+ private SchemaValidator handleValidatorCreation(JsonNode schemaNode) throws IncorrectInternalFileReferenceException{
try {
return new SchemaValidator("StndDefinedSchemaValidator", schemaNode);
} catch (ResolutionException e) {
diff --git a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/FileReaderTest.java b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/FileReaderTest.java
index 5d391a69..8f9f54c5 100644
--- a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/FileReaderTest.java
+++ b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/FileReaderTest.java
@@ -31,7 +31,7 @@ class FileReaderTest {
public static final String TEST_RESOURCES = "src/main/test/resources/";
@Test
- public void shouldReturnEmptyStringWhenFileNotFound() {
+ void shouldReturnEmptyStringWhenFileNotFound() {
//given
String expectedContent = "";
String fileName = "dummyFileName";
@@ -44,7 +44,7 @@ class FileReaderTest {
}
@Test
- public void shouldReturnFileContentWhenFileExists() {
+ void shouldReturnFileContentWhenFileExists() {
//given
String expectedContent = "{\n" +
" \"someObject\": \"dummyValue\"\n" +
@@ -59,7 +59,7 @@ class FileReaderTest {
}
@Test
- public void shouldReturnFalseWhenFileDoesNotExist() {
+ void shouldReturnFalseWhenFileDoesNotExist() {
//when
boolean doesFileExists = new FileReader("dummyFileName").doesFileExists();
@@ -68,7 +68,7 @@ class FileReaderTest {
}
@Test
- public void shouldReturnTrueWhenFileExists() {
+ void shouldReturnTrueWhenFileExists() {
//when
boolean doesFileExists = new FileReader(TEST_RESOURCES + "file_with_one_line.json").doesFileExists();
diff --git a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/JsonFragmentRetrieverTest.java b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/JsonFragmentRetrieverTest.java
index f1cae3f5..b5e3df69 100644
--- a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/JsonFragmentRetrieverTest.java
+++ b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/JsonFragmentRetrieverTest.java
@@ -41,7 +41,7 @@ class JsonFragmentRetrieverTest {
private ObjectMapper objectMapper = new ObjectMapper();
@Test
- public void shouldReturnJsonFragmentAtValidPath() throws IOException {
+ void shouldReturnJsonFragmentAtValidPath() throws IOException {
//given
JsonNode jsonContent = objectMapper.readTree(VALID_JSON_CONTENT);
JsonNode expectedJsonNode = objectMapper.readTree("true");
@@ -55,7 +55,7 @@ class JsonFragmentRetrieverTest {
}
@Test
- public void shouldThrowErrorWhenPathDoesNotExistInJsonContent() throws IOException {
+ void shouldThrowErrorWhenPathDoesNotExistInJsonContent() throws IOException {
//given
JsonNode jsonContent = objectMapper.readTree(VALID_JSON_CONTENT);
String dummyPath = "dummyPath";
diff --git a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceJsonGeneratorTest.java b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceJsonGeneratorTest.java
index 42bc21c1..4c8cd189 100644
--- a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceJsonGeneratorTest.java
+++ b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceJsonGeneratorTest.java
@@ -33,7 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
class SchemaReferenceJsonGeneratorTest {
@Test
- public void shouldReturnValidSchemaReferenceWhenUrlIsInValidFormat() throws IOException {
+ void shouldReturnValidSchemaReferenceWhenUrlIsInValidFormat() throws IOException {
//given
String validUrl = "src/main/test/resources/file_with_one_line.json#/elo";
String schemaReferenceContent = "{\"$ref\":\"" + validUrl + "\"}";
@@ -49,7 +49,7 @@ class SchemaReferenceJsonGeneratorTest {
}
@Test
- public void shouldThrowErrorWhenUrlIsInInvalidFormat() {
+ void shouldThrowErrorWhenUrlIsInInvalidFormat() {
//given
String invalidFormatUrl = "\"someDummyValue\n\t";
SchemaReferenceResolver schemaReferenceResolver = new SchemaReferenceResolver(invalidFormatUrl);
diff --git a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceMapperTest.java b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceMapperTest.java
index 1f5ddfb2..1658b51b 100644
--- a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceMapperTest.java
+++ b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/SchemaReferenceMapperTest.java
@@ -30,7 +30,7 @@ class SchemaReferenceMapperTest {
public static final String SCHEMAS_PATH = "src/main/test/resources";
@Test
- public void shouldReturnProperReferenceWhenSchemaReferenceHasNoHash() {
+ void shouldReturnProperReferenceWhenSchemaReferenceHasNoHash() {
//given
SchemaReferenceMapper schemaReferenceMapper = getSchemaReferenceMapper();
String publicUrlWithoutHash = "http://someExternalUrl/external";
@@ -47,7 +47,7 @@ class SchemaReferenceMapperTest {
}
@Test
- public void shouldReturnProperReferenceWhenSchemaReferenceContainsHash() {
+ void shouldReturnProperReferenceWhenSchemaReferenceContainsHash() {
//given
SchemaReferenceMapper schemaReferenceMapper = getSchemaReferenceMapper();
String publicUrlWithHash = "http://someExternalUrl/external#someString";
diff --git a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidatorBuilderTest.java b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidatorBuilderTest.java
index 56631543..5e21be57 100644
--- a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidatorBuilderTest.java
+++ b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidatorBuilderTest.java
@@ -26,7 +26,7 @@ import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
-public class StndDefinedValidatorBuilderTest {
+class StndDefinedValidatorBuilderTest {
private static final String TEST_RESOURCES = "src/main/test/resources/externalRepo/";
@@ -38,7 +38,7 @@ public class StndDefinedValidatorBuilderTest {
Map<String, String> mappingsCache = getMappingsCache(validator);
//then
- assertThat(mappingsCache.size()).isEqualTo(6);
+ assertThat(mappingsCache).hasSize(6);
}
@Test
@@ -48,7 +48,7 @@ public class StndDefinedValidatorBuilderTest {
Map<String, String> mappingsCache = getMappingsCache(validator);
//then
- assertThat(mappingsCache.size()).isEqualTo(5);
+ assertThat(mappingsCache).hasSize(5);
}
@Test
@@ -58,7 +58,7 @@ public class StndDefinedValidatorBuilderTest {
Map<String, String> mappingsCache = getMappingsCache(validator);
//then
- assertThat(mappingsCache.size()).isEqualTo(4);
+ assertThat(mappingsCache).hasSize(4);
}
@Test
@@ -68,7 +68,7 @@ public class StndDefinedValidatorBuilderTest {
Map<String, String> mappingsCache = getMappingsCache(validator);
//then
- assertThat(mappingsCache.size()).isEqualTo(3);
+ assertThat(mappingsCache).hasSize(3);
}
@Test
@@ -78,7 +78,7 @@ public class StndDefinedValidatorBuilderTest {
Map<String, String> mappingsCache = getMappingsCache(validator);
//then
- assertThat(mappingsCache.size()).isEqualTo(0);
+ assertThat(mappingsCache.size()).isZero();
}
@Test
@@ -88,7 +88,7 @@ public class StndDefinedValidatorBuilderTest {
Map<String, String> mappingsCache = getMappingsCache(validator);
//then
- assertThat(mappingsCache.size()).isEqualTo(0);
+ assertThat(mappingsCache.size()).isZero();
}
private StndDefinedValidator getValidator(String mappingFilePath) {
diff --git a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidatorTest.java b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidatorTest.java
index be4bea9d..f53b70c5 100644
--- a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidatorTest.java
+++ b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/StndDefinedValidatorTest.java
@@ -32,7 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-public class StndDefinedValidatorTest {
+class StndDefinedValidatorTest {
private static final String TEST_RESOURCES = "src/main/test/resources/";
private static final String MAPPING_FILE_PATH = TEST_RESOURCES + "externalRepo/schema-map.json";
diff --git a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/UrlMapperTest.java b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/UrlMapperTest.java
index 60214eb8..0031094a 100644
--- a/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/UrlMapperTest.java
+++ b/services/external-schema-manager/src/main/test/org/onap/dcaegen2/services/sdk/services/external/schema/manager/service/UrlMapperTest.java
@@ -40,7 +40,7 @@ class UrlMapperTest {
}
@Test
- public void shouldThrowExceptionWhenNoMappingExists() {
+ void shouldThrowExceptionWhenNoMappingExists() {
//given
String notMappedPublicUrl = "http://localhost:8080/notExisting";
@@ -50,7 +50,7 @@ class UrlMapperTest {
}
@Test
- public void shouldThrowExceptionWhenLocalSchemaFileIsEmpty() {
+ void shouldThrowExceptionWhenLocalSchemaFileIsEmpty() {
//given
String publicUrlToEmptyLocal = "http://someExternalUrl/emptySchema";
@@ -60,7 +60,7 @@ class UrlMapperTest {
}
@Test
- public void shouldThrowExceptionWhenFileHasInvalidYamlStructure() {
+ void shouldThrowExceptionWhenFileHasInvalidYamlStructure() {
//given
String publicUrlToInvalidYamlLocal = "http://someExternalUrl/invalidYamlFile";
@@ -70,7 +70,7 @@ class UrlMapperTest {
}
@Test
- public void shouldThrowExceptionWhenLocalFileDoesNotExist() {
+ void shouldThrowExceptionWhenLocalFileDoesNotExist() {
//given
String publicUrlToNotExistingLocalFile = "http://someExternalUrl/missingFile";
@@ -80,7 +80,7 @@ class UrlMapperTest {
}
@Test
- public void shouldReturnLocalUrlWhenFileValidAndFound() {
+ void shouldReturnLocalUrlWhenFileValidAndFound() {
//given
String publicUrl = "http://someExternalUrl/external";
@@ -90,7 +90,7 @@ class UrlMapperTest {
}
@Test
- public void shouldNotThrowExceptionWhenMappingFileDoesNotExist() {
+ void shouldNotThrowExceptionWhenMappingFileDoesNotExist() {
String invalidMappingFilePath = "src/main/test/resources/missing-schema.json";
Assertions.assertDoesNotThrow(() -> new UrlMapperFactory().getUrlMapper(invalidMappingFilePath, SCHEMAS_PATH));