Skip to content
Permalink
Browse files

test: replace tests that call does not error with tests that call doe…

…s expected stuff
  • Loading branch information...
rhwood committed May 15, 2019
1 parent f900bc4 commit 003e1db2f3714e0de111a60ab7e822ec3af85dd2
Showing with 38 additions and 3 deletions.
  1. +38 −3 java/test/jmri/server/json/operations/JsonOperationsSocketServiceTest.java
@@ -1,11 +1,15 @@
package jmri.server.json.operations;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Locale;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.junit.After;
@@ -32,6 +36,27 @@
@Test
public void testOnListCar() throws IOException, JmriException, JsonException {
service.onList(JsonOperations.CAR, mapper.createObjectNode(), locale, 0);
JsonNode message = connection.getMessage();
assertNotNull(message);
assertEquals(9, message.size());
assertEquals(JsonOperations.CAR, message.path(0).path(JSON.TYPE).asText());
assertEquals("CP777", message.path(0).path(JSON.DATA).path(JSON.NAME).asText());
assertEquals(JsonOperations.CAR, message.path(1).path(JSON.TYPE).asText());
assertEquals("CP888", message.path(1).path(JSON.DATA).path(JSON.NAME).asText());
assertEquals(JsonOperations.CAR, message.path(2).path(JSON.TYPE).asText());
assertEquals("CP99", message.path(2).path(JSON.DATA).path(JSON.NAME).asText());
assertEquals(JsonOperations.CAR, message.path(3).path(JSON.TYPE).asText());
assertEquals("CPC10099", message.path(3).path(JSON.DATA).path(JSON.NAME).asText());
assertEquals(JsonOperations.CAR, message.path(4).path(JSON.TYPE).asText());
assertEquals("CPC20099", message.path(4).path(JSON.DATA).path(JSON.NAME).asText());
assertEquals(JsonOperations.CAR, message.path(5).path(JSON.TYPE).asText());
assertEquals("CPX10001", message.path(5).path(JSON.DATA).path(JSON.NAME).asText());
assertEquals(JsonOperations.CAR, message.path(6).path(JSON.TYPE).asText());
assertEquals("CPX10002", message.path(6).path(JSON.DATA).path(JSON.NAME).asText());
assertEquals(JsonOperations.CAR, message.path(7).path(JSON.TYPE).asText());
assertEquals("CPX20001", message.path(7).path(JSON.DATA).path(JSON.NAME).asText());
assertEquals(JsonOperations.CAR, message.path(8).path(JSON.TYPE).asText());
assertEquals("CPX20002", message.path(8).path(JSON.DATA).path(JSON.NAME).asText());
}

@Test
@@ -41,15 +66,25 @@ public void testOnMessageKernel() throws IOException, JmriException, JsonExcepti
locale, 42);
fail("Expected exception not thrown");
} catch (JsonException ex) {
if (ex.getCode() != 404) {
throw ex;
}
assertEquals(404, ex.getCode());
}
}

@Test
public void testOnListKernel() throws IOException, JmriException, JsonException {
service.onList(JsonOperations.KERNEL, mapper.createObjectNode(), locale, 0);
JsonNode message = connection.getMessage();
assertNotNull(message);
assertEquals(1, message.size());
assertEquals(JsonOperations.KERNEL, message.path(0).path(JSON.TYPE).asText());
JsonNode kernel = message.path(0).path(JSON.DATA);
assertNotNull(kernel);
assertEquals(1, kernel.path(JsonOperations.CARS).size());
assertFalse(kernel.path(JsonOperations.LEAD).isMissingNode());
assertEquals(kernel.path(JsonOperations.LEAD), kernel.path(JsonOperations.CARS).path(0));
assertFalse(kernel.path(JsonOperations.WEIGHT).isMissingNode());
assertEquals(0, kernel.path(JsonOperations.WEIGHT).asInt());
assertEquals(94, kernel.path(JSON.LENGTH).asInt());
}

@Before

0 comments on commit 003e1db

Please sign in to comment.
You can’t perform that action at this time.