-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93ad14c
commit 486e1b8
Showing
16 changed files
with
538 additions
and
23 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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.jsfr.json; | ||
|
||
public class Employee { | ||
public String name; | ||
public int age; | ||
public String[] emails; | ||
public Employee boss; | ||
} |
46 changes: 46 additions & 0 deletions
46
jsurfer-all/src/test/java/org/jsfr/json/JacksonCBORParserTest.java
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.jsfr.json; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.cbor.CBORFactory; | ||
import org.jsfr.json.provider.JacksonProvider; | ||
import org.junit.Before; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class JacksonCBORParserTest extends JsonSurferTest { | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
provider = new JacksonProvider(); | ||
surfer = new JsonSurfer(new JacksonParser(new CBORFactory()), provider); | ||
} | ||
|
||
@Override | ||
protected InputStream read(String resourceName) throws IOException { | ||
ObjectMapper om = new ObjectMapper(); | ||
JsonNode node = om.readTree(this.readAsString(resourceName)); | ||
CBORFactory f = new CBORFactory(); | ||
ObjectMapper cborMapper = new ObjectMapper(f); | ||
byte[] cborData = cborMapper.writeValueAsBytes(node); | ||
return new ByteArrayInputStream(cborData); | ||
} | ||
|
||
@Override | ||
public void testCollectAllFromString() throws Exception { | ||
// skip non-byte-based source | ||
} | ||
|
||
@Override | ||
public void testCollectOneFromString() throws Exception { | ||
// skip non-byte-based source | ||
} | ||
|
||
@Override | ||
public void testWildcardAtRoot() throws Exception { | ||
// skip non-byte-based source | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
jsurfer-all/src/test/java/org/jsfr/json/JacksonIonParserTest.java
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.jsfr.json; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.ion.IonFactory; | ||
import org.jsfr.json.provider.JacksonProvider; | ||
import org.junit.Before; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class JacksonIonParserTest extends JsonSurferTest { | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
provider = new JacksonProvider(); | ||
surfer = new JsonSurfer(new JacksonParser(new IonFactory()), provider); | ||
} | ||
|
||
@Override | ||
protected InputStream read(String resourceName) throws IOException { | ||
ObjectMapper om = new ObjectMapper(); | ||
JsonNode node = om.readTree(this.readAsString(resourceName)); | ||
IonFactory f = new IonFactory(); | ||
ObjectMapper cborMapper = new ObjectMapper(f); | ||
byte[] ionData = cborMapper.writeValueAsBytes(node); | ||
return new ByteArrayInputStream(ionData); | ||
} | ||
|
||
@Override | ||
public void testCollectAllFromString() throws Exception { | ||
// skip non-byte-based source | ||
} | ||
|
||
@Override | ||
public void testCollectOneFromString() throws Exception { | ||
// skip non-byte-based source | ||
} | ||
|
||
@Override | ||
public void testWildcardAtRoot() throws Exception { | ||
// skip non-byte-based source | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -24,10 +24,22 @@ | |
|
||
package org.jsfr.json; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.avro.AvroFactory; | ||
import com.fasterxml.jackson.dataformat.avro.AvroMapper; | ||
import com.fasterxml.jackson.dataformat.avro.AvroSchema; | ||
import com.fasterxml.jackson.dataformat.protobuf.ProtobufFactory; | ||
import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper; | ||
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema; | ||
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader; | ||
import org.apache.avro.Schema; | ||
import org.jsfr.json.provider.JacksonProvider; | ||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Matchers.any; | ||
|
@@ -64,4 +76,70 @@ public void testNonBlockingParser() throws Exception { | |
verify(mockListener).onValue(eq(provider.primitive("abcd")), any(ParsingContext.class)); | ||
} | ||
|
||
@Ignore | ||
@Test | ||
public void testProtobufParser() throws Exception { | ||
JsonPathListener mockListener = mock(JsonPathListener.class); | ||
|
||
ObjectMapper mapper = new ProtobufMapper(); | ||
String protobuf_str = "message Employee {\n" | ||
+ " required string name = 1;\n" | ||
+ " required int32 age = 2;\n" | ||
+ " repeated string emails = 3;\n" | ||
+ " optional Employee boss = 4;\n" | ||
+ "}\n"; | ||
final ProtobufSchema schema = ProtobufSchemaLoader.std.parse(protobuf_str); | ||
|
||
// Employee boss = new Employee(); | ||
// boss.age = 30; | ||
// boss.emails = new String[]{"[email protected]"}; | ||
// boss.name = "bar"; | ||
|
||
Employee empl = new Employee(); | ||
empl.age = 30; | ||
empl.emails = new String[]{"[email protected]"}; | ||
empl.name = "foo"; | ||
// empl.boss = boss; | ||
|
||
byte[] protobufData = mapper.writer(schema) | ||
.writeValueAsBytes(empl); | ||
|
||
// TODO Jackson's bug | ||
JsonSurfer protobufSurfer = new JsonSurfer(new JacksonParser(new ProtobufFactory(), schema), provider); | ||
SurfingConfiguration config = protobufSurfer.configBuilder().bind("$.name", mockListener).build(); | ||
protobufSurfer.surf(new ByteArrayInputStream(protobufData), config); | ||
verify(mockListener).onValue(eq(provider.primitive("foo")), any(ParsingContext.class)); | ||
} | ||
|
||
@Test | ||
public void testAvroParser() throws Exception { | ||
JsonPathListener mockListener = mock(JsonPathListener.class); | ||
|
||
String SCHEMA_JSON = "{\n" | ||
+ "\"type\": \"record\",\n" | ||
+ "\"name\": \"Employee\",\n" | ||
+ "\"fields\": [\n" | ||
+ " {\"name\": \"name\", \"type\": \"string\"},\n" | ||
+ " {\"name\": \"age\", \"type\": \"int\"},\n" | ||
+ " {\"name\": \"emails\", \"type\": {\"type\": \"array\", \"items\": \"string\"}},\n" | ||
+ " {\"name\": \"boss\", \"type\": [\"Employee\",\"null\"]}\n" | ||
+ "]}"; | ||
Schema raw = new Schema.Parser().setValidate(true).parse(SCHEMA_JSON); | ||
final AvroSchema schema = new AvroSchema(raw); | ||
|
||
Employee empl = new Employee(); | ||
empl.age = 30; | ||
empl.emails = new String[]{"[email protected]"}; | ||
empl.name = "foo"; | ||
|
||
AvroMapper mapper = new AvroMapper(); | ||
byte[] avroData = mapper.writer(schema) | ||
.writeValueAsBytes(empl); | ||
|
||
JsonSurfer avroSurfer = new JsonSurfer(new JacksonParser(new AvroFactory(), schema), provider); | ||
SurfingConfiguration config = avroSurfer.configBuilder().bind("$.name", mockListener).build(); | ||
avroSurfer.surf(new ByteArrayInputStream(avroData), config); | ||
verify(mockListener).onValue(eq(provider.primitive("foo")), any(ParsingContext.class)); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
jsurfer-all/src/test/java/org/jsfr/json/JacksonSmileParserTest.java
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.jsfr.json; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.smile.SmileFactory; | ||
import org.jsfr.json.provider.JacksonProvider; | ||
import org.junit.Before; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class JacksonSmileParserTest extends JsonSurferTest { | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
provider = new JacksonProvider(); | ||
surfer = new JsonSurfer(new JacksonParser(new SmileFactory()), provider); | ||
} | ||
|
||
@Override | ||
protected InputStream read(String resourceName) throws IOException { | ||
ObjectMapper om = new ObjectMapper(); | ||
JsonNode node = om.readTree(this.readAsString(resourceName)); | ||
SmileFactory f = new SmileFactory(); | ||
ObjectMapper cborMapper = new ObjectMapper(f); | ||
byte[] smileData = cborMapper.writeValueAsBytes(node); | ||
return new ByteArrayInputStream(smileData); | ||
} | ||
|
||
@Override | ||
public void testCollectAllFromString() throws Exception { | ||
// skip non-byte-based source | ||
} | ||
|
||
@Override | ||
public void testCollectOneFromString() throws Exception { | ||
// skip non-byte-based source | ||
} | ||
|
||
@Override | ||
public void testWildcardAtRoot() throws Exception { | ||
// skip non-byte-based source | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.