use of org.openmuc.framework.driver.csv.CsvFile in project OpenMUC by isc-konstanz.
the class SamplingModeHhmmssTest method testNewDayRewind.
@Test
public void testNewDayRewind() throws ConnectionException, ArgumentSyntaxException {
String deviceSettings = "samplingmode=hhmmss;rewind=true";
CsvFile connectionSpy = PowerMockito.spy(CsvTestFactory.newConnection(DEVICE_ADDRESS, deviceSettings));
System.out.println(String.format("%10s, %10s", "hhmmss", "power_grid"));
PowerMockito.mockStatic(System.class);
PowerMockito.when(System.currentTimeMillis()).thenReturn(TIMESTAMP_3LINE);
read(connectionSpy, containers);
assertEquals(20.0, containers.get(INDEX_HHMMSS).getRecord().getValue().asDouble());
// rewind should performed so first line can be read
PowerMockito.when(System.currentTimeMillis()).thenReturn(TIMESTAMP_1LINE);
read(connectionSpy, containers);
assertEquals(10.0, containers.get(INDEX_HHMMSS).getRecord().getValue().asDouble());
}
use of org.openmuc.framework.driver.csv.CsvFile in project OpenMUC by isc-konstanz.
the class SamplingModeHhmmssTest method testNewDayWithoutRewind.
@Test
public void testNewDayWithoutRewind() throws ConnectionException, ArgumentSyntaxException {
String deviceSettings = "samplingmode=hhmmss";
CsvFile connectionSpy = PowerMockito.spy(CsvTestFactory.newConnection(DEVICE_ADDRESS, deviceSettings));
System.out.println(String.format("%10s, %10s", "hhmmss", "power_grid"));
PowerMockito.mockStatic(System.class);
PowerMockito.when(System.currentTimeMillis()).thenReturn(TIMESTAMP_3LINE);
read(connectionSpy, containers);
assertEquals(20.0, containers.get(INDEX_HHMMSS).getRecord().getValue().asDouble());
// no rewind, causes timetravel exception resulting in NaN
PowerMockito.when(System.currentTimeMillis()).thenReturn(TIMESTAMP_1LINE);
read(connectionSpy, containers);
assertEquals(Double.NaN, containers.get(INDEX_HHMMSS).getRecord().getValue().asDouble());
}
use of org.openmuc.framework.driver.csv.CsvFile in project OpenMUC by isc-konstanz.
the class SamplingModeHhmmssTest method testNormal.
@Test
public void testNormal() throws Exception {
String deviceSettings = "samplingmode=hhmmss";
CsvFile connectionSpy = PowerMockito.spy(CsvTestFactory.newConnection(DEVICE_ADDRESS, deviceSettings));
System.out.println(String.format("%10s, %10s", "hhmmss", "power_grid"));
PowerMockito.mockStatic(System.class);
PowerMockito.when(System.currentTimeMillis()).thenReturn(TIMESTAMP_1LINE);
read(connectionSpy, containers);
assertEquals(10.0, containers.get(INDEX_HHMMSS).getRecord().getValue().asDouble());
PowerMockito.when(System.currentTimeMillis()).thenReturn(TIMESTAMP_2LINE);
read(connectionSpy, containers);
assertEquals(15.0, containers.get(INDEX_HHMMSS).getRecord().getValue().asDouble());
PowerMockito.when(System.currentTimeMillis()).thenReturn(TIMESTAMP_3LINE);
read(connectionSpy, containers);
assertEquals(20.0, containers.get(INDEX_HHMMSS).getRecord().getValue().asDouble());
PowerMockito.when(System.currentTimeMillis()).thenReturn(TIMESTAMP_AFTER_3LINE);
read(connectionSpy, containers);
assertEquals(20.0, containers.get(INDEX_HHMMSS).getRecord().getValue().asDouble());
}
use of org.openmuc.framework.driver.csv.CsvFile in project OpenMUC by isc-konstanz.
the class SamplingModeHhmmssTest method testBeforeAvailableData.
@Test
public void testBeforeAvailableData() throws ConnectionException, ArgumentSyntaxException {
String deviceSettings = "samplingmode=hhmmss";
CsvFile connectionSpy = PowerMockito.spy(CsvTestFactory.newConnection(DEVICE_ADDRESS, deviceSettings));
System.out.println(String.format("%10s, %10s", "hhmmss", "power_grid"));
PowerMockito.mockStatic(System.class);
PowerMockito.when(System.currentTimeMillis()).thenReturn(TIMESTAMP_BEFORE_1LINE);
read(connectionSpy, containers);
assertEquals(Double.NaN, containers.get(INDEX_HHMMSS).getRecord().getValue().asDouble());
}
use of org.openmuc.framework.driver.csv.CsvFile in project OpenMUC by isc-konstanz.
the class SamplingModeHhmmssTest method testAfterAvailableData.
@Test
public void testAfterAvailableData() throws ConnectionException, ArgumentSyntaxException {
String deviceSettings = "samplingmode=hhmmss";
CsvFile connectionSpy = PowerMockito.spy(CsvTestFactory.newConnection(DEVICE_ADDRESS, deviceSettings));
System.out.println(String.format("%10s, %10s", "hhmmss", "power_grid"));
// last line of file should be returned
PowerMockito.mockStatic(System.class);
PowerMockito.when(System.currentTimeMillis()).thenReturn(TIMESTAMP_AFTER_3LINE);
read(connectionSpy, containers);
assertEquals(20.0, containers.get(INDEX_HHMMSS).getRecord().getValue().asDouble());
}
Aggregations