Vita Rara: A Life Uncommon

Groovy GPath: That WOW Moment


Categories: |

I'm writing a lot of integration tests for Quadran. I just wrote one where I needed to traverse a a complicated series of relationships, including collective relationships, through my domain model to test that a collection was initialized by Hibernate JPA. Here's the code:

void testFindForViewPoAssociationsAreFetched () {
    def dao = SpringContextTestFactory.getJpaContext().getBean ("orderDao");
    def order = dao.findForViewPo ("4371665");
    assertTrue ("TransportOrders were not fetched", 
                order.orderLineItems.orderShipments.shipmentLineItem.shipment.transportOrders.size > 0);
}

Notice the Groovy Path statement in the assertTrue method call. That would be a lot longer in Java to do the same thing. At least two iterators, and a whole lot of getThis, getThat ugliness.

I wrote that one and just said a big mental, "WOW!"

Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
  • Allowed HTML tags: <a> <img> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <h1> <h2> <h3>
  • Lines and paragraphs break automatically.
More information about formatting options