Examples of TestUnion


Examples of thrift.test.TestUnion

    swau.write(proto);
    new Empty().read(proto);
  }

  public void testSkip() throws Exception {
    TestUnion tu = TestUnion.string_field("string");
    byte[] tuSerialized = new TSerializer().serialize(tu);
    TestUnionMinusStringField tums = new TestUnionMinusStringField();
    new TDeserializer().deserialize(tums, tuSerialized);
    assertNull(tums.getSetField());
    assertNull(tums.getFieldValue());
View Full Code Here

Examples of thrift.test.TestUnion

  public void testJavaSerializable() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
   
    TestUnion tu = TestUnion.string_field("string");

    // Serialize tu the Java way...
    oos.writeObject(tu);
    byte[] serialized = baos.toByteArray();

    // Attempt to deserialize it
    ByteArrayInputStream bais = new ByteArrayInputStream(serialized);
    ObjectInputStream ois = new ObjectInputStream(bais);
    TestUnion tu2 = (TestUnion) ois.readObject();

    assertEquals(tu, tu2);
  }
View Full Code Here

Examples of thrift.test.TestUnion

import thrift.test.TestUnionMinusStringField;

public class TestTUnion extends TestCase {

  public void testBasic() throws Exception {
    TestUnion union = new TestUnion();

    assertFalse(union.isSet());
    assertFalse(union.isSetI32_field());
    assertNull(union.getFieldValue());

    union = new TestUnion(TestUnion._Fields.I32_FIELD, 25);

    assertEquals(Integer.valueOf(25), union.getFieldValue());
 
    assertEquals(Integer.valueOf(25), union.getFieldValue(TestUnion._Fields.I32_FIELD));
   
    assertTrue(union.isSetI32_field());
 
    try {
      union.getFieldValue(TestUnion._Fields.STRING_FIELD);
      fail("should have thrown an exception");
    } catch (IllegalArgumentException e) {
      // cool!
    }

    union = new TestUnion();

    // should not throw an exception here
    union.hashCode();

    union.setI32_field(1);
    assertEquals(1, union.getI32_field());
    union.hashCode();

    assertFalse(union.isSetString_field());
   
    try {
      union.getString_field();
      fail("should have thrown an exception");
    } catch (Exception e) {
      // sweet
    }

    union = TestUnion.i32_field(1);

    assertFalse(union.equals((TestUnion)null));

    union = TestUnion.enum_field(SomeEnum.ONE);
    union.hashCode();

    union = new TestUnion();
    // should not throw an exception
    union.toString();
  }
View Full Code Here

Examples of thrift.test.TestUnion

  public static void main(String[] args) throws TException {
    //Root:StructWithAUnion
    //  1:Union
    //    1.3:OneOfEach
    OneOfEach Level3OneOfEach = Fixtures.oneOfEach;
    TestUnion Level2TestUnion = new TestUnion(TestUnion._Fields.STRUCT_FIELD, Level3OneOfEach);
    StructWithAUnion Level1SWU = new StructWithAUnion(Level2TestUnion);

    Backwards bw = new Backwards(2, 1);
    PrimitiveThenStruct pts = new PrimitiveThenStruct(12345, 67890, bw);

    for (TProtocolFactory factory : PROTOCOLS) {
      //Full deserialization test
      testPartialDeserialize(factory, Level1SWU, new StructWithAUnion(), Level1SWU);

      //Level 2 test
      testPartialDeserialize(factory, Level1SWU, new TestUnion(), Level2TestUnion, StructWithAUnion._Fields.TEST_UNION);

      //Level 3 on 3rd field test
      testPartialDeserialize(factory, Level1SWU, new OneOfEach(), Level3OneOfEach, StructWithAUnion._Fields.TEST_UNION, TestUnion._Fields.STRUCT_FIELD);

      //Test early termination when traversed path Field.id exceeds the one being searched for
View Full Code Here

Examples of thrift.test.TestUnion

    testSerialization();
    testCompareTo();
  }

  public static void testBasic() throws Exception {
    TestUnion union = new TestUnion();

    if (union.isSet()) {
      throw new RuntimeException("new union with default constructor counts as set!");
    }

    if (union.getFieldValue() != null) {
      throw new RuntimeException("unset union didn't return null for value");
    }

    union = new TestUnion(TestUnion._Fields.I32_FIELD, 25);

    if ((Integer)union.getFieldValue() != 25) {
      throw new RuntimeException("set i32 field didn't come out as planned");
    }

    if ((Integer)union.getFieldValue(TestUnion._Fields.I32_FIELD) != 25) {
      throw new RuntimeException("set i32 field didn't come out of TBase getFieldValue");
    }

    try {
      union.getFieldValue(TestUnion._Fields.STRING_FIELD);
      throw new RuntimeException("was expecting an exception around wrong set field");
    } catch (IllegalArgumentException e) {
      // cool!
    }

    System.out.println(union);

    union = new TestUnion();
    union.setI32_field(1);
    if (union.getI32_field() != 1) {
      throw new RuntimeException("didn't get the right value for i32 field!");
    }
    union.hashCode();

    try {
      union.getString_field();
      throw new RuntimeException("should have gotten an exception");
    } catch (Exception e) {
      // sweet
    }

    union = TestUnion.i32_field(1);
   
    if (union.equals((TestUnion)null)) {
      throw new RuntimeException("uh oh, union.equals(null)!");
    }

    union = TestUnion.enum_field(SomeEnum.ONE);
    union.hashCode();
  }
View Full Code Here

Examples of thrift.test.TestUnion

    union.hashCode();
  }


  public static void testEquality() throws Exception {
    TestUnion union = new TestUnion(TestUnion._Fields.I32_FIELD, 25);

    TestUnion otherUnion = new TestUnion(TestUnion._Fields.STRING_FIELD, "blah!!!");

    if (union.equals(otherUnion)) {
      throw new RuntimeException("shouldn't be equal");
    }

    otherUnion = new TestUnion(TestUnion._Fields.I32_FIELD, 400);

    if (union.equals(otherUnion)) {
      throw new RuntimeException("shouldn't be equal");
    }

    otherUnion = new TestUnion(TestUnion._Fields.OTHER_I32_FIELD, 25);

    if (union.equals(otherUnion)) {
      throw new RuntimeException("shouldn't be equal");
    }
  }
View Full Code Here

Examples of thrift.test.TestUnion

    }
  }


  public static void testSerialization() throws Exception {
    TestUnion union = new TestUnion(TestUnion._Fields.I32_FIELD, 25);

    TMemoryBuffer buf = new TMemoryBuffer(0);
    TProtocol proto = new TBinaryProtocol(buf);

    union.write(proto);

    TestUnion u2 = new TestUnion();

    u2.read(proto);

    if (!u2.equals(union)) {
      throw new RuntimeException("serialization fails!");
    }

    StructWithAUnion swau = new StructWithAUnion(u2);
View Full Code Here

Examples of thrift.test.TestUnion

import thrift.test.TestUnionMinusStringField;

public class TestTUnion extends TestCase {

  public void testBasic() throws Exception {
    TestUnion union = new TestUnion();

    assertFalse(union.isSet());
    assertFalse(union.isSetI32_field());
    assertNull(union.getFieldValue());

    union = new TestUnion(TestUnion._Fields.I32_FIELD, 25);

    assertEquals(Integer.valueOf(25), union.getFieldValue());
 
    assertEquals(Integer.valueOf(25), union.getFieldValue(TestUnion._Fields.I32_FIELD));
   
    assertTrue(union.isSetI32_field());
 
    try {
      union.getFieldValue(TestUnion._Fields.STRING_FIELD);
      fail("should have thrown an exception");
    } catch (IllegalArgumentException e) {
      // cool!
    }

    union = new TestUnion();

    // should not throw an exception here
    union.hashCode();

    union.setI32_field(1);
    assertEquals(1, union.getI32_field());
    union.hashCode();

    assertFalse(union.isSetString_field());
   
    try {
      union.getString_field();
      fail("should have thrown an exception");
    } catch (Exception e) {
      // sweet
    }

    union = TestUnion.i32_field(1);

    assertFalse(union.equals((TestUnion)null));

    union = TestUnion.enum_field(SomeEnum.ONE);
    union.hashCode();

    union = new TestUnion();
    // should not throw an exception
    union.toString();
  }
View Full Code Here

Examples of thrift.test.TestUnion

    cu = ComparableUnion.binary_field(ByteBuffer.wrap(new byte[]{1}));

    assertTrue(cu.compareTo(cu2) < 0);
    assertTrue(cu2.compareTo(cu) > 0);
   
    TestUnion union1 = new TestUnion(TestUnion._Fields.STRUCT_LIST, new ArrayList<RandomStuff>());
    TestUnion union2 = new TestUnion(TestUnion._Fields.STRUCT_LIST, new ArrayList<RandomStuff>());
    assertTrue(union1.compareTo(union2) == 0);

    TestUnion union3 = new TestUnion(TestUnion._Fields.I32_SET, new HashSet<Integer>());
    Set<Integer> i32_set = new HashSet<Integer>();
    i32_set.add(1);
    TestUnion union4 = new TestUnion(TestUnion._Fields.I32_SET, i32_set);
    assertTrue(union3.compareTo(union4) < 0);

    Map<Integer, Integer> i32_map = new HashMap<Integer, Integer>();
    i32_map.put(1,1);
    TestUnion union5 = new TestUnion(TestUnion._Fields.I32_MAP, i32_map);
    TestUnion union6 = new TestUnion(TestUnion._Fields.I32_MAP, new HashMap<Integer, Integer>());
    assertTrue(union5.compareTo(union6) > 0);
  }
View Full Code Here

Examples of thrift.test.TestUnion

    TestUnion union6 = new TestUnion(TestUnion._Fields.I32_MAP, new HashMap<Integer, Integer>());
    assertTrue(union5.compareTo(union6) > 0);
  }

  public void testEquality() throws Exception {
    TestUnion union = new TestUnion(TestUnion._Fields.I32_FIELD, 25);

    TestUnion otherUnion = new TestUnion(TestUnion._Fields.STRING_FIELD, "blah!!!");

    assertFalse(union.equals(otherUnion));

    otherUnion = new TestUnion(TestUnion._Fields.I32_FIELD, 400);

    assertFalse(union.equals(otherUnion));

    otherUnion = new TestUnion(TestUnion._Fields.OTHER_I32_FIELD, 25);

    assertFalse(union.equals(otherUnion));
  }
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.