* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
* Copyright (C) 2021 Nokia.
+ * Copyright (C) 2021 Samsung Electronics.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
private boolean isCached(String id) {
boolean isPresent = eventsCache.contains(id);
if(isPresent) {
- logger.unwrap().info("Skipping. This event is already waiting in cache to be processed: " + id);
+ logger.unwrap().info("Skipping. This event is already waiting in cache to be processed: {}", id);
}
return isPresent;
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Nokia.
+ * Copyright (C) 2021 Samsung Electronics.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
private static final int DEFAULT_LIMIT_RATE = 1;
private static final String ENV_THREADS_MULTIPLIER = "THREADS_MULTIPLIER";
private static final String ENV_PROCESSING_THREADS_COUNT = "PROCESSING_THREADS_COUNT";
+ private static final String ENV_VARIABLE_INCORRECT_MSG = " environment variable has incorrect value.\n";
private static final int DEFAULT_MULTIPLIER = 1;
private static final ONAPLogAdapter logger = new ONAPLogAdapter(
.orElseGet(this::getDefaultLimitRate);
} catch (NumberFormatException exception) {
throw new EnvironmentConfigException(
- ENV_LIMIT_RATE + " environment variable has incorrect value.\n"
+ ENV_LIMIT_RATE + ENV_VARIABLE_INCORRECT_MSG
, exception);
}
}
private Integer parseIntegerValue(String val) throws NumberFormatException {
Integer value = Integer.valueOf(val);
- logger.unwrap().info(ENV_LIMIT_RATE + " value is: " + value);
+ logger.unwrap().info(ENV_LIMIT_RATE + " value is: {}", value);
return value;
}
.orElseGet(this::getDefaultMultiplier);
} catch (NumberFormatException exception) {
throw new EnvironmentConfigException(
- ENV_THREADS_MULTIPLIER + " environment variable has incorrect value.\n", exception);
+ ENV_THREADS_MULTIPLIER + ENV_VARIABLE_INCORRECT_MSG, exception);
}
}
.orElseGet(this::getDefaultThreadsCount);
} catch (NumberFormatException exception) {
throw new EnvironmentConfigException(
- ENV_PROCESSING_THREADS_COUNT + " environment variable has incorrect value.\n", exception);
+ ENV_PROCESSING_THREADS_COUNT + ENV_VARIABLE_INCORRECT_MSG, exception);
}
}
private int getDefaultThreadsCount() {
int defaultThreadsCount = Runtime.getRuntime().availableProcessors();
logger.unwrap().info(ENV_PROCESSING_THREADS_COUNT +
- " env not present. Setting threads count to available cores: " + defaultThreadsCount);
+ " env not present. Setting threads count to available cores: {}", defaultThreadsCount);
return defaultThreadsCount;
}
}
* -
* * ============LICENSE_START=======================================================
* * Copyright (C) 2019 Nordix Foundation.
+ * * Copyright (C) 2021 Samsung Electronics.
* * ================================================================================
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
/**
* Creates a new server resource with a custom method and endpoint.
+ *
* @param httpMethod Method that the resource should be accessible by.
* @param endpointTemplate Endpoint that the resource should be accessible by.
*/
- public ServerResource(String httpMethod, String endpointTemplate) {
+ protected ServerResource(String httpMethod, String endpointTemplate) {
this.httpMethod = httpMethod;
this.endpointTemplate = endpointTemplate;
}
/**
* Creates a new server resource with a custom endpoint and method 'get'.
+ *
* @param endpointTemplate Endpoint that the resource should be accessible by.
*/
- public ServerResource(String endpointTemplate) {
+ protected ServerResource(String endpointTemplate) {
this.httpMethod = GET_STRING;
this.endpointTemplate = endpointTemplate;
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2021 Samsung Electronics.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
-import java.util.Base64;
import static java.nio.file.Files.readAllBytes;
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2021 Samsung Electronics.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@Override
public MeasFilterConfig read(JsonReader jsonReader) throws IOException {
- JsonElement rootElement = new JsonParser().parse(jsonReader);
+ JsonElement rootElement = JsonParser.parseReader(jsonReader);
if (rootElement.isJsonObject()) {
logger.unwrap().debug("Reading filter as an object.");
return new Gson().fromJson(rootElement, MeasFilterConfig.class);
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2021 Samsung Electronics.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
objUnderTest.handleRequest(httpServerExchange);
verify(eventReceiver, times(1)).receive(any(Event.class));
- assertEquals(logAppender.list.get(0).getMarker().getName(), "ENTRY");
+ assertEquals("ENTRY", logAppender.list.get(0).getMarker().getName());
assertNotNull(logAppender.list.get(0).getMDCPropertyMap().get("InvocationID"));
assertNotNull(logAppender.list.get(0).getMDCPropertyMap().get("RequestID"));
- assertEquals(logAppender.list.get(1).getMarker().getName(), "EXIT");
+ assertEquals("EXIT", logAppender.list.get(1).getMarker().getName());
logAppender.stop();
}
}
\ No newline at end of file
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
* Copyright (C) 2021 Nokia.
+ * Copyright (C) 2021 Samsung Electronics.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import static org.mockito.Mockito.when;
import com.google.gson.Gson;
+
import freemarker.core.Environment;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.onap.dcaegen2.services.pmmapper.model.EventMetadata;
import org.onap.dcaegen2.services.pmmapper.utils.MeasConverter;
import org.powermock.reflect.Whitebox;
+
import utils.ArgumentCreator;
import utils.EventUtils;
private static final Path schema = Paths.get("src/test/resources/mapper_test/CommonEventFormat_30.1-ONAP.json");
private static final Path METADATA_DIRECTORY = Paths.get("src/test/resources/metadata/");
- private static final Path FIFTH_GENERATION_METADATA = Paths.get(METADATA_DIRECTORY.toString()+"/valid_5g_metadata.json");
- private static final Path FOURTH_GENERATION_METADATA = Paths.get(METADATA_DIRECTORY.toString()+"/valid_4g_metadata.json");
+ private static final Path FIFTH_GENERATION_METADATA = Paths.get(METADATA_DIRECTORY.toString() + "/valid_5g_metadata.json");
+ private static final Path FOURTH_GENERATION_METADATA = Paths.get(METADATA_DIRECTORY.toString() + "/valid_4g_metadata.json");
private static final Path TEMPLATES_DIRECTORY = Paths.get("src/main/resources/templates/");
private static final Path dataDirectory = Paths.get("src/test/resources/mapper_test/mapping_data/");
String fourthGenMetadataFileContents = new String(Files.readAllBytes(FOURTH_GENERATION_METADATA));
fourthGenerationMetadata = new Gson().fromJson(fourthGenMetadataFileContents, EventMetadata.class);
String fifthGenMetadataFileContents = new String(Files.readAllBytes(FIFTH_GENERATION_METADATA));
- fifthGenerationMetadata = new Gson().fromJson(fifthGenMetadataFileContents, EventMetadata.class);
+ fifthGenerationMetadata = new Gson().fromJson(fifthGenMetadataFileContents, EventMetadata.class);
converter = new MeasConverter();
}
@Test
void testFailureToParseLte() {
- assertThrows(MappingException.class, () ->
- objUnderTest.map(EventUtils.makeMockEvent("not xml", fourthGenerationMetadata)));
+ assertThrows(MappingException.class, () -> EventUtils.makeMockEvent("not xml", fourthGenerationMetadata));
}
@Test
void testFailureToParseNr() {
- assertThrows(MappingException.class, () ->
- objUnderTest.map(EventUtils.makeMockEvent("not xml", fifthGenerationMetadata)));
+ assertThrows(MappingException.class, () -> EventUtils.makeMockEvent("not xml", fifthGenerationMetadata));
}
@Test
void testInvalidPath() {
- assertThrows(IllegalArgumentException.class, () -> new Mapper(Paths.get("not a path"),converter));
+ Path path = Paths.get("not a path");
+ assertThrows(IllegalArgumentException.class, () -> new Mapper(path, converter));
}
@Test
void testInvalidTemplateDirectory() {
- assertThrows(IllegalArgumentException.class, () -> new Mapper(Paths.get("fake dir"), new MeasConverter()));
+ Path path = Paths.get("fake dir");
+ MeasConverter measConverter = new MeasConverter();
+ assertThrows(IllegalArgumentException.class, () -> new Mapper(path, measConverter));
}
+
@Test
void testTemplateNotFound() {
EventMetadata testMetadata = mock(EventMetadata.class);
@Test
void testNullPath() {
- assertThrows(NullPointerException.class, () -> new Mapper(null,converter));
+ assertThrows(NullPointerException.class, () -> new Mapper(null, converter));
}
@Test
static List<Arguments> getValidEvents() {
ArgumentCreator creator = (Path path, EventMetadata metadata) -> {
- Path testEventPath = Paths.get(path.toString()+"/test.xml");
- Path metadataPath = Paths.get(path.toString()+"/metadata.json");
+ Path testEventPath = Paths.get(path.toString() + "/test.xml");
+ Path metadataPath = Paths.get(path.toString() + "/metadata.json");
EventMetadata eventMetadata = null;
try {
eventMetadata = new Gson().fromJson(new String(Files.readAllBytes(metadataPath)), EventMetadata.class);
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2021 Samsung Electronics.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@Test
void testInvalidConfigObject() throws IOException {
String filter = "{\"filters\": \"invalid\"}";
- assertThrows(JsonSyntaxException.class, () -> objUnderTest.read(new JsonReader(new StringReader(filter))));
+ JsonReader jsonReader = new JsonReader(new StringReader(filter));
+ assertThrows(JsonSyntaxException.class, () -> objUnderTest.read(jsonReader));
}
@Test
void testInvalidConfigString() throws IOException {
- String filter ="\"{\\\"filters\\\": [{\"pmDefVsn\":\\\"V9\\\", \\\"nfType\\\": \\\"NrRadio\\\"," +
+ String filter = "\"{\\\"filters\\\": [{\"pmDefVsn\":\\\"V9\\\", \\\"nfType\\\": \\\"NrRadio\\\"," +
"\\\"vendor\\\": \\\"Ericsson\\\", \\\"measTypes\\\": [\\\"A\\\", \\\"B\\\"]}]}\"";
- assertThrows(JsonSyntaxException.class, () -> objUnderTest.read(new JsonReader(new StringReader(filter))));
+ JsonReader jsonReader = new JsonReader(new StringReader(filter));
+ assertThrows(JsonSyntaxException.class, () -> objUnderTest.read(jsonReader));
}
@Test
void testUnsupportedJSONType() throws IOException {
String filter = "[]";
- assertThrows(UnsupportedOperationException.class, () -> objUnderTest.read(new JsonReader(new StringReader(filter))));
+ JsonReader jsonReader = new JsonReader(new StringReader(filter));
+ assertThrows(UnsupportedOperationException.class, () -> objUnderTest.read(jsonReader));
}
@Test
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
* Copyright (C) 2021 Nokia.
+ * Copyright (C) 2021 Samsung Electronics.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
String result = new RequestSender().send(url);
client.verify(req, VerificationTimes.atLeast(1));
- assertEquals(result, "ResponseBody");
+ assertEquals("ResponseBody", result);
assertTrue(logAppender.list.get(1).getMessage().contains("Sending"));
assertTrue(logAppender.list.get(2).getMessage().contains("Received"));
logAppender.stop();