From 811237c1850b52c3cac3b51b9da99412fe47af62 Mon Sep 17 00:00:00 2001 From: baardl Date: Sat, 16 Nov 2019 09:25:44 +0100 Subject: [PATCH] #2 Validate part of joson --- pom.xml | 6 ++++++ .../java/no/entra/bacnet/json/BacNetParserTest.java | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0012167..9663017 100644 --- a/pom.xml +++ b/pom.xml @@ -70,6 +70,12 @@ ${mockito.version} test + + org.skyscreamer + jsonassert + 1.5.0 + test + diff --git a/src/test/java/no/entra/bacnet/json/BacNetParserTest.java b/src/test/java/no/entra/bacnet/json/BacNetParserTest.java index 93324ca..84c3e99 100644 --- a/src/test/java/no/entra/bacnet/json/BacNetParserTest.java +++ b/src/test/java/no/entra/bacnet/json/BacNetParserTest.java @@ -9,6 +9,7 @@ import com.serotonin.bacnet4j.type.Encodable; import com.serotonin.bacnet4j.type.constructed.ServicesSupported; import com.serotonin.bacnet4j.util.sero.ByteQueue; +import org.json.JSONException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -16,11 +17,19 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.skyscreamer.jsonassert.JSONAssert.assertEquals; public class BacNetParserTest { private static final Logger log = LoggerFactory.getLogger( BacNetParserTest.class ); private Gson gson; + private static final String partOfApu = "{\"subscriberProcessIdentifier\": {\n" + + " \"smallValue\": 0,\n" + + " \"bigValue\": null,\n" + + " \"tagNumber\": 0,\n" + + " \"typeId\": 2,\n" + + " \"contextSpecific\": true\n" + + " }}"; @BeforeEach void setUp() { gson = new GsonBuilder() @@ -31,7 +40,7 @@ void setUp() { } @Test - void buildJsonFromAdpuHexString() throws BACnetException { + void buildJsonFromAdpuHexString() throws BACnetException, JSONException { String byteHex = "100209001c020007d12c020007d139004e09702e91002f09cb2e2ea4770b0105b40d2300442f2f09c42e91002f4f"; final ByteQueue queue = new ByteQueue(byteHex); ServicesSupported services = new ServicesSupported(); @@ -45,6 +54,7 @@ void buildJsonFromAdpuHexString() throws BACnetException { UnconfirmedRequestService service = unconfirmedRequest.getService(); String json = gson.toJson(service); log.debug("Json built: {}", json); + assertEquals(partOfApu, json, false); } }