Search in sources :

Example 51 with Reporter

use of jmri.Reporter in project JMRI by JMRI.

the class AbstractReporterMgrTestBase method testRename.

@Test
public void testRename() {
    // get reporter
    Reporter t1 = l.newReporter(getSystemName(getNameToTest1()), "before");
    Assert.assertNotNull("t1 real object ", t1);
    t1.setUserName("after");
    Reporter t2 = l.getByUserName("after");
    Assert.assertEquals("same object", t1, t2);
    Assert.assertEquals("no old object", null, l.getByUserName("before"));
}
Also used : Reporter(jmri.Reporter) Test(org.junit.Test)

Example 52 with Reporter

use of jmri.Reporter in project JMRI by JMRI.

the class ProxyReporterManagerTest method testProvideUser.

@Test
public void testProvideUser() {
    Reporter l1 = l.provideReporter("211");
    l1.setUserName("user 1");
    Reporter l2 = l.provideReporter("user 1");
    Reporter l3 = l.getReporter("user 1");
    Assert.assertNotNull(l1);
    Assert.assertNotNull(l2);
    Assert.assertNotNull(l3);
    Assert.assertEquals(l1, l2);
    Assert.assertEquals(l3, l2);
    Assert.assertEquals(l1, l3);
    Reporter l4 = l.getReporter("JLuser 1");
    Assert.assertNull(l4);
}
Also used : Reporter(jmri.Reporter) Test(org.junit.Test)

Example 53 with Reporter

use of jmri.Reporter in project JMRI by JMRI.

the class JsonReporterHttpServiceTest method testDoPost.

@Test
public void testDoPost() throws JmriException {
    ObjectMapper mapper = new ObjectMapper();
    JsonReporterHttpService service = new JsonReporterHttpService(mapper);
    ReporterManager manager = InstanceManager.getDefault(ReporterManager.class);
    Reporter reporter1 = manager.provideReporter("IR1");
    JsonNode result;
    JsonNode message;
    try {
        // set off
        message = mapper.createObjectNode().put(JSON.NAME, "IR1").put(JsonReporter.REPORT, "close");
        result = service.doPost(REPORTER, "IR1", message, Locale.ENGLISH);
        Assert.assertEquals("close", reporter1.getCurrentReport());
        Assert.assertNotNull(result);
        Assert.assertEquals("close", result.path(JSON.DATA).path(JsonReporter.REPORT).asText());
        // set on
        message = mapper.createObjectNode().put(JSON.NAME, "IR1").put(JsonReporter.REPORT, "throw");
        result = service.doPost(REPORTER, "IR1", message, Locale.ENGLISH);
        Assert.assertEquals("throw", reporter1.getCurrentReport());
        Assert.assertNotNull(result);
        Assert.assertEquals("throw", result.path(JSON.DATA).path(JsonReporter.REPORT).asText());
        // set null
        message = mapper.createObjectNode().put(JSON.NAME, "IR1").putNull(JsonReporter.REPORT);
        result = service.doPost(REPORTER, "IR1", message, Locale.ENGLISH);
        Assert.assertNull(reporter1.getCurrentReport());
        Assert.assertEquals("null", result.path(JSON.DATA).path(JsonReporter.REPORT).asText());
    } catch (JsonException ex) {
        Assert.fail(ex.getMessage());
    }
}
Also used : JsonException(jmri.server.json.JsonException) ReporterManager(jmri.ReporterManager) Reporter(jmri.Reporter) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 54 with Reporter

use of jmri.Reporter in project JMRI by JMRI.

the class JsonReporterSocketServiceTest method testReporterChange.

@Test
public void testReporterChange() {
    try {
        JsonMockConnection connection = new JsonMockConnection((DataOutputStream) null);
        JsonNode message = connection.getObjectMapper().createObjectNode().put(JSON.NAME, "IR1");
        JsonReporterSocketService service = new JsonReporterSocketService(connection);
        ReporterManager manager = InstanceManager.getDefault(ReporterManager.class);
        Reporter memory1 = manager.provideReporter("IR1");
        service.onMessage(JsonReporter.REPORTER, message, Locale.ENGLISH);
        // TODO: test that service is listener in ReporterManager
        // default null value of memory1 has text representation "null" in JSON
        Assert.assertEquals("null", connection.getMessage().path(JSON.DATA).path(JsonReporter.REPORT).asText());
        memory1.setReport("throw");
        JUnitUtil.waitFor(() -> {
            return memory1.getCurrentReport().equals("throw");
        }, "Reporter to throw");
        Assert.assertEquals("throw", connection.getMessage().path(JSON.DATA).path(JsonReporter.REPORT).asText());
        memory1.setReport("close");
        JUnitUtil.waitFor(() -> {
            return memory1.getCurrentReport().equals("close");
        }, "Reporter to close");
        Assert.assertEquals("close", memory1.getCurrentReport());
        Assert.assertEquals("close", connection.getMessage().path(JSON.DATA).path(JsonReporter.REPORT).asText());
        service.onClose();
    // TODO: test that service is no longer a listener in ReporterManager
    } catch (IOException | JmriException | JsonException ex) {
        Assert.fail(ex.getMessage());
    }
}
Also used : JsonException(jmri.server.json.JsonException) ReporterManager(jmri.ReporterManager) JsonMockConnection(jmri.server.json.JsonMockConnection) Reporter(jmri.Reporter) JmriException(jmri.JmriException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Test(org.junit.Test)

Example 55 with Reporter

use of jmri.Reporter in project JMRI by JMRI.

the class JsonReporterSocketServiceTest method testOnMessageChange.

@Test
public void testOnMessageChange() {
    try {
        JsonMockConnection connection = new JsonMockConnection((DataOutputStream) null);
        JsonNode message;
        JsonReporterSocketService service = new JsonReporterSocketService(connection);
        ReporterManager manager = InstanceManager.getDefault(ReporterManager.class);
        Reporter memory1 = manager.provideReporter("IR1");
        // Reporter "close"
        message = connection.getObjectMapper().createObjectNode().put(JSON.NAME, "IR1").put(JsonReporter.REPORT, "close");
        service.onMessage(JsonReporter.REPORTER, message, Locale.ENGLISH);
        Assert.assertEquals("close", memory1.getCurrentReport());
        // Reporter "throw"
        message = connection.getObjectMapper().createObjectNode().put(JSON.NAME, "IR1").put(JsonReporter.REPORT, "throw");
        service.onMessage(JsonReporter.REPORTER, message, Locale.ENGLISH);
        Assert.assertEquals("throw", memory1.getCurrentReport());
        // Reporter UNKNOWN - remains ON
        message = connection.getObjectMapper().createObjectNode().put(JSON.NAME, "IR1").putNull(JsonReporter.REPORT);
        service.onMessage(JsonReporter.REPORTER, message, Locale.ENGLISH);
        Assert.assertEquals(null, memory1.getCurrentReport());
        memory1.setReport("throw");
        // Reporter no value
        message = connection.getObjectMapper().createObjectNode().put(JSON.NAME, "IR1");
        JsonException exception = null;
        try {
            service.onMessage(JsonReporter.REPORTER, message, Locale.ENGLISH);
        } catch (JsonException ex) {
            exception = ex;
        }
        Assert.assertEquals("throw", memory1.getCurrentReport());
        Assert.assertNull(exception);
    } catch (IOException | JmriException | JsonException ex) {
        Assert.fail(ex.getMessage());
    }
}
Also used : JsonException(jmri.server.json.JsonException) ReporterManager(jmri.ReporterManager) JsonMockConnection(jmri.server.json.JsonMockConnection) Reporter(jmri.Reporter) JmriException(jmri.JmriException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Reporter (jmri.Reporter)55 Test (org.junit.Test)18 ReporterManager (jmri.ReporterManager)10 Block (jmri.Block)6 Element (org.jdom2.Element)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 IOException (java.io.IOException)4 BlockManager (jmri.BlockManager)4 JsonException (jmri.server.json.JsonException)4 Date (java.util.Date)3 JmriException (jmri.JmriException)3 Sensor (jmri.Sensor)3 OBlock (jmri.jmrit.logix.OBlock)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ParseException (java.text.ParseException)2 PhysicalLocationReporter (jmri.PhysicalLocationReporter)2 Location (jmri.jmrit.operations.locations.Location)2 JsonMockConnection (jmri.server.json.JsonMockConnection)2 GuiLafPreferencesManager (apps.gui.GuiLafPreferencesManager)1