Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Jul 24, 2023
1 parent 1c6caf3 commit febe92e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
7 changes: 4 additions & 3 deletions binding/src/main/java/org/jsonx/ObjectCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ else if (codec instanceof ArrayCodec) {
return abort(Error.DECODE_EXCEPTION(reader, e), reader, index);
}
catch (final InvocationTargetException e) {
if (e.getCause() instanceof IOException)
throw (IOException)e.getCause();
final Throwable cause = e.getCause();
if (cause instanceof IOException)
throw (IOException)cause;

return abort(Error.DECODE_EXCEPTION(reader, e.getCause()), reader, index);
return abort(Error.DECODE_EXCEPTION(reader, cause), reader, index);
}
catch (final InstantiationException e) {
throw new RuntimeException(Throwables.copy(e, new InstantiationException(type.getName())));
Expand Down
6 changes: 3 additions & 3 deletions jsonx-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<schemas>
<schema>src/test/resources/test.jsd</schema>
<schema>src/test/resources/test.jsdx</schema>
<schema>src/test/resources/camera.jsdx</schema>
<schema>src/test/resources/sensor.jsdx</schema>
</schemas>
</configuration>
</execution>
Expand All @@ -106,7 +106,7 @@
<schemas>
<schema>src/test/resources/test.jsd</schema>
<schema>src/test/resources/test.jsdx</schema>
<schema>src/test/resources/camera.jsdx</schema>
<schema>src/test/resources/sensor.jsdx</schema>
</schemas>
</configuration>
</execution>
Expand All @@ -120,7 +120,7 @@
<schemas>
<schema>src/test/resources/test.jsd</schema>
<schema>src/test/resources/test.jsdx</schema>
<schema>src/test/resources/camera.jsdx</schema>
<schema>src/test/resources/sensor.jsdx</schema>
</schemas>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import org.junit.Test;
import org.openjax.json.JsonReader;

public class CameraITest {
private static final String json = "{\"cameras\":[{\"ordinal\":0,\"state\":\"manual\",\"dois\":5,\"pan\":0.0,\"tilt\":0.0,\"zoom\":1.0},{\"ordinal\":1,\"state\":\"manual\",\"dois\":5}],\"periods\":[[1619506964,60]],\"captureDelay\":0}";
public class SensorITest {
private static final String json = "{\"sensors\":[{\"index\":0,\"mode\":\"auto\",\"facets\":5,\"x\":0.0,\"y\":0.0,\"z\":1.0},{\"index\":1,\"mode\":\"auto\",\"facets\":5}],\"sequences\":[[1619506964,60]],\"delay\":0}";

@Test
public void test() throws IOException, DecodeException {
final oz.Capture capture;
final stub.Assembly assembly;
try (final JsonReader in = new JsonReader(json)) {
capture = JxDecoder.VALIDATING.parseObject(in, oz.Capture.class);
assembly = JxDecoder.VALIDATING.parseObject(in, stub.Assembly.class);
}

System.out.println(capture);
System.out.println(assembly);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
xmlns="http://www.jsonx.org/schema-0.4.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jsonx.org/schema-0.4.xsd http://www.jsonx.org/schema.xsd"
targetNamespace="http://www.jsonx.org/jsonx-maven-plugin/test/camera.jsdx">
targetNamespace="http://www.jsonx.org/jsonx-maven-plugin/test/sensor.jsdx">

<number name="ordinal" scale="0" range="[0,1]">
<number name="index" scale="0" range="[0,1]">
<binding lang="java" type="byte"/>
</number>
<number name="degreeDecimal360" scale="1" range="[0,360)"/>
Expand All @@ -37,36 +37,37 @@
<number name="positiveInt" scale="0" range="[1,2147483647]">
<binding lang="java" type="int"/>
</number>

<array name="tupleInt">
<reference type="nonNegativeInt" minOccurs="1" maxOccurs="2" nullable="false"/>
</array>
<array name="tupleInts">
<reference type="tupleInt" minOccurs="0" nullable="false"/>
</array>
<string name="state" pattern="manual|stopped|error"/>
<string name="mode" pattern="auto|manual|stopped|error"/>

<object name="ptz">
<property name="pan" xsi:type="reference" type="degreeDecimal360" nullable="false" use="optional"/>
<property name="tilt" xsi:type="reference" type="degreeDecimal90" nullable="false" use="optional"/>
<property name="zoom" xsi:type="number" scale="1" range="[0,100]" nullable="false" use="optional"/>
<object name="vector">
<property name="x" xsi:type="reference" type="degreeDecimal360" nullable="false" use="optional"/>
<property name="y" xsi:type="reference" type="degreeDecimal90" nullable="false" use="optional"/>
<property name="z" xsi:type="number" scale="1" range="[0,100]" nullable="false" use="optional"/>
</object>

<object name="camera" extends="ptz">
<property name="ordinal" xsi:type="reference" type="ordinal" nullable="false"/>
<property name="dois" xsi:type="reference" type="positiveByteObj" nullable="false" use="optional"/>
<property name="state" xsi:type="reference" type="state" nullable="false" use="optional"/>
<object name="sensor" extends="vector">
<property name="index" xsi:type="reference" type="index" nullable="false"/>
<property name="facets" xsi:type="reference" type="positiveByteObj" nullable="false" use="optional"/>
<property name="mode" xsi:type="reference" type="mode" nullable="false" use="optional"/>
</object>

<object name="Oz" abstract="true">
<property name="uptime" xsi:type="object" nullable="false" use="optional">
<property name="uptime" xsi:type="reference" type="positiveInt" nullable="false"/>
<object name="Stub" abstract="true">
<property name="runtime" xsi:type="object" nullable="false" use="optional">
<property name="runtime" xsi:type="reference" type="positiveInt" nullable="false"/>
</property>
<property name="capture" xsi:type="object" nullable="false" use="optional">
<property name="cameras" xsi:type="array" nullable="false">
<reference type="camera" minOccurs="1" maxOccurs="2" nullable="false"/>
<property name="assembly" xsi:type="object" nullable="false" use="optional">
<property name="sensors" xsi:type="array" nullable="false">
<reference type="sensor" minOccurs="1" maxOccurs="2" nullable="false"/>
</property>
<property name="periods" xsi:type="reference" type="tupleInts" nullable="false" use="optional"/>
<property name="captureDelay" xsi:type="reference" type="nonNegativeByteObj" nullable="false" use="optional"/>
<property name="sequences" xsi:type="reference" type="tupleInts" nullable="false" use="optional"/>
<property name="delay" xsi:type="reference" type="nonNegativeByteObj" nullable="false" use="optional"/>
</property>
</object>

Expand Down

0 comments on commit febe92e

Please sign in to comment.