Software Testing Program 2
Software Testing Program 2
9. Glossary
Event: An occurrence such as a movie, concert, or travel schedule for which tickets can
be booked.
Booking: The process of reserving a seat for an event.
Payment Gateway: A service that processes credit card payments for online and offline
businesses.
10. Appendices
This SRS document provides a detailed outline of the requirements for an Online Ticket Booking
System, ensuring that all stakeholders have a clear understanding of the system functionalities
and constraints.
Program: User.java
// Constructor
public User(String email, String password) {
this.email = email;
this.password = password;
}
// Getters
public String getEmail() {
return email;
}
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
@Before
public void setUp() {
userService = new UserService();
}
@Test
public void testRegisterUser() {
assertTrue(userService.registerUser("[email protected]", "password123"));
assertFalse(userService.registerUser("[email protected]", "password123")); //
Duplicate registration
assertFalse(userService.registerUser("", "password123")); // Invalid email
assertFalse(userService.registerUser("[email protected]", "")); // Invalid password
}
@Test
public void testAuthenticateUser() {
userService.registerUser("[email protected]", "password123");
assertTrue(userService.authenticateUser("[email protected]", "password123"));
assertFalse(userService.authenticateUser("[email protected]", "wrongpassword"));
assertFalse(userService.authenticateUser("[email protected]", "password123"));
}
}
2. Event Management
Program: Event.java
// Constructor
public Event(String title, String date, String location, int availableSeats) {
this.title = title;
this.date = date;
this.location = location;
this.availableSeats = availableSeats;
}
import java.util.HashMap;
import java.util.Map;
public boolean addEvent(String title, String date, String location, int availableSeats) {
if (title == null || title.isEmpty() || date == null || date.isEmpty() || location == null ||
location.isEmpty() || availableSeats <= 0) {
return false;
}
events.put(title, new Event(title, date, location, availableSeats));
return true;
}
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
@Before
public void setUp() {
eventService = new EventService();
}
@Test
public void testAddEvent() {
assertTrue(eventService.addEvent("Concert", "2024-08-20", "Stadium", 100));
assertFalse(eventService.addEvent("Concert", "2024-08-20", "Stadium", 100)); //
Duplicate event
assertFalse(eventService.addEvent("", "2024-08-20", "Stadium", 100)); // Invalid title
assertFalse(eventService.addEvent("Concert", "", "Stadium", 100)); // Invalid date
assertFalse(eventService.addEvent("Concert", "2024-08-20", "", 100)); // Invalid location
assertFalse(eventService.addEvent("Concert", "2024-08-20", "Stadium", -10)); // Invalid
seats
}
@Test
public void testGetEvent() {
eventService.addEvent("Concert", "2024-08-20", "Stadium", 100);
Event event = eventService.getEvent("Concert");
assertNotNull(event);
assertEquals("Concert", event.getTitle());
assertEquals("2024-08-20", event.getDate());
assertEquals("Stadium", event.getLocation());
assertEquals(100, event.getAvailableSeats());
}
@Test
public void testUpdateEventSeats() {
eventService.addEvent("Concert", "2024-08-20", "Stadium", 100);
assertTrue(eventService.updateEventSeats("Concert", 90));
assertFalse(eventService.updateEventSeats("Concert", -10)); // Invalid seats
assertFalse(eventService.updateEventSeats("Unknown Event", 50)); // Non-existent
event
}
}
3. Ticket Booking and Seat Selection
Program: Booking.java
// Constructor
public Booking(String eventTitle, String userEmail, int seats) {
this.eventTitle = eventTitle;
this.userEmail = userEmail;
this.seats = seats;
}
// Getters
public String getEventTitle() {
return eventTitle;
}
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
@Before
public void setUp() {
eventService = new EventService();
bookingService = new BookingService(eventService);
eventService.addEvent("Concert", "2024-08-20", "Stadium", 100);
}
@Test
public void testBookTicket() {
assertTrue(bookingService.bookTicket("Concert", "[email protected]", 5));
assertFalse(bookingService.bookTicket("Concert", "[email protected]", 0)); // Invalid
seats
assertFalse(bookingService.bookTicket("Concert", "[email protected]", 200)); // Not
enough seats
assertFalse(bookingService.bookTicket("Unknown Event", "[email protected]", 5)); //
Non-existent event
}
@Test
public void testGetBookings() {
bookingService.bookTicket("Concert", "[email protected]", 5);
bookingService.bookTicket("Concert", "[email protected]", 10);
assertEquals(2, bookingService.getBookings().size());
}
}
4. Payment Processing
For payment processing, we can mock the payment gateway interactions to test our code without
actually making real payments.
Program: PaymentService.java
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
@Before
public void setUp() {
paymentService = new PaymentService();
}
@Test
public void testProcessPayment() {
assertTrue(paymentService.processPayment("[email protected]", 100.00));
assertFalse(paymentService.processPayment("", 100.00)); // Invalid email
assertFalse(paymentService.processPayment("[email protected]", -50.00)); // Invalid
amount
assertFalse(paymentService.processPayment(null, 100.00)); // Null email
}
}
Running the Tests
To run the tests, you can use any IDE that supports JUnit (such as Eclipse or IntelliJ IDEA) or
run them using the command line with Maven or Gradle.
These unit tests ensure that each individual component of the Online Ticket Booking System
behaves as expected. As your system evolves, you can expand these tests or add more complex
integration tests.