List of usage examples for com.fasterxml.jackson.dataformat.cbor CBORFactory CBORFactory
public CBORFactory()
From source file:com.diffeo.dossier.fc.FeatureCollectionTest.java
@Test public void deserializeEmptyMetadata() throws IOException { CBORFactory cborf = new CBORFactory(); ObjectMapper mapper = new ObjectMapper(cborf); byte[] ref = { (byte) 0x82, // array of 2 items (byte) 0xa0, // map of 0 items (byte) 0xa0, // map of 0 items };//from www . java 2 s .com try { mapper.readValue(ref, FeatureCollection.class); assertThat("empty metadata", is("rejected")); } catch (JsonMappingException e) { // expected case } }
From source file:com.diffeo.dossier.fc.FeatureCollectionTest.java
@Test public void deserializeMissingVersion() throws IOException { CBORFactory cborf = new CBORFactory(); ObjectMapper mapper = new ObjectMapper(cborf); byte[] ref = { (byte) 0x82, // array of 2 items (byte) 0xa1, // map of 1 item (byte) 0x62, 0x72, 0x6f, // string "ro" (byte) 0x01, // integer 1 (byte) 0xa0, // map of 0 items };//from w ww. j a v a 2s . co m try { mapper.readValue(ref, FeatureCollection.class); assertThat("missing version", is("rejected")); } catch (JsonMappingException e) { // expected case } }
From source file:com.diffeo.dossier.fc.FeatureCollectionTest.java
@Test public void deserializeWrongVersion() throws IOException { CBORFactory cborf = new CBORFactory(); ObjectMapper mapper = new ObjectMapper(cborf); byte[] ref = { (byte) 0x82, // array of 2 items (byte) 0xa1, // map of 1 item (byte) 0x61, 0x76, // string "v" (byte) 0x64, 0x46, 0x4F, 0x4F, 0x21, // string "FOO!" (byte) 0xa0, // map of 0 items };/*ww w. ja va 2 s . c o m*/ try { mapper.readValue(ref, FeatureCollection.class); assertThat("incorrect version", is("rejected")); } catch (JsonMappingException e) { // expected case } }
From source file:com.diffeo.dossier.fc.FeatureCollectionTest.java
@Test public void serializeStringFeature() throws JsonProcessingException { StringFeature sf = new StringFeature("foo"); FeatureCollection fc = new FeatureCollection(); fc.getFeatures().put("f", sf); CBORFactory cborf = new CBORFactory(); ObjectMapper mapper = new ObjectMapper(cborf); byte[] cbor = mapper.writeValueAsBytes(fc); byte[] ref = { (byte) 0x9f, // array of ??? items (byte) 0xbf, // map of ??? items (byte) 0x61, 0x76, // string "v" (byte) 0x64, 0x66, 0x63, 0x30, 0x31, // string "fc01" (byte) 0xff, // end metadata map (byte) 0xbf, // map of ??? items (byte) 0x61, 0x66, // string "f" (byte) 0x63, 0x66, 0x6f, 0x6f, // string "foo" (byte) 0xff, // end content map (byte) 0xff, // end array };/* w w w . jav a 2 s .c o m*/ assertThat(cbor, is(equalTo(ref))); }
From source file:com.diffeo.dossier.fc.FeatureCollectionTest.java
@Test public void deserializeStringFeature() throws IOException { CBORFactory cborf = new CBORFactory(); ObjectMapper mapper = new ObjectMapper(cborf); byte[] ref = { (byte) 0x82, // array of 2 items (byte) 0xa1, // map of 1 item (byte) 0x61, 0x76, // string "v" (byte) 0x64, 0x66, 0x63, 0x30, 0x31, // string "fc01" (byte) 0xa1, // map of 1 item (byte) 0x61, 0x66, // string "f" (byte) 0x63, 0x66, 0x6f, 0x6f, // string "foo" };//from w w w .j a v a2 s . c o m FeatureCollection fc = mapper.readValue(ref, FeatureCollection.class); Map<String, Feature> features = fc.getFeatures(); assertThat(features.size(), is(1)); assertThat(features, hasKey("f")); Feature f = features.get("f"); assertThat(f, instanceOf(StringFeature.class)); StringFeature sf = (StringFeature) f; assertThat(sf.getValue(), is("foo")); }
From source file:com.diffeo.dossier.fc.FeatureCollectionTest.java
@Test public void serializeStringCounter() throws JsonProcessingException { StringCounter sc = new StringCounter(); sc.add("a", 1); FeatureCollection fc = new FeatureCollection(); fc.getFeatures().put("sc", sc); CBORFactory cborf = new CBORFactory(); ObjectMapper mapper = new ObjectMapper(cborf); byte[] cbor = mapper.writeValueAsBytes(fc); byte[] ref = { (byte) 0x9f, (byte) 0xbf, 0x61, 0x76, 0x64, 0x66, 0x63, 0x30, 0x31, (byte) 0xff, (byte) 0xbf, // header (byte) 0x62, 0x73, 0x63, // string "sc" (byte) 0xd9, (byte) 0xd9, (byte) 0xf8, // tag 55080 (byte) 0xbf, // map of ??? items (byte) 0x61, 0x61, // string "a" (byte) 0x01, // integer 1 (byte) 0xff, // end StringCounter map (byte) 0xff, (byte) 0xff // footer };//from www. j a v a 2 s . co m assertThat(cbor, is(equalTo(ref))); }
From source file:com.diffeo.dossier.fc.FeatureCollectionTest.java
@Test public void deserializeTaggedStringCounter() throws IOException { CBORFactory cborf = new CBORFactory(); ObjectMapper mapper = new ObjectMapper(cborf); byte[] ref = { (byte) 0x82, (byte) 0xa1, 0x61, 0x76, 0x64, 0x66, 0x63, 0x30, 0x31, // header (byte) 0xa1, // map of 1 item (byte) 0x64, 0x66, 0x65, 0x61, 0x74, // string "feat" (byte) 0xd9, (byte) 0xd9, (byte) 0xf8, // tag 55080 (byte) 0xa1, // map of 1 item (byte) 0x61, 0x6b, // string "k" (byte) 0x0a, // integer 10 };//from ww w . ja v a 2 s. com FeatureCollection fc = mapper.readValue(ref, FeatureCollection.class); assertThat(fc.getFeatures(), hasKey("feat")); Feature feat = fc.getFeatures().get("feat"); assertThat(feat, is(instanceOf(StringCounter.class))); StringCounter sc = (StringCounter) feat; assertThat(sc.getStrings(), hasEntry("k", new Integer(10))); assertThat(sc.getStrings().size(), is(1)); }
From source file:com.diffeo.dossier.fc.FeatureCollectionTest.java
@Test public void deserializeUntaggedStringCounter() throws IOException { CBORFactory cborf = new CBORFactory(); ObjectMapper mapper = new ObjectMapper(cborf); byte[] ref = { (byte) 0x82, (byte) 0xa1, 0x61, 0x76, 0x64, 0x66, 0x63, 0x30, 0x31, // header (byte) 0xa1, // map of 1 item (byte) 0x61, 0x66, // string "f" (byte) 0xa2, // map of 1 item (byte) 0x63, 0x6b, 0x65, 0x79, // string "key" (byte) 0x0a, // integer 10 (byte) 0x65, 0x76, 0x61, 0x6c, 0x75, 0x65, // string "value" (byte) 0x0b, // integer 11 };// w ww . ja v a2 s . co m FeatureCollection fc = mapper.readValue(ref, FeatureCollection.class); assertThat(fc.getFeatures(), hasKey("f")); Feature feat = fc.getFeatures().get("f"); assertThat(feat, is(instanceOf(StringCounter.class))); StringCounter sc = (StringCounter) feat; assertThat(sc.getStrings(), hasEntry("key", new Integer(10))); assertThat(sc.getStrings(), hasEntry("value", new Integer(11))); assertThat(sc.getStrings().size(), is(2)); }
From source file:com.diffeo.dossier.fc.FeatureCollectionTest.java
@Test public void deserializeMixedFeatures() throws IOException { CBORFactory cborf = new CBORFactory(); ObjectMapper mapper = new ObjectMapper(cborf); byte[] ref = { (byte) 0x82, (byte) 0xa1, 0x61, 0x76, 0x64, 0x66, 0x63, 0x30, 0x31, // header (byte) 0xa2, // map of 2 item (byte) 0x66, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, // "string" (byte) 0x64, 0x6b, 0x6e, 0x6f, 0x74, // "knot" (byte) 0x62, 0x73, 0x63, // "sc" (byte) 0xd9, (byte) 0xd9, (byte) 0xf8, // tag 55080 (byte) 0xa0, // empty map };/* www. j av a 2s . com*/ FeatureCollection fc = mapper.readValue(ref, FeatureCollection.class); assertThat(fc.getFeatures(), hasKey("string")); Feature string = fc.getFeatures().get("string"); assertThat(string, is(instanceOf(StringFeature.class))); assertThat(((StringFeature) string).getValue(), is("knot")); assertThat(fc.getFeatures(), hasKey("sc")); Feature sc = fc.getFeatures().get("sc"); assertThat(sc, is(instanceOf(StringCounter.class))); assertThat(((StringCounter) sc).getStrings().size(), is(0)); }
From source file:com.diffeo.dossier.fc.FeatureCollectionTest.java
@Test public void deserializeROCounter() throws IOException { CBORFactory cborf = new CBORFactory(); ObjectMapper mapper = new ObjectMapper(cborf); byte[] ref = { (byte) 0x82, // array of 2 items (byte) 0xa2, // map of 2 items (byte) 0x61, 0x76, 0x64, 0x66, 0x63, 0x30, 0x31, // "v": "fc01" (byte) 0x62, 0x72, 0x6f, 0x01, // "ro": 1 (byte) 0xa1, // map of 1 item (byte) 0x61, 0x63, // "c": ... (byte) 0xd9, (byte) 0xd9, (byte) 0xf8, // tag 55080 (byte) 0xa1, // map of 1 item (byte) 0x61, 0x61, 0x01, // "a": 1 };/*www . jav a 2 s . c o m*/ FeatureCollection fc = mapper.readValue(ref, FeatureCollection.class); // If every test so far has passed, this should sail through StringCounter sc = (StringCounter) (fc.getFeatures().get("c")); assertThat(fc.isReadOnly(), is(true)); assertThat(sc.isReadOnly(), is(true)); try { sc.add("a", 1); assertThat("UnsupportedOperationException", is("thrown")); } catch (UnsupportedOperationException e) { } try { fc.getFeatures().put("str", new StringFeature("str")); assertThat("UnsupportedOperationException", is("thrown")); } catch (UnsupportedOperationException e) { } }