ATEST-259:
- fixing QueryRestController tests before adding the CORS filter
This commit is contained in:
6
.project
6
.project
@ -5,6 +5,11 @@
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
@ -20,5 +25,6 @@
|
||||
<nature>org.springframework.ide.eclipse.core.springnature</nature>
|
||||
<nature>org.springsource.ide.eclipse.gradle.core.nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
@ -10,14 +10,12 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
|
||||
import ch.psi.daq.cassandra.reader.CassandraReader;
|
||||
import ch.psi.daq.domain.reader.DataReader;
|
||||
import ch.psi.daq.query.processor.QueryProcessor;
|
||||
import ch.psi.daq.query.processor.QueryProcessorLocal;
|
||||
import ch.psi.daq.test.cassandra.admin.CassandraTestAdmin;
|
||||
import ch.psi.daq.test.cassandra.admin.CassandraTestAdminImpl;
|
||||
import ch.psi.daq.test.query.config.LocalQueryTestConfig;
|
||||
import ch.psi.daq.test.queryrest.query.DummyCassandraReader;
|
||||
import ch.psi.daq.test.queryrest.query.DummyDataReader;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
@ -35,12 +33,7 @@ public class DaqWebMvcConfig extends WebMvcConfigurationSupport {
|
||||
|
||||
@Bean
|
||||
public QueryProcessor cassandraQueryProcessorLocal() {
|
||||
return new QueryProcessorLocal(dataReader());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataReader dataReader() {
|
||||
return new DummyDataReader();
|
||||
return new QueryProcessorLocal(cassandraReader());
|
||||
}
|
||||
|
||||
@Bean CassandraReader cassandraReader() {
|
||||
|
@ -3,7 +3,6 @@ package ch.psi.daq.test.queryrest.controller;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
@ -31,20 +30,8 @@ public class DaqRestControllerTest extends AbstractDaqRestTest {
|
||||
@Resource
|
||||
private CassandraDataGen dataGen;
|
||||
|
||||
private static final boolean initialized = false;
|
||||
|
||||
private static final int DATA_KEYSPACE = 1;
|
||||
public static final String[] TEST_CHANNEL_NAMES = new String[]{"testChannel1", "testChannel2"};
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
if (!initialized) {
|
||||
cassandraTestAdmin.truncateAll();
|
||||
|
||||
dataGen.writeData(DATA_KEYSPACE, 100, 2, TEST_CHANNEL_NAMES);
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {}
|
||||
|
||||
@ -59,10 +46,26 @@ public class DaqRestControllerTest extends AbstractDaqRestTest {
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0]").value("testChannel1"))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").value("testChannel2"))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[2]").doesNotExist());
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0]").value("BooleanScalar"))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").value("BooleanWaveform"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecificChannelSearch() throws Exception {
|
||||
this.mockMvc.perform(
|
||||
MockMvcRequestBuilders
|
||||
.get(QueryRestController.CHANNELS + "/integer")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0]").value("IntegerScalar"))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").value("IntegerWaveform"))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[2]").value("UIntegerScalar"))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[3]").value("UIntegerWaveform"))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[4]").doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -182,23 +185,23 @@ public class DaqRestControllerTest extends AbstractDaqRestTest {
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.min").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.min.value").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.min.value").value(100))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.min.event").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.min.event.channel").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.min.event.channel").value(TEST_CHANNEL_NAMES[0]))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.min.event.pulseId").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.min.event.pulseId").value(100))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.maxima").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.max").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.max.value").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.max.value").value(101))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.max.event").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.max.event.channel").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.max.event.channel").value(TEST_CHANNEL_NAMES[0]))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.max.event.pulseId").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.max.event.pulseId").value(101));
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].channel").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].channel").value(TEST_CHANNEL_NAMES[0]))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima.min").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima.min.value").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima.min.value").value(Double.valueOf(100)))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima.min.event").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima.min.event.pulseId").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima.min.event.pulseId").value(100))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima.max").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima.max.value").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima.max.value").value(Double.valueOf(101)))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima.max.event").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima.max.event.pulseId").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima.max.event.pulseId").value(101));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,9 +3,9 @@
|
||||
*/
|
||||
package ch.psi.daq.test.queryrest.query;
|
||||
|
||||
import java.awt.image.MultiPixelPackedSampleModel;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -74,7 +74,12 @@ public class DummyCassandraReader implements CassandraReader {
|
||||
*/
|
||||
@Override
|
||||
public Stream<String> getChannelStream(String regex) {
|
||||
return Stream.of(channels);
|
||||
Stream<String> channelStream = Stream.of(channels);
|
||||
if (regex != null) {
|
||||
Pattern pattern = Pattern.compile(regex.toLowerCase());
|
||||
channelStream = Stream.of(channels).filter(channel -> pattern.matcher(channel.toLowerCase()).find());
|
||||
}
|
||||
return channelStream;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,7 +137,27 @@ public class DummyCassandraReader implements CassandraReader {
|
||||
|
||||
|
||||
private Stream<? extends DataEvent> getDummyEventStream(String channel, long startIndex, long endIndex) {
|
||||
return dataGen.generateData(startIndex, (endIndex-startIndex), channel).stream();
|
||||
|
||||
return dataGen.generateData(startIndex, (endIndex-startIndex + 1),
|
||||
i -> i,
|
||||
i -> i,
|
||||
i -> i,
|
||||
i -> i,
|
||||
i -> i,
|
||||
i -> Long.valueOf(i),
|
||||
channel).stream();
|
||||
}
|
||||
|
||||
private List<? extends DataEvent> getDummyEvents(String channel, long startIndex, long endIndex) {
|
||||
|
||||
return dataGen.generateData(startIndex, (endIndex-startIndex + 1),
|
||||
i -> i,
|
||||
i -> i,
|
||||
i -> i,
|
||||
i -> i,
|
||||
i -> i,
|
||||
i -> Long.valueOf(i),
|
||||
channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,9 +182,9 @@ public class DummyCassandraReader implements CassandraReader {
|
||||
@Override
|
||||
public ChannelEvent getEvent(ChannelEventQueryInfo queryInfo, String... columns) {
|
||||
if (queryInfo.getPulseId() > 0) {
|
||||
return dataGen.generateData(queryInfo.getPulseId(), 1, queryInfo.getChannel()).get(0);
|
||||
return (ChannelEvent) getDummyEvents(queryInfo.getChannel(), queryInfo.getPulseId(), queryInfo.getPulseId()).get(0);
|
||||
}
|
||||
return dataGen.generateData(queryInfo.getGlobalMillis(), 1, queryInfo.getChannel()).get(0);
|
||||
return (ChannelEvent) getDummyEvents(queryInfo.getChannel(), queryInfo.getGlobalMillis(), queryInfo.getGlobalMillis()).get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,10 +200,15 @@ public class DummyCassandraReader implements CassandraReader {
|
||||
*/
|
||||
@Override
|
||||
public Stream<? extends ChannelEventQuery> getChannelEventQueryStream(PulseIdRangeQuery query) {
|
||||
|
||||
|
||||
return dataGen.generateMetaPulseId(
|
||||
KEYSPACE,
|
||||
query.getStartPulseId(),
|
||||
(query.getEndPulseId() - query.getStartPulseId()),
|
||||
(query.getEndPulseId() - query.getStartPulseId() + 1),
|
||||
i -> i,
|
||||
i -> i,
|
||||
i -> i,
|
||||
query.getChannel()).stream();
|
||||
}
|
||||
|
||||
@ -187,15 +217,16 @@ public class DummyCassandraReader implements CassandraReader {
|
||||
*/
|
||||
@Override
|
||||
public Stream<? extends ChannelEventQuery> getChannelEventQueryStream(TimeRangeQuery query) {
|
||||
|
||||
|
||||
return dataGen.generateMetaTime(
|
||||
KEYSPACE,
|
||||
query.getStartMillis(),
|
||||
(query.getEndMillis() - query.getStartMillis()),
|
||||
query.getChannel())
|
||||
.stream()
|
||||
.map(e -> {
|
||||
return (ChannelEventQuery) e;
|
||||
});
|
||||
(query.getEndMillis() - query.getStartMillis() + 1),
|
||||
i -> i,
|
||||
i -> i,
|
||||
i -> i,
|
||||
query.getChannel()).stream();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,10 +234,9 @@ public class DummyCassandraReader implements CassandraReader {
|
||||
*/
|
||||
@Override
|
||||
public Stream<MetaPulseId> getMetaPulseIdStream(PulseIdRangeQuery query) {
|
||||
return dataGen.generateMetaPulseId(
|
||||
KEYSPACE,
|
||||
query.getStartPulseId(), (query.getEndPulseId() - query.getStartPulseId()),
|
||||
query.getChannel()).stream();
|
||||
|
||||
return getChannelEventQueryStream(query).map(r -> { return (MetaPulseId) r; });
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -215,10 +245,8 @@ public class DummyCassandraReader implements CassandraReader {
|
||||
*/
|
||||
@Override
|
||||
public Stream<MetaTime> getMetaTimeStream(TimeRangeQuery query) {
|
||||
return dataGen.generateMetaTime(
|
||||
KEYSPACE,
|
||||
query.getStartMillis(), (query.getEndMillis() - query.getStartMillis()),
|
||||
query.getChannel()).stream();
|
||||
|
||||
return getChannelEventQueryStream(query).map(r -> { return (MetaTime) r; });
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user