use of org.mapstruct.ap.test.selection.jaxb.test1.OrderType in project mapstruct by mapstruct.
the class JaxbBasedMapperTest method shouldMapJaxb.
@Test
public void shouldMapJaxb() throws ParseException, JAXBException {
SourceTargetMapper mapper = SourceTargetMapper.INSTANCE;
OrderDto source1 = new OrderDto();
source1.setOrderDetails(new OrderDetailsDto());
source1.setOrderNumber(11L);
source1.setOrderDate(createDate("31-08-1982 10:20:56"));
source1.setShippingAddress(new ShippingAddressDto());
source1.getShippingAddress().setCity("SmallTown");
source1.getShippingAddress().setHouseNumber("11a");
source1.getShippingAddress().setStreet("Awesome rd");
source1.getShippingAddress().setCountry("USA");
source1.getOrderDetails().setDescription(new ArrayList<String>());
source1.getOrderDetails().setName("Shopping list for a Mapper");
source1.getOrderDetails().getDescription().add("1 MapStruct");
source1.getOrderDetails().getDescription().add("3 Lines of Code");
source1.getOrderDetails().getDescription().add("1 Dose of Luck");
source1.getOrderDetails().setStatus(OrderStatusDto.ORDERED);
// map to JAXB
OrderType target = mapper.targetToSource(source1);
// do a pretty print
ObjectFactory of = new ObjectFactory();
System.out.println(toXml(of.createOrder(target)));
// map back from JAXB
OrderDto source2 = mapper.sourceToTarget(target);
// verify that source1 and source 2 are equal
assertThat(source2.getOrderNumber()).isEqualTo(source1.getOrderNumber());
assertThat(source2.getOrderDate()).isEqualTo(source1.getOrderDate());
assertThat(source2.getOrderDetails().getDescription().size()).isEqualTo(source1.getOrderDetails().getDescription().size());
assertThat(source2.getOrderDetails().getDescription().get(0)).isEqualTo(source1.getOrderDetails().getDescription().get(0));
assertThat(source2.getOrderDetails().getDescription().get(1)).isEqualTo(source1.getOrderDetails().getDescription().get(1));
assertThat(source2.getOrderDetails().getDescription().get(2)).isEqualTo(source1.getOrderDetails().getDescription().get(2));
assertThat(source2.getOrderDetails().getName()).isEqualTo(source1.getOrderDetails().getName());
assertThat(source2.getOrderDetails().getStatus()).isEqualTo(source1.getOrderDetails().getStatus());
}
use of org.mapstruct.ap.test.selection.jaxb.test1.OrderType in project mapstruct by mapstruct.
the class JaxbFactoryMethodSelectionTest method shouldMatchOnNameAndOrScope.
@Test
public void shouldMatchOnNameAndOrScope() {
OrderType target = OrderMapper.INSTANCE.targetToSource(createSource());
// qname and value should match for orderNumbers (distinct 1, 2)
assertThat(target.getOrderNumber1().getValue()).isEqualTo(15L);
assertThat(target.getOrderNumber1().getName()).isEqualTo(org.mapstruct.ap.test.selection.jaxb.test1.ObjectFactory.ORDER_TYPE_ORDER_NUMBER1_QNAME);
assertThat(target.getOrderNumber2().getValue()).isEqualTo(31L);
assertThat(target.getOrderNumber2().getName()).isEqualTo(org.mapstruct.ap.test.selection.jaxb.test1.ObjectFactory.ORDER_TYPE_ORDER_NUMBER2_QNAME);
// qname should match for shipping details
assertThat(target.getShippingDetails().getName()).isEqualTo(org.mapstruct.ap.test.selection.jaxb.test1.ObjectFactory.ORDER_TYPE_SHIPPING_DETAILS_QNAME);
OrderShippingDetailsType shippingDetails = target.getShippingDetails().getValue();
// qname and value should match (ObjectFactory = test2.ObjectFactory)
assertThat(shippingDetails.getOrderShippedFrom().getValue()).isEqualTo("from");
assertThat(shippingDetails.getOrderShippedFrom().getName()).isEqualTo(ObjectFactory.ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_FROM_QNAME);
assertThat(shippingDetails.getOrderShippedTo().getValue()).isEqualTo("to");
assertThat(shippingDetails.getOrderShippedTo().getName()).isEqualTo(ObjectFactory.ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_TO_QNAME);
}
Aggregations