Skip to content

ccdita/myBookstore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

myBookstore

Welcome to myBookStore! myBookStore is a command-line application that enables users to create an account, log in, and purchase and sell books. I built this application to demonstrate what I have learned so far in Spring.

Built With:

Spring Boot for simplifying Spring configuration

  • myBookstore uses Spring Boot to simplify Spring configuration and dependency management.

Spring Data, Hibernate, and MySQL for data persistence and Object-Relational Mapping

  • myBookstore handles data persistence by employing Spring Data JPA and Hibernate, mapping Java objects to a relational MySQL database and executing seamless CRUD operations without the use of raw SQL queries.

JUnit and Mockito for unit and integration testing

  • myBookstore utilizes JUnit 5 and Mockito to thoroughly test the application's logic and database interactions. JUnit 5 is used for unit testing, as well as integration testing with Spring Data JPA. Mockito is used for mocking dependencies and isolating testing of service-level classes.

Design

myBookstore is implemented using N-tier architecture. The data access layer is abstracted through Data Access Object interfaces, and business logic is handled by service classes. Finally, UI classes within the presentation layer handle all user interactions and send requests to the logic layer for processing. Altogether, this design promotes modularity, security, and maintainability.

Lessons Learned:

In designing and building this project, I learned the following:

  • The purpose of Inversion of Control (IoC) and Dependency Injection (DI). Spring follows the principle of IoC, and one pattern of IoC that it uses is DI. By transferring the responsibility of an object's lifecycle to the Spring IoC container, the application becomes loosely coupled. The code therefore becomes more modular and testable; developers can reuse components in different contexts and test them in isolation via mocks.
  • Setting up a Spring Boot CRUD application. With the help of Chad Darby's Spring Boot course on Udemy, I learned how to connect to a MySQL database, create and configure entity classes and Data Access Objects, and implement JPA CRUD operations.
  • Testing classes in the data access layer. I learned how to use the @DataJpaTest annotation to create an embedded in-memory (H2) database and perform transactional operations that were automatically rolled back after execution. Moreover, I learned how to use the @Import annotation to load custom repository implementations, since @DataJpaTest only scans for Spring Data JPA repositories.
  • Testing logic-level classes in isolation using the Mockito framework. I learned the importance of using mock dependencies to test business logic code in a controlled environment (i.e., without interference from data access dependencies).
  • Spring Annotations:
    • Fundamental annotations such as @SpringBootApplication, @Component, and @Autowired
    • Functionality-related annotations such as @Service, @Repository, and @Transactional
    • JPA mapping annotations such as @Entity, @Table, @GeneratedValue, and @Column
    • Test-related annotations such as @DataJpaTest, @Mock, and @InjectMocks

Contact:

Christal Dita | LinkedIn

References:

I used the following resources to guide my learning:

About

A virtual bookstore for selling and buying books

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages