Skip to content

Commit 701b713

Browse files
committed
ChannelProcessorManager test
1 parent 7d9d3dc commit 701b713

File tree

2 files changed

+89
-3
lines changed

2 files changed

+89
-3
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
}

src/test/resources/application_test.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ demo_auth.enabled = true
5454

5555
############## Group-->Role Mapping ##############
5656
# Customize group names here
57-
admin-groups=cf-admins,sys-admins
57+
admin-groups=cf-admins,sys-admins, ADMIN
5858
channel-groups=cf-channels
5959
property-groups=cf-properties
6060
tag-groups=cf-tags
@@ -109,6 +109,6 @@ aa.auto_pause=pvStatus,archive
109109
############################## Metrics ###############################
110110
#actuator
111111
management.endpoints.web.exposure.include=prometheus, metrics, health, info
112-
metrics.tags=group4_10
113-
metrics.properties=group4: 10; group5: 10
112+
metrics.tags=
113+
metrics.properties=
114114
metrics.updateInterval=1

0 commit comments

Comments
 (0)