Skip to content

Commit

Permalink
Fixed timezone bug in booking API
Browse files Browse the repository at this point in the history
  • Loading branch information
mwinteringham committed Oct 3, 2018
1 parent fb82963 commit 71eaa4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 8 additions & 0 deletions booking/src/main/java/api/BookingApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import javax.annotation.PostConstruct;
import java.util.TimeZone;

@SpringBootApplication
@ComponentScan()
public class BookingApplication {

@PostConstruct
void started() {
TimeZone.setDefault(TimeZone.getTimeZone("Etc/UTC"));
}

public static void main(String[] args) {
SpringApplication.run(BookingApplication.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Date;
import java.util.GregorianCalendar;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
Expand Down Expand Up @@ -55,14 +56,19 @@ public void testCreateBooking(){
// exists but it won't process whether it is valid or not.
String token = "abc123";

// We want to create a couple of date objects that we are going to us in our bookingPayload
// and then again in the assertion to make sure they were processed correctly.
Date checkindate = new GregorianCalendar(2018,1,1).getTime();
Date checkoutdate = new GregorianCalendar(2018,1,2).getTime();

// We next create our booking payload to send to the Booking webservice
Booking bookingPayload = new Booking.BookingBuilder()
.setFirstname("Mark")
.setLastname("Winteringham")
.setTotalprice(200)
.setDepositpaid(true)
.setCheckin(new GregorianCalendar(2018,1,1).getTime())
.setCheckout(new GregorianCalendar(2018,1,2).getTime())
.setCheckin(checkindate)
.setCheckout(checkoutdate)
.build();

// We then send our request to the Booking webservice to create our booking
Expand All @@ -81,8 +87,8 @@ public void testCreateBooking(){
assertThat(response.getBooking().getLastname(), is("Winteringham"));
assertThat(response.getBooking().getTotalprice(), is(200));
assertThat(response.getBooking().isDepositpaid(), is(true));
assertThat(response.getBooking().getBookingDates().getCheckin().toString(), containsString("Thu Feb 01"));
assertThat(response.getBooking().getBookingDates().getCheckout().toString(), containsString("Fri Feb 02"));
assertThat(response.getBooking().getBookingDates().getCheckin(), is(checkindate));
assertThat(response.getBooking().getBookingDates().getCheckout(), is(checkoutdate));
}


Expand Down

0 comments on commit 71eaa4b

Please sign in to comment.