ATEST-827: adding test case

This commit is contained in:
Christof Zellweger
2017-10-09 10:09:10 +02:00
parent 73863224b1
commit cbecaa7198

View File

@@ -19,8 +19,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import ch.psi.daq.domain.backend.Backend;
import ch.psi.daq.domain.config.DomainConfig;
import ch.psi.daq.domain.query.DAQQuery;
import ch.psi.daq.domain.query.operation.Aggregation;
import ch.psi.daq.domain.query.operation.AggregationDescriptor;
import ch.psi.daq.domain.query.operation.Compression;
import ch.psi.daq.domain.query.response.Response;
import ch.psi.daq.domain.request.range.RequestRangeDate;
import ch.psi.daq.domain.request.range.RequestRangePulseId;
import ch.psi.daq.queryrest.response.csv.CSVHTTPResponse;
import ch.psi.daq.queryrest.response.json.JSONHTTPResponse;
@@ -40,16 +43,16 @@ public class ResponseQueryTest extends AbstractDaqRestTest{
@Test
public void test_JSON_01() throws JsonParseException, JsonMappingException, IOException {
Response respose = new CSVHTTPResponse();
String value = mapper.writeValueAsString(respose);
Response deserial = mapper.readValue(value, Response.class);
assertEquals(respose.getClass(), deserial.getClass());
assertEquals(respose.getFormat(), deserial.getFormat());
assertEquals(respose.getCompression(), deserial.getCompression());
}
@Test
public void test_JSON_02() throws JsonParseException, JsonMappingException, IOException {
DAQQuery query = new DAQQuery(
@@ -58,19 +61,39 @@ public class ResponseQueryTest extends AbstractDaqRestTest{
100),
"TestChannel_01");
query.setResponse(new CSVHTTPResponse(Compression.GZIP));
String value = mapper.writeValueAsString(query);
DAQQuery deserial = mapper.readValue(value, DAQQuery.class);
assertNotNull(deserial.getResponse());
assertEquals(query.getResponse().getClass(), deserial.getResponse().getClass());
assertEquals(query.getResponse().getFormat(), deserial.getResponse().getFormat());
assertEquals(query.getResponse().getCompression(), deserial.getResponse().getCompression());
assertEquals(query.getResponse().getCompression().getFileSuffix(), deserial.getResponse().getFileSuffix());
}
@Test
public void test_JSON_02_01() throws JsonParseException, JsonMappingException, IOException {
DAQQuery query = new DAQQuery(
new RequestRangeDate(
"2017-09-25T19:00:05.319+02:00",
"2017-09-25T19:03:05.319+02:00"),
new AggregationDescriptor().setDurationPerBin(100),
"TestChannel_01");
query.setResponse(new CSVHTTPResponse(Compression.GZIP));
// String value = mapper.writeValueAsString(query);
String value = "{\"channels\":[{\"backend\":\"queryrest-1\",\"name\":\"TestChannel_01\"}],\"fields\":[\"globalMillis\",\"globalDate\",\"value\",\"shape\",\"eventCount\"],\"range\":{\"startDate\":\"2017-09-25T19:02:57.318+02:00\",\"endDate\":\"2017-09-25T19:03:05.319+02:00\"},\"aggregation\":{\"durationPerBin\":\"PT15M\"},\"response\":{\"format\":\"csv\",\"compression\":\"none\"}}";
// System.out.println(value);
DAQQuery deserial = mapper.readValue(value, DAQQuery.class);
assertNotNull(deserial.getResponse());
assertEquals(query.getResponse().getClass(), deserial.getResponse().getClass());
assertEquals(query.getResponse().getCompression(), deserial.getResponse().getCompression());
}
@Test
public void test_JSON_03() throws JsonParseException, JsonMappingException, IOException {
DAQQuery query = new DAQQuery(
@@ -79,9 +102,9 @@ public class ResponseQueryTest extends AbstractDaqRestTest{
100),
"TestChannel_01");
query.setResponse(new JSONHTTPResponse(Compression.NONE));
String value = mapper.writeValueAsString(query);
int index = value.indexOf("format");
assertTrue(index >= 0);
index = value.indexOf("format", index + 1);
@@ -89,15 +112,15 @@ public class ResponseQueryTest extends AbstractDaqRestTest{
assertEquals(-1, index);
DAQQuery deserial = mapper.readValue(value, DAQQuery.class);
assertNotNull(deserial.getResponse());
assertEquals(query.getResponse().getClass(), deserial.getResponse().getClass());
assertEquals(query.getResponse().getFormat(), deserial.getResponse().getFormat());
assertEquals(query.getResponse().getCompression(), deserial.getResponse().getCompression());
assertEquals(query.getResponse().getFormat().getFileSuffix(), deserial.getResponse().getFileSuffix());
}
@Test
public void test_JSON_04() throws JsonParseException, JsonMappingException, IOException {
DAQQuery query = new DAQQuery(
@@ -105,11 +128,13 @@ public class ResponseQueryTest extends AbstractDaqRestTest{
0,
100),
"TestChannel_01");
String value = mapper.writeValueAsString(query);
DAQQuery deserial = mapper.readValue(value, DAQQuery.class);
assertNull(deserial.getResponse());
}
}