Examples of House


Examples of game.slot.House

      playerXStats.add(fourOfAKind);
      SmallStraight small = new SmallStraight("Small straight", 15);
      playerXStats.add(small);
      LargeStraight large = new LargeStraight("Large Straight", 20);
      playerXStats.add(large);
      House house = new House("House", 28);
      playerXStats.add(house);
      Chance chance = new Chance("Chance", 30);
      playerXStats.add(chance);
      Yahtzee yahtzee = new Yahtzee("Yahtzee", 50);
      playerXStats.add(yahtzee);
View Full Code Here

Examples of lec04.glab.realestate.House

   */
  public static void main(String[] args) {



    House houOne = new House(
        "5519 Dorchester Ave.",
        101.25,
        Asciify.getAsciiChars(
            "http://www.bradfitzpatrick.com/stock_illustration/images/cartoon_house_001.gif",
            100), false);

    House houSame = houOne;
    System.out.println("houOne and houSame point the same instantiated object in memory space? " + (houOne == houSame));
    houSame.setMarketValue(21.00);
   
    System.out.println(houOne.getMarketValue());
    System.out.println(houSame.getMarketValue());
   
    System.out.println("##############################");
   

   
    House houTwo = null;
    try {
      houTwo = houOne.clone();
    } catch (CloneNotSupportedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    System.out.println("houOne and houTwo point the same instantiated object in memory space? " + (houOne == houTwo));
   
    houTwo.setMarketValue(57.00);
 
   
    System.out.println("market value: " + houOne.getMarketValue() + " : time stamp " +  houOne.getDatInstantiated().getTime());
    System.out.println("market value: " + houTwo.getMarketValue()  + " : time stamp " +  houTwo.getDatInstantiated().getTime());
   
   
    //deep copy or not; depends if House deep copies the mutable fields of House or not.
    System.out.println("houOne.getDatInstantiated() and houTwo.getDatInstantiated() point the same instantiated object in memory space? " + (houOne.getDatInstantiated() == houTwo.getDatInstantiated()));
   


  }
View Full Code Here

Examples of org.codehaus.enunciate.examples.c.schema.structures.House

    if (this.skipCTests) {
      System.out.println("C tests have been disabled.");
      return;
    }

    House house = new House();
    Rectangle base = new Rectangle();
    base.setColor(Color.BLUE);
    base.setHeight(80);
    base.setWidth(80);
    base.setLineStyle(LineStyle.solid);
    base.setId("baseid");
    house.setBase(base);
    Rectangle door = new Rectangle();
    door.setColor(Color.YELLOW);
    door.setHeight(35);
    door.setWidth(20);
    door.setLineStyle(LineStyle.solid);
    door.setId("doorId");
    house.setDoor(door);
    Circle knob = new Circle();
    knob.setColor(Color.RED);
    knob.setId("knobId");
    knob.setLineStyle(LineStyle.dashed);
    knob.setRadius(2);
    house.setDoorKnob(knob);
    Label label1 = new Label();
    label1.setValue("bachelor-pad");
    Label label2 = new Label();
    label2.setValue("single-family-dwelling");
    house.setLabels(Arrays.asList(label1, label2));
    Triangle roof = new Triangle();
    roof.setBase(84);
    roof.setHeight(20);
    roof.setColor(Color.YELLOW);
    roof.setLineStyle(LineStyle.solid);
    house.setRoof(roof);
    Rectangle window = new Rectangle();
    window.setColor(Color.YELLOW);
    window.setHeight(10);
    window.setWidth(10);
    window.setLineStyle(LineStyle.solid);
    house.setWindows(Arrays.asList(window));
    Date date = new Date();
    house.setConstructedDate(new DateTime(date, DateTimeZone.UTC));
    house.setType(XmlQNameEnumUtil.toQName(HouseType.brick));
    house.setStyle(XmlQNameEnumUtil.toQName(HouseStyle.latin));
    house.setColor(XmlQNameEnumUtil.toURI(HouseColor.blue));

    house = processThroughXml(house);

    base = house.getBase();
    assertSame(Color.BLUE, base.getColor());
    assertSame(LineStyle.solid, base.getLineStyle());
    assertEquals(80, base.getHeight());
    assertEquals(80, base.getWidth());
    assertEquals("baseid", base.getId());
    door = house.getDoor();
    assertSame(Color.YELLOW, door.getColor());
    assertSame(LineStyle.solid, door.getLineStyle());
    assertEquals(35, door.getHeight());
    assertEquals(20, door.getWidth());
    assertEquals("doorId", door.getId());
    knob = house.getDoorKnob();
    assertSame(Color.RED, knob.getColor());
    assertSame(LineStyle.dashed, knob.getLineStyle());
    assertEquals(2, knob.getRadius());
    assertEquals("knobId", knob.getId());
    List<String> labels = Arrays.asList("bachelor-pad", "single-family-dwelling");
    house.getLabels().size();
    for (Object l : house.getLabels()) {
      Label label = (Label) l;
      assertTrue(labels.contains(label.getValue()));
    }
    roof = house.getRoof();
    assertSame(Color.YELLOW, roof.getColor());
    assertSame(LineStyle.solid, roof.getLineStyle());
    assertNull(roof.getId());
    assertEquals(84, roof.getBase());
    assertEquals(20, roof.getHeight());
    assertEquals(1, house.getWindows().size());
    window = house.getWindows().get(0);
    assertSame(Color.YELLOW, window.getColor());
    assertSame(LineStyle.solid, window.getLineStyle());
    assertEquals(10, window.getHeight());
    assertEquals(10, window.getWidth());
    assertNull(window.getId());
    assertNotNull(house.getConstructedDate());
    assertEquals(date.getTime() - (date.getTime() % 1000), house.getConstructedDate().getMillis());
    assertEquals(XmlQNameEnumUtil.toQName(HouseType.brick), house.getType());
    assertEquals(XmlQNameEnumUtil.toQName(HouseStyle.latin), house.getStyle());
    assertEquals(XmlQNameEnumUtil.toURI(HouseColor.blue), house.getColor());
  }
View Full Code Here

Examples of org.codehaus.enunciate.examples.c.schema.structures.House

    Cat cat = new Cat();
    cat.setId("catId");
    Circle catFace = new Circle();
    catFace.setRadius(30);
    cat.setFace(catFace);
    House house = new House();
    house.setId("houseId");
    Rectangle houseBase = new Rectangle();
    houseBase.setWidth(76);
    house.setBase(houseBase);
    canvas.setFigures(Arrays.asList(bus, cat, house));
    Rectangle rectangle = new Rectangle();
    rectangle.setHeight(50);
    rectangle.setId("rectId");
    Circle circle = new Circle();
    circle.setRadius(10);
    circle.setId("circleId");
    Triangle triangle = new Triangle();
    triangle.setBase(80);
    triangle.setId("triId");
    canvas.setShapes(Arrays.asList(rectangle, circle, triangle));
//    byte[] swaRefBytes = "This is a bunch of random bytes that are to be used as an SWA ref attachment.".getBytes();
//    byte[] explicitBase64Bytes = "This is some more random bytes that are to be used as a base 64 encoded attachment.".getBytes();
//    byte[] attachment1Bytes = "This is some more random bytes that are to be used as the first MTOM attachment.".getBytes();
//    byte[] attachment2Bytes = "This is some more random bytes that are to be used as the second MTOM attachment.".getBytes();
//    byte[] attachment3Bytes = "This is some more random bytes that are to be used as the third MTOM attachment.".getBytes();
//    CanvasAttachment attachment1 = new CanvasAttachment();
//    attachment1.setValue(attachment1Bytes);
//    CanvasAttachment attachment2 = new CanvasAttachment();
//    attachment2.setValue(attachment2Bytes);
//    CanvasAttachment attachment3 = new CanvasAttachment();
//    attachment3.setValue(attachment3Bytes);
//    ByteArrayDataSource dataSource = new ByteArrayDataSource(swaRefBytes, "application/octet-stream");
//    dataSource.setName("somename");
//    canvas.setBackgroundImage(new DataHandler(dataSource));
//    canvas.setExplicitBase64Attachment(explicitBase64Bytes);
//    canvas.setOtherAttachments(Arrays.asList(attachment1, attachment2, attachment3));

    canvas = processThroughXml(canvas);

    Collection shapes = canvas.getShapes();
    assertEquals(3, shapes.size());
    for (Object Shape : shapes) {
      if (Shape instanceof Circle) {
        assertEquals("circleId", ((Circle) Shape).getId());
        assertEquals(10, ((Circle) Shape).getRadius());
      }
      else if (Shape instanceof Rectangle) {
        assertEquals("rectId", ((Rectangle) Shape).getId());
        assertEquals(50, ((Rectangle) Shape).getHeight());
      }
      else if (Shape instanceof Triangle) {
        assertEquals("triId", ((Triangle) Shape).getId());
        assertEquals(80, ((Triangle) Shape).getBase());
      }
      else {
        fail("Unknown shape: " + Shape);
      }
    }

    Collection figures = canvas.getFigures();
    assertEquals(3, figures.size());
    for (Object Figure : figures) {
      if (Figure instanceof Bus) {
        bus = (Bus) Figure;
        assertEquals("busId", bus.getId());
        Rectangle BusFrame = bus.getFrame();
        assertNotNull(BusFrame);
        assertEquals(100, busFrame.getWidth());
      }
      else if (Figure instanceof Cat) {
        cat = (Cat) Figure;
        assertEquals("catId", cat.getId());
        Circle CatFace = cat.getFace();
        assertNotNull(CatFace);
        assertEquals(30, CatFace.getRadius());
      }
      else if (Figure instanceof House) {
        house = (House) Figure;
        assertEquals("houseId", house.getId());
        Rectangle HouseBase = house.getBase();
        assertNotNull(HouseBase);
        assertEquals(76, HouseBase.getWidth());
      }
      else {
        fail("Unknown figure: " + Figure);
View Full Code Here

Examples of org.codehaus.enunciate.examples.csharp.schema.structures.House

    if (this.skipCSharpTests) {
      System.out.println("CSharp tests have been disabled.");
      return;
    }

    House house = new House();
    Rectangle base = new Rectangle();
    base.setColor(Color.BLUE);
    base.setHeight(80);
    base.setWidth(80);
    base.setLineStyle(LineStyle.solid);
    base.setId("baseid");
    house.setBase(base);
    Rectangle door = new Rectangle();
    door.setColor(Color.YELLOW);
    door.setHeight(35);
    door.setWidth(20);
    door.setLineStyle(LineStyle.solid);
    door.setId("doorId");
    house.setDoor(door);
    Circle knob = new Circle();
    knob.setColor(Color.RED);
    knob.setId("knobId");
    knob.setLineStyle(LineStyle.dashed);
    knob.setRadius(2);
    house.setDoorKnob(knob);
    Label label1 = new Label();
    label1.setValue("bachelor-pad");
    Label label2 = new Label();
    label2.setValue("single-family-dwelling");
    house.setLabels(Arrays.asList(label1, label2));
    Triangle roof = new Triangle();
    roof.setBase(84);
    roof.setHeight(20);
    roof.setColor(Color.YELLOW);
    roof.setLineStyle(LineStyle.solid);
    house.setRoof(roof);
    Rectangle window = new Rectangle();
    window.setColor(Color.YELLOW);
    window.setHeight(10);
    window.setWidth(10);
    window.setLineStyle(LineStyle.solid);
    house.setWindows(Arrays.asList(window));
    Date date = new Date();
//    house.setConstructedDate(new DateTime(date, DateTimeZone.UTC));
    house.setType(XmlQNameEnumUtil.toQName(HouseType.brick));
    house.setStyle(XmlQNameEnumUtil.toQName(HouseStyle.latin));
    house.setColor(XmlQNameEnumUtil.toURI(HouseColor.blue));

    house = processThroughXml(house);

    base = house.getBase();
    assertSame(Color.BLUE, base.getColor());
    assertSame(LineStyle.solid, base.getLineStyle());
    assertEquals(80, base.getHeight());
    assertEquals(80, base.getWidth());
    assertEquals("baseid", base.getId());
    door = house.getDoor();
    assertSame(Color.YELLOW, door.getColor());
    assertSame(LineStyle.solid, door.getLineStyle());
    assertEquals(35, door.getHeight());
    assertEquals(20, door.getWidth());
    assertEquals("doorId", door.getId());
    knob = house.getDoorKnob();
    assertSame(Color.RED, knob.getColor());
    assertSame(LineStyle.dashed, knob.getLineStyle());
    assertEquals(2, knob.getRadius());
    assertEquals("knobId", knob.getId());
    List<String> labels = Arrays.asList("bachelor-pad", "single-family-dwelling");
    house.getLabels().size();
    for (Object l : house.getLabels()) {
      Label label = (Label) l;
      assertTrue(labels.contains(label.getValue()));
    }
    roof = house.getRoof();
    assertSame(Color.YELLOW, roof.getColor());
    assertSame(LineStyle.solid, roof.getLineStyle());
    assertNull(roof.getId());
    assertEquals(84, roof.getBase());
    assertEquals(20, roof.getHeight());
    assertEquals(1, house.getWindows().size());
    window = house.getWindows().get(0);
    assertSame(Color.YELLOW, window.getColor());
    assertSame(LineStyle.solid, window.getLineStyle());
    assertEquals(10, window.getHeight());
    assertEquals(10, window.getWidth());
    assertNull(window.getId());
    assertNull("constructed date should be null (C# value type should not be serialized)", house.getConstructedDate());
    assertEquals(XmlQNameEnumUtil.toQName(HouseType.brick), house.getType());
    assertEquals(XmlQNameEnumUtil.toQName(HouseStyle.latin), house.getStyle());
    assertEquals(XmlQNameEnumUtil.toURI(HouseColor.blue), house.getColor());
    //todo: figure out the timezone particulars.
    //assertEquals(new DateTime(date, DateTimeZone.UTC), house.getConstructedDate());

  }
View Full Code Here

Examples of org.codehaus.enunciate.examples.csharp.schema.structures.House

    Cat cat = new Cat();
    cat.setId("catId");
    Circle catFace = new Circle();
    catFace.setRadius(30);
    cat.setFace(catFace);
    House house = new House();
    house.setId("houseId");
    Rectangle houseBase = new Rectangle();
    houseBase.setWidth(76);
    house.setBase(houseBase);
    canvas.setFigures(Arrays.asList(bus, cat, house));
    Rectangle rectangle = new Rectangle();
    rectangle.setHeight(50);
    rectangle.setId("rectId");
    Circle circle = new Circle();
    circle.setRadius(10);
    circle.setId("circleId");
    Triangle triangle = new Triangle();
    triangle.setBase(80);
    triangle.setId("triId");
    canvas.setShapes(Arrays.asList(rectangle, circle, triangle));
//    byte[] swaRefBytes = "This is a bunch of random bytes that are to be used as an SWA ref attachment.".getBytes();
//    byte[] explicitBase64Bytes = "This is some more random bytes that are to be used as a base 64 encoded attachment.".getBytes();
//    byte[] attachment1Bytes = "This is some more random bytes that are to be used as the first MTOM attachment.".getBytes();
//    byte[] attachment2Bytes = "This is some more random bytes that are to be used as the second MTOM attachment.".getBytes();
//    byte[] attachment3Bytes = "This is some more random bytes that are to be used as the third MTOM attachment.".getBytes();
//    CanvasAttachment attachment1 = new CanvasAttachment();
//    attachment1.setValue(attachment1Bytes);
//    CanvasAttachment attachment2 = new CanvasAttachment();
//    attachment2.setValue(attachment2Bytes);
//    CanvasAttachment attachment3 = new CanvasAttachment();
//    attachment3.setValue(attachment3Bytes);
//    ByteArrayDataSource dataSource = new ByteArrayDataSource(swaRefBytes, "application/octet-stream");
//    dataSource.setName("somename");
//    canvas.setBackgroundImage(new DataHandler(dataSource));
//    canvas.setExplicitBase64Attachment(explicitBase64Bytes);
//    canvas.setOtherAttachments(Arrays.asList(attachment1, attachment2, attachment3));

    canvas = processThroughXml(canvas);

    Collection shapes = canvas.getShapes();
    assertEquals(3, shapes.size());
    for (Object Shape : shapes) {
      if (Shape instanceof Circle) {
        assertEquals("circleId", ((Circle) Shape).getId());
        assertEquals(10, ((Circle) Shape).getRadius());
      }
      else if (Shape instanceof Rectangle) {
        assertEquals("rectId", ((Rectangle) Shape).getId());
        assertEquals(50, ((Rectangle) Shape).getHeight());
      }
      else if (Shape instanceof Triangle) {
        assertEquals("triId", ((Triangle) Shape).getId());
        assertEquals(80, ((Triangle) Shape).getBase());
      }
      else {
        fail("Unknown shape: " + Shape);
      }
    }

    Collection figures = canvas.getFigures();
    assertEquals(3, figures.size());
    for (Object Figure : figures) {
      if (Figure instanceof Bus) {
        bus = (Bus) Figure;
        assertEquals("busId", bus.getId());
        Rectangle BusFrame = bus.getFrame();
        assertNotNull(BusFrame);
        assertEquals(100, busFrame.getWidth());
      }
      else if (Figure instanceof Cat) {
        cat = (Cat) Figure;
        assertEquals("catId", cat.getId());
        Circle CatFace = cat.getFace();
        assertNotNull(CatFace);
        assertEquals(30, CatFace.getRadius());
      }
      else if (Figure instanceof House) {
        house = (House) Figure;
        assertEquals("houseId", house.getId());
        Rectangle HouseBase = house.getBase();
        assertNotNull(HouseBase);
        assertEquals(76, HouseBase.getWidth());
      }
      else {
        fail("Unknown figure: " + Figure);
View Full Code Here

Examples of org.codehaus.enunciate.examples.jaxws_client.schema.structures.House

  /**
   * tests house.  This one has things like nillable and required properties.
   */
  public void testHouse() throws Exception {
    House house = new House();
    Rectangle base = new Rectangle();
    base.setColor(Color.BLUE);
    base.setHeight(80);
    base.setWidth(80);
    base.setLineStyle(LineStyle.solid);
    base.setId("baseid");
    house.setBase(base);
    Rectangle door = new Rectangle();
    door.setColor(Color.YELLOW);
    door.setHeight(35);
    door.setWidth(20);
    door.setLineStyle(LineStyle.solid);
    door.setId("doorId");
    house.setDoor(door);
    Circle knob = new Circle();
    knob.setColor(Color.RED);
    knob.setId("knobId");
    knob.setLineStyle(LineStyle.dashed);
    knob.setRadius(2);
    house.setDoorKnob(knob);
    Label label1 = new Label();
    label1.setValue("bachelor-pad");
    Label label2 = new Label();
    label2.setValue("single-family-dwelling");
    house.setLabels(Arrays.asList(label1, label2));
    Triangle roof = new Triangle();
    roof.setBase(84);
    roof.setHeight(20);
    roof.setColor(Color.YELLOW);
    roof.setLineStyle(LineStyle.solid);
    house.setRoof(roof);
    Rectangle window = new Rectangle();
    window.setColor(Color.YELLOW);
    window.setHeight(10);
    window.setWidth(10);
    window.setLineStyle(LineStyle.solid);
    house.setWindows(Arrays.asList(window));
    house.setConstructedDate(new DateTime(3L));
    house.setType(XmlQNameEnumUtil.toQName(HouseType.brick));
    house.setStyle(XmlQNameEnumUtil.toQName(HouseStyle.latin));
    house.setColor(XmlQNameEnumUtil.toURI(HouseColor.blue));

    JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
    ObjectMapper houseMapper = provider.locateMapper(House.class, MediaType.APPLICATION_JSON_TYPE);
    ObjectMapper clientMapper = new ObjectMapper();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    houseMapper.writeValue(out, house);
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    shapes.json.structures.House clientHouse = clientMapper.readValue(in, shapes.json.structures.House.class);

    shapes.json.Rectangle clientBase = clientHouse.getBase();
    assertSame(shapes.json.Color.BLUE, clientBase.getColor());
    assertSame(shapes.json.LineStyle.solid, clientBase.getLineStyle());
    assertEquals(80, clientBase.getHeight());
    assertEquals(80, clientBase.getWidth());
    assertEquals("baseid", clientBase.getId());
    shapes.json.Rectangle clientDoor = clientHouse.getDoor();
    assertSame(shapes.json.Color.YELLOW, clientDoor.getColor());
    assertSame(shapes.json.LineStyle.solid, clientDoor.getLineStyle());
    assertEquals(35, clientDoor.getHeight());
    assertEquals(20, clientDoor.getWidth());
    assertEquals("doorId", clientDoor.getId());
    shapes.json.Circle clientKnob = clientHouse.getDoorKnob();
    assertSame(shapes.json.Color.RED, clientKnob.getColor());
    assertSame(shapes.json.LineStyle.dashed, clientKnob.getLineStyle());
    assertEquals(2, clientKnob.getRadius());
    assertEquals("knobId", clientKnob.getId());
    List<String> labels = Arrays.asList("bachelor-pad", "single-family-dwelling");
    clientHouse.getLabels().size();
    for (Object l : clientHouse.getLabels()) {
      shapes.json.Label label = (shapes.json.Label) l;
      assertTrue(labels.contains(label.getValue()));
    }
    shapes.json.Triangle clientRoof = clientHouse.getRoof();
    assertSame(shapes.json.Color.YELLOW, clientRoof.getColor());
    assertSame(shapes.json.LineStyle.solid, clientRoof.getLineStyle());
    assertNull(clientRoof.getId());
    assertEquals(84, clientRoof.getBase());
    assertEquals(20, clientRoof.getHeight());
    assertEquals(1, clientHouse.getWindows().size());
    shapes.json.Rectangle clientWindow = (shapes.json.Rectangle) clientHouse.getWindows().get(0);
    assertSame(shapes.json.Color.YELLOW, clientWindow.getColor());
    assertSame(shapes.json.LineStyle.solid, clientWindow.getLineStyle());
    assertEquals(10, clientWindow.getHeight());
    assertEquals(10, clientWindow.getWidth());
    assertNull(clientWindow.getId());
    assertEquals(new Date(3L), clientHouse.getConstructedDate());

    out = new ByteArrayOutputStream();
    clientMapper.writeValue(out, clientHouse);
    house = houseMapper.readValue(new ByteArrayInputStream(out.toByteArray()), House.class);
    base = house.getBase();
    assertSame(Color.BLUE, base.getColor());
    assertSame(LineStyle.solid, base.getLineStyle());
    assertEquals(80, base.getHeight());
    assertEquals(80, base.getWidth());
    assertEquals("baseid", base.getId());
    door = house.getDoor();
    assertSame(Color.YELLOW, door.getColor());
    assertSame(LineStyle.solid, door.getLineStyle());
    assertEquals(35, door.getHeight());
    assertEquals(20, door.getWidth());
    assertEquals("doorId", door.getId());
    knob = house.getDoorKnob();
    assertSame(Color.RED, knob.getColor());
    assertSame(LineStyle.dashed, knob.getLineStyle());
    assertEquals(2, knob.getRadius());
    assertEquals("knobId", knob.getId());
    labels = Arrays.asList("bachelor-pad", "single-family-dwelling");
    house.getLabels().size();
    for (Object l : house.getLabels()) {
      Label label = (Label) l;
      assertTrue(labels.contains(label.getValue()));
    }
    roof = house.getRoof();
    assertSame(Color.YELLOW, roof.getColor());
    assertSame(LineStyle.solid, roof.getLineStyle());
    assertNull(roof.getId());
    assertEquals(84, roof.getBase());
    assertEquals(20, roof.getHeight());
    assertEquals(1, house.getWindows().size());
    window = house.getWindows().get(0);
    assertSame(Color.YELLOW, window.getColor());
    assertSame(LineStyle.solid, window.getLineStyle());
    assertEquals(10, window.getHeight());
    assertEquals(10, window.getWidth());
    assertNull(window.getId());
    assertEquals(new DateTime(3L), house.getConstructedDate());
    assertEquals(XmlQNameEnumUtil.toQName(HouseType.brick), house.getType());
    assertEquals(XmlQNameEnumUtil.toQName(HouseStyle.latin), house.getStyle());
    assertEquals(XmlQNameEnumUtil.toURI(HouseColor.blue), house.getColor());

    //now let's check the nillable and required stuff:

    //roof is required, but nillable.
    clientHouse.setRoof(null);
    out = new ByteArrayOutputStream();
    clientMapper.writeValue(out, clientHouse);
    house = houseMapper.readValue(new ByteArrayInputStream(out.toByteArray()), House.class);
    base = house.getBase();
    assertSame(Color.BLUE, base.getColor());
    assertSame(LineStyle.solid, base.getLineStyle());
    assertEquals(80, base.getHeight());
    assertEquals(80, base.getWidth());
    assertEquals("baseid", base.getId());
    door = house.getDoor();
    assertSame(Color.YELLOW, door.getColor());
    assertSame(LineStyle.solid, door.getLineStyle());
    assertEquals(35, door.getHeight());
    assertEquals(20, door.getWidth());
    assertEquals("doorId", door.getId());
    knob = house.getDoorKnob();
    assertSame(Color.RED, knob.getColor());
    assertSame(LineStyle.dashed, knob.getLineStyle());
    assertEquals(2, knob.getRadius());
    assertEquals("knobId", knob.getId());
    labels = Arrays.asList("bachelor-pad", "single-family-dwelling");
    house.getLabels().size();
    for (Object l : house.getLabels()) {
      Label label = (Label) l;
      assertTrue(labels.contains(label.getValue()));
    }
    roof = house.getRoof();
    assertNull(roof);
    assertEquals(1, house.getWindows().size());
    window = house.getWindows().get(0);
    assertSame(Color.YELLOW, window.getColor());
    assertSame(LineStyle.solid, window.getLineStyle());
    assertEquals(10, window.getHeight());
    assertEquals(10, window.getWidth());
    assertNull(window.getId());

    //windows are nillable...
    clientHouse.setWindows(null);
    out = new ByteArrayOutputStream();
    clientMapper.writeValue(out, clientHouse);
    house = houseMapper.readValue(new ByteArrayInputStream(out.toByteArray()), House.class);
    base = house.getBase();
    assertSame(Color.BLUE, base.getColor());
    assertSame(LineStyle.solid, base.getLineStyle());
    assertEquals(80, base.getHeight());
    assertEquals(80, base.getWidth());
    assertEquals("baseid", base.getId());
    door = house.getDoor();
    assertSame(Color.YELLOW, door.getColor());
    assertSame(LineStyle.solid, door.getLineStyle());
    assertEquals(35, door.getHeight());
    assertEquals(20, door.getWidth());
    assertEquals("doorId", door.getId());
    knob = house.getDoorKnob();
    assertSame(Color.RED, knob.getColor());
    assertSame(LineStyle.dashed, knob.getLineStyle());
    assertEquals(2, knob.getRadius());
    assertEquals("knobId", knob.getId());
    labels = Arrays.asList("bachelor-pad", "single-family-dwelling");
    house.getLabels().size();
    for (Object l : house.getLabels()) {
      Label label = (Label) l;
      assertTrue(labels.contains(label.getValue()));
    }
    roof = house.getRoof();
    assertNull(roof);
    assertNull(house.getWindows());
  }
View Full Code Here

Examples of org.codehaus.enunciate.examples.jaxws_client.schema.structures.House

    Cat cat = new Cat();
    cat.setId("catId");
    Circle catFace = new Circle();
    catFace.setRadius(30);
    cat.setFace(catFace);
    House house = new House();
    house.setId("houseId");
    Rectangle houseBase = new Rectangle();
    houseBase.setWidth(76);
    house.setBase(houseBase);
    canvas.setFigures(Arrays.asList(bus, cat, house));
    Rectangle rectangle = new Rectangle();
    rectangle.setHeight(50);
    rectangle.setId("rectId");
    Circle circle = new Circle();
    circle.setRadius(10);
    circle.setId("circleId");
    Triangle triangle = new Triangle();
    triangle.setBase(80);
    triangle.setId("triId");
    canvas.setShapes(Arrays.asList(rectangle, circle, triangle));
    byte[] swaRefBytes = "This is a bunch of random bytes that are to be used as an SWA ref attachment.".getBytes();
    byte[] explicitBase64Bytes = "This is some more random bytes that are to be used as a base 64 encoded attachment.".getBytes();
    byte[] attachment1Bytes = "This is some more random bytes that are to be used as the first MTOM attachment.".getBytes();
    byte[] attachment2Bytes = "This is some more random bytes that are to be used as the second MTOM attachment.".getBytes();
    byte[] attachment3Bytes = "This is some more random bytes that are to be used as the third MTOM attachment.".getBytes();
    CanvasAttachment attachment1 = new CanvasAttachment();
    attachment1.setValue(attachment1Bytes);
    CanvasAttachment attachment2 = new CanvasAttachment();
    attachment2.setValue(attachment2Bytes);
    CanvasAttachment attachment3 = new CanvasAttachment();
    attachment3.setValue(attachment3Bytes);
    ByteArrayDataSource dataSource = new ByteArrayDataSource(swaRefBytes, "application/octet-stream");
    dataSource.setName("somename");
    //todo: uncomment when JAXB bug is fixed
//    canvas.setBackgroundImage(new DataHandler(dataSource));
    canvas.setExplicitBase64Attachment(explicitBase64Bytes);
    canvas.setOtherAttachments(Arrays.asList(attachment1, attachment2, attachment3));

    JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
    ObjectMapper canvasMapper = provider.locateMapper(Canvas.class, MediaType.APPLICATION_JSON_TYPE);
    ObjectMapper clientMapper = new ObjectMapper();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    canvasMapper.writeValue(out, canvas);
    //set up the attachments that were written

    shapes.json.draw.Canvas clientCanvas = clientMapper.readValue(new ByteArrayInputStream(out.toByteArray()), shapes.json.draw.Canvas.class);
    Collection<ObjectNode> clientShapes = clientCanvas.getShapes();
    assertEquals(3, clientShapes.size());
    for (ObjectNode shape : clientShapes) {
      assertEquals(1, shape.size());
      String shapeKey = shape.getFields().next().getKey();
      shape = (ObjectNode) shape.get(shapeKey);
      if ("circle".equals(shapeKey)) {
        assertEquals("circleId", shape.get("id").getTextValue());
        assertEquals(10, shape.get("radius").getIntValue());
      }
      else if ("triangle".equals(shapeKey)) {
        assertEquals("triId", shape.get("id").getTextValue());
        assertEquals(80, shape.get("base").getIntValue());
      }
      else if ("rectangle".equals(shapeKey)) {
        assertEquals("rectId", shape.get("id").getTextValue());
        assertEquals(50, shape.get("height").getIntValue());
      }
      else {
        fail("Unknown shape: " + shapeKey);
      }
    }

    Collection<ObjectNode> clientFigures = clientCanvas.getFigures();
    assertEquals(3, clientFigures.size());
    for (ObjectNode figure : clientFigures) {
      assertEquals(1, figure.size());
      String figureKey = figure.getFields().next().getKey();
      figure = (ObjectNode) figure.get(figureKey);
      if ("bus".equals(figureKey)) {
        assertEquals("busId", figure.get("id").getTextValue());
        assertTrue(figure.get("frame") != null);
        assertEquals(100, figure.get("frame").get("width").getIntValue());
      }
      else if ("cat".equals(figureKey)) {
        assertEquals("catId", figure.get("id").getTextValue());
        assertTrue(figure.get("circle") != null);
        assertEquals(30, figure.get("circle").get("radius").getIntValue());
      }
      else if ("house".equals(figureKey)) {
        assertEquals("houseId", figure.get("id").getTextValue());
        assertTrue(figure.get("base") != null);
        assertEquals(76, figure.get("base").get("width").getIntValue());
      }
      else {
        fail("Unknown figure: " + figure);
      }
    }

//    DataHandler backgroundImage = clientCanvas.getBackgroundImage();
//    InputStream attachmentStream = backgroundImage.getInputStream();
//    ByteArrayOutputStream bgImageIn = new ByteArrayOutputStream();
//    int byteIn = attachmentStream.read();
//    while (byteIn > 0) {
//      bgImageIn.write(byteIn);
//      byteIn = attachmentStream.read();
//    }
//    assertTrue(Arrays.equals(swaRefBytes, bgImageIn.toByteArray()));

    byte[] base64Attachment = clientCanvas.getExplicitBase64Attachment();
    assertNotNull(base64Attachment);
    assertTrue(Arrays.equals(explicitBase64Bytes, base64Attachment));

    Collection otherAttachments = clientCanvas.getOtherAttachments();
    assertEquals(3, otherAttachments.size());
    Iterator attachmentsIt = otherAttachments.iterator();
    int attachmentCount = 0;
    while (attachmentsIt.hasNext()) {
      shapes.json.draw.CanvasAttachment otherAttachment = (shapes.json.draw.CanvasAttachment) attachmentsIt.next();
      byte[] otherAttachmentBytes = otherAttachment.getValue();
      if (Arrays.equals(attachment1Bytes, otherAttachmentBytes)) {
        attachmentCount++;
      }
      else if (Arrays.equals(attachment2Bytes, otherAttachmentBytes)) {
        attachmentCount++;
      }
      else if (Arrays.equals(attachment3Bytes, otherAttachmentBytes)) {
        attachmentCount++;
      }
      else {
        fail("Unknown attachment.");
      }
    }
    assertEquals(3, attachmentCount);

    clientCanvas.setShapes(null); //@XmlElementRefs can't be (de)serialized.
    out = new ByteArrayOutputStream();
    clientMapper.writeValue(out, clientCanvas);
    canvas = canvasMapper.readValue(new ByteArrayInputStream(out.toByteArray()), Canvas.class);

    Collection shapes = canvas.getShapes();
    assertNull(shapes);
//    assertEquals(3, shapes.size());
//    for (Object Shape : shapes) {
//      if (Shape instanceof Circle) {
//        assertEquals("circleId", ((Circle) Shape).getId());
//        assertEquals(10, ((Circle) Shape).getRadius());
//      }
//      else if (Shape instanceof Rectangle) {
//        assertEquals("rectId", ((Rectangle) Shape).getId());
//        assertEquals(50, ((Rectangle) Shape).getHeight());
//      }
//      else if (Shape instanceof Triangle) {
//        assertEquals("triId", ((Triangle) Shape).getId());
//        assertEquals(80, ((Triangle) Shape).getBase());
//      }
//      else {
//        fail("Unknown shape: " + Shape);
//      }
//    }

    Collection figures = canvas.getFigures();
    assertEquals(3, figures.size());
    for (Object Figure : figures) {
      if (Figure instanceof Bus) {
        bus = (Bus) Figure;
        assertEquals("busId", bus.getId());
        Rectangle BusFrame = bus.getFrame();
        assertNotNull(BusFrame);
        assertEquals(100, busFrame.getWidth());
      }
      else if (Figure instanceof Cat) {
        cat = (Cat) Figure;
        assertEquals("catId", cat.getId());
        Circle CatFace = cat.getFace();
        assertNotNull(CatFace);
        assertEquals(30, CatFace.getRadius());
      }
      else if (Figure instanceof House) {
        house = (House) Figure;
        assertEquals("houseId", house.getId());
        Rectangle HouseBase = house.getBase();
        assertNotNull(HouseBase);
        assertEquals(76, HouseBase.getWidth());
      }
      else {
        fail("Unknown figure: " + Figure);
View Full Code Here

Examples of org.codehaus.enunciate.examples.jaxws_client.schema.structures.House

  /**
   * tests house.  This one has things like nillable and required properties.
   */
  public void testHouse() throws Exception {
    House house = new House();
    Rectangle base = new Rectangle();
    base.setColor(Color.BLUE);
    base.setHeight(80);
    base.setWidth(80);
    base.setLineStyle(LineStyle.solid);
    base.setId("baseid");
    house.setBase(base);
    Rectangle door = new Rectangle();
    door.setColor(Color.YELLOW);
    door.setHeight(35);
    door.setWidth(20);
    door.setLineStyle(LineStyle.solid);
    door.setId("doorId");
    house.setDoor(door);
    Circle knob = new Circle();
    knob.setColor(Color.RED);
    knob.setId("knobId");
    knob.setLineStyle(LineStyle.dashed);
    knob.setRadius(2);
    house.setDoorKnob(knob);
    Label label1 = new Label();
    label1.setValue("bachelor-pad");
    Label label2 = new Label();
    label2.setValue("single-family-dwelling");
    house.setLabels(Arrays.asList(label1, label2));
    Triangle roof = new Triangle();
    roof.setBase(84);
    roof.setHeight(20);
    roof.setColor(Color.YELLOW);
    roof.setLineStyle(LineStyle.solid);
    house.setRoof(roof);
    Rectangle window = new Rectangle();
    window.setColor(Color.YELLOW);
    window.setHeight(10);
    window.setWidth(10);
    window.setLineStyle(LineStyle.solid);
    house.setWindows(Arrays.asList(window));
    house.setConstructedDate(new DateTime(3L));
    house.setType(XmlQNameEnumUtil.toQName(HouseType.brick));
    house.setStyle(XmlQNameEnumUtil.toQName(HouseStyle.latin));
    house.setColor(XmlQNameEnumUtil.toURI(HouseColor.blue));

    JAXBContext context = JAXBContext.newInstance(House.class);
    JAXBContext clientContext = JAXBContext.newInstance(shapes.structures.House.class);
    Marshaller marshaller = context.createMarshaller();
    Marshaller clientMarshaller = clientContext.createMarshaller();
    Unmarshaller clientUnmarshaller = clientContext.createUnmarshaller();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    marshaller.marshal(house, out);
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    shapes.structures.House clientHouse = (shapes.structures.House) clientUnmarshaller.unmarshal(in);

    shapes.Rectangle clientBase = clientHouse.getBase();
    assertSame(shapes.Color.BLUE, clientBase.getColor());
    assertSame(shapes.LineStyle.solid, clientBase.getLineStyle());
    assertEquals(80, clientBase.getHeight());
    assertEquals(80, clientBase.getWidth());
    assertEquals("baseid", clientBase.getId());
    shapes.Rectangle clientDoor = clientHouse.getDoor();
    assertSame(shapes.Color.YELLOW, clientDoor.getColor());
    assertSame(shapes.LineStyle.solid, clientDoor.getLineStyle());
    assertEquals(35, clientDoor.getHeight());
    assertEquals(20, clientDoor.getWidth());
    assertEquals("doorId", clientDoor.getId());
    shapes.Circle clientKnob = clientHouse.getDoorKnob();
    assertSame(shapes.Color.RED, clientKnob.getColor());
    assertSame(shapes.LineStyle.dashed, clientKnob.getLineStyle());
    assertEquals(2, clientKnob.getRadius());
    assertEquals("knobId", clientKnob.getId());
    List<String> labels = Arrays.asList("bachelor-pad", "single-family-dwelling");
    clientHouse.getLabels().size();
    for (Object l : clientHouse.getLabels()) {
      shapes.Label label = (shapes.Label) l;
      assertTrue(labels.contains(label.getValue()));
    }
    shapes.Triangle clientRoof = clientHouse.getRoof();
    assertSame(shapes.Color.YELLOW, clientRoof.getColor());
    assertSame(shapes.LineStyle.solid, clientRoof.getLineStyle());
    assertNull(clientRoof.getId());
    assertEquals(84, clientRoof.getBase());
    assertEquals(20, clientRoof.getHeight());
    assertEquals(1, clientHouse.getWindows().size());
    shapes.Rectangle clientWindow = (shapes.Rectangle) clientHouse.getWindows().get(0);
    assertSame(shapes.Color.YELLOW, clientWindow.getColor());
    assertSame(shapes.LineStyle.solid, clientWindow.getLineStyle());
    assertEquals(10, clientWindow.getHeight());
    assertEquals(10, clientWindow.getWidth());
    assertNull(clientWindow.getId());
    assertEquals(new Date(3L), clientHouse.getConstructedDate());

    out = new ByteArrayOutputStream();
    clientMarshaller.marshal(clientHouse, out);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    house = (House) unmarshaller.unmarshal(new ByteArrayInputStream(out.toByteArray()));
    base = house.getBase();
    assertSame(Color.BLUE, base.getColor());
    assertSame(LineStyle.solid, base.getLineStyle());
    assertEquals(80, base.getHeight());
    assertEquals(80, base.getWidth());
    assertEquals("baseid", base.getId());
    door = house.getDoor();
    assertSame(Color.YELLOW, door.getColor());
    assertSame(LineStyle.solid, door.getLineStyle());
    assertEquals(35, door.getHeight());
    assertEquals(20, door.getWidth());
    assertEquals("doorId", door.getId());
    knob = house.getDoorKnob();
    assertSame(Color.RED, knob.getColor());
    assertSame(LineStyle.dashed, knob.getLineStyle());
    assertEquals(2, knob.getRadius());
    assertEquals("knobId", knob.getId());
    labels = Arrays.asList("bachelor-pad", "single-family-dwelling");
    house.getLabels().size();
    for (Object l : house.getLabels()) {
      Label label = (Label) l;
      assertTrue(labels.contains(label.getValue()));
    }
    roof = house.getRoof();
    assertSame(Color.YELLOW, roof.getColor());
    assertSame(LineStyle.solid, roof.getLineStyle());
    assertNull(roof.getId());
    assertEquals(84, roof.getBase());
    assertEquals(20, roof.getHeight());
    assertEquals(1, house.getWindows().size());
    window = house.getWindows().get(0);
    assertSame(Color.YELLOW, window.getColor());
    assertSame(LineStyle.solid, window.getLineStyle());
    assertEquals(10, window.getHeight());
    assertEquals(10, window.getWidth());
    assertNull(window.getId());
    assertEquals(new DateTime(3L), house.getConstructedDate());
    assertEquals(XmlQNameEnumUtil.toQName(HouseType.brick), house.getType());
    assertEquals(XmlQNameEnumUtil.toQName(HouseStyle.latin), house.getStyle());
    assertEquals(XmlQNameEnumUtil.toURI(HouseColor.blue), house.getColor());

    //now let's check the nillable and required stuff:

    //roof is required, but nillable.
    clientHouse.setRoof(null);
    out = new ByteArrayOutputStream();
    clientMarshaller.marshal(clientHouse, out);
    house = (House) unmarshaller.unmarshal(new ByteArrayInputStream(out.toByteArray()));
    base = house.getBase();
    assertSame(Color.BLUE, base.getColor());
    assertSame(LineStyle.solid, base.getLineStyle());
    assertEquals(80, base.getHeight());
    assertEquals(80, base.getWidth());
    assertEquals("baseid", base.getId());
    door = house.getDoor();
    assertSame(Color.YELLOW, door.getColor());
    assertSame(LineStyle.solid, door.getLineStyle());
    assertEquals(35, door.getHeight());
    assertEquals(20, door.getWidth());
    assertEquals("doorId", door.getId());
    knob = house.getDoorKnob();
    assertSame(Color.RED, knob.getColor());
    assertSame(LineStyle.dashed, knob.getLineStyle());
    assertEquals(2, knob.getRadius());
    assertEquals("knobId", knob.getId());
    labels = Arrays.asList("bachelor-pad", "single-family-dwelling");
    house.getLabels().size();
    for (Object l : house.getLabels()) {
      Label label = (Label) l;
      assertTrue(labels.contains(label.getValue()));
    }
    roof = house.getRoof();
    assertNull(roof);
    assertEquals(1, house.getWindows().size());
    window = house.getWindows().get(0);
    assertSame(Color.YELLOW, window.getColor());
    assertSame(LineStyle.solid, window.getLineStyle());
    assertEquals(10, window.getHeight());
    assertEquals(10, window.getWidth());
    assertNull(window.getId());

    //windows are nillable...
    clientHouse.setWindows(null);
    out = new ByteArrayOutputStream();
    clientMarshaller.marshal(clientHouse, out);
    house = (House) unmarshaller.unmarshal(new ByteArrayInputStream(out.toByteArray()));
    base = house.getBase();
    assertSame(Color.BLUE, base.getColor());
    assertSame(LineStyle.solid, base.getLineStyle());
    assertEquals(80, base.getHeight());
    assertEquals(80, base.getWidth());
    assertEquals("baseid", base.getId());
    door = house.getDoor();
    assertSame(Color.YELLOW, door.getColor());
    assertSame(LineStyle.solid, door.getLineStyle());
    assertEquals(35, door.getHeight());
    assertEquals(20, door.getWidth());
    assertEquals("doorId", door.getId());
    knob = house.getDoorKnob();
    assertSame(Color.RED, knob.getColor());
    assertSame(LineStyle.dashed, knob.getLineStyle());
    assertEquals(2, knob.getRadius());
    assertEquals("knobId", knob.getId());
    labels = Arrays.asList("bachelor-pad", "single-family-dwelling");
    house.getLabels().size();
    for (Object l : house.getLabels()) {
      Label label = (Label) l;
      assertTrue(labels.contains(label.getValue()));
    }
    roof = house.getRoof();
    assertNull(roof);
    assertNull(house.getWindows());
  }
View Full Code Here

Examples of org.codehaus.enunciate.examples.jaxws_client.schema.structures.House

    Cat cat = new Cat();
    cat.setId("catId");
    Circle catFace = new Circle();
    catFace.setRadius(30);
    cat.setFace(catFace);
    House house = new House();
    house.setId("houseId");
    Rectangle houseBase = new Rectangle();
    houseBase.setWidth(76);
    house.setBase(houseBase);
    canvas.setFigures(Arrays.asList(bus, cat, house));
    Rectangle rectangle = new Rectangle();
    rectangle.setHeight(50);
    rectangle.setId("rectId");
    Circle circle = new Circle();
    circle.setRadius(10);
    circle.setId("circleId");
    Triangle triangle = new Triangle();
    triangle.setBase(80);
    triangle.setId("triId");
    canvas.setShapes(Arrays.asList(rectangle, circle, triangle));
    byte[] swaRefBytes = "This is a bunch of random bytes that are to be used as an SWA ref attachment.".getBytes();
    byte[] explicitBase64Bytes = "This is some more random bytes that are to be used as a base 64 encoded attachment.".getBytes();
    byte[] attachment1Bytes = "This is some more random bytes that are to be used as the first MTOM attachment.".getBytes();
    byte[] attachment2Bytes = "This is some more random bytes that are to be used as the second MTOM attachment.".getBytes();
    byte[] attachment3Bytes = "This is some more random bytes that are to be used as the third MTOM attachment.".getBytes();
    CanvasAttachment attachment1 = new CanvasAttachment();
    attachment1.setValue(attachment1Bytes);
    CanvasAttachment attachment2 = new CanvasAttachment();
    attachment2.setValue(attachment2Bytes);
    CanvasAttachment attachment3 = new CanvasAttachment();
    attachment3.setValue(attachment3Bytes);
    ByteArrayDataSource dataSource = new ByteArrayDataSource(swaRefBytes, "application/octet-stream");
    dataSource.setName("somename");
    //todo: uncomment when JAXB bug is fixed
//    canvas.setBackgroundImage(new DataHandler(dataSource));
    canvas.setExplicitBase64Attachment(explicitBase64Bytes);
    canvas.setOtherAttachments(Arrays.asList(attachment1, attachment2, attachment3));

    JAXBContext context = JAXBContext.newInstance(Canvas.class);
    JAXBContext clientContext = JAXBContext.newInstance(shapes.draw.Canvas.class);
    Marshaller marshaller = context.createMarshaller();
    AttachmentMarshaller attachmentHandler = new AttachmentMarshaller() {
      public String addMtomAttachment(DataHandler data, String elementNamespace, String elementLocalName) {
        return null;
      }

      public String addMtomAttachment(byte[] data, int offset, int length, String mimeType, String elementNamespace, String elementLocalName) {
        return null;
      }

      public String addSwaRefAttachment(DataHandler data) {
        return null;
      }

    };
    marshaller.setAttachmentMarshaller(attachmentHandler);
    Marshaller clientMarshaller = clientContext.createMarshaller();
    clientMarshaller.setAttachmentMarshaller(attachmentHandler);
    Unmarshaller clientUnmarshaller = clientContext.createUnmarshaller();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    marshaller.marshal(canvas, out);
    //set up the attachments that were written

    shapes.draw.Canvas clientCanvas = (shapes.draw.Canvas) clientUnmarshaller.unmarshal(new ByteArrayInputStream(out.toByteArray()));
    Collection clientShapes = clientCanvas.getShapes();
    assertEquals(3, clientShapes.size());
    for (Object clientShape : clientShapes) {
      if (clientShape instanceof shapes.Circle) {
        assertEquals("circleId", ((shapes.Circle) clientShape).getId());
        assertEquals(10, ((shapes.Circle) clientShape).getRadius());
      }
      else if (clientShape instanceof shapes.Rectangle) {
        assertEquals("rectId", ((shapes.Rectangle) clientShape).getId());
        assertEquals(50, ((shapes.Rectangle) clientShape).getHeight());
      }
      else if (clientShape instanceof shapes.Triangle) {
        assertEquals("triId", ((shapes.Triangle) clientShape).getId());
        assertEquals(80, ((shapes.Triangle) clientShape).getBase());
      }
      else {
        fail("Unknown shape: " + clientShape);
      }
    }

    Collection clientFigures = clientCanvas.getFigures();
    assertEquals(3, clientFigures.size());
    for (Object clientFigure : clientFigures) {
      if (clientFigure instanceof shapes.vehicles.Bus) {
        shapes.vehicles.Bus clientBus = (shapes.vehicles.Bus) clientFigure;
        assertEquals("busId", clientBus.getId());
        shapes.Rectangle clientBusFrame = clientBus.getFrame();
        assertNotNull(clientBusFrame);
        assertEquals(100, busFrame.getWidth());
      }
      else if (clientFigure instanceof shapes.animals.Cat) {
        shapes.animals.Cat clientCat = (shapes.animals.Cat) clientFigure;
        assertEquals("catId", clientCat.getId());
        shapes.Circle clientCatFace = clientCat.getFace();
        assertNotNull(clientCatFace);
        assertEquals(30, clientCatFace.getRadius());
      }
      else if (clientFigure instanceof shapes.structures.House) {
        shapes.structures.House clientHouse = (shapes.structures.House) clientFigure;
        assertEquals("houseId", clientHouse.getId());
        shapes.Rectangle clientHouseBase = clientHouse.getBase();
        assertNotNull(clientHouseBase);
        assertEquals(76, clientHouseBase.getWidth());
      }
      else {
        fail("Unknown figure: " + clientFigure);
      }
    }

//    DataHandler backgroundImage = clientCanvas.getBackgroundImage();
//    InputStream attachmentStream = backgroundImage.getInputStream();
//    ByteArrayOutputStream bgImageIn = new ByteArrayOutputStream();
//    int byteIn = attachmentStream.read();
//    while (byteIn > 0) {
//      bgImageIn.write(byteIn);
//      byteIn = attachmentStream.read();
//    }
//    assertTrue(Arrays.equals(swaRefBytes, bgImageIn.toByteArray()));

    byte[] base64Attachment = clientCanvas.getExplicitBase64Attachment();
    assertNotNull(base64Attachment);
    assertTrue(Arrays.equals(explicitBase64Bytes, base64Attachment));

    Collection otherAttachments = clientCanvas.getOtherAttachments();
    assertEquals(3, otherAttachments.size());
    Iterator attachmentsIt = otherAttachments.iterator();
    int attachmentCount = 0;
    while (attachmentsIt.hasNext()) {
      shapes.draw.CanvasAttachment otherAttachment = (shapes.draw.CanvasAttachment) attachmentsIt.next();
      byte[] otherAttachmentBytes = otherAttachment.getValue();
      if (Arrays.equals(attachment1Bytes, otherAttachmentBytes)) {
        attachmentCount++;
      }
      else if (Arrays.equals(attachment2Bytes, otherAttachmentBytes)) {
        attachmentCount++;
      }
      else if (Arrays.equals(attachment3Bytes, otherAttachmentBytes)) {
        attachmentCount++;
      }
      else {
        fail("Unknown attachment.");
      }
    }
    assertEquals(3, attachmentCount);

    out = new ByteArrayOutputStream();
    clientMarshaller.marshal(clientCanvas, out);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    canvas = (Canvas) unmarshaller.unmarshal(new ByteArrayInputStream(out.toByteArray()));

    Collection shapes = canvas.getShapes();
    assertEquals(3, shapes.size());
    for (Object Shape : shapes) {
      if (Shape instanceof Circle) {
        assertEquals("circleId", ((Circle) Shape).getId());
        assertEquals(10, ((Circle) Shape).getRadius());
      }
      else if (Shape instanceof Rectangle) {
        assertEquals("rectId", ((Rectangle) Shape).getId());
        assertEquals(50, ((Rectangle) Shape).getHeight());
      }
      else if (Shape instanceof Triangle) {
        assertEquals("triId", ((Triangle) Shape).getId());
        assertEquals(80, ((Triangle) Shape).getBase());
      }
      else {
        fail("Unknown shape: " + Shape);
      }
    }

    Collection figures = canvas.getFigures();
    assertEquals(3, figures.size());
    for (Object Figure : figures) {
      if (Figure instanceof Bus) {
        bus = (Bus) Figure;
        assertEquals("busId", bus.getId());
        Rectangle BusFrame = bus.getFrame();
        assertNotNull(BusFrame);
        assertEquals(100, busFrame.getWidth());
      }
      else if (Figure instanceof Cat) {
        cat = (Cat) Figure;
        assertEquals("catId", cat.getId());
        Circle CatFace = cat.getFace();
        assertNotNull(CatFace);
        assertEquals(30, CatFace.getRadius());
      }
      else if (Figure instanceof House) {
        house = (House) Figure;
        assertEquals("houseId", house.getId());
        Rectangle HouseBase = house.getBase();
        assertNotNull(HouseBase);
        assertEquals(76, HouseBase.getWidth());
      }
      else {
        fail("Unknown figure: " + Figure);
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.