From 66380431022c4ff290b464d19131181cc30137b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=A4rki?= Date: Thu, 9 Jun 2016 12:48:45 +0200 Subject: [PATCH] Intermediate... --- .../daq/queryrest/config/QueryRestConfig.java | 4 +- .../QueryRestControllerJsonTest.java | 62 ++++++++++++++++--- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java b/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java index b989c91..f5d116c 100644 --- a/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java +++ b/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java @@ -27,7 +27,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.ObjectMapper; -import ch.psi.daq.common.statistic.StorelessStatistics; +import ch.psi.daq.common.statistic.Statistics; import ch.psi.daq.domain.DataEvent; import ch.psi.daq.domain.query.operation.Aggregation; import ch.psi.daq.domain.query.operation.QueryField; @@ -85,7 +85,7 @@ public class QueryRestConfig extends WebMvcConfigurerAdapter { // Mixin which is used dynamically to filter out which properties get serialised and which // won't. This way, the user can specify which columns are to be received. objectMapper.addMixIn(DataEvent.class, PropertyFilterMixin.class); - objectMapper.addMixIn(StorelessStatistics.class, PropertyFilterMixin.class); + objectMapper.addMixIn(Statistics.class, PropertyFilterMixin.class); objectMapper.addMixIn(EnumMap.class, PropertyFilterMixin.class); objectMapper.addMixIn(Response.class, PolymorphicResponseMixIn.class); diff --git a/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerJsonTest.java b/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerJsonTest.java index c7d9230..190d8ed 100644 --- a/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerJsonTest.java +++ b/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerJsonTest.java @@ -582,10 +582,17 @@ public class QueryRestControllerJsonTest extends AbstractDaqRestTest { .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].globalSeconds").value( TestTimeUtils.getTimeStr(1, 0))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].value.min").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].value.mean").value(102.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].value.max").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].pulseId").value(105)) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].globalSeconds").value( TestTimeUtils.getTimeStr(1, 50000000))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].eventCount").value(5)); + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].value.min").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].value.mean").value(107.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].value.max").value(109.0)); } @Test @@ -623,42 +630,81 @@ public class QueryRestControllerJsonTest extends AbstractDaqRestTest { .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].globalSeconds").value( TestTimeUtils.getTimeStr(10, 0))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].value.min").value(1000.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].value.mean").value(1004.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[0].value.max").value(1009.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].pulseId").value(1010)) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].globalSeconds").value( TestTimeUtils.getTimeStr(10, 100000000))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].value.min").value(1010.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].value.mean").value(1014.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].value.max").value(1019.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].pulseId").value(1020)) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].globalSeconds").value( TestTimeUtils.getTimeStr(10, 200000000))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].value.min").value(1020.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].value.mean").value(1024.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[2].value.max").value(1029.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[3].pulseId").value(1030)) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[3].globalSeconds").value( TestTimeUtils.getTimeStr(10, 300000000))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[3].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[3].value.min").value(1030.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[3].value.mean").value(1034.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[3].value.max").value(1039.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[4].pulseId").value(1040)) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[4].globalSeconds").value( TestTimeUtils.getTimeStr(10, 400000000))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[4].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[4].value.min").value(1040.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[4].value.mean").value(1044.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[4].value.max").value(1049.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[5].pulseId").value(1050)) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[5].globalSeconds").value( TestTimeUtils.getTimeStr(10, 500000000))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[5].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[5].value.min").value(1050.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[5].value.mean").value(1054.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[5].value.max").value(1059.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[6].pulseId").value(1060)) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[6].globalSeconds").value( TestTimeUtils.getTimeStr(10, 600000000))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[6].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[6].value.min").value(1060.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[6].value.mean").value(1064.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[6].value.max").value(1069.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[7].pulseId").value(1070)) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[7].globalSeconds").value( TestTimeUtils.getTimeStr(10, 700000000))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[7].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[7].value.min").value(1070.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[7].value.mean").value(1074.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[7].value.max").value(1079.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[8].pulseId").value(1080)) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[8].globalSeconds").value( TestTimeUtils.getTimeStr(10, 800000000))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[8].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[8].value.min").value(1080.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[8].value.mean").value(1084.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[8].value.max").value(1089.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[9].pulseId").value(1090)) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[9].globalSeconds").value( TestTimeUtils.getTimeStr(10, 900000000))) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[9].eventCount").value(10)); + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[9].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[9].value.min").value(1090.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[9].value.mean").value(1094.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[9].value.max").value(1099.0)); } @Test @@ -704,14 +750,14 @@ public class QueryRestControllerJsonTest extends AbstractDaqRestTest { .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.header().string("Content-Disposition", "attachment; filename=data.json")); } - + @Test public void testBadAggregation_01() throws Exception { DAQQuery request = new DAQQuery( new RequestRangePulseId( 10, 11), - new AggregationDescriptor().setDurationPerBin(1000), + new AggregationDescriptor().setDurationPerBin(1000), TEST_CHANNEL_NAMES); String content = mapper.writeValueAsString(request); @@ -726,14 +772,14 @@ public class QueryRestControllerJsonTest extends AbstractDaqRestTest { .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().isBadRequest()); } - + @Test public void testBadAggregation_02() throws Exception { DAQQuery request = new DAQQuery( new RequestRangeTime( TimeUtils.getTimeFromMillis(0, 0), TimeUtils.getTimeFromMillis(10, 0)), - new AggregationDescriptor().setPulsesPerBin(100), + new AggregationDescriptor().setPulsesPerBin(100), TEST_CHANNEL_NAMES); String content = mapper.writeValueAsString(request); @@ -748,14 +794,14 @@ public class QueryRestControllerJsonTest extends AbstractDaqRestTest { .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().isBadRequest()); } - + @Test public void testBadAggregation_03() throws Exception { DAQQuery request = new DAQQuery( new RequestRangePulseId( 10, 11), - new AggregationDescriptor().setDurationPerBin(1000).setNrOfBins(100), + new AggregationDescriptor().setDurationPerBin(1000).setNrOfBins(100), TEST_CHANNEL_NAMES); String content = mapper.writeValueAsString(request);