Query expansion and others

This commit is contained in:
Fabian Märki 2018-09-07 15:49:13 +02:00
parent 1c6b5cd4ef
commit af230f339b
2 changed files with 256 additions and 0 deletions

View File

@ -93,6 +93,10 @@ public class EventQueryValidator implements Validator, ApplicationContextAware {
}
}
if (range.isStartExpansion() && !range.isStartInclusive()) {
errors.reject("startExpansion", "Start needs to be inclusive for start-expansion.");
}
range.validate(maxPulseRange, maxTimeRange, query.getOrdering(), query.getLimit());
query.setRange(range);

View File

@ -388,6 +388,158 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest implements
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].iocMillis").value(1010));
}
@Test
public void testPulseRangeQuery_StartExpansion() throws Exception {
DAQQuery request = new DAQQuery(
new RequestRangePulseId(
100,
true,
101,
false),
TEST_CHANNEL_NAMES);
request.addEventField(EventField.pulseId);
request.addEventField(EventField.globalSeconds);
request.addEventField(EventField.globalMillis);
request.addEventField(EventField.iocSeconds);
request.addEventField(EventField.iocMillis);
String content = mapper.writeValueAsString(request);
System.out.println(content);
this.mockMvc
.perform(MockMvcRequestBuilders
.post(DomainConfig.PATH_QUERY)
.contentType(MediaType.APPLICATION_JSON)
.content(content))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
.andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].channel.name").value(TEST_CHANNEL_01))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].pulseId").value(99))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].globalSeconds").value(
TestTimeUtils.getTimeStr(0, 990000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].globalMillis").value(990))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].iocSeconds").value(
TestTimeUtils.getTimeStr(0, 990000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].iocMillis").value(990))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].pulseId").value(100))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].globalMillis").value(1000))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].iocSeconds").value(
TestTimeUtils.getTimeStr(1, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].iocMillis").value(1000))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].pulseId").value(101))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 10000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].globalMillis").value(1010))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].iocSeconds").value(
TestTimeUtils.getTimeStr(1, 10000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].iocMillis").value(1010))
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$[1].channel.name").value(TEST_CHANNEL_02))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data").isArray())
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].pulseId").value(99))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].globalSeconds").value(
TestTimeUtils.getTimeStr(0, 990000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].globalMillis").value(990))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].iocSeconds").value(
TestTimeUtils.getTimeStr(0, 990000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].iocMillis").value(990))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].pulseId").value(100))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].globalMillis").value(1000))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].iocSeconds").value(
TestTimeUtils.getTimeStr(1, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].iocMillis").value(1000))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].pulseId").value(101))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 10000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].globalMillis").value(1010))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].iocSeconds").value(
TestTimeUtils.getTimeStr(1, 10000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].iocMillis").value(1010));
}
@Test
public void testPulseRangeQuery_EndExpansion() throws Exception {
DAQQuery request = new DAQQuery(
new RequestRangePulseId(
99,
false,
100,
true),
TEST_CHANNEL_NAMES);
request.addEventField(EventField.pulseId);
request.addEventField(EventField.globalSeconds);
request.addEventField(EventField.globalMillis);
request.addEventField(EventField.iocSeconds);
request.addEventField(EventField.iocMillis);
String content = mapper.writeValueAsString(request);
System.out.println(content);
this.mockMvc
.perform(MockMvcRequestBuilders
.post(DomainConfig.PATH_QUERY)
.contentType(MediaType.APPLICATION_JSON)
.content(content))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
.andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].channel.name").value(TEST_CHANNEL_01))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].pulseId").value(99))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].globalSeconds").value(
TestTimeUtils.getTimeStr(0, 990000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].globalMillis").value(990))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].iocSeconds").value(
TestTimeUtils.getTimeStr(0, 990000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].iocMillis").value(990))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].pulseId").value(100))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].globalMillis").value(1000))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].iocSeconds").value(
TestTimeUtils.getTimeStr(1, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].iocMillis").value(1000))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].pulseId").value(101))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 10000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].globalMillis").value(1010))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].iocSeconds").value(
TestTimeUtils.getTimeStr(1, 10000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].iocMillis").value(1010))
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$[1].channel.name").value(TEST_CHANNEL_02))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data").isArray())
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].pulseId").value(99))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].globalSeconds").value(
TestTimeUtils.getTimeStr(0, 990000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].globalMillis").value(990))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].iocSeconds").value(
TestTimeUtils.getTimeStr(0, 990000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].iocMillis").value(990))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].pulseId").value(100))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].globalMillis").value(1000))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].iocSeconds").value(
TestTimeUtils.getTimeStr(1, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].iocMillis").value(1000))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].pulseId").value(101))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 10000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].globalMillis").value(1010))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].iocSeconds").value(
TestTimeUtils.getTimeStr(1, 10000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].iocMillis").value(1010));
}
@Test
public void testPulseRangeQuery_Fields() throws Exception {
DAQQuery request = new DAQQuery(
@ -567,6 +719,106 @@ public class JsonQueryRestControllerTest extends AbstractDaqRestTest implements
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].globalSeconds").value(
TestTimeUtils.getTimeStr(2, 10000000)));
}
@Test
public void testTimeRangeQuery_01_StartExpansion() throws Exception {
DAQQuery request = new DAQQuery(
new RequestRangeTime(
TimeUtils.getTimeFromMillis(2000, 0),
true,
TimeUtils.getTimeFromMillis(2010, 0),
false),
TEST_CHANNEL_NAMES);
String content = mapper.writeValueAsString(request);
this.mockMvc.perform(MockMvcRequestBuilders
.post(DomainConfig.PATH_QUERY)
.contentType(MediaType.APPLICATION_JSON)
.content(content))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
.andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].channel").isMap())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].channel.name").value(TEST_CHANNEL_01))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].configs").doesNotExist())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data").isArray())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].pulseId").value(199))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 990000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].pulseId").value(200))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].globalSeconds").value(
TestTimeUtils.getTimeStr(2, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].pulseId").value(201))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].globalSeconds").value(
TestTimeUtils.getTimeStr(2, 10000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$[1].channel").isMap())
.andExpect(MockMvcResultMatchers.jsonPath("$[1].channel.name").value(TEST_CHANNEL_02))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].configs").doesNotExist())
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data").isArray())
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].pulseId").value(199))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 990000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].pulseId").value(200))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].globalSeconds").value(
TestTimeUtils.getTimeStr(2, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].pulseId").value(201))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].globalSeconds").value(
TestTimeUtils.getTimeStr(2, 10000000)));
}
@Test
public void testTimeRangeQuery_01_EndExpansion() throws Exception {
DAQQuery request = new DAQQuery(
new RequestRangeTime(
TimeUtils.getTimeFromMillis(1990, 0),
false,
TimeUtils.getTimeFromMillis(2000, 0),
true),
TEST_CHANNEL_NAMES);
String content = mapper.writeValueAsString(request);
this.mockMvc.perform(MockMvcRequestBuilders
.post(DomainConfig.PATH_QUERY)
.contentType(MediaType.APPLICATION_JSON)
.content(content))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
.andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].channel").isMap())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].channel.name").value(TEST_CHANNEL_01))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].configs").doesNotExist())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data").isArray())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].pulseId").value(199))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 990000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].pulseId").value(200))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].globalSeconds").value(
TestTimeUtils.getTimeStr(2, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].pulseId").value(201))
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].globalSeconds").value(
TestTimeUtils.getTimeStr(2, 10000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$[1].channel").isMap())
.andExpect(MockMvcResultMatchers.jsonPath("$[1].channel.name").value(TEST_CHANNEL_02))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].configs").doesNotExist())
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data").isArray())
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].pulseId").value(199))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 990000000)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].pulseId").value(200))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].globalSeconds").value(
TestTimeUtils.getTimeStr(2, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].pulseId").value(201))
.andExpect(MockMvcResultMatchers.jsonPath("$[1].data[2].globalSeconds").value(
TestTimeUtils.getTimeStr(2, 10000000)));
}
@Test
public void testTimeRangeQuery_01_ConfigFields() throws Exception {