diff options
author | 2021-07-19 12:59:13 +0200 | |
---|---|---|
committer | 2021-07-28 15:03:59 +0200 | |
commit | 5995a778e7a5a7718c480a8099b9c2f47549530d (patch) | |
tree | 043c2400f820b2febc4a8331004aecdc59f387f8 /src/test/java/org/onap/a1pesimulator/service/fileready/CommonFileReady.java | |
parent | c7bc54b6e81532ad906de88f5ad7ed63259ff586 (diff) |
O1 PM Bulk support - Unit test - II
Issue-ID: INT-1945
Signed-off-by: Stanislav Marszalek <s.marszalek2@partner.samsung.com>
Change-Id: I02d3684c98d563d7f386de2fdf032e930ac41b3f
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.java | 80 |
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; + } } |