Move query tests to daq.query (where the classes are).
This commit is contained in:
@ -1,15 +0,0 @@
|
||||
package ch.psi.daq.test.queryrest.queries;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class AbstractQueryTest {
|
||||
|
||||
protected static final List<String> DEFAULT_PROPERTIES = Lists.newArrayList("channel", "pulseId");
|
||||
|
||||
protected long startMillis = new Date().getTime();
|
||||
protected long endMillis = new Date().getTime() + TimeUnit.SECONDS.toMillis(10);
|
||||
}
|
@ -1,164 +0,0 @@
|
||||
package ch.psi.daq.test.queryrest.queries;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import ch.psi.daq.cassandra.reader.Ordering;
|
||||
import ch.psi.daq.query.bin.BinningStrategyBinCount;
|
||||
import ch.psi.daq.query.bin.BinningStrategyLengthPulse;
|
||||
import ch.psi.daq.query.bin.BinningStrategyLengthTime;
|
||||
import ch.psi.daq.query.model.AggregationType;
|
||||
import ch.psi.daq.query.model.BinningStrategyEnum;
|
||||
import ch.psi.daq.query.model.TimeRangeQuery;
|
||||
import ch.psi.daq.query.range.QueryRange;
|
||||
import ch.psi.daq.query.range.QueryRangeImpl;
|
||||
|
||||
@RunWith(BlockJUnit4ClassRunner.class)
|
||||
public class AbstractQueryTestTest extends AbstractQueryTest {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void test_NoChannels_exception() {
|
||||
|
||||
long startMillis = new Date().getTime();
|
||||
long endMillis = new Date().getTime() + TimeUnit.SECONDS.toMillis(10);
|
||||
|
||||
QueryRange range = new QueryRangeImpl(startMillis, 0, endMillis, 0);
|
||||
|
||||
new TimeRangeQuery(
|
||||
Ordering.asc,
|
||||
null, // should throw exception
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.count,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
null, // startDateTime : String
|
||||
null); // endDateTime : String
|
||||
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void test_NoFields_exception() {
|
||||
|
||||
long startMillis = new Date().getTime();
|
||||
long endMillis = new Date().getTime() + TimeUnit.SECONDS.toMillis(10);
|
||||
QueryRange range = new QueryRangeImpl(startMillis, 0, endMillis, 0);
|
||||
|
||||
new TimeRangeQuery(
|
||||
Ordering.asc,
|
||||
Lists.newArrayList(),
|
||||
null, // fields
|
||||
BinningStrategyEnum.count,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
null, // startDateTime : String
|
||||
null); // endDateTime : String
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_nullBinningStrategyEnum_exception() {
|
||||
|
||||
long startMillis = new Date().getTime();
|
||||
long endMillis = new Date().getTime() + TimeUnit.SECONDS.toMillis(10);
|
||||
QueryRange range = new QueryRangeImpl(startMillis, 0, endMillis, 0);
|
||||
TimeRangeQuery query = new TimeRangeQuery(
|
||||
Ordering.asc,
|
||||
Lists.newArrayList(),
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
null,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
null, // startDateTime : String
|
||||
null); // endDateTime : String
|
||||
|
||||
Assert.assertTrue(query.getBinningStrategy() != null);
|
||||
Assert.assertEquals(BinningStrategyBinCount.class, query.getBinningStrategy().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_LengthBinningTimeStrategy() {
|
||||
|
||||
long startMillis = new Date().getTime();
|
||||
long endMillis = new Date().getTime() + TimeUnit.SECONDS.toMillis(10);
|
||||
QueryRange range = new QueryRangeImpl(startMillis, 0, endMillis, 0);
|
||||
TimeRangeQuery query = new TimeRangeQuery(
|
||||
Ordering.asc,
|
||||
Lists.newArrayList(),
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.length,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
null, // startDateTime : String
|
||||
null); // endDateTime : String
|
||||
|
||||
Assert.assertTrue(query.getBinningStrategy() != null);
|
||||
Assert.assertEquals(BinningStrategyLengthTime.class, query.getBinningStrategy().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_LengthBinningPulseStrategy() {
|
||||
|
||||
long startPulse = 100l;
|
||||
long endPulse = 105l;
|
||||
QueryRange range = new QueryRangeImpl(startPulse, endPulse);
|
||||
TimeRangeQuery query = new TimeRangeQuery(
|
||||
Ordering.asc,
|
||||
Lists.newArrayList(),
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.length,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
null, // startDateTime : String
|
||||
null); // endDateTime : String
|
||||
|
||||
Assert.assertTrue(query.getBinningStrategy() != null);
|
||||
Assert.assertEquals(BinningStrategyLengthPulse.class, query.getBinningStrategy().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_BinCountBinningStrategy() {
|
||||
|
||||
long startMillis = new Date().getTime();
|
||||
long endMillis = new Date().getTime() + TimeUnit.SECONDS.toMillis(10);
|
||||
QueryRange range = new QueryRangeImpl(startMillis, 0, endMillis, 0);
|
||||
TimeRangeQuery query = new TimeRangeQuery(
|
||||
Ordering.asc,
|
||||
Lists.newArrayList(),
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.count,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
null, // startDateTime : String
|
||||
null); // endDateTime : String
|
||||
|
||||
Assert.assertTrue(query.getBinningStrategy() != null);
|
||||
Assert.assertEquals(BinningStrategyBinCount.class, query.getBinningStrategy().getClass());
|
||||
}
|
||||
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package ch.psi.daq.test.queryrest.queries;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import ch.psi.daq.cassandra.reader.Ordering;
|
||||
import ch.psi.daq.query.model.AggregationType;
|
||||
import ch.psi.daq.query.model.BinningStrategyEnum;
|
||||
import ch.psi.daq.query.model.TimeRangeQuery;
|
||||
import ch.psi.daq.query.range.QueryRange;
|
||||
import ch.psi.daq.query.range.QueryRangeImpl;
|
||||
|
||||
@RunWith(BlockJUnit4ClassRunner.class)
|
||||
public class TimeRangeQueryTest extends AbstractQueryTest {
|
||||
|
||||
@Test
|
||||
public void test_startAndEndDateTime_asString() throws ParseException {
|
||||
|
||||
// allowed format: yyyy/MM/dd hh:mm:ss.SSS
|
||||
String startDateTime = "2014/01/01 12:00:00.000";
|
||||
String endDateTime = "2014/01/01 18:00:00.000";
|
||||
|
||||
QueryRange range = new QueryRangeImpl(-1, 0, -1, 0);
|
||||
|
||||
TimeRangeQuery query = new TimeRangeQuery(
|
||||
Ordering.asc,
|
||||
Lists.newArrayList(), // DummyQueryProcessor simply returns a fixed list
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.count,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
startDateTime, // startDateTime : String
|
||||
endDateTime); // endDateTime : String
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat(TimeRangeQuery.DATE_FORMAT_STRING);
|
||||
|
||||
Assert.assertEquals(format.parse(startDateTime).getTime(), query.getQueryRange().getStartMillis());
|
||||
Assert.assertEquals(format.parse(endDateTime).getTime(), query.getQueryRange().getEndMillis());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_wrongFormat_exception() {
|
||||
String startDateTime = "2014-01-01 12:00:00.000";
|
||||
String endDateTime = "2014/01/01 18:00:00.000";
|
||||
QueryRange range = new QueryRangeImpl(-1, 0, -1, 0);
|
||||
TimeRangeQuery query = new TimeRangeQuery(
|
||||
Ordering.asc,
|
||||
Lists.newArrayList(), // DummyQueryProcessor simply returns a fixed list
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.count,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null,
|
||||
range,
|
||||
startDateTime, // startDateTime : String
|
||||
endDateTime); // endDateTime : String
|
||||
|
||||
Assert.assertEquals(-1, query.getQueryRange().getStartMillis());
|
||||
Assert.assertEquals(-1, query.getQueryRange().getStartMillis());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user