#1321 Added Tests
This commit is contained in:
@ -1,43 +1,43 @@
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2019 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.ashishtrivedi16.transactionscript.db;
|
||||
|
||||
/**
|
||||
* Custom exception.
|
||||
*/
|
||||
public class CustomException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CustomException() {
|
||||
}
|
||||
|
||||
public CustomException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CustomException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2019 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.ashishtrivedi16.transactionscript;
|
||||
|
||||
/**
|
||||
* Custom exception.
|
||||
*/
|
||||
public class CustomException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CustomException() {
|
||||
}
|
||||
|
||||
public CustomException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CustomException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.ashishtrivedi16.transactionscript;
|
||||
|
||||
import com.ashishtrivedi16.transactionscript.db.HotelDaoImpl;
|
||||
import java.util.Optional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -25,10 +24,10 @@ public class Hotel {
|
||||
Optional<Room> room = hotelDao.getById(roomNumber);
|
||||
|
||||
if (room.isEmpty()) {
|
||||
LOGGER.info(roomNumber + " does not exist");
|
||||
throw new Exception("Room number: " + roomNumber + " does not exist");
|
||||
} else {
|
||||
if (room.get().isBooked()) {
|
||||
LOGGER.info("Room already booked!");
|
||||
throw new Exception("Room already booked!");
|
||||
} else {
|
||||
Room updateRoomBooking = room.get();
|
||||
updateRoomBooking.setBooked(true);
|
||||
@ -48,7 +47,7 @@ public class Hotel {
|
||||
Optional<Room> room = hotelDao.getById(roomNumber);
|
||||
|
||||
if (room.isEmpty()) {
|
||||
LOGGER.info("Room number: " + roomNumber + " does not exist");
|
||||
throw new Exception("Room number: " + roomNumber + " does not exist");
|
||||
} else {
|
||||
if (room.get().isBooked()) {
|
||||
Room updateRoomBooking = room.get();
|
||||
@ -59,7 +58,7 @@ public class Hotel {
|
||||
LOGGER.info("Booking cancelled for room number: " + roomNumber);
|
||||
LOGGER.info(refundAmount + " is refunded");
|
||||
} else {
|
||||
LOGGER.info("No booking for the room exists");
|
||||
throw new Exception("No booking for the room exists");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
package com.ashishtrivedi16.transactionscript.db;
|
||||
|
||||
import com.ashishtrivedi16.transactionscript.Room;
|
||||
package com.ashishtrivedi16.transactionscript;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
@ -1,6 +1,5 @@
|
||||
package com.ashishtrivedi16.transactionscript.db;
|
||||
package com.ashishtrivedi16.transactionscript;
|
||||
|
||||
import com.ashishtrivedi16.transactionscript.Room;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -116,7 +115,7 @@ public class HotelDaoImpl implements HotelDao {
|
||||
@Override
|
||||
public Boolean delete(Room room) throws Exception {
|
||||
try (var connection = getConnection();
|
||||
var statement = connection.prepareStatement("DELETE FROM CUSTOMERS WHERE ID = ?")) {
|
||||
var statement = connection.prepareStatement("DELETE FROM ROOMS WHERE ID = ?")) {
|
||||
statement.setInt(1, room.getId());
|
||||
return statement.executeUpdate() > 0;
|
||||
} catch (SQLException ex) {
|
@ -21,7 +21,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.ashishtrivedi16.transactionscript.db;
|
||||
package com.ashishtrivedi16.transactionscript;
|
||||
|
||||
/**
|
||||
* Customer Schema SQL Class.
|
@ -1,8 +1,5 @@
|
||||
package com.ashishtrivedi16.transactionscript;
|
||||
|
||||
import com.ashishtrivedi16.transactionscript.db.CustomException;
|
||||
import com.ashishtrivedi16.transactionscript.db.HotelDaoImpl;
|
||||
import com.ashishtrivedi16.transactionscript.db.RoomSchemaSql;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import javax.sql.DataSource;
|
||||
@ -15,7 +12,6 @@ public class TransactionScriptApp {
|
||||
|
||||
private static final String H2_DB_URL = "jdbc:h2:~/test";
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TransactionScriptApp.class);
|
||||
private static final String ALL_ROOMS = "customerDao.getAllRooms(): ";
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
|
Reference in New Issue
Block a user