Technology Stack
Back end Framework: Spring Boot
Spring Boot simplifies Java application development with built-in servers (Tomcat, Jetty, Undertow) and auto-configuration based on project dependencies. Its extensive ecosystem includes Spring Data, Spring Security, and Spring Cloud for rapid application development and integration.
Frontend Framework: Vue.js
Vue.js employs virtual DOM technology for efficient UI updates through reactive data binding. Its component-based architecture offers flexibility and maintainability in frontend development.
Database: MySQL
MySQL is an open-source relational database management system supporting multiple platforms (Windows, Linux, macOS). Its active community provides extensive documentation and tools for various develpoment scenarios.
System Testing
Testing Objectives
System testing ensures quality and reliability by validating functionality against requirements. It identifies defects through simulated user scenarios, focusing on usability and logical consistency.
Functional Testing
Login Functionality
| Input Data | Expected Result | Actual Result | Analysis |
|---|---|---|---|
| Valid credentials | Successful login | Login successful | Pass |
| Invalid password | Error message | Password error displayed | Pass |
| Empty username | Validation prompt | Username required | Pass |
User Management
| Action | Expected Result | Actual Result | Analysis |
|---|---|---|---|
| Add user | User appears in list | User added successfully | Pass |
| Edit user | Information updated | Changes reflected | Pass |
| Delete user | Confirmation dialog | User removed | Pass |
Code Implementation
@RestController
public class AuthController {
@PostMapping("/authenticate")
public Response login(@RequestParam String username,
@RequestParam String password) {
User user = userService.findByUsername(username);
if (user == null || !password.equals(user.getPassword())) {
return Response.error("Invalid credentials");
}
String accessToken = tokenService.createToken(user.getId(), user.getRole());
return Response.ok().withData("token", accessToken);
}
}
@Service
public class TokenService {
public String createToken(Long userId, String role) {
String token = RandomStringUtils.randomAlphanumeric(32);
Date expiry = DateUtils.addHours(new Date(), 1);
Token existing = tokenRepository.findByUserId(userId);
if (existing != null) {
existing.updateToken(token, expiry);
} else {
tokenRepository.save(new Token(userId, role, token, expiry));
}
return token;
}
}
Database Schema
CREATE TABLE auth_tokens (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT NOT NULL,
token_value VARCHAR(200) NOT NULL,
role VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
expires_at TIMESTAMP NOT NULL
);
INSERT INTO auth_tokens VALUES
(1, 101, 'a1b2c3d4', 'admin', NOW(), DATE_ADD(NOW(), INTERVAL 1 HOUR));