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!"