Package info.archinnov.achilles.codec

Examples of info.archinnov.achilles.codec.Codec.decode()


        final Codec codec = factory.parseSimpleField(createContext(field));

        //Then
        assertThat(codec).isInstanceOf(NativeCodec.class);
        assertThat(codec.encode("toto")).isEqualTo("toto");
        assertThat(codec.decode("toto")).isEqualTo("toto");
    }

    @Test
    public void should_create_simple_codec_from_transformer() throws Exception {
        //Given
View Full Code Here


        final Codec codec = factory.parseSimpleField(createContext(field));

        //Then
        assertThat(codec).isInstanceOf(EnumNameCodec.class);
        assertThat(codec.encode(PropertyType.COUNTER)).isEqualTo("COUNTER");
        assertThat(codec.decode("ID")).isEqualTo(PropertyType.ID);
    }

    @Test
    public void should_create_enum_ordinal_codec() throws Exception {
        //Given
View Full Code Here

        final Codec codec = factory.parseSimpleField(createContext(field));

        //Then
        assertThat(codec).isInstanceOf(EnumOrdinalCodec.class);
        assertThat(codec.encode(PropertyType.COUNTER)).isEqualTo(6);
        assertThat(codec.decode(0)).isEqualTo(PropertyType.ID);
    }

    @Test
    public void should_create_byte_primitive_codec() throws Exception {
        //Given
View Full Code Here

        final Codec codec = factory.parseSimpleField(createContext(field));

        //Then
        assertThat(codec).isInstanceOf(ByteCodec.class);
        assertThat(((ByteBuffer)codec.encode((byte)3)).array()).containsOnly((byte) 3);
        assertThat(codec.decode(ByteBuffer.wrap(new byte[]{(byte)5}))).isEqualTo((byte)5);
    }

    @Test
    public void should_create_byte_object_codec() throws Exception {
        //Given
View Full Code Here

        final Codec codec = factory.parseSimpleField(createContext(field));

        //Then
        assertThat(codec).isInstanceOf(ByteCodec.class);
        assertThat(((ByteBuffer)codec.encode(new Byte((byte)3))).array()).containsOnly((byte) 3);
        assertThat(codec.decode(ByteBuffer.wrap(new byte[]{(byte)5}))).isEqualTo((byte)5);
    }


    @Test
    public void should_create_byte_primitive_array_codec() throws Exception {
View Full Code Here

        final Codec codec = factory.parseSimpleField(createContext(field));

        //Then
        assertThat(codec).isInstanceOf(ByteArrayPrimitiveCodec.class);
        assertThat(((ByteBuffer)codec.encode(new byte[]{(byte)2,(byte)3})).array()).containsOnly((byte) 2, (byte) 3);
        assertThat((byte[])codec.decode(ByteBuffer.wrap(new byte[]{(byte)5, (byte)6}))).containsOnly((byte) 5, (byte) 6);
    }

    @Test
    public void should_create_byte_object_array_codec() throws Exception {
        //Given
View Full Code Here

        final Codec codec = factory.parseSimpleField(createContext(field));

        //Then
        assertThat(codec).isInstanceOf(ByteArrayCodec.class);
        assertThat(((ByteBuffer)codec.encode(new Byte[]{(byte)2,(byte)3})).array()).containsOnly((byte) 2, (byte) 3);
        assertThat((Byte[]) codec.decode(ByteBuffer.wrap(new byte[]{(byte)5, (byte)6}))).containsOnly((byte) 5, (byte) 6);
    }

    @Test
    public void should_create_JSON_codec() throws Exception {
        class Test {
View Full Code Here

        Field field = Test.class.getDeclaredField("json");

        //When
        final Codec codec = factory.parseSimpleField(createContext(field));
        final String encoded = (String) codec.encode(bean);
        final Pojo decoded = (Pojo) codec.decode("{\"id\":11,\"name\":\"John\"}");

        //Then
        assertThat(encoded).isEqualTo("{\"id\":10,\"name\":\"DuyHai\"}");
        assertThat(decoded.getId()).isEqualTo(11L);
        assertThat(decoded.getName()).isEqualTo("John");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.