Search in sources :

Example 1 with BoolLatch

use of il.ac.technion.cs.smarthouse.utils.BoolLatch in project Smartcity-Smarthouse by TechnionYP5777.

the class ApplicationsCoreTest method onAppsListChangeTest.

@Test(timeout = 1000)
public void onAppsListChangeTest() throws Exception {
    final BoolLatch wasCalled = new BoolLatch();
    appCore.setOnAppsListChange(() -> wasCalled.setTrueAndRelease());
    Assert.assertNotNull(appCore.addApplication(new ApplicationPath(PathType.CLASS_NAME, APP1_CLASSPATH)));
    wasCalled.blockUntilTrue();
}
Also used : BoolLatch(il.ac.technion.cs.smarthouse.utils.BoolLatch) ApplicationPath(il.ac.technion.cs.smarthouse.system.applications.installer.ApplicationPath) Test(org.junit.Test)

Example 2 with BoolLatch

use of il.ac.technion.cs.smarthouse.utils.BoolLatch in project Smartcity-Smarthouse by TechnionYP5777.

the class SensorApiTest method subscribeTest.

@Test(timeout = 1000)
public void subscribeTest() {
    printTestName();
    final BoolLatch wasCalled = new BoolLatch();
    final int param1Data = 1234;
    SensorApi<MySensor> s = getSensor(SENSOR_COMM_NAME, MySensor.class, null);
    Assert.assertEquals(s.isConnected(), false);
    sensorConnect();
    Assert.assertEquals(s.isConnected(), true);
    s.subscribe(sensorData -> {
        Assert.assertEquals(sensorData.getParam1(), param1Data);
        Assert.assertEquals(sensorData.getCommercialName(), SENSOR_COMM_NAME);
        Assert.assertEquals(sensorData.getSensorLocation(), SensorLocation.UNDEFINED);
        wasCalled.setTrueAndRelease();
    });
    sensorSendMsg(param1Data + "");
    wasCalled.blockUntilTrue();
}
Also used : BoolLatch(il.ac.technion.cs.smarthouse.utils.BoolLatch) Test(org.junit.Test)

Example 3 with BoolLatch

use of il.ac.technion.cs.smarthouse.utils.BoolLatch in project Smartcity-Smarthouse by TechnionYP5777.

the class FileSystemImplTest method subscribeAndSendTest.

@Test(timeout = 1000)
public void subscribeAndSendTest() {
    final int NEW_VAL = 5;
    final BoolLatch wasCalled = new BoolLatch();
    resultNum = 0;
    fs.subscribe((path, data) -> {
        wasCalled.setTrueAndRelease();
        resultNum = (int) data;
    }, "");
    fs.sendMessage(NEW_VAL, "");
    wasCalled.blockUntilTrue();
    assert resultNum == NEW_VAL;
}
Also used : BoolLatch(il.ac.technion.cs.smarthouse.utils.BoolLatch) Test(org.junit.Test)

Example 4 with BoolLatch

use of il.ac.technion.cs.smarthouse.utils.BoolLatch in project Smartcity-Smarthouse by TechnionYP5777.

the class FileSystemImplTest method subscribeAndSendTest2.

@Test(timeout = 1000)
public void subscribeAndSendTest2() {
    final int NEW_VAL = 5;
    final BoolLatch wasCalled = new BoolLatch();
    resultNum = 0;
    resultString = "";
    fs.subscribe((path, data) -> {
        wasCalled.setTrueAndRelease();
        resultNum = (int) data;
        resultString = path;
    }, "a.b");
    fs.sendMessage(NEW_VAL, "a.b.c.d");
    wasCalled.blockUntilTrue();
    assert resultNum == NEW_VAL;
    Assert.assertEquals(resultString, "a.b.c.d");
    assert fs.getData("a") == null;
    assert fs.getData("a.b") == null;
    assert fs.getData("a.b.d") == null;
    assert fs.<Integer>getData("a.b.c.d") == NEW_VAL;
    assert fs.getChildren("a").contains("b");
    assert !fs.getChildren("a").contains("c");
    assert fs.getChildren("a.b").contains("c");
    assert fs.getChildren("a.b.c").contains("d");
    assert !fs.getChildren("a.b.c").contains("e");
    assert fs.getChildren("a.b.c.d").isEmpty();
    assert fs.getChildren("s").isEmpty();
    assert !fs.wasPathInitiated("s");
    assert fs.wasPathInitiated("a");
    assert fs.<Integer>getMostRecentDataOnBranch("a") == NEW_VAL;
}
Also used : BoolLatch(il.ac.technion.cs.smarthouse.utils.BoolLatch) Test(org.junit.Test)

Example 5 with BoolLatch

use of il.ac.technion.cs.smarthouse.utils.BoolLatch in project Smartcity-Smarthouse by TechnionYP5777.

the class SensorApiTest method sendMsgBeforeSubscribeTest.

@Test(timeout = 4000)
public void sendMsgBeforeSubscribeTest() {
    printTestName();
    final BoolLatch wasCalled = new BoolLatch();
    final int param1Data = 1234;
    SensorApi<MySensor> s = getSensor(SENSOR_COMM_NAME, MySensor.class, null);
    sensorConnect();
    sensorSendMsg(param1Data + "");
    s.subscribeOnTime(sensorData -> {
        Assert.assertEquals(sensorData.getParam1(), param1Data);
        Assert.assertEquals(sensorData.getCommercialName(), SENSOR_COMM_NAME);
        Assert.assertEquals(sensorData.getSensorLocation(), SensorLocation.UNDEFINED);
        wasCalled.setTrueAndRelease();
    }, LocalTime.now().plusSeconds(2));
    wasCalled.blockUntilTrue();
}
Also used : BoolLatch(il.ac.technion.cs.smarthouse.utils.BoolLatch) Test(org.junit.Test)

Aggregations

BoolLatch (il.ac.technion.cs.smarthouse.utils.BoolLatch)6 Test (org.junit.Test)6 ApplicationPath (il.ac.technion.cs.smarthouse.system.applications.installer.ApplicationPath)1