2bittester/rbp-data-set huggingface dataset:
Question: How does the method getBookingDates work for BookingSummary?
Answer:
public BookingDates getBookingDates()
{
    return bookingDates;
}
Question: How does the method setBookingDates work for BookingSummary?
Answer:
public void setBookingDates(BookingDates bookingDates)
{
    this.bookingDates = bookingDates;
}
Question: What package does BookingDates belong to
Answer:
package com.automationintesting.model.db;
Question: What is the class declaration for BookingDates
Answer:
@Entity
public class BookingDates {

}
Question: List variables declared in BookingDates
Answer:
@JsonProperty
@NotNull
private LocalDate checkin;
Question: List variables declared in BookingDates
Answer:
@JsonProperty
@NotNull
private LocalDate checkout;
Question: How does the method getCheckin work for BookingDates?
Answer:
public LocalDate getCheckin()
{
    return checkin;
}
Question: How does the method setCheckin work for BookingDates?
Answer:
public void setCheckin(LocalDate checkin)
{
    this.checkin = checkin;
}
Question: How does the method getCheckout work for BookingDates?
Answer:
public LocalDate getCheckout()
{
    return checkout;
}
Question: How does the method setCheckout work for BookingDates?
Answer:
public void setCheckout(LocalDate checkout)
{
    this.checkout = checkout;
}
Question: How does the method toString work for BookingDates?
Answer:
@Override
public String toString()
{
    return "BookingDates{" + "checkin=" + checkin.toString() + ", checkout=" + checkout.toString() + '}';
}
Question: What package does Bookings belong to
Answer:
package com.automationintesting.model.db;
Question: What is the class declaration for Bookings
Answer:
public class Bookings {

}
Question: List variables declared in Bookings
Answer:
@JsonProperty
private List<Booking> bookings;
Question: How does the method getBookings work for Bookings?
Answer:
public List<Booking> getBookings()
{
    return bookings;
}
Question: How does the method setBookings work for Bookings?
Answer:
public void setBookings(List<Booking> bookings)
{
    this.bookings = bookings;
}
Question: What package does Token belong to
Answer:
package com.automationintesting.model.db;
Question: What package does BookingSummaries belong to
Answer:
package com.automationintesting.model.db;
Question: What is the class declaration for BookingSummaries
Answer:
public class BookingSummaries {

}
Question: List variables declared in BookingSummaries
Answer:
@JsonProperty
private List<BookingSummary> bookings;
Question: How does the method getBookings work for BookingSummaries?
Answer:
public List<BookingSummary> getBookings()
{
    return bookings;
}
Question: How does the method setBookings work for BookingSummaries?
Answer:
public void setBookings(List<BookingSummary> bookings)
{
    this.bookings = bookings;
}
Question: What package does BookingResult belong to
Answer:
package com.automationintesting.model.service;
Question: What is the class declaration for BookingResult
Answer:
public class BookingResult {

}
Question: List variables declared in BookingResult
Answer:
private Booking booking;
Question: List variables declared in BookingResult
Answer:
private CreatedBooking createdBooking;
Question: List variables declared in BookingResult
Answer:
private Bookings bookings;
Question: List variables declared in BookingResult
Answer:
private HttpStatus result;
Question: How does the method getStatus work for BookingResult?
Answer:
public HttpStatus getStatus()
{
    return result;
}
Question: How does the method getBooking work for BookingResult?
Answer:
public Booking getBooking()
{
    return booking;
}
Question: How does the method getCreatedBooking work for BookingResult?
Answer:
public CreatedBooking getCreatedBooking()
{
    return createdBooking;
}
Question: How does the method getBookings work for BookingResult?
Answer:
public Bookings getBookings()
{
    return bookings;
}
Question: What package does BookingDB belong to
Answer:
package com.automationintesting.db;
Question: What is the class declaration for BookingDB
Answer:
@Component
public class BookingDB {

}
Question: List variables declared in BookingDB
Answer:
private Connection connection;
Question: What is the variable logger assigned to in BookingDB?
Answer:
private Logger logger = LoggerFactory.getLogger(BookingDB.class);
Question: What is the variable SELECT_BY_BOOKINGID assigned to in BookingDB?
Answer:
private String SELECT_BY_BOOKINGID = "SELECT * FROM BOOKINGS WHERE bookingid=?";
Question: What is the variable DELETE_BY_ID assigned to in BookingDB?
Answer:
private String DELETE_BY_ID = "DELETE FROM BOOKINGS WHERE bookingid = ?";
Question: What is the variable SELECT_DATE_CONFLICTS assigned to in BookingDB?
Answer:
private String SELECT_DATE_CONFLICTS = "SELECT * FROM BOOKINGS WHERE ((checkin BETWEEN ? AND ?) OR (checkout BETWEEN ? AND ?) OR (checkin <= ? AND checkout >= ?)) AND (roomid = ?)";
Question: What is the variable DELETE_ALL_BOOKINGS assigned to in BookingDB?
Answer:
private String DELETE_ALL_BOOKINGS = "DELETE FROM BOOKINGS";
Question: What is the variable RESET_INCREMENT assigned to in BookingDB?
Answer:
private String RESET_INCREMENT = "ALTER TABLE BOOKINGS ALTER COLUMN bookingid RESTART WITH 1";
Question: How does the method create work for BookingDB?
Answer:
public CreatedBooking create(Booking booking) throws SQLException
{
    InsertSql insertSql = new InsertSql(connection, booking);
    PreparedStatement createPs = insertSql.getPreparedStatement();
    if (createPs.executeUpdate() > 0) {
        ResultSet lastInsertId = connection.prepareStatement("SELECT LAST_INSERT_ID()").executeQuery();
        lastInsertId.next();
        PreparedStatement ps = connection.prepareStatement(SELECT_BY_BOOKINGID);
        ps.setInt(1, lastInsertId.getInt("LAST_INSERT_ID()"));
        ResultSet result = ps.executeQuery();
        result.next();
        Booking createdBooking = new Booking(result);
        return new CreatedBooking(result.getInt("bookingid"), createdBooking);
    } else {
        return null;
    }
}
Question: How does the method queryBookingsById work for BookingDB?
Answer:
public List<Booking> queryBookingsById(String roomid) throws SQLException
{
    List<Booking> listToReturn = new ArrayList<Booking>();
    String sql = "SELECT * FROM BOOKINGS WHERE roomid = " + roomid;
    ResultSet results = connection.prepareStatement(sql).executeQuery();
    while (results.next()) {
        listToReturn.add(new Booking(results));
    }
    return listToReturn;
}
Question: How does the method query work for BookingDB?
Answer:
public Booking query(int id) throws SQLException
{
    PreparedStatement ps = connection.prepareStatement(SELECT_BY_BOOKINGID);
    ps.setInt(1, id);
    ResultSet result = ps.executeQuery();
    result.next();
    return new Booking(result);
}
Question: How does the method delete work for BookingDB?
Answer:
public Boolean delete(int bookingid) throws SQLException
{
    PreparedStatement ps = connection.prepareStatement(DELETE_BY_ID);
    ps.setInt(1, bookingid);
    int resultSet = ps.executeUpdate();
    return resultSet == 1;
}
Question: How does the method update work for BookingDB?
Answer:
public CreatedBooking update(int id, Booking booking) throws SQLException
{
    UpdateSql updateSql = new UpdateSql(connection, id, booking);
    PreparedStatement updatePs = updateSql.getPreparedStatement();
    if (updatePs.executeUpdate() > 0) {
        PreparedStatement ps = connection.prepareStatement(SELECT_BY_BOOKINGID);
        ps.setInt(1, id);
        ResultSet result = ps.executeQuery();
        result.next();
        Booking createdBooking = new Booking(result);
        return new CreatedBooking(result.getInt("bookingid"), createdBooking);
    } else {
        return null;
    }
}
Question: How does the method resetDB work for BookingDB?
Answer:
public void resetDB() throws SQLException, IOException
{
    PreparedStatement ps = connection.prepareStatement(DELETE_ALL_BOOKINGS);
    ps.executeUpdate();
    PreparedStatement ps2 = connection.prepareStatement(RESET_INCREMENT);
    ps2.executeUpdate();
    executeSqlFile("seed.sql");
}
Question: How does the method checkForBookingConflict work for BookingDB?
Answer:
public Boolean checkForBookingConflict(Booking bookingToCheck) throws SQLException
{
    PreparedStatement ps = connection.prepareStatement(SELECT_DATE_CONFLICTS);
    Calendar parseCheckinDate = Calendar.getInstance();
    parseCheckinDate.setTime(Date.valueOf(bookingToCheck.getBookingDates().getCheckin()));
    parseCheckinDate.add(Calendar.DATE, 1);
    for (int i = 1; i <= 6; i++) {
        if (i % 2 == 0) {
            ps.setDate(i, new Date(Date.valueOf(bookingToCheck.getBookingDates().getCheckout()).getTime()));
        } else {
            ps.setDate(i, new Date(parseCheckinDate.getTimeInMillis()));
        }
    }
    ps.setInt(7, bookingToCheck.getRoomid());
    ResultSet result = ps.executeQuery();
    List<Integer> bookingIds = new ArrayList<>();
    while (result.next()) {
        bookingIds.add(result.getInt("bookingid"));
    }
    if (bookingIds.size() == 0) {
        return false;
    } else if (bookingIds.size() == 1) {
        return bookingIds.get(0) != bookingToCheck.getBookingid();
    } else {
        return true;
    }
}
Question: How does the method queryAllBookings work for BookingDB?
Answer:
public List<Booking> queryAllBookings() throws SQLException
{
    List<Booking> listToReturn = new ArrayList<Booking>();
    String sql = "SELECT * FROM PUBLIC.BOOKINGS";
    ResultSet results = connection.prepareStatement(sql).executeQuery();
    while (results.next()) {
        listToReturn.add(new Booking(results));
    }
    return listToReturn;
}
Question: How does the method queryBookingSummariesById work for BookingDB?
Answer:
public List<BookingSummary> queryBookingSummariesById(String roomid) throws SQLException
{
    List<BookingSummary> listToReturn = new ArrayList<BookingSummary>();
    String sql = "SELECT * FROM BOOKINGS WHERE roomid = " + roomid;
    ResultSet results = connection.prepareStatement(sql).executeQuery();
    while (results.next()) {
        listToReturn.add(new BookingSummary(results));
    }
    return listToReturn;
}
Question: How does the method executeSqlFile work for BookingDB?
Answer:
private void executeSqlFile(String filename) throws IOException, SQLException
{
    Reader reader = new InputStreamReader(new ClassPathResource(filename).getInputStream());
    Scanner sc = new Scanner(reader);
    StringBuffer sb = new StringBuffer();
    while (sc.hasNext()) {
        sb.append(sc.nextLine());
    }
    connection.prepareStatement(sb.toString()).executeUpdate();
}
Question: What package does BookingApplication belong to
Answer:
package com.automationintesting.api;
Question: What is the class declaration for BookingApplication
Answer:
@SpringBootApplication
@ComponentScan
public class BookingApplication {

}
Question: How does the method main work for BookingApplication?
Answer:
public static void main(String[] args)
{
    TimeZone.setDefault(TimeZone.getTimeZone("Etc/UTC"));
    SpringApplication.run(BookingApplication.class, args);
}
Question: How does the method openAPI work for SwaggerConfig?
Answer:
@Bean
public OpenAPI openAPI()
{
    return new OpenAPI().addServersItem(new Server().url("/booking/"));
}
Question: How does the method publicApi work for SwaggerConfig?
Answer:
@Bean
public GroupedOpenApi publicApi()
{
    return GroupedOpenApi.builder().group("booking-api").pathsToMatch("/**").build();
}
Question: What package does BookingController belong to
Answer:
package com.automationintesting.api;
Question: What is the class declaration for BookingController
Answer:
@RestController
public class BookingController {

}
Question: List variables declared in BookingController
Answer:
@Autowired
private BookingService bookingService;
Question: How does the method getBookings work for BookingController?
Answer:
@RequestMapping
public ResponseEntity getBookings(@RequestParam("roomid") Optional<String> roomid, @CookieValue(value = "token", required = false) String token) throws SQLException
{
    BookingResult bookingResult = bookingService.getBookings(roomid, token);
    return ResponseEntity.status(bookingResult.getStatus()).body(bookingResult.getBookings());
}
Question: How does the method createBooking work for BookingController?
Answer:
@RequestMapping
public ResponseEntity createBooking(@Valid @RequestBody Booking booking) throws SQLException
{
    BookingResult bookingResult = bookingService.createBooking(booking);
    return ResponseEntity.status(bookingResult.getStatus()).body(bookingResult.getCreatedBooking());
}
Question: How does the method getBooking work for BookingController?
Answer:
@RequestMapping
public ResponseEntity getBooking(@PathVariable(value = "id") int bookingId, @CookieValue(value = "token", required = false) String token) throws SQLException
{
    BookingResult bookingResult = bookingService.getIndividualBooking(bookingId, token);
    return ResponseEntity.status(bookingResult.getStatus()).body(bookingResult.getBooking());
}
Question: How does the method deleteBooking work for BookingController?
Answer:
@RequestMapping
public ResponseEntity deleteBooking(@PathVariable(value = "id") int id, @CookieValue(value = "token", required = false) String token) throws SQLException
{
    HttpStatus deleteHttpStatus = bookingService.deleteBooking(id, token);
    return ResponseEntity.status(deleteHttpStatus).build();
}
Question: How does the method updateBooking work for BookingController?
Answer:
@RequestMapping
public ResponseEntity<CreatedBooking> updateBooking(@Valid @RequestBody Booking booking, @PathVariable(value = "id") int id, @CookieValue(value = "token", required = false) String token) throws SQLException
{
    BookingResult updateResult = bookingService.updateBooking(id, booking, token);
    return ResponseEntity.status(updateResult.getStatus()).body(updateResult.getCreatedBooking());
}
Question: How does the method getSummaries work for BookingController?
Answer:
@RequestMapping
public ResponseEntity getSummaries(@RequestParam("roomid") String roomid) throws SQLException
{
    BookingSummaries bookingSummaries = bookingService.getBookingSummaries(roomid);
    return ResponseEntity.status(HttpStatus.OK).body(bookingSummaries);
}
Question: What package does BookingService belong to
Answer:
package com.automationintesting.service;
Question: What is the class declaration for BookingService
Answer:
@Service
public class BookingService {

}
Question: List variables declared in BookingService
Answer:
@Autowired
private BookingDB bookingDB;
Question: List variables declared in BookingService
Answer:
private AuthRequests authRequests;
Question: List variables declared in BookingService
Answer:
private DateCheckValidator dateCheckValidator;
Question: List variables declared in BookingService
Answer:
private MessageRequests messageRequests;
Question: How does the method beginDbScheduler work for BookingService?
Answer:
@EventListener
public void beginDbScheduler()
{
    DatabaseScheduler databaseScheduler = new DatabaseScheduler();
    databaseScheduler.startScheduler(bookingDB, TimeUnit.MINUTES);
}
Question: How does the method getBookings work for BookingService?
Answer:
public BookingResult getBookings(Optional<String> roomId, String token) throws SQLException
{
    if (authRequests.postCheckAuth(token)) {
        List<Booking> bookingList;
        if (roomId.isPresent()) {
            bookingList = bookingDB.queryBookingsById(roomId.get());
        } else {
            bookingList = bookingDB.queryAllBookings();
        }
        return new BookingResult(new Bookings(bookingList), HttpStatus.OK);
    } else {
        return new BookingResult(HttpStatus.FORBIDDEN);
    }
}
Question: How does the method getIndividualBooking work for BookingService?
Answer:
public BookingResult getIndividualBooking(int bookingId, String token) throws SQLException
{
    if (authRequests.postCheckAuth(token)) {
        try {
            Booking booking = bookingDB.query(bookingId);
            return new BookingResult(booking, HttpStatus.OK);
        } catch (JdbcSQLNonTransientException e) {
            return new BookingResult(HttpStatus.NOT_FOUND);
        }
    } else {
        return new BookingResult(HttpStatus.FORBIDDEN);
    }
}
Question: How does the method deleteBooking work for BookingService?
Answer:
public HttpStatus deleteBooking(int bookingid, String token) throws SQLException
{
    if (authRequests.postCheckAuth(token)) {
        if (bookingDB.delete(bookingid)) {
            return HttpStatus.ACCEPTED;
        } else {
            return HttpStatus.NOT_FOUND;
        }
    } else {
        return HttpStatus.FORBIDDEN;
    }
}
Question: How does the method updateBooking work for BookingService?
Answer:
public BookingResult updateBooking(int bookingId, Booking bookingToUpdate, String token) throws SQLException
{
    if (authRequests.postCheckAuth(token)) {
        if (dateCheckValidator.isValid(bookingToUpdate.getBookingDates())) {
            if (bookingDB.checkForBookingConflict(bookingToUpdate)) {
                return new BookingResult(HttpStatus.CONFLICT);
            } else {
                CreatedBooking updatedBooking = bookingDB.update(bookingId, bookingToUpdate);
                if (updatedBooking != null) {
                    return new BookingResult(updatedBooking, HttpStatus.OK);
                } else {
                    return new BookingResult(HttpStatus.NOT_FOUND);
                }
            }
        } else {
            return new BookingResult(HttpStatus.CONFLICT);
        }
    } else {
        return new BookingResult(HttpStatus.FORBIDDEN);
    }
}
Question: How does the method createBooking work for BookingService?
Answer:
public BookingResult createBooking(Booking bookingToCreate) throws SQLException
{
    if (dateCheckValidator.isValid(bookingToCreate.getBookingDates())) {
        if (bookingDB.checkForBookingConflict(bookingToCreate)) {
            return new BookingResult(HttpStatus.CONFLICT);
        } else {
            CreatedBooking createdBooking = bookingDB.create(bookingToCreate);
            if (bookingToCreate.getEmail() != null && bookingToCreate.getPhone() != null) {
                MessageBuilder messageBuilder = new MessageBuilder();
                Message message = messageBuilder.build(bookingToCreate);
                messageRequests.postMessage(message);
            }
            return new BookingResult(createdBooking, HttpStatus.CREATED);
        }
    } else {
        return new BookingResult(HttpStatus.CONFLICT);
    }
}
Question: How does the method getBookingSummaries work for BookingService?
Answer:
public BookingSummaries getBookingSummaries(String roomId) throws SQLException
{
    List<BookingSummary> bookingList;
    bookingList = bookingDB.queryBookingSummariesById(roomId);
    return new BookingSummaries(bookingList);
}
Question: What package does MessageBuilder belong to
Answer:
package com.automationintesting.service;
Question: What is the class declaration for MessageBuilder
Answer:
public class MessageBuilder {

}
Question: How does the method build work for MessageBuilder?
Answer:
public Message build(Booking booking)
{
    String name = booking.getFirstname() + " " + booking.getLastname();
    String description = "You have a new booking from " + name + ". They have booked a room for the following dates: " + booking.getBookingDates().getCheckin().toString() + " to " + booking.getBookingDates().getCheckout().toString();
    String email = booking.getEmail().get();
    String phone = booking.getPhone().get();
    return new Message(name, email, phone, "You have a new booking!", description);
}
Question: What package does DateCheckValidator belong to
Answer:
package com.automationintesting.service;
Question: What is the class declaration for DateCheckValidator
Answer:
public class DateCheckValidator {

}
Question: How does the method isValid work for DateCheckValidator?
Answer:
public boolean isValid(BookingDates dateBooking)
{
    final LocalDate checkin = dateBooking.getCheckin();
    final LocalDate checkout = dateBooking.getCheckout();
    if (checkin == null || checkout == null) {
        return false;
    }
    return checkin.compareTo(checkout) < 0;
}
Question: How does the method startScheduler work for DatabaseScheduler?
Answer:
public void startScheduler(BookingDB bookingDB, TimeUnit timeUnit)
{
    if (resetCount > 0) {
        ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
        Runnable r = () -> {
            if (!stop) {
                try {
                    logger.info("Resetting database");
                    bookingDB.resetDB();
                } catch (Exception e) {
                    logger.error("Scheduler failed " + e.getMessage());
                }
            }
        };
        executor.scheduleAtFixedRate(r, 0L, resetCount, timeUnit);
    } else {
        logger.info("No env var was set for DB refresh (or set as 0) so not running DB reset");
    }
}
Question: List variables declared in BaseTest
Answer:
protected MessageDB messageDB;
Question: How does the method createMessageDb work for BaseTest?
Answer:
@BeforeAll
public static void createMessageDb() throws SQLException, IOException
{
    if (!dbOpen) {
        messageDB = new MessageDB();
        dbOpen = true;
    }
    messageDB.resetDB();
}
Question: What package does MessageDBTest belong to
Answer:
package com.automationintesting.unit.db;
Question: What is the class declaration for MessageDBTest
Answer:
public class MessageDBTest {

}
Question: List variables declared in MessageDBTest
Answer:
private int currentMessageId;
Question: How does the method resetDB work for MessageDBTest?
Answer:
@BeforeEach
public void resetDB() throws SQLException, IOException
{
    messageDB.resetDB();
    Message message = new Message("James", "james@dean.com", "01821 123321", "Just getting a message setup", "Lorem ipsum dolores est");
    Message createdMessage = messageDB.create(message);
    currentMessageId = createdMessage.getMessageid();
}
Question: How does the method testQueryMessage work for MessageDBTest?
Answer:
@Test
public void testQueryMessage() throws SQLException
{
    Message queriedMessage = messageDB.query(currentMessageId);
    String queriedMessageString = queriedMessage.toString();
    assertEquals("Message{messageid=" + currentMessageId + ", name='James', email='james@dean.com', phone='01821 123321', subject='Just getting a message setup', description='Lorem ipsum dolores est'}", queriedMessageString);
}
Question: How does the method testCreateMessage work for MessageDBTest?
Answer:
@Test
public void testCreateMessage() throws SQLException
{
    Message message = new Message("Mark", "mark@mwtestconsultancy.co.uk", "01821 912812", "A subject you may be interested in", "In posuere accumsan aliquet.");
    Message createdMessage = messageDB.create(message);
    String createdMessageString = createdMessage.toString();
    assertEquals("Message{messageid=" + (currentMessageId + 1) + ", name='Mark', email='mark@mwtestconsultancy.co.uk', phone='01821 912812', subject='A subject you may be interested in', description='In posuere accumsan aliquet.'}", createdMessageString);
}
Question: How does the method testDeleteMessage work for MessageDBTest?
Answer:
@Test
public void testDeleteMessage() throws SQLException
{
    boolean isDeleted = messageDB.delete(currentMessageId);
    assertThat(isDeleted, is(true));
}
Question: How does the method testGetMessages work for MessageDBTest?
Answer:
@Test
public void testGetMessages() throws SQLException
{
    Message message = new Message("Mark", "mark@mwtestconsultancy.co.uk", "01821 912812", "A subject you may be interested in", "In posuere accumsan aliquet.");
    messageDB.create(message);
    List<MessageSummary> messageSummaries = messageDB.queryMessages();
    Approvals.verify(messageSummaries.toString());
}
Question: How does the method testReadCount work for MessageDBTest?
Answer:
@Test
public void testReadCount() throws SQLException
{
    int currentMessageCount = messageDB.getUnreadCount();
    assertThat(currentMessageCount, is(2));
}