0% found this document useful (0 votes)
21 views

Software Testing Program 2

To generate a unit testing for online ticket booking system

Uploaded by

Vish P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Software Testing Program 2

To generate a unit testing for online ticket booking system

Uploaded by

Vish P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

7.

Use Case Diagrams

 Use Case Diagram for User:


o Register
o Login
o View Events
o Select Event
o Select Seats
o Make Payment
o Receive Confirmation
o Manage Bookings
 Use Case Diagram for Admin:
o Login
o Manage Users
o Manage Events
o View Reports
 Use Case Diagram for Event Organizer:
o Login
o List Event
o Update Event
o Delete Event
o View Bookings

8. Detailed Use Case Descriptions

 Use Case: User Registration


o Actor: User
o Description: User registers by providing email and password.
o Preconditions: User is not logged in.
o Postconditions: User account is created and can log in.
o Flow:
1. User navigates to the registration page.
2. User enters email and password.
3. System validates the input.
4. System creates a new user account.
5. System sends a confirmation email to the user.
 Use Case: Book Ticket
o Actor: User
o Description: User books a ticket for an event.
o Preconditions: User is logged in and event is available.
o Postconditions: Ticket is reserved and payment is processed.
o Flow:
1. User selects an event.
2. User views available seats and selects desired seats.
3. User proceeds to payment.
4. System processes the payment.
5. System sends a booking confirmation to the user.

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

 Appendix A: Example UI Mockups


 Appendix B: Example Database Schema
 Appendix C: API Documentation for Payment Gateway Integration

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.

TO GENERATE UNIT TESTING FOR THE ONLINE TICKET BOOKING SYSTEM


To generate unit testing for the Online Ticket Booking System, we'll use Java along with JUnit. Below are
some examples of unit tests for the main functionalities of the system, including user registration, event
management, ticket booking, and payment processing.

1. User Registration and Authentication

Program: User.java

public class User {


private String email;
private String password;

// Constructor
public User(String email, String password) {
this.email = email;
this.password = password;
}
// Getters
public String getEmail() {
return email;
}

public String getPassword() {


return password;
}
}
Program: UserService.java

import java.util.HashMap;
import java.util.Map;

public class UserService {


private Map<String, User> users = new HashMap<>();

public boolean registerUser(String email, String password) {


if (email == null || email.isEmpty() || password == null || password.isEmpty()) {
return false;
}
if (users.containsKey(email)) {
return false;
}
users.put(email, new User(email, password));
return true;
}
public boolean authenticateUser(String email, String password) {
User user = users.get(email);
return user != null && user.getPassword().equals(password);
}
}
Test: UserServiceTest.java

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

public class UserServiceTest {


private UserService userService;

@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

public class Event {


private String title;
private String date;
private String location;
private int availableSeats;

// Constructor
public Event(String title, String date, String location, int availableSeats) {
this.title = title;
this.date = date;
this.location = location;
this.availableSeats = availableSeats;
}

// Getters and Setters


public String getTitle() {
return title;
}

public String getDate() {


return date;
}

public String getLocation() {


return location;
}

public int getAvailableSeats() {


return availableSeats;
}

public void setAvailableSeats(int availableSeats) {


this.availableSeats = availableSeats;
}
}
Program: EventService.java

import java.util.HashMap;
import java.util.Map;

public class EventService {


private Map<String, Event> events = new HashMap<>();

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;
}

public Event getEvent(String title) {


return events.get(title);
}

public boolean updateEventSeats(String title, int seats) {


Event event = events.get(title);
if (event != null && seats >= 0) {
event.setAvailableSeats(seats);
return true;
}
return false;
}
}
Test: EventServiceTest.java

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

public class EventServiceTest {


private EventService eventService;

@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

public class Booking {


private String eventTitle;
private String userEmail;
private int seats;

// Constructor
public Booking(String eventTitle, String userEmail, int seats) {
this.eventTitle = eventTitle;
this.userEmail = userEmail;
this.seats = seats;
}

// Getters
public String getEventTitle() {
return eventTitle;
}

public String getUserEmail() {


return userEmail;
}

public int getSeats() {


return seats;
}
}
Program: BookingService.java

import java.util.ArrayList;
import java.util.List;

public class BookingService {


private List<Booking> bookings = new ArrayList<>();
private EventService eventService;

public BookingService(EventService eventService) {


this.eventService = eventService;
}

public boolean bookTicket(String eventTitle, String userEmail, int seats) {


Event event = eventService.getEvent(eventTitle);
if (event != null && event.getAvailableSeats() >= seats && seats > 0) {
bookings.add(new Booking(eventTitle, userEmail, seats));
eventService.updateEventSeats(eventTitle, event.getAvailableSeats() - seats);
return true;
}
return false;
}

public List<Booking> getBookings() {


return bookings;
}
}
Test: BookingServiceTest.java

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

public class BookingServiceTest {


private EventService eventService;
private BookingService bookingService;

@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

public class PaymentService {


public boolean processPayment(String userEmail, double amount) {
// Mock payment processing
if (userEmail == null || userEmail.isEmpty() || amount <= 0) {
return false;
}
// Assume payment is always successful for valid inputs
return true;
}
}
Test: PaymentServiceTest.java

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

public class PaymentServiceTest {


private PaymentService paymentService;

@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.

You might also like