aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--netconfsimulator/src/main/java/org/onap/netconfsimulator/Main.java4
-rw-r--r--netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/Message.java (renamed from netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/MessageDTO.java)2
-rw-r--r--netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreController.java4
-rw-r--r--netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java37
-rw-r--r--netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/listener/KafkaListenerEntry.java8
-rw-r--r--netconfsimulator/src/main/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfiguration.java (renamed from netconfsimulator/src/main/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationTO.java)2
-rw-r--r--netconfsimulator/src/main/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationService.java4
-rw-r--r--netconfsimulator/src/main/java/org/onap/netconfsimulator/websocket/NetconfEndpoint.java4
-rw-r--r--netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/EmbeddedKafkaConfig.java11
-rw-r--r--netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/StoreControllerTest.java29
-rw-r--r--netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/StoreServiceTest.java26
-rw-r--r--netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationReaderTest.java2
-rw-r--r--netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationServiceTest.java20
-rw-r--r--netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/model/NetconfModelLoaderServiceTest.java4
-rw-r--r--netconfsimulator/src/test/java/org/onap/netconfsimulator/websocket/NetconfEndpointTest.java12
-rw-r--r--netconfsimulator/src/test/java/org/onap/netconfsimulator/websocket/message/NetconfMessageListenerTest.java2
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/Main.java4
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java22
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/TemplateController.java9
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java2
-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
22 files changed, 165 insertions, 105 deletions
diff --git a/netconfsimulator/src/main/java/org/onap/netconfsimulator/Main.java b/netconfsimulator/src/main/java/org/onap/netconfsimulator/Main.java
index e2a0ed0..1065e71 100644
--- a/netconfsimulator/src/main/java/org/onap/netconfsimulator/Main.java
+++ b/netconfsimulator/src/main/java/org/onap/netconfsimulator/Main.java
@@ -25,7 +25,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Main {
- public static void main(String[] args) {
+ // We are excluding this line in Sonar due to fact that
+ // Spring is handling arguments
+ public static void main(String[] args) { // NOSONAR
SpringApplication.run(Main.class, args);
}
}
diff --git a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/MessageDTO.java b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/Message.java
index 4311cd6..9a7debc 100644
--- a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/MessageDTO.java
+++ b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/Message.java
@@ -25,7 +25,7 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
-class MessageDTO {
+class Message {
private long timestamp;
private String configuration;
}
diff --git a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreController.java b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreController.java
index 2a196d9..d4414ee 100644
--- a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreController.java
+++ b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreController.java
@@ -47,12 +47,12 @@ public class StoreController {
}
@GetMapping("cm-history")
- public List<MessageDTO> getAllConfigurationChanges() {
+ public List<Message> getAllConfigurationChanges() {
return service.getAllMessages();
}
@GetMapping("/less")
- public List<MessageDTO> less(@RequestParam(value = "offset", required = false, defaultValue = "${spring.kafka.default-offset}") long offset) {
+ public List<Message> less(@RequestParam(value = "offset", required = false, defaultValue = "${spring.kafka.default-offset}") long offset) {
return service.getLastMessages(offset);
}
diff --git a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java
index 5fddff5..6bd8390 100644
--- a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java
+++ b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/StoreService.java
@@ -7,9 +7,9 @@
* 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.
@@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.stereotype.Service;
+import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
@@ -48,33 +49,33 @@ public class StoreService {
this.consumerFactory = consumerFactory;
}
- List<MessageDTO> getAllMessages() {
- List<MessageDTO> messages = new ArrayList<>();
- String clientID = Long.toString(Instant.now().getEpochSecond());
- try (Consumer<String, String> consumer = consumerFactory.createConsumer(clientID, clientID)) {
+ List<Message> getAllMessages() {
+ List<Message> messages = new ArrayList<>();
+ String clientId = Long.toString(Instant.now().getEpochSecond());
+ try (Consumer<String, String> consumer = consumerFactory.createConsumer(clientId, clientId)) {
consumer.subscribe(TOPICS_TO_SUBSCRIBE);
- ConsumerRecords<String, String> consumerRecords = consumer.poll(CONSUMING_DURATION_IN_MS);
+ ConsumerRecords<String, String> consumerRecords = pollConsumerRecords(consumer);
consumerRecords.forEach(
consumerRecord ->
- messages.add(new MessageDTO(consumerRecord.timestamp(), consumerRecord.value())));
+ messages.add(new Message(consumerRecord.timestamp(), consumerRecord.value())));
log.debug(String.format("consumed %d messages", consumerRecords.count()));
- }
+ }
return messages;
}
- List<MessageDTO> getLastMessages(long offset) {
- List<MessageDTO> messages = new ArrayList<>();
+ List<Message> getLastMessages(long offset) {
+ List<Message> messages = new ArrayList<>();
try (Consumer<String, String> consumer = createConsumer(offset)) {
- ConsumerRecords<String, String> consumerRecords = consumer.poll(CONSUMING_DURATION_IN_MS);
+ ConsumerRecords<String, String> consumerRecords = pollConsumerRecords(consumer);
consumerRecords.forEach(consumerRecord ->
- messages.add(new MessageDTO(consumerRecord.timestamp(), consumerRecord.value())));
+ messages.add(new Message(consumerRecord.timestamp(), consumerRecord.value())));
}
return messages;
}
private Consumer<String, String> createConsumer(long offsetFromLastIndex) {
- String clientID = Long.toString(Instant.now().getEpochSecond());
- Consumer<String, String> consumer = consumerFactory.createConsumer(clientID, clientID);
+ String clientId = Long.toString(Instant.now().getEpochSecond());
+ Consumer<String, String> consumer = consumerFactory.createConsumer(clientId, clientId);
consumer.subscribe(TOPICS_TO_SUBSCRIBE);
seekConsumerTo(consumer, offsetFromLastIndex);
return consumer;
@@ -82,10 +83,14 @@ public class StoreService {
private void seekConsumerTo(Consumer<String, String> consumer, long offsetFromLastIndex) {
consumer.seekToEnd(consumer.assignment());
- consumer.poll(CONSUMING_DURATION_IN_MS);
+ pollConsumerRecords(consumer);
TopicPartition topicPartition = consumer.assignment().iterator().next();
long topicCurrentSize = consumer.position(topicPartition);
long indexToSeek = offsetFromLastIndex > topicCurrentSize ? 0 : topicCurrentSize - offsetFromLastIndex;
consumer.seek(topicPartition, indexToSeek);
}
+
+ private ConsumerRecords<String, String> pollConsumerRecords(Consumer<String, String> consumer) {
+ return consumer.poll(Duration.ofMillis(CONSUMING_DURATION_IN_MS));
+ }
}
diff --git a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/listener/KafkaListenerEntry.java b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/listener/KafkaListenerEntry.java
index e3c04c9..501d36b 100644
--- a/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/listener/KafkaListenerEntry.java
+++ b/netconfsimulator/src/main/java/org/onap/netconfsimulator/kafka/listener/KafkaListenerEntry.java
@@ -7,9 +7,9 @@
* 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.
@@ -27,9 +27,9 @@ import org.springframework.kafka.listener.AbstractMessageListenerContainer;
public class KafkaListenerEntry {
private String clientId;
- private AbstractMessageListenerContainer listenerContainer;
+ private AbstractMessageListenerContainer<String, String> listenerContainer;
- public KafkaListenerEntry(String clientId, AbstractMessageListenerContainer listenerContainer) {
+ public KafkaListenerEntry(String clientId, AbstractMessageListenerContainer<String, String> listenerContainer) {
this.clientId = clientId;
this.listenerContainer = listenerContainer;
}
diff --git a/netconfsimulator/src/main/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationTO.java b/netconfsimulator/src/main/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfiguration.java
index e43ff69..51f31ae 100644
--- a/netconfsimulator/src/main/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationTO.java
+++ b/netconfsimulator/src/main/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfiguration.java
@@ -25,7 +25,7 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
-public class NetconfConfigurationTO {
+public class NetconfConfiguration {
private String configuration;
diff --git a/netconfsimulator/src/main/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationService.java b/netconfsimulator/src/main/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationService.java
index 248aec4..8f6f0ba 100644
--- a/netconfsimulator/src/main/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationService.java
+++ b/netconfsimulator/src/main/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationService.java
@@ -64,8 +64,8 @@ public class NetconfConfigurationService {
public String editCurrentConfiguration(MultipartFile newConfiguration) throws IOException, JNCException {
Element configurationElement = convertMultipartToXmlElement(newConfiguration);
configurationEditor.editConfig(configurationElement);
-
- LOGGER.debug("Loading new configuration: \n{}", configurationElement.toXMLString());
+ String configurationXmlString = configurationElement.toXMLString();
+ LOGGER.debug("Loading new configuration: \n{}", configurationXmlString);
return CONFIGURATION_HAS_BEEN_ACTIVATED;
}
diff --git a/netconfsimulator/src/main/java/org/onap/netconfsimulator/websocket/NetconfEndpoint.java b/netconfsimulator/src/main/java/org/onap/netconfsimulator/websocket/NetconfEndpoint.java
index 5870ee1..5719214 100644
--- a/netconfsimulator/src/main/java/org/onap/netconfsimulator/websocket/NetconfEndpoint.java
+++ b/netconfsimulator/src/main/java/org/onap/netconfsimulator/websocket/NetconfEndpoint.java
@@ -84,11 +84,11 @@ class NetconfEndpoint extends Endpoint {
private void addKafkaListener(RemoteEndpoint.Basic remoteEndpoint) {
- MessageListener messageListener = new NetconfMessageListener(remoteEndpoint);
+ MessageListener<String, String> messageListener = new NetconfMessageListener(remoteEndpoint);
KafkaListenerEntry kafkaListener = kafkaListenerHandler.createKafkaListener(messageListener, TOPIC_NAME);
- AbstractMessageListenerContainer listenerContainer = kafkaListener.getListenerContainer();
+ AbstractMessageListenerContainer<String,String> listenerContainer = kafkaListener.getListenerContainer();
listenerContainer.start();
entry = Optional.of(kafkaListener);
}
diff --git a/netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/EmbeddedKafkaConfig.java b/netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/EmbeddedKafkaConfig.java
index 5ddf2b2..6d487b2 100644
--- a/netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/EmbeddedKafkaConfig.java
+++ b/netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/EmbeddedKafkaConfig.java
@@ -7,9 +7,9 @@
* 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.
@@ -22,6 +22,7 @@ package org.onap.netconfsimulator.kafka;
import java.util.Map;
+
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -40,20 +41,20 @@ import static org.onap.netconfsimulator.kafka.StoreServiceTest.embeddedKafka;
class EmbeddedKafkaConfig {
@Bean
- KafkaTemplate<String, String> kafkaTemplate(){
+ KafkaTemplate<String, String> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
@Bean
@Autowired
- ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory(ConsumerFactory<String, String> consumerFactory){
+ ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory(ConsumerFactory<String, String> consumerFactory) {
ConcurrentKafkaListenerContainerFactory<String, String> containerFactory = new ConcurrentKafkaListenerContainerFactory<>();
containerFactory.setConsumerFactory(consumerFactory);
return containerFactory;
}
@Bean
- ConsumerFactory<String, String> consumerFactory(){
+ ConsumerFactory<String, String> consumerFactory() {
Map<String, Object> consumerProperties =
KafkaTestUtils.consumerProps("sender", "false", embeddedKafka.getEmbeddedKafka());
consumerProperties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
diff --git a/netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/StoreControllerTest.java b/netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/StoreControllerTest.java
index 02eec12..bd6fd14 100644
--- a/netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/StoreControllerTest.java
+++ b/netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/StoreControllerTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -22,6 +22,7 @@ package org.onap.netconfsimulator.kafka;
import java.time.Instant;
import java.util.List;
+
import org.assertj.core.api.Assertions;
import org.assertj.core.util.Lists;
import org.junit.Test;
@@ -39,9 +40,9 @@ public class StoreControllerTest {
private static final String MESSAGE_2 = "message 2";
private static final String MESSAGE_1 = "message 1";
- private static final List<MessageDTO> ALL_MESSAGES = Lists.newArrayList(new MessageDTO(Instant.now().getEpochSecond(), MESSAGE_1),
- new MessageDTO(Instant.now().getEpochSecond(), MESSAGE_2),
- new MessageDTO(Instant.now().getEpochSecond(), MESSAGE_3));
+ private static final List<Message> ALL_MESSAGES = Lists.newArrayList(new Message(Instant.now().getEpochSecond(), MESSAGE_1),
+ new Message(Instant.now().getEpochSecond(), MESSAGE_2),
+ new Message(Instant.now().getEpochSecond(), MESSAGE_3));
@Mock
private StoreService service;
@@ -54,33 +55,33 @@ public class StoreControllerTest {
public void lessShouldTakeAllMessagesTest() {
when(service.getLastMessages(3)).thenReturn(ALL_MESSAGES);
- List<MessageDTO> lessResponse = storeController.less(3);
+ List<Message> lessResponse = storeController.less(3);
assertResponseContainsExpectedMessages(lessResponse, 3, MESSAGE_1, MESSAGE_2, MESSAGE_3);
}
@Test
public void lessShouldTakeTwoMessagesTest() {
- when(service.getLastMessages(2)).thenReturn(Lists.newArrayList(new MessageDTO(Instant.now().getEpochSecond(), MESSAGE_1)));
+ when(service.getLastMessages(2)).thenReturn(Lists.newArrayList(new Message(Instant.now().getEpochSecond(), MESSAGE_1)));
- List<MessageDTO> lessResult = storeController.less(2);
+ List<Message> lessResult = storeController.less(2);
assertResponseContainsExpectedMessages(lessResult, 1, MESSAGE_1);
}
@Test
- public void shouldGetAllMessages(){
+ public void shouldGetAllMessages() {
when(service.getAllMessages()).thenReturn(ALL_MESSAGES);
- List<MessageDTO> allMsgResult = storeController.getAllConfigurationChanges();
+ List<Message> allMsgResult = storeController.getAllConfigurationChanges();
assertResponseContainsExpectedMessages(allMsgResult, 3, MESSAGE_1, MESSAGE_2, MESSAGE_3);
}
- private void assertResponseContainsExpectedMessages(List<MessageDTO> actualMessages, int expectedMessageCount, String... expectedMessages){
- Assertions.assertThat(actualMessages.stream().map(MessageDTO::getConfiguration))
- .hasSize(expectedMessageCount)
- .containsExactly(expectedMessages);
+ private void assertResponseContainsExpectedMessages(List<Message> actualMessages, int expectedMessageCount, String... expectedMessages) {
+ Assertions.assertThat(actualMessages.stream().map(Message::getConfiguration))
+ .hasSize(expectedMessageCount)
+ .containsExactly(expectedMessages);
}
}
diff --git a/netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/StoreServiceTest.java b/netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/StoreServiceTest.java
index fd36116..fdba959 100644
--- a/netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/StoreServiceTest.java
+++ b/netconfsimulator/src/test/java/org/onap/netconfsimulator/kafka/StoreServiceTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -59,38 +59,38 @@ public class StoreServiceTest {
}
@Test
- public void testShouldReturnAllAvailableMessages(){
+ public void testShouldReturnAllAvailableMessages() {
- List<MessageDTO> actualMessages = service.getAllMessages();
+ List<Message> actualMessages = service.getAllMessages();
assertResponseContainsExpectedMessages(actualMessages, 3, MESSAGE_1, MESSAGE_2, MESSAGE_3);
}
@Test
- public void testShouldGetLastMessagesRespectingOffset(){
+ public void testShouldGetLastMessagesRespectingOffset() {
- List<MessageDTO> wantedLastMsg = service.getLastMessages(1L);
+ List<Message> wantedLastMsg = service.getLastMessages(1L);
assertResponseContainsExpectedMessages(wantedLastMsg, 1, MESSAGE_3);
}
@Test
- public void testShouldGetAll3Messages() {
- List<MessageDTO> wantedLastMsgs = service.getLastMessages(3L);
+ public void testShouldGetAll3Messages() {
+ List<Message> wantedLastMsgs = service.getLastMessages(3L);
assertResponseContainsExpectedMessages(wantedLastMsgs, 3, MESSAGE_1, MESSAGE_2, MESSAGE_3);
}
- private void prepareProducer(){
+ private void prepareProducer() {
kafkaTemplate.send("config", "message1");
kafkaTemplate.send("config", "message2");
kafkaTemplate.send("config", "message3");
}
- private void assertResponseContainsExpectedMessages(List<MessageDTO> actualMessages, int expectedMessageCount, String... expectedMessages){
- assertThat(actualMessages.stream().map(MessageDTO::getConfiguration))
- .hasSize(expectedMessageCount)
- .containsExactly(expectedMessages);
+ private void assertResponseContainsExpectedMessages(List<Message> actualMessages, int expectedMessageCount, String... expectedMessages) {
+ assertThat(actualMessages.stream().map(Message::getConfiguration))
+ .hasSize(expectedMessageCount)
+ .containsExactly(expectedMessages);
}
}
diff --git a/netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationReaderTest.java b/netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationReaderTest.java
index a0a15b9..7095040 100644
--- a/netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationReaderTest.java
+++ b/netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationReaderTest.java
@@ -65,7 +65,7 @@ class NetconfConfigurationReaderTest {
}
@Test
- void properlyReadXML() throws IOException, JNCException {
+ void properlyReadXml() throws IOException, JNCException {
when(netconfSession.getConfig()).thenReturn(nodeSet);
when(nodeSet.toXMLString()).thenReturn(EXPECTED_STRING_XML);
diff --git a/netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationServiceTest.java b/netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationServiceTest.java
index 6da6572..f42ad84 100644
--- a/netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationServiceTest.java
+++ b/netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/configuration/NetconfConfigurationServiceTest.java
@@ -28,8 +28,10 @@ import static org.mockito.MockitoAnnotations.initMocks;
import com.tailf.jnc.Element;
import com.tailf.jnc.JNCException;
+
import java.io.IOException;
import java.nio.file.Files;
+
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
@@ -49,11 +51,11 @@ class NetconfConfigurationServiceTest {
@InjectMocks
NetconfConfigurationService service;
- private static String CURRENT_CONFIG_XML_STRING =
- "<config xmlns=\"http://onap.org/pnf-simulator\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
- + " <itemValue1>100</itemValue1>\n"
- + " <itemValue2>200</itemValue2>\n"
- + "</config>\n";
+ private static String CURRENT_CONFIG_XML_STRING =
+ "<config xmlns=\"http://onap.org/pnf-simulator\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+ + " <itemValue1>100</itemValue1>\n"
+ + " <itemValue2>200</itemValue2>\n"
+ + "</config>\n";
@BeforeEach
void setUp() {
@@ -71,16 +73,16 @@ class NetconfConfigurationServiceTest {
}
@Test
- void testShouldThrowExceptionWhenCurrentConfigurationDoesNotExists() throws IOException, JNCException{
+ void testShouldThrowExceptionWhenCurrentConfigurationDoesNotExists() throws IOException, JNCException {
when(reader.getRunningConfig()).thenThrow(JNCException.class);
assertThatThrownBy(() -> service.getCurrentConfiguration()).isInstanceOf(JNCException.class);
}
@Test
- void testShouldEditConfigurationSuccessfully() throws IOException, JNCException{
+ void testShouldEditConfigurationSuccessfully() throws IOException, JNCException {
byte[] bytes =
- Files.readAllBytes(ResourceUtils.getFile("classpath:updatedConfig.xml").toPath());
+ Files.readAllBytes(ResourceUtils.getFile("classpath:updatedConfig.xml").toPath());
MockMultipartFile editConfigXmlContent = new MockMultipartFile("editConfigXml", bytes);
ArgumentCaptor<Element> elementCaptor = ArgumentCaptor.forClass(Element.class);
doNothing().when(editor).editConfig(elementCaptor.capture());
@@ -93,7 +95,7 @@ class NetconfConfigurationServiceTest {
@Test
void testShouldRaiseExceptionWhenMultipartFileIsInvalidXmlFile() throws IOException {
byte[] bytes =
- Files.readAllBytes(ResourceUtils.getFile("classpath:invalidXmlFile.xml").toPath());
+ Files.readAllBytes(ResourceUtils.getFile("classpath:invalidXmlFile.xml").toPath());
MockMultipartFile editConfigXmlContent = new MockMultipartFile("editConfigXml", bytes);
assertThatThrownBy(() -> service.editCurrentConfiguration(editConfigXmlContent)).isInstanceOf(JNCException.class);
diff --git a/netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/model/NetconfModelLoaderServiceTest.java b/netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/model/NetconfModelLoaderServiceTest.java
index a10876b..8d26881 100644
--- a/netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/model/NetconfModelLoaderServiceTest.java
+++ b/netconfsimulator/src/test/java/org/onap/netconfsimulator/netconfcore/model/NetconfModelLoaderServiceTest.java
@@ -61,7 +61,6 @@ class NetconfModelLoaderServiceTest {
@Test
void shouldSendMultipartToServer() throws IOException {
//given
- String loadModelAddress = modelLoaderService.getBackendAddress();
makeMockClientReturnStatusOk(httpClient, HttpPost.class);
ArgumentCaptor<HttpPost> postArgumentCaptor = ArgumentCaptor.forClass(HttpPost.class);
MultipartFile yangMmodel = mock(MultipartFile.class);
@@ -69,6 +68,7 @@ class NetconfModelLoaderServiceTest {
String moduleName = "moduleName";
when(yangMmodel.getInputStream()).thenReturn(getEmptyImputStream());
when(initialConfig.getInputStream()).thenReturn(getEmptyImputStream());
+ String loadModelAddress = modelLoaderService.getBackendAddress();
//when
LoadModelResponse response = modelLoaderService.loadYangModel(yangMmodel, initialConfig, moduleName);
@@ -86,9 +86,9 @@ class NetconfModelLoaderServiceTest {
void shouldSendDeleteRequestToServer() throws IOException {
//given
String yangModelName = "sampleModel";
- String deleteModelAddress = modelLoaderService.getDeleteAddress(yangModelName);
makeMockClientReturnStatusOk(httpClient, HttpDelete.class);
ArgumentCaptor<HttpDelete> deleteArgumentCaptor = ArgumentCaptor.forClass(HttpDelete.class);
+ String deleteModelAddress = modelLoaderService.getDeleteAddress(yangModelName);
//when
LoadModelResponse response = modelLoaderService.deleteYangModel(yangModelName);
diff --git a/netconfsimulator/src/test/java/org/onap/netconfsimulator/websocket/NetconfEndpointTest.java b/netconfsimulator/src/test/java/org/onap/netconfsimulator/websocket/NetconfEndpointTest.java
index c1484d4..e0bffc1 100644
--- a/netconfsimulator/src/test/java/org/onap/netconfsimulator/websocket/NetconfEndpointTest.java
+++ b/netconfsimulator/src/test/java/org/onap/netconfsimulator/websocket/NetconfEndpointTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -74,7 +74,7 @@ class NetconfEndpointTest {
@Test
void shouldCreateKafkaListenerWhenClientInitializeConnection() {
NetconfEndpoint netconfEndpoint = new NetconfEndpoint(kafkaListenerHandler);
- AbstractMessageListenerContainer abstractMessageListenerContainer = getListenerContainer();
+ AbstractMessageListenerContainer<String, String> abstractMessageListenerContainer = getListenerContainer();
when(session.getBasicRemote()).thenReturn(remoteEndpoint);
KafkaListenerEntry kafkaListenerEntry = new KafkaListenerEntry("sampleGroupId",
abstractMessageListenerContainer);
@@ -93,7 +93,7 @@ class NetconfEndpointTest {
@Test
void shouldCloseListenerWhenClientDisconnects() {
NetconfEndpoint netconfEndpoint = new NetconfEndpoint(kafkaListenerHandler);
- AbstractMessageListenerContainer abstractMessageListenerContainer = getListenerContainer();
+ AbstractMessageListenerContainer<String, String> abstractMessageListenerContainer = getListenerContainer();
netconfEndpoint.setEntry( Optional.of(new KafkaListenerEntry("sampleGroupId", abstractMessageListenerContainer)) );
netconfEndpoint.onClose(session, mock(CloseReason.class));
@@ -101,7 +101,7 @@ class NetconfEndpointTest {
verify(abstractMessageListenerContainer).stop();
}
- class TestAbstractMessageListenerContainer extends AbstractMessageListenerContainer {
+ class TestAbstractMessageListenerContainer extends AbstractMessageListenerContainer<String,String> {
TestAbstractMessageListenerContainer(ContainerProperties containerProperties) {
@@ -124,7 +124,7 @@ class NetconfEndpointTest {
}
}
- private AbstractMessageListenerContainer getListenerContainer() {
+ private AbstractMessageListenerContainer<String, String> getListenerContainer() {
ContainerProperties containerProperties = new ContainerProperties("config");
containerProperties.setGroupId("sample");
containerProperties.setMessageListener(mock(GenericMessageListener.class));
diff --git a/netconfsimulator/src/test/java/org/onap/netconfsimulator/websocket/message/NetconfMessageListenerTest.java b/netconfsimulator/src/test/java/org/onap/netconfsimulator/websocket/message/NetconfMessageListenerTest.java
index bb040d1..c6e58c9 100644
--- a/netconfsimulator/src/test/java/org/onap/netconfsimulator/websocket/message/NetconfMessageListenerTest.java
+++ b/netconfsimulator/src/test/java/org/onap/netconfsimulator/websocket/message/NetconfMessageListenerTest.java
@@ -69,5 +69,7 @@ class NetconfMessageListenerTest {
doThrow(new EncodeException("","")).when(remoteEndpoint).sendObject(any(KafkaMessage.class));
netconfMessageListener.onMessage(KAFKA_RECORD);
+
+ verify(remoteEndpoint).sendObject(any(KafkaMessage.class));
}
}
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/Main.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/Main.java
index e0eace2..708f27f 100644
--- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/Main.java
+++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/Main.java
@@ -43,7 +43,9 @@ public class Main {
this.fsToDbTemplateSynchronizer = fsToDbTemplateSynchronizer;
}
- public static void main(String[] args) {
+ // We are excluding this line in Sonar due to fact that
+ // Spring is handling arguments
+ public static void main(String[] args) { // NOSONAR
SpringApplication.run(Main.class, args);
}
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..401dc77 100644
--- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java
+++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java
@@ -96,14 +96,14 @@ public class SimulatorController {
@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());
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");
@@ -140,7 +140,7 @@ public class SimulatorController {
@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 +151,33 @@ 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 {
+ public ResponseEntity<Map<String,Object>> cancelEvent(@PathVariable String jobName) throws SchedulerException {
LOGGER.info(ENTRY, "Cancel called on {}.", replaceBreakingCharacters(jobName));
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 +189,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 +197,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 +212,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/TemplateController.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/TemplateController.java
index 444e23b..7eaa9ff 100644
--- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/TemplateController.java
+++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/TemplateController.java
@@ -30,8 +30,6 @@ import org.onap.pnfsimulator.rest.model.TemplateRequest;
import org.onap.pnfsimulator.rest.model.SearchExp;
import org.onap.pnfsimulator.template.Template;
import org.onap.pnfsimulator.template.search.IllegalJsonValueException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@@ -53,7 +51,6 @@ public class TemplateController {
static final String TEMPLATE_NOT_FOUND_MSG = "A template with given name does not exist";
static final String CANNOT_OVERRIDE_TEMPLATE_MSG = "Cannot overwrite existing template. Use override=true to override";
private final Storage<Template> service;
- private static final Logger LOG = LoggerFactory.getLogger(TemplateController.class);
@Autowired
public TemplateController(Storage<Template> service) {
@@ -61,7 +58,7 @@ public class TemplateController {
}
@GetMapping("list")
- public ResponseEntity<?> list() {
+ public ResponseEntity<List<Template>> list() {
return new ResponseEntity<>(service.getAll(), HttpStatus.OK);
}
@@ -77,7 +74,7 @@ public class TemplateController {
}
@PostMapping("upload")
- public ResponseEntity<?> upload(
+ public ResponseEntity<String> upload(
@RequestBody @Valid TemplateRequest templateRequest,
@RequestParam(required = false) boolean override) {
String msg = "";
@@ -91,7 +88,7 @@ public class TemplateController {
}
@PostMapping("search")
- public ResponseEntity<?> searchByCriteria(@RequestBody SearchExp queryJson) {
+ public ResponseEntity<List<String>> searchByCriteria(@RequestBody SearchExp queryJson) {
try {
List<String> templateNames = service.getIdsByContentCriteria(queryJson.getSearchExpr());
return new ResponseEntity<>(templateNames, HttpStatus.OK);
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/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