Merge branch 'master' into ATEST-128

This commit is contained in:
Fabian Märki
2015-07-31 14:36:26 +02:00
10 changed files with 216 additions and 86 deletions
@@ -5,9 +5,10 @@ import javax.annotation.Resource;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
@@ -18,21 +19,25 @@ import org.springframework.web.context.WebApplicationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import ch.psi.daq.queryrest.QueryRestApplication;
import ch.psi.daq.queryrest.config.QueryRestConfig;
import ch.psi.daq.test.cassandra.CassandraDaqUnitDependencyInjectionTestExecutionListener;
@TestExecutionListeners({
CassandraDaqUnitDependencyInjectionTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class})
//@SpringApplicationConfiguration(classes = {QueryRestApplication.class, DaqWebMvcConfig.class})
//@EmbeddedCassandra
@SpringApplicationConfiguration(classes = {
QueryRestApplication.class
,QueryRestConfig.class
,DaqWebMvcConfig.class
})
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@WebAppConfiguration
@ContextConfiguration(classes = DaqWebMvcConfig.class)
@RunWith(SpringJUnit4ClassRunner.class)
public abstract class AbstractDaqRestTest {
@Resource
@Autowired
protected WebApplicationContext webApplicationContext;
protected MockMvc mockMvc;
@@ -1,6 +1,7 @@
package ch.psi.daq.test.queryrest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
@@ -8,16 +9,20 @@ import org.springframework.context.annotation.PropertySources;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import ch.psi.daq.query.processor.QueryProcessorLocal;
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.CassandraAdmin;
import ch.psi.daq.test.cassandra.admin.CassandraAdminImpl;
import ch.psi.daq.test.query.config.LocalQueryTestConfig;
import ch.psi.daq.test.queryrest.query.DummyDataReader;
@Configuration
@ComponentScan
@EnableWebMvc
@PropertySources(value = {
@PropertySource(value = {"classpath:queryrest-test.properties"})
})
@EnableWebMvc
public class DaqWebMvcConfig extends WebMvcConfigurationSupport {
// ensure that properties in dispatcher.properties are loaded first and then overwritten by the
@@ -25,9 +30,19 @@ public class DaqWebMvcConfig extends WebMvcConfigurationSupport {
@Import(value = {LocalQueryTestConfig.class})
static class InnerConfiguration {
}
@Bean
public QueryProcessor queryProcessor() {
return new QueryProcessorLocal(new DummyDataReader());
}
}
@Bean
public DataReader dataReader() {
return new DummyDataReader();
}
@Bean
public CassandraAdmin cassandraAdmin() {
return new CassandraAdminImpl();
}
}
@@ -48,6 +48,23 @@ public class DaqRestControllerTest extends AbstractDaqRestTest {
@After
public void tearDown() throws Exception {}
@Test
public void testChannelNameQuery() throws Exception {
this.mockMvc.perform(
MockMvcRequestBuilders
.get("/" + QueryRestController.CHANNELS)
.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("testChannel1"))
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").value("testChannel2"))
.andExpect(MockMvcResultMatchers.jsonPath("$[2]").doesNotExist());
}
@Test
public void testPulseRangeQuery() throws Exception {
PulseRangeQuery request = new PulseRangeQuery(
@@ -56,9 +73,13 @@ public class DaqRestControllerTest extends AbstractDaqRestTest {
TEST_CHANNEL_NAMES);
String content = mapper.writeValueAsString(request);
System.out.println(content);
content = "{\"channels\":[\"testChannel1\",\"testChannel2\"],\"startPulseId\":100,\"endPulseId\":101}";
this.mockMvc
.perform(MockMvcRequestBuilders.post(QueryRestController.QUERY)
.perform(MockMvcRequestBuilders
.post("/" + QueryRestController.QUERY)
.contentType(MediaType.APPLICATION_JSON)
.content(content))
@@ -86,8 +107,8 @@ public class DaqRestControllerTest extends AbstractDaqRestTest {
String content = mapper.writeValueAsString(request);
this.mockMvc
.perform(MockMvcRequestBuilders.post(QueryRestController.QUERY)
this.mockMvc.perform(MockMvcRequestBuilders
.post("/" + QueryRestController.QUERY)
.contentType(MediaType.APPLICATION_JSON)
.content(content))
@@ -116,12 +137,15 @@ public class DaqRestControllerTest extends AbstractDaqRestTest {
TEST_CHANNEL_NAMES);
String content = mapper.writeValueAsString(request);
System.out.println(content);
this.mockMvc
.perform(MockMvcRequestBuilders.post(QueryRestController.QUERY)
.perform(
MockMvcRequestBuilders
.post("/" + QueryRestController.QUERY)
.contentType(MediaType.APPLICATION_JSON)
.content(content))
.content(content)
)
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
@@ -150,7 +174,7 @@ public class DaqRestControllerTest extends AbstractDaqRestTest {
String content = mapper.writeValueAsString(request);
this.mockMvc
.perform(MockMvcRequestBuilders.post(QueryRestController.QUERY)
.perform(MockMvcRequestBuilders.post("/" + QueryRestController.QUERY)
.contentType(MediaType.APPLICATION_JSON)
.content(content))
@@ -177,20 +201,4 @@ public class DaqRestControllerTest extends AbstractDaqRestTest {
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.max.event.pulseId").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$.minima.max.event.pulseId").value(101));
}
@Test
public void testChannelNameQuery() throws Exception {
this.mockMvc
.perform(MockMvcRequestBuilders.get(QueryRestController.CHANNELS)
.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("testChannel1"))
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").value("testChannel2"))
.andExpect(MockMvcResultMatchers.jsonPath("$[2]").doesNotExist());
}
}
@@ -1,7 +1,6 @@
package ch.psi.daq.test.queryrest.query;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;
import java.util.stream.LongStream;
import java.util.stream.Stream;
@@ -52,7 +51,8 @@ public class DummyDataReader implements DataReader {
i,
i,
0,
"data_" + UUID.randomUUID().toString());
123 // dummy value
);
});
}
}