/**
* 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());
}