Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Update JsonSignalHeadHttpServiceTest.java
remove unused calls to set variables null Add nullChecks
1 parent
554142d
commit 0b53ea8
Showing
1 changed file
with
5 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| } | |||
| @Test | |||
| public void testDoPost() throws JmriException, JsonException { | |||
| //create a signalhead for testing | |||
| String sysName = "IH1"; | |||
| String userName = "SH1"; | |||
| SignalHead s = new jmri.implementation.VirtualSignalHead(sysName, userName); | |||
| jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).register(s); | |||
| assertNotNull(s); | |||
|
|
|||
| JsonNode result = null; | |||
| JsonNode message = null; | |||
| JsonNode result; | |||
| JsonNode message; | |||
|
|
|||
| //set signalhead to Green and verify change | |||
| message = mapper.createObjectNode().put(JSON.NAME, userName).put(JSON.STATE, SignalHead.GREEN); | |||
|
|||
|
|||
| result = service.doPost(JsonSignalHead.SIGNAL_HEAD, userName, message, new JsonRequest(locale, JSON.V5, JSON.GET, 42)); | |||
| validate(result); | |||
| assertEquals(SignalHead.GREEN, s.getState()); | |||
| assertEquals(SignalHead.GREEN, result.path(JSON.DATA).path(JSON.STATE).asInt()); | |||
|
|
|||
| // try to set to FLASHLUNAR, which should not be allowed for this signalHead, | |||
| // so check for error, and verify state does not change | |||
| result = null; | |||
| message = null; | |||
| try { | |||
| message = mapper.createObjectNode().put(JSON.NAME, userName).put(JSON.STATE, SignalHead.FLASHLUNAR); | |||
| result = service.doPost(JsonSignalHead.SIGNAL_HEAD, userName, message, new JsonRequest(locale, JSON.V5, JSON.GET, 42)); | |||
| assertNotNull(result); | |||
| fail("Expected exception not thrown"); | |||
| } catch (JsonException ex) { | |||
| assertEquals(400, ex.getCode()); | |||
| } | |||
| assertEquals(SignalHead.GREEN, s.getState()); | |||
| assertEquals(false, s.getHeld()); | |||
| // set signalmast to Held, then verify | |||
| message = mapper.createObjectNode().put(JSON.NAME, userName).put(JSON.STATE, SignalHead.HELD); | |||
| result = service.doPost(JsonSignalHead.SIGNAL_HEAD, userName, message, new JsonRequest(locale, JSON.V5, JSON.GET, 42)); | |||
| assertNotNull(result); | |||
| assertEquals(true, s.getHeld()); | |||
|
|
|||
| assertEquals(true, s.getHeld()); | |||
| // set signalmast to something other than Held, then verify Held is released | |||
| message = mapper.createObjectNode().put(JSON.NAME, userName).put(JSON.STATE, SignalHead.RED); | |||
| result = service.doPost(JsonSignalHead.SIGNAL_HEAD, userName, message, new JsonRequest(locale, JSON.V5, JSON.GET, 42)); | |||
| assertNotNull(result); | |||
| assertEquals(false, s.getHeld()); | |||
| } | |||
|
|
|||
| @Test | |||