diff --git a/src/main/test/java/lk.gov.govtech.covid19/controller/NotificationControllerTest.java b/src/main/test/java/lk.gov.govtech.covid19/controller/NotificationControllerTest.java new file mode 100644 index 0000000..00432fc --- /dev/null +++ b/src/main/test/java/lk.gov.govtech.covid19/controller/NotificationControllerTest.java @@ -0,0 +1,83 @@ +package lk.gov.govtech.covid19.controller; + +import lk.gov.govtech.covid19.service.NotificationService; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.RequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +@ExtendWith(SpringExtension.class) +@SpringBootTest +@AutoConfigureMockMvc(addFilters = false) //avoiding authentication for tests +class NotificationControllerTest { + + @Autowired + private MockMvc mvc; + + @Autowired + @InjectMocks + private NotificationController notificationController; + + @Mock + private NotificationService notificationService; + + @Test + void addNewAlert() throws Exception { + String jsonContent = "{\n" + + " \"source\":\"Test src\",\n" + + " \"title\":{\n" + + " \"english\":\"This is a test notification\",\n" + + " \"sinhala\":\"මෙය පරීක්ෂණයකි\",\n" + + " \"tamil\":\"இது ஒரு சோதனை\"\n" + + " },\n" + + " \"message\":{\n" + + " \"english\":\"
Hi
\",\n" + + " \"sinhala\":\"සාදරයෙන් පිළිගනිමු
\",\n" + + " \"tamil\":\"வரவேற்பு
\"\n" + + " }\n" + + "}"; + RequestBuilder addNewAlertReq = MockMvcRequestBuilders.post("/notification/alert/add") + .content(jsonContent).contentType(MediaType.APPLICATION_JSON); + mvc.perform(addNewAlertReq).andExpect(MockMvcResultMatchers.status().isAccepted()); + } + + @Test + void addNewCase() throws Exception { + String jsonContent = "{\n" + + " \"caseNumber\":\"DHIS/WP/COL/1234\",\n" + + " \"locations\":[\n" + + " {\n" + + " \"date\":\"2020/02/02\",\n" + + " \"from\":\"2020/02/02 00:00:00\",\n" + + " \"to\":\"2020/02/02 11:59:59\",\n" + + " \"address\":\"Colombo Municipal Council\",\n" + + " \"longitude\":\"1234\",\n" + + " \"latitude\":\"4321\"\n" + + " },\n" + + " {\n" + + " \"date\":\"2020/03/02\",\n" + + " \"from\":\"2020/03/02 13:00:00\",\n" + + " \"to\":\"2020/03/02 15:45:00\",\n" + + " \"address\":\"Galadari Hotel\",\n" + + " \"longitude\":\"1234\",\n" + + " \"latitude\":\"4321\"\n" + + " }\n" + + " ],\n" + + " \"message_en\":\"Person confirmed with COVID-19\",\n" + + " \"message_si\":\"COVID-19 සමඟ තහවුරු කළ පුද්ගලයා\",\n" + + " \"message_ta\":\"COVID-19 உடன் நபர் உறுதிப்படுத்தப்பட்டார்\"\n" + + "}"; + RequestBuilder addNewAlertReq = MockMvcRequestBuilders.post("/notification/case/add") + .content(jsonContent).contentType(MediaType.APPLICATION_JSON); + mvc.perform(addNewAlertReq).andExpect(MockMvcResultMatchers.status().isAccepted()); + } +} \ No newline at end of file diff --git a/src/main/test/java/lk.gov.govtech.covid19/scheduler/CacheScheduler.java b/src/main/test/java/lk.gov.govtech.covid19/scheduler/CacheScheduler.java new file mode 100644 index 0000000..71833d3 --- /dev/null +++ b/src/main/test/java/lk.gov.govtech.covid19/scheduler/CacheScheduler.java @@ -0,0 +1,41 @@ +package lk.gov.govtech.covid19.scheduler; + +import lk.gov.govtech.covid19.controller.NotificationController; +import lk.gov.govtech.covid19.service.NotificationService; +import org.junit.Assert; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cache.CacheManager; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.web.servlet.MockMvc; + +import java.util.Collection; + +@ExtendWith(SpringExtension.class) +@SpringBootTest +@AutoConfigureMockMvc(addFilters = false) //avoiding authentication for tests +class CacheSchedulerTest { + + @Autowired + private MockMvc mvc; + + @Autowired + @InjectMocks + private CacheScheduler cacheScheduler; + + @Mock + private CacheManager cacheManager; + + @Test + void evictAllCaches() { + //FIXME this can be improved + cacheScheduler.evictAllCaches(); + Collection