aboutsummaryrefslogtreecommitdiffstats
path: root/pnfsimulator/src
diff options
context:
space:
mode:
Diffstat (limited to 'pnfsimulator/src')
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/event/EventData.java13
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java34
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java2
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/KeywordsHandler.java10
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/KeywordsHandlerException.java28
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java45
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/template/FsToDbTemplateSynchronizer.java14
-rw-r--r--pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/keywords/TwoParameterKeywordTest.java48
8 files changed, 118 insertions, 76 deletions
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/event/EventData.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/event/EventData.java
index 23b1c21..ff85367 100644
--- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/event/EventData.java
+++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/event/EventData.java
@@ -24,12 +24,14 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
+import lombok.ToString;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Field;
@Builder
@Getter
@Setter
+@ToString(exclude = "incrementValue")
public class EventData {
@Id
private String id;
@@ -62,15 +64,4 @@ public class EventData {
this.keywords = keywords;
this.incrementValue = incrementValue;
}
-
- @Override
- public String toString() {
- return "EventData{"
- + "id='" + id + '\''
- + ", template='" + template + '\''
- + ", patched='" + patched + '\''
- + ", input='" + input + '\''
- + ", keywords='" + keywords + '\''
- + '}';
- }
}
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java
index 3647ecc..023b163 100644
--- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java
+++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java
@@ -94,16 +94,20 @@ public class SimulatorController {
this.eventDataService = eventDataService;
}
+ /**
+ * @deprecated
+ */
@PostMapping("test")
@Deprecated
- public ResponseEntity test(@Valid @RequestBody SimulatorRequest simulatorRequest) {
+ public ResponseEntity<Map<String,Object>> test(@Valid @RequestBody SimulatorRequest simulatorRequest) {
MDC.put("test", "test");
- LOGGER.info(ENTRY, simulatorRequest.toString());
+ String simulatorRequestString = simulatorRequest.toString();
+ LOGGER.info(ENTRY, simulatorRequestString);
return buildResponse(OK, ImmutableMap.of(MESSAGE, "message1234"));
}
@PostMapping(value = "start")
- public ResponseEntity start(@RequestHeader HttpHeaders headers,
+ public ResponseEntity<Map<String,Object>> start(@RequestHeader HttpHeaders headers,
@Valid @RequestBody SimulatorRequest triggerEventRequest) {
logContextHeaders(headers, "/simulator/start");
LOGGER.info(ENTRY, "Simulator started");
@@ -138,9 +142,12 @@ public class SimulatorController {
}
}
+ /**
+ * @deprecated
+ */
@GetMapping("all-events")
@Deprecated
- public ResponseEntity allEvents() {
+ public ResponseEntity<Map<String,Object>> allEvents() {
List<EventData> eventDataList = eventDataService.getAllEvents();
StringBuilder sb = new StringBuilder();
eventDataList.forEach(e -> sb.append(e).append(System.lineSeparator()));
@@ -151,33 +158,34 @@ public class SimulatorController {
}
@GetMapping("config")
- public ResponseEntity getConfig() {
+ public ResponseEntity<Map<String,Object>> getConfig() {
SimulatorConfig configToGet = simulatorService.getConfiguration();
return buildResponse(OK, ImmutableMap.of("simulatorConfig", configToGet));
}
@PutMapping("config")
- public ResponseEntity updateConfig(@Valid @RequestBody SimulatorConfig newConfig) {
+ public ResponseEntity<Map<String,Object>> updateConfig(@Valid @RequestBody SimulatorConfig newConfig) {
SimulatorConfig updatedConfig = simulatorService.updateConfiguration(newConfig);
return buildResponse(OK, ImmutableMap.of("simulatorConfig", updatedConfig));
}
@PostMapping("cancel/{jobName}")
- public ResponseEntity cancelEvent(@PathVariable String jobName) throws SchedulerException {
- LOGGER.info(ENTRY, "Cancel called on {}.", replaceBreakingCharacters(jobName));
+ public ResponseEntity<Map<String,Object>> cancelEvent(@PathVariable String jobName) throws SchedulerException {
+ String jobNameNoBreakingCharacters = replaceBreakingCharacters(jobName);
+ LOGGER.info(ENTRY, "Cancel called on {}.", jobNameNoBreakingCharacters);
boolean isCancelled = simulatorService.cancelEvent(jobName);
return createCancelEventResponse(isCancelled);
}
@PostMapping("cancel")
- public ResponseEntity cancelAllEvent() throws SchedulerException {
+ public ResponseEntity<Map<String,Object>> cancelAllEvent() throws SchedulerException {
LOGGER.info(ENTRY, "Cancel called on all jobs");
boolean isCancelled = simulatorService.cancelAllEvents();
return createCancelEventResponse(isCancelled);
}
@PostMapping("event")
- public ResponseEntity sendEventDirectly(@RequestHeader HttpHeaders headers, @Valid @RequestBody FullEvent event)
+ public ResponseEntity<Map<String,Object>> sendEventDirectly(@RequestHeader HttpHeaders headers, @Valid @RequestBody FullEvent event)
throws IOException, GeneralSecurityException {
logContextHeaders(headers, "/simulator/event");
LOGGER.info(ENTRY, "Trying to send one-time event directly to VES Collector");
@@ -189,7 +197,7 @@ public class SimulatorController {
return jobName.replaceAll(BREAKING_CHARACTER_REGEX, "_");
}
- private ResponseEntity processRequest(SimulatorRequest triggerEventRequest)
+ private ResponseEntity<Map<String,Object>> processRequest(SimulatorRequest triggerEventRequest)
throws IOException, SchedulerException, GeneralSecurityException {
String jobName = simulatorService.triggerEvent(triggerEventRequest);
@@ -197,7 +205,7 @@ public class SimulatorController {
return buildResponse(OK, ImmutableMap.of(MESSAGE, "Request started", "jobName", jobName));
}
- private ResponseEntity buildResponse(HttpStatus endStatus, Map<String, Object> parameters) {
+ private ResponseEntity<Map<String,Object>> buildResponse(HttpStatus endStatus, Map<String, Object> parameters) {
ResponseBuilder builder = ResponseBuilder
.status(endStatus)
.put(TIMESTAMP, DateUtil.getTimestamp(responseDateFormat));
@@ -212,7 +220,7 @@ public class SimulatorController {
MDC.put(SERVICE_NAME, serviceName);
}
- private ResponseEntity createCancelEventResponse(boolean isCancelled) {
+ private ResponseEntity<Map<String,Object>> createCancelEventResponse(boolean isCancelled) {
if (isCancelled) {
return buildResponse(OK, ImmutableMap.of(MESSAGE, "Event(s) was cancelled"));
} else {
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java
index 5fca25a..1fdd7cf 100644
--- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java
+++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java
@@ -50,7 +50,7 @@ public class ResponseBuilder {
return this;
}
- public ResponseEntity build() {
+ public ResponseEntity<Map<String,Object>> build() {
if (body.isEmpty()) {
return ResponseEntity.status(httpStatus).build();
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/KeywordsHandler.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/KeywordsHandler.java
index 51e0c1f..ac80647 100644
--- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/KeywordsHandler.java
+++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/KeywordsHandler.java
@@ -24,9 +24,11 @@ import com.google.gson.JsonElement;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
+
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
+
import org.springframework.stereotype.Component;
@Component
@@ -43,14 +45,14 @@ public class KeywordsHandler {
public JsonElement substituteKeywords(JsonElement jsonBody, String jobId) {
int counter = incrementProvider.getAndIncrement(jobId);
try (
- JsonReader reader = new JsonReader(new StringReader(jsonBody.toString()));
- StringWriter stringWriter = new StringWriter();
- JsonWriter jsonWriter = new JsonWriter(stringWriter);
+ JsonReader reader = new JsonReader(new StringReader(jsonBody.toString()));
+ StringWriter stringWriter = new StringWriter();
+ JsonWriter jsonWriter = new JsonWriter(stringWriter);
) {
modify(reader, jsonWriter, counter);
return new Gson().fromJson(stringWriter.getBuffer().toString(), JsonElement.class);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new KeywordsHandlerException(e);
}
}
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/KeywordsHandlerException.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/KeywordsHandlerException.java
new file mode 100644
index 0000000..9685bc3
--- /dev/null
+++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/KeywordsHandlerException.java
@@ -0,0 +1,28 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.simulator;
+
+public class KeywordsHandlerException extends RuntimeException {
+
+ public KeywordsHandlerException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java
index ee5fdb7..1887d37 100644
--- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java
+++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java
@@ -20,6 +20,9 @@
package org.onap.pnfsimulator.simulator.client.utils.ssl;
import java.io.Serializable;
+
+import lombok.Getter;
+import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Primary;
@@ -29,6 +32,8 @@ import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "ssl")
@RefreshScope
@Primary
+@Getter
+@Setter
public class SslAuthenticationHelper implements Serializable {
private boolean clientCertificateEnabled;
@@ -36,44 +41,4 @@ public class SslAuthenticationHelper implements Serializable {
private String clientCertificatePassword;
private String trustStoreDir;
private String trustStorePassword;
-
- public boolean isClientCertificateEnabled() {
- return clientCertificateEnabled;
- }
-
- public void setClientCertificateEnabled(boolean clientCertificateEnabled) {
- this.clientCertificateEnabled = clientCertificateEnabled;
- }
-
- public String getClientCertificateDir() {
- return clientCertificateDir;
- }
-
- public void setClientCertificateDir(String clientCertificateDir) {
- this.clientCertificateDir = clientCertificateDir;
- }
-
- public String getClientCertificatePassword() {
- return clientCertificatePassword;
- }
-
- public void setClientCertificatePassword(String clientCertificatePassword) {
- this.clientCertificatePassword = clientCertificatePassword;
- }
-
- public String getTrustStoreDir() {
- return trustStoreDir;
- }
-
- public void setTrustStoreDir(String trustStoreDir) {
- this.trustStoreDir = trustStoreDir;
- }
-
- public String getTrustStorePassword() {
- return trustStorePassword;
- }
-
- public void setTrustStorePassword(String trustStorePassword) {
- this.trustStorePassword = trustStorePassword;
- }
}
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/FsToDbTemplateSynchronizer.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/FsToDbTemplateSynchronizer.java
index 91c5a67..0080813 100644
--- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/FsToDbTemplateSynchronizer.java
+++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/template/FsToDbTemplateSynchronizer.java
@@ -20,12 +20,6 @@
package org.onap.pnfsimulator.template;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.stream.Stream;
-
import org.bson.json.JsonParseException;
import org.onap.pnfsimulator.db.Storage;
import org.onap.pnfsimulator.filesystem.WatcherEventProcessor;
@@ -35,6 +29,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.stream.Stream;
+
@Service
public class FsToDbTemplateSynchronizer {
@@ -66,7 +66,7 @@ public class FsToDbTemplateSynchronizer {
WatcherEventProcessor.MODIFIED.processEvent(path, storage);
} catch (IOException | JsonParseException e) {
LOGGER
- .error("Cannot synchronize template: {}", path.getFileName().toString(), e);
+ .error("Cannot synchronize template: {}", path.getFileName(), e);
}
});
}
diff --git a/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/keywords/TwoParameterKeywordTest.java b/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/keywords/TwoParameterKeywordTest.java
new file mode 100644
index 0000000..6477fbf
--- /dev/null
+++ b/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/keywords/TwoParameterKeywordTest.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Simulator
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.simulator.keywords;
+
+
+import io.vavr.Tuple1;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.Assert.assertEquals;
+
+class TwoParameterKeywordTest {
+ @Test
+ public void whenGivenKeywordShouldReturnTwoParameterKeywordObjectWithParsedValues() {
+ //given
+ final String expectedName = "TEST";
+ final Integer expectedParam1 = 123;
+ final Integer expectedParam2 = 456;
+
+ String keyword = "#" + expectedName + "(" + expectedParam1 + "," + expectedParam2 + ")";
+
+ //when
+ Tuple1<TwoParameterKeyword> keywordTuple = TwoParameterKeyword.twoParameterKeyword(keyword);
+ TwoParameterKeyword twoParameterKeyword = keywordTuple._1();
+
+ //then
+ assertEquals(twoParameterKeyword.getName(), expectedName);
+ assertEquals(twoParameterKeyword.getAdditionalParameter1(), expectedParam1);
+ assertEquals(twoParameterKeyword.getAdditionalParameter2(), expectedParam2);
+ }
+} \ No newline at end of file