|
| 1 | +package org.phoebus.channelfinder.processors; |
| 2 | + |
| 3 | +import static org.hamcrest.Matchers.containsInAnyOrder; |
| 4 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 5 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; |
| 6 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; |
| 7 | + |
| 8 | +import java.util.List; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 11 | +import org.mockito.Mockito; |
| 12 | +import org.phoebus.channelfinder.CFResourceDescriptors; |
| 13 | +import org.phoebus.channelfinder.ChannelScroll; |
| 14 | +import org.phoebus.channelfinder.entity.Scroll; |
| 15 | +import org.springframework.beans.factory.annotation.Autowired; |
| 16 | +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; |
| 17 | +import org.springframework.boot.test.mock.mockito.MockBean; |
| 18 | +import org.springframework.http.HttpHeaders; |
| 19 | +import org.springframework.test.context.TestPropertySource; |
| 20 | +import org.springframework.test.context.junit.jupiter.SpringExtension; |
| 21 | +import org.springframework.test.web.servlet.MockMvc; |
| 22 | +import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; |
| 23 | +import org.springframework.util.Base64Utils; |
| 24 | + |
| 25 | +@ExtendWith(SpringExtension.class) |
| 26 | +@WebMvcTest(ChannelProcessorManager.class) |
| 27 | +@TestPropertySource( |
| 28 | + value = "classpath:application_test.properties", |
| 29 | + properties = {"elasticsearch.create.indices = false"}) |
| 30 | +class ChannelProcessorManagerIT { |
| 31 | + |
| 32 | + protected static final String AUTHORIZATION = |
| 33 | + "Basic " + Base64Utils.encodeToString("admin:adminPass".getBytes()); |
| 34 | + |
| 35 | + @Autowired protected MockMvc mockMvc; |
| 36 | + @MockBean ChannelScroll channelScroll; |
| 37 | + |
| 38 | + @Test |
| 39 | + void testProcessorCount() throws Exception { |
| 40 | + MockHttpServletRequestBuilder request = |
| 41 | + get("/" + CFResourceDescriptors.CHANNEL_PROCESSOR_RESOURCE_URI + "/count"); |
| 42 | + mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().string("2")); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void testProcessorsInfo() throws Exception { |
| 47 | + MockHttpServletRequestBuilder request = |
| 48 | + get("/" + CFResourceDescriptors.CHANNEL_PROCESSOR_RESOURCE_URI + "/processors"); |
| 49 | + mockMvc |
| 50 | + .perform(request) |
| 51 | + .andExpect(status().isOk()) |
| 52 | + .andExpect( |
| 53 | + jsonPath("$[*].name", containsInAnyOrder("AAChannelProcessor", "DummyProcessor"))); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + void testProcessorEnabled() throws Exception { |
| 58 | + MockHttpServletRequestBuilder request = |
| 59 | + put("/" |
| 60 | + + CFResourceDescriptors.CHANNEL_PROCESSOR_RESOURCE_URI |
| 61 | + + "/processor/AAChannelProcessor/enabled") |
| 62 | + .header(HttpHeaders.AUTHORIZATION, AUTHORIZATION) |
| 63 | + .contentType("application/json") |
| 64 | + .content("{\"enabled\": false}"); |
| 65 | + mockMvc.perform(request).andExpect(status().isOk()); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + void testProcessAllChannels() throws Exception { |
| 70 | + Mockito.when(channelScroll.query(Mockito.any())).thenReturn(new Scroll("", List.of())); |
| 71 | + |
| 72 | + MockHttpServletRequestBuilder request = |
| 73 | + put("/" + CFResourceDescriptors.CHANNEL_PROCESSOR_RESOURCE_URI + "/process/all") |
| 74 | + .header(HttpHeaders.AUTHORIZATION, AUTHORIZATION); |
| 75 | + mockMvc.perform(request).andExpect(status().isOk()); |
| 76 | + } |
| 77 | + |
| 78 | + @Test |
| 79 | + void testProcessQuery() throws Exception { |
| 80 | + Mockito.when(channelScroll.query(Mockito.any())).thenReturn(new Scroll("", List.of())); |
| 81 | + MockHttpServletRequestBuilder request = |
| 82 | + put("/" + CFResourceDescriptors.CHANNEL_PROCESSOR_RESOURCE_URI + "/process/query") |
| 83 | + .header(HttpHeaders.AUTHORIZATION, AUTHORIZATION); |
| 84 | + mockMvc.perform(request).andExpect(status().isOk()); |
| 85 | + } |
| 86 | +} |
0 commit comments