Search in sources :

Example 21 with Person

use of org.apache.dubbo.common.serialize.model.Person in project dubbo by alibaba.

the class AbstractSerializationPersonFailTest method test_PersonSet.

@Test
public void test_PersonSet() throws Exception {
    Set<Person> args = new HashSet<Person>();
    args.add(new Person());
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(args);
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        System.out.println("--------" + expected.getMessage());
        assertThat(expected.getMessage(), containsString(FAIL_STRING));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) Person(org.apache.dubbo.common.serialize.model.Person) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 22 with Person

use of org.apache.dubbo.common.serialize.model.Person in project dubbo by alibaba.

the class AbstractSerializationPersonFailTest method test_StringPersonListMap.

@Test
public void test_StringPersonListMap() throws Exception {
    Map<String, List<Person>> args = new HashMap<String, List<Person>>();
    List<Person> sublist = new ArrayList<Person>();
    sublist.add(new Person());
    args.put("1", sublist);
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(args);
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString(FAIL_STRING));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.containsString(org.hamcrest.Matchers.containsString) Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Example 23 with Person

use of org.apache.dubbo.common.serialize.model.Person in project dubbo by alibaba.

the class AbstractSerializationPersonFailTest method test_Person.

@Test
public void test_Person() throws Exception {
    try {
        ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
        objectOutput.writeObject(new Person());
        fail();
    } catch (NotSerializableException expected) {
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString(FAIL_STRING));
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectOutput(org.apache.dubbo.common.serialize.ObjectOutput) Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Example 24 with Person

use of org.apache.dubbo.common.serialize.model.Person in project dubbo by alibaba.

the class AvroObjectInputOutputTest method testWriteReadObject.

@Test
public void testWriteReadObject() throws IOException, ClassNotFoundException {
    Person p = new Person();
    p.setAge(30);
    p.setName("abc");
    avroObjectOutput.writeObject(p);
    avroObjectOutput.flushBuffer();
    pos.close();
    Person result = avroObjectInput.readObject(Person.class);
    assertThat(result, not(nullValue()));
    assertThat(result.getName(), is("abc"));
    assertThat(result.getAge(), is(30));
}
Also used : Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Example 25 with Person

use of org.apache.dubbo.common.serialize.model.Person in project dubbo by apache.

the class AvroObjectInputOutputTest method testWriteReadObject.

@Test
public void testWriteReadObject() throws IOException, ClassNotFoundException {
    Person p = new Person();
    p.setAge(30);
    p.setName("abc");
    avroObjectOutput.writeObject(p);
    avroObjectOutput.flushBuffer();
    pos.close();
    Person result = avroObjectInput.readObject(Person.class);
    assertThat(result, not(nullValue()));
    assertThat(result.getName(), is("abc"));
    assertThat(result.getAge(), is(30));
}
Also used : Person(org.apache.dubbo.common.serialize.model.Person) Test(org.junit.jupiter.api.Test)

Aggregations

Person (org.apache.dubbo.common.serialize.model.Person)36 Test (org.junit.jupiter.api.Test)36 NotSerializableException (java.io.NotSerializableException)21 ObjectOutput (org.apache.dubbo.common.serialize.ObjectOutput)21 List (java.util.List)10 StringReader (java.io.StringReader)9 Method (java.lang.reflect.Method)6 Type (java.lang.reflect.Type)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 Organization (org.apache.dubbo.common.serialize.model.Organization)3 HashSet (java.util.HashSet)2