Package org.springframework.data.redis.serializer

Source Code of org.springframework.data.redis.serializer.Jackson2JsonRedisSerializerTests

/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.serializer;

import static org.junit.Assert.*;

import java.util.Arrays;

import org.hamcrest.core.Is;
import org.hamcrest.core.IsNull;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.Person;
import org.springframework.data.redis.PersonObjectFactory;

/**
* @author Thomas Darimont
* @author Christoph Strobl
*/
public class Jackson2JsonRedisSerializerTests {

  private Jackson2JsonRedisSerializer<Person> serializer;

  @Before
  public void setUp() {
    this.serializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
  }

  /**
   * @see DATAREDIS-241
   */
  @Test
  public void testJackson2JsonSerializer() throws Exception {

    Person person = new PersonObjectFactory().instance();
    assertEquals(person, serializer.deserialize(serializer.serialize(person)));
  }

  /**
   * @see DATAREDIS-241
   */
  @Test
  public void testJackson2JsonSerializerShouldReturnEmptyByteArrayWhenSerializingNull() {
    assertThat(serializer.serialize(null), Is.is(new byte[0]));
  }

  /**
   * @see DTATREDIS-241
   */
  @Test
  public void testJackson2JsonSerializerShouldReturnNullWhenDerserializingEmtyByteArray() {
    assertThat(serializer.deserialize(new byte[0]), IsNull.nullValue());
  }

  /**
   * @see DTATREDIS-241
   */
  @Test(expected = SerializationException.class)
  public void testJackson2JsonSerilizerShouldThrowExceptionWhenDeserializingInvalidByteArray() {

    Person person = new PersonObjectFactory().instance();
    byte[] serializedValue = serializer.serialize(person);
    Arrays.sort(serializedValue); // corrupt serialization result

    serializer.deserialize(serializedValue);
  }

  /**
   * @see DTATREDIS-241
   */
  @Test(expected = IllegalArgumentException.class)
  public void testJackson2JsonSerilizerThrowsExceptionWhenSettingNullObjectMapper() {
    serializer.setObjectMapper(null);
  }

}
TOP

Related Classes of org.springframework.data.redis.serializer.Jackson2JsonRedisSerializerTests

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.