aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/a1pesimulator/service/fileready/CommonFileReady.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/a1pesimulator/service/fileready/CommonFileReady.java')
-rw-r--r--src/test/java/org/onap/a1pesimulator/service/fileready/CommonFileReady.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/test/java/org/onap/a1pesimulator/service/fileready/CommonFileReady.java b/src/test/java/org/onap/a1pesimulator/service/fileready/CommonFileReady.java
index 75ce7a0..d65ad7c 100644
--- a/src/test/java/org/onap/a1pesimulator/service/fileready/CommonFileReady.java
+++ b/src/test/java/org/onap/a1pesimulator/service/fileready/CommonFileReady.java
@@ -5,20 +5,42 @@ import static org.onap.a1pesimulator.util.Constants.TEMP_DIR;
import java.io.File;
import java.io.IOException;
+import java.net.URISyntaxException;
import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.UUID;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
+import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
+import org.onap.a1pesimulator.data.fileready.EventMemoryHolder;
+import org.onap.a1pesimulator.data.ves.VesEvent;
+import org.onap.a1pesimulator.service.VesBrokerServiceImplTest;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
public class CommonFileReady {
public List<File> filesToDelete; //we collect files created during testing and then delete them
public static final String PM_BULK_FILE = "pmBulkFile.xml";
public static final String ARCHIVED_PM_BULK_FILE = "pmBulkFile.xml.gz";
+ public static final Integer NO_OF_EVENTS = 3;
+
+ @InjectMocks
+ private ObjectMapper mapper;
+
@BeforeEach
void setUp() {
@@ -49,4 +71,62 @@ public class CommonFileReady {
return null;
}
}
+
+ /**
+ * Generate NO_OF_EVENTS test EventMemoryHolder list
+ *
+ * @return EventMemoryHolder list
+ */
+ protected List<EventMemoryHolder> getTestEvents() {
+ List<EventMemoryHolder> collectedEvents = new ArrayList<>();
+ for (int i = 0; i < NO_OF_EVENTS; i++) {
+ EventMemoryHolder eventMemoryHolder = new EventMemoryHolder("Cell1", UUID.randomUUID().toString(), 10, ZonedDateTime.now(), loadEventFromFile());
+ collectedEvents.add(eventMemoryHolder);
+ }
+ return collectedEvents;
+ }
+
+ /**
+ * Converts json to VESEvent object
+ *
+ * @return created VESEvent
+ */
+ protected VesEvent loadEventFromFile() {
+ try {
+ return mapper.readValue(loadFileContent("VesBrokerControllerTest_pm_ves.json"), VesEvent.class);
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * Get json string from specified json file
+ *
+ * @param fileName name of test json file
+ * @return json file as string
+ */
+ private String loadFileContent(String fileName) {
+ Path path;
+ try {
+ path = Paths.get(VesBrokerServiceImplTest.class.getResource(fileName).toURI());
+ return new String(Files.readAllBytes(path));
+ } catch (URISyntaxException | IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * Create common log
+ *
+ * @return ListAppender<ILoggingEvent>
+ */
+ protected ListAppender<ILoggingEvent> createCommonLog(Class clazz) {
+ Logger testLog = (Logger) LoggerFactory.getLogger(clazz);
+ ListAppender<ILoggingEvent> appender = new ListAppender<>();
+ appender.start();
+ testLog.addAppender(appender);
+ return appender;
+ }
}