0

I'm seeing some strange behavior in a spock test for a service using Grails 2.3.7.

This test works fine:

void "create spot order"() {
    given:
    def createOrderCommand = newCreateOrderCommand(OrderType.S)

    when:
    def orderId = service.createOrder(createOrderCommand, user).id.toInteger()

    then:
    Order.count() == 1

    when:
    def order = service.orderById(orderId)

    then:
    // a bunch of assertions
}

This test also works fine:

void "create command with invalid order id"() {
    when:
    service.commandForOrderId(999)

    then:
    def exception = thrown(CreateOrderException)
    exception.key == "orderService.invalid.order.id"
}

However this test fails - I've set a breakpoint at the beginning commandForOrderId, and it is never hit. command is null (this is where the test fails, on the line checking for null on command), which would never be returned from this service method:

void "create spot command"() {
    given:
    def createOrderCommand = newCreateOrderCommand(OrderType.S)

    when:
    def order = service.createOrder(createOrderCommand, user)

    then: 
    Order.count() == 1

    when:
    def orderId = order.id.toInteger()
    def command = service.commandForOrderId(orderId)

    then:
    command
    // a bunch more assertions
}

I've tried removing the @Transactional annotation from the service, using the transactional static field, as well as using neither of these. I've also tried changing the service method to a closure, all with no luck.

  • go to `service.createOrder()` and see what's wrong there first, if you got any error please add them to the original message – roeygol Feb 20 '15 at 18:14
  • createOrder is creating the Order as expected. The first snippet I posted is meant to demonstrate this. I have debugged the test method to verify. Also, in the setup for the test, I have the following so as to not persist Order info in between tests: `def errors = [:] MockUtils.mockDomain(Order, errors, [])` – AlowishusDevedanderAbercrombie Feb 20 '15 at 18:21
  • run: `grails clean` or things like that and see what happens – roeygol Feb 20 '15 at 19:54
  • any news regarding my last comment ? – roeygol Feb 21 '15 at 15:59
  • 1
    Yes, I just added an answer below. I had to change the method to a closure and blow away my target directories, and then it started working. – AlowishusDevedanderAbercrombie Feb 21 '15 at 16:25

1 Answers1

1

I changed the service method to a closure, cleared my target directories, did every manner of clean I know of (within GGTS and grails commands), and the service method started getting hit in the test. I'm still unsure of the actual cause of this error, however.