-
Notifications
You must be signed in to change notification settings - Fork 0
/
AirportIntegrationSpec.groovy
71 lines (52 loc) · 2.15 KB
/
AirportIntegrationSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.softwood.domain.gorm
import grails.testing.mixin.integration.Integration
import grails.transaction.*
import spock.lang.Specification
@Integration
@Rollback
class AirportIntegrationSpec extends Specification {
def setup() {
Airport manchester = new UkAirport (name:"Manchester", shortCode:"MAN")
manchester.save(failOnError:true)
}
def cleanup() {
}
void "two airports and one flight "() {
given :
Airport gatwick = new UkAirport (name:"Gatwick", shortCode:"LGW")
Airport stansted = new UkAirport (name:"Stansted", shortCode:"STN")
Airport manchester = UkAirport.get(1L)
assert manchester.shortCode == "MAN"
gatwick.save ()
stansted.save ()
when:
Flight flight = new Flight<UkAirport>(flightCode:"F123-LGW-STN")
gatwick.addToOutboundFlights(flight)
stansted.addToInboundFlights(flight)
flight.save (failOnError:true)
assert gatwick.outboundFlights.size() == 1
assert gatwick.inboundFlights.size() == 0
assert stansted.outboundFlights.size() == 0
assert stansted.inboundFlights.size() == 1
// -all ok until we get to here - if you evaluate manchester before you use it - test works
//if you comment out and use before you evaluate it fails !
assert manchester.inboundFlights.size() == 0 //comment out makes test fail !
Flight flight2 = new Flight<UkAirport>(flightCode:"F789-LGW-MAN")
gatwick.addToOutboundFlights(flight2)
manchester.addToInboundFlights(flight2)
flight2.save (failOnError:true)
assert gatwick.outboundFlights.size() == 2
assert manchester.inboundFlights.size() == 1
then :""
flight.id == 1
flight2.id == 2
gatwick.inboundFlights.size() == 0
gatwick.outboundFlights.size() == 2
stansted.outboundFlights.size() == 0
stansted.inboundFlights.size() == 1
flight.departureAirport.name == "Gatwick"
flight.arrivalAirport.name == "Stansted"
flight2.departureAirport.name == "Gatwick"
flight2.arrivalAirport.name == "Manchester"
}
}