ATEST-344
This commit is contained in:
@@ -12,12 +12,15 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupp
|
||||
|
||||
import ch.psi.daq.cassandra.reader.CassandraReader;
|
||||
import ch.psi.daq.domain.reader.DataReader;
|
||||
import ch.psi.daq.domain.status.StatusReader;
|
||||
import ch.psi.daq.query.config.QueryConfig;
|
||||
import ch.psi.daq.query.processor.QueryProcessor;
|
||||
import ch.psi.daq.query.processor.QueryProcessorLocal;
|
||||
import ch.psi.daq.test.query.config.LocalQueryTestConfig;
|
||||
import ch.psi.daq.test.queryrest.query.DummyArchiverApplianceReader;
|
||||
import ch.psi.daq.test.queryrest.query.DummyCassandraReader;
|
||||
import ch.psi.daq.test.queryrest.status.DummyArchiverApplianceStatusReader;
|
||||
import ch.psi.daq.test.queryrest.status.DummyCassandraStatusReader;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
@@ -50,4 +53,16 @@ public class DaqWebMvcConfig extends WebMvcConfigurationSupport {
|
||||
public DataReader archiverApplianceReader() {
|
||||
return new DummyArchiverApplianceReader();
|
||||
}
|
||||
|
||||
@Bean(name = QueryConfig.BEAN_NAME_CASSANDRA_STATUS_READER)
|
||||
@Lazy
|
||||
public StatusReader cassandraStatusReader() {
|
||||
return new DummyCassandraStatusReader();
|
||||
}
|
||||
|
||||
@Bean(name = QueryConfig.BEAN_NAME_ARCHIVER_APPLIANCE_STATUS_READER)
|
||||
@Lazy
|
||||
public StatusReader archiverApplianceStatusReader() {
|
||||
return new DummyArchiverApplianceStatusReader();
|
||||
}
|
||||
}
|
||||
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
package ch.psi.daq.test.queryrest.controller;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
|
||||
import ch.psi.daq.common.time.TimeUtils;
|
||||
import ch.psi.daq.domain.json.ChannelName;
|
||||
import ch.psi.daq.domain.query.status.channel.ChannelStatusQuery;
|
||||
import ch.psi.daq.domain.reader.Backend;
|
||||
import ch.psi.daq.queryrest.controller.QueryRestController;
|
||||
import ch.psi.daq.test.queryrest.AbstractDaqRestTest;
|
||||
|
||||
/**
|
||||
* Tests the {@link DaqController} implementation.
|
||||
*/
|
||||
public class QueryRestControllerChannelStatusTest extends AbstractDaqRestTest {
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {}
|
||||
|
||||
@Test
|
||||
public void testChannelStatusQuery_01() throws Exception {
|
||||
ChannelStatusQuery query = new ChannelStatusQuery("DataBuffer1", "DataBuffer2");
|
||||
|
||||
String content = mapper.writeValueAsString(query);
|
||||
System.out.println(content);
|
||||
|
||||
this.mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post(QueryRestController.PATH_STATUS_CHANNELS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content))
|
||||
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].channel.backend").value(Backend.SF_DATABUFFER.getKey()))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].channel.name").value("DataBuffer1"))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].recording").value(false))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].connected").value(false))
|
||||
.andExpect(
|
||||
MockMvcResultMatchers.jsonPath("$[0].lastEventDate").value(
|
||||
TimeUtils.format(TimeUtils.getTimeFromMillis(0, 0))))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[1].channel.backend").value(Backend.SF_DATABUFFER.getKey()))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[1].channel.name").value("DataBuffer2"))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[1].recording").value(false))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[1].connected").value(false))
|
||||
.andExpect(
|
||||
MockMvcResultMatchers.jsonPath("$[1].lastEventDate").value(
|
||||
TimeUtils.format(TimeUtils.getTimeFromMillis(0, 0))))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[2]").doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChannelStatusQuery_02() throws Exception {
|
||||
ChannelStatusQuery query = new ChannelStatusQuery();
|
||||
query.addChannel(new ChannelName("ArchiverAppliance1", Backend.SF_ARCHIVERAPPLIANCE));
|
||||
query.addChannel(new ChannelName("ArchiverAppliance2", Backend.SF_ARCHIVERAPPLIANCE));
|
||||
|
||||
String content = mapper.writeValueAsString(query);
|
||||
System.out.println(content);
|
||||
|
||||
this.mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post(QueryRestController.PATH_STATUS_CHANNELS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content))
|
||||
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists())
|
||||
.andExpect(
|
||||
MockMvcResultMatchers.jsonPath("$[0].channel.backend").value(Backend.SF_ARCHIVERAPPLIANCE.getKey()))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].channel.name").value("ArchiverAppliance1"))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].recording").value(true))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].connected").value(true))
|
||||
.andExpect(
|
||||
MockMvcResultMatchers.jsonPath("$[0].lastEventDate").value(
|
||||
TimeUtils.format(TimeUtils.getTimeFromMillis(1467638000000L, 0))))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists())
|
||||
.andExpect(
|
||||
MockMvcResultMatchers.jsonPath("$[1].channel.backend").value(Backend.SF_ARCHIVERAPPLIANCE.getKey()))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[1].channel.name").value("ArchiverAppliance2"))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[1].recording").value(true))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[1].connected").value(true))
|
||||
.andExpect(
|
||||
MockMvcResultMatchers.jsonPath("$[1].lastEventDate").value(
|
||||
TimeUtils.format(TimeUtils.getTimeFromMillis(1467638000000L, 0))))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[2]").doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChannelStatusQuery_03() throws Exception {
|
||||
ChannelStatusQuery query = new ChannelStatusQuery();
|
||||
query.addChannel(new ChannelName("ArchiverAppliance1", Backend.SF_ARCHIVERAPPLIANCE));
|
||||
query.addChannel(new ChannelName("ArchiverAppliance2", Backend.SF_ARCHIVERAPPLIANCE));
|
||||
|
||||
String content = mapper.writeValueAsString(query);
|
||||
System.out.println(content);
|
||||
|
||||
MvcResult result = this.mockMvc.perform(MockMvcRequestBuilders
|
||||
.post(QueryRestController.PATH_STATUS_CHANNELS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(content))
|
||||
.andDo(MockMvcResultHandlers.print())
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andReturn();
|
||||
|
||||
String response = result.getResponse().getContentAsString();
|
||||
System.out.println("Response: " + response);
|
||||
|
||||
assertFalse(response.contains("lastEventTime"));
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package ch.psi.daq.test.queryrest.status;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import ch.psi.daq.common.time.TimeUtils;
|
||||
import ch.psi.daq.domain.json.ChannelName;
|
||||
import ch.psi.daq.domain.json.status.channel.ChannelStatus;
|
||||
import ch.psi.daq.domain.reader.Backend;
|
||||
import ch.psi.daq.domain.status.AbstractStatusReader;
|
||||
|
||||
public class DummyArchiverApplianceStatusReader extends AbstractStatusReader {
|
||||
|
||||
public DummyArchiverApplianceStatusReader() {
|
||||
super(Backend.SF_ARCHIVERAPPLIANCE, 30);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ChannelStatus> getChannelStatusAsync(String channel) {
|
||||
return CompletableFuture.completedFuture(new ChannelStatus(new ChannelName(channel, getBackend()), true, true,
|
||||
TimeUtils.getTimeFromMillis(1467638000000L, 0)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package ch.psi.daq.test.queryrest.status;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import ch.psi.daq.common.time.TimeUtils;
|
||||
import ch.psi.daq.domain.json.ChannelName;
|
||||
import ch.psi.daq.domain.json.status.channel.ChannelStatus;
|
||||
import ch.psi.daq.domain.reader.Backend;
|
||||
import ch.psi.daq.domain.status.AbstractStatusReader;
|
||||
|
||||
public class DummyCassandraStatusReader extends AbstractStatusReader {
|
||||
|
||||
public DummyCassandraStatusReader() {
|
||||
super(Backend.SF_DATABUFFER, 30);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ChannelStatus> getChannelStatusAsync(String channel) {
|
||||
return CompletableFuture.completedFuture(new ChannelStatus(new ChannelName(channel, getBackend()), false, false,
|
||||
TimeUtils.getTimeFromMillis(0, 0)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user