Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
#2 Validate part of joson
Browse files Browse the repository at this point in the history
  • Loading branch information
baardl committed Nov 16, 2019
1 parent 00eaaba commit 811237c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
12 changes: 11 additions & 1 deletion src/test/java/no/entra/bacnet/json/BacNetParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,27 @@
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;
import org.slf4j.LoggerFactory;

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()
Expand All @@ -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();
Expand All @@ -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);

}
}

0 comments on commit 811237c

Please sign in to comment.