Search in sources :

Example 1 with CsvFile

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());
}
Also used : CsvFile(org.openmuc.framework.driver.csv.CsvFile) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with CsvFile

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());
}
Also used : CsvFile(org.openmuc.framework.driver.csv.CsvFile) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with CsvFile

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());
}
Also used : CsvFile(org.openmuc.framework.driver.csv.CsvFile) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with CsvFile

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());
}
Also used : CsvFile(org.openmuc.framework.driver.csv.CsvFile) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with CsvFile

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());
}
Also used : CsvFile(org.openmuc.framework.driver.csv.CsvFile) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.junit.Test)8 CsvFile (org.openmuc.framework.driver.csv.CsvFile)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)1 ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)1 ScanException (org.openmuc.framework.config.ScanException)1 CsvDriver (org.openmuc.framework.driver.csv.CsvDriver)1 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)1