A layered Java 17 application with JOptionPane UI, built in NetBeans 27.
Implements JDBC repositories with a Singleton connection manager, secure password hashing, and custom exception handling.
- User Management: Multi-user system with Admin and Member roles
- Security: BCrypt password hashing and role-based access control
- Book Operations: Browse, search, and manage book inventory
- Lending System: Borrow, return, and track book loans
- Member Management: Registration and profile management
- Admin Features: System configuration and advanced management options
- Comprehensive Testing: JUnit 5 test suite with Mockito for service layer testing
The project includes comprehensive unit tests for the service layer using JUnit 5 and Mockito:
-
BookServiceImplTest: Tests for book management operations
- Book addition with ISBN validation
- Duplicate ISBN checks
- Stock management validation
- Book search functionality
-
LendingServiceImplTest: Tests for lending operations
- Book lending process
- Return book functionality
- Lending limits enforcement
- Due date management
-
MemberServiceImplTest: Tests for member management
- Member registration
- Role validation
- Member search functionality
- Active/inactive member management
- Service layer business logic
- Input validation
- Error handling
- Business rules enforcement
- Edge cases
- JUnit 5 for test framework
- Mockito for dependency mocking
- AssertJ for fluent assertions
com.codeup.novabook
ββ domain/ # Domain models (POJOs)
β ββ Book.java
β ββ Member.java
β ββ Lending.java
β ββ User.java
ββ exceptions/ # Custom exceptions
β ββ DatabaseException.java
ββ repository/ # Repository interfaces
β ββ BookRepository.java
β ββ MemberRepository.java
β ββ LendingRepository.java
β ββ UserRepository.java
ββ repository/jdbc/ # JDBC implementations
β ββ BookRepositoryJDBC.java
β ββ MemberRepositoryJDBC.java
β ββ LendingRepositoryJDBC.java
β ββ UserRepositoryJDBC.java
ββ service/ # Service interfaces
β ββ BookService.java
β ββ MemberService.java
β ββ LendingService.java
β ββ UserService.java
ββ service/impl/ # Service implementations
β ββ BookServiceImpl.java
β ββ MemberServiceImpl.java
β ββ LendingServiceImpl.java
β ββ UserServiceImpl.java
ββ connection/ # Database connection (Singleton)
β ββ ConnectionFactory.java
β ββ TestConnection.java
ββ infra/config/ # Configuration
β ββ AppConfig.java
ββ ui/ # JOptionPane UI layer
β ββ NovaBookUI.java
ββ NovaBook.java # Main application class
- JDK: 17
- IDE: NetBeans 27 (recommended)
- Database: MySQL 8.0+
- Maven: for dependency management and build
- MySQL Connector/J: 8.0+
First, create the database and tables:
-- Run the SQL script in src/main/java/com/codeup/novabook/db/NovaBookDBSchema.sql
CREATE DATABASE IF NOT EXISTS novabook_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE novabook_db;
-- The script will create all necessary tables and userConfigure the database connection in src/main/resources/application.properties:
db.vendor=mysql
db.host=localhost
db.port=3306
db.name=novabook_db
db.user=root
db.password=Qwe.123*
db.useSSL=falseThe project includes a comprehensive test suite. You can run the tests using Maven:
# Run all tests
mvn test
# Run specific test class
mvn test -Dtest=BookServiceImplTest
mvn test -Dtest=LendingServiceImplTest
mvn test -Dtest=MemberServiceImplTestTest results will be available in the target/surefire-reports directory.
mvn clean compile
mvn exec:java -Dexec.mainClass="com.codeup.novabook.NovaBook"- Open the project in NetBeans 27
- Right-click on the project β Run Project
- Or run the
NovaBookmain class directly
# Compile
javac -cp "target/classes:lib/*" src/main/java/com/codeup/novabook/*.java
# Run
java -cp "target/classes:lib/*" com.codeup.novabook.NovaBook- β Add new books with ISBN validation
- β Search books by title, author, or availability
- β Update book information
- β Remove books from library
- β Stock management
- β Register new members (Regular/Premium)
- β Search members by name
- β Update member information
- β Deactivate/activate members
- β Role management
- β Lend books to members
- β Return books
- β Track active lendings
- β View overdue lendings
- β Extend lending periods
- β Automatic fine calculation
- β Register system users (User/Admin)
- β User authentication
- β Update user profiles
- β Deactivate users
- β Role-based access control
- β Library statistics
- β Member statistics
- β Lending statistics
- β Overdue tracking
- Domain Layer: Entity classes (Book, Member, Lending, User)
- Repository Layer: Data access interfaces and JDBC implementations
- Service Layer: Business logic interfaces and implementations
- UI Layer: JOptionPane-based user interface
ConnectionFactoryensures only one database connection instance- Thread-safe implementation with double-checked locking
- Using Mockito for dependency injection in tests
- Isolation of system under test
- Controlled testing environment
- Abstracts data access operations
- Easy to switch between different data sources
- Clean separation of concerns
DatabaseExceptionfor database-related errors- Proper error propagation and handling
- Users Table: System users with roles and access levels
- Book Table: Library books with ISBN, title, author, and stock
- Member Table: Library members with roles and status
- Lending Table: Book lending transactions with due dates
- ConnectionFactory: Singleton database connection manager
- AppConfig: Configuration management using Properties
- Repository Interfaces: Define data access contracts
- Service Layer: Business logic and validation
- UI Layer: User-friendly JOptionPane dialogs
- Email format validation
- ISBN format validation
- Stock cannot be negative
- Member/user name validation
- Business rule enforcement (max books per member, etc.)
- Select "Book Management" β "Add Book"
- Enter ISBN, title, author, and stock
- System validates ISBN format and saves book
- Select "Lending Management" β "Lend Book"
- Enter member ID, book ID, and lending days
- System checks availability and creates lending record
- Select "Reports" β "Library Statistics"
- View total books, members, users, and lendings
- Verify MySQL is running
- Check database credentials in
app.props - Ensure
novabook_dbdatabase exists - Run the schema script to create tables
- Ensure JDK 17 is installed
- Check MySQL Connector/J is in classpath
- Verify all dependencies are available
- Check database connection
- Verify user permissions
- Review error messages in console
Developed by AdriΓ‘n GutiΓ©rrez
- Implemented BCrypt password hashing with work factor 12
- Added salted password storage
- Improved password verification process
- Fixed loan management functionality
- Updated method naming for consistency (lending β loan)
- Improved user session handling
- Enhanced input validation
- Fixed date handling in database operations
- Resolved date casting issues in lending operations
- Fixed user session management
- Corrected method name inconsistencies
- Improved error handling and user feedback
This project is licensed under the MIT License - see the LICENSE file for details.