391 lines
10 KiB
Markdown
391 lines
10 KiB
Markdown
# Test Scripts for JAX-WS Services
|
|
|
|
This folder contains test scripts to interact with the JAX-WS services.
|
|
|
|
## Available Test Scripts
|
|
|
|
- `test_all_services.py` - **Unified test script for all services** (Recommended)
|
|
- `test_hello_world.py` - Test the Hello World SOAP service
|
|
- `test_register_customer.py` - Test the Customer Registration SOAP service
|
|
- `simple_test.py` - Simple automated test script for CI/CD
|
|
|
|
## Unified Test Script (Recommended)
|
|
|
|
### test_all_services.py
|
|
|
|
This is the **recommended** way to test all services. It provides comprehensive testing for all three service operations in a single script.
|
|
|
|
**Features:**
|
|
- Tests all service operations (Hello World, Customer Registration, Loan Processing)
|
|
- Automated test suite with 20+ test cases
|
|
- Interactive mode for manual testing
|
|
- Clear pass/fail indicators with test summary
|
|
- Comprehensive error handling and validation testing
|
|
|
|
**Running the unified test:**
|
|
|
|
**Windows:**
|
|
```cmd
|
|
cd scripts
|
|
python test_all_services.py
|
|
```
|
|
|
|
**Linux/Mac:**
|
|
```bash
|
|
cd scripts
|
|
python3 test_all_services.py
|
|
# OR
|
|
chmod +x test_all_services.py
|
|
./test_all_services.py
|
|
```
|
|
|
|
**What it tests:**
|
|
|
|
1. **Hello World Service**
|
|
- Normal greetings
|
|
- Edge cases (empty names)
|
|
|
|
2. **Customer Registration Service**
|
|
- Regular customer registration
|
|
- Blacklisted customer registration
|
|
- Duplicate registration handling
|
|
- Validation error handling
|
|
|
|
3. **Loan Application Processing**
|
|
- High credit score approvals (3.5% rate)
|
|
- Good credit score approvals (5.5% rate)
|
|
- Fair credit score approvals (8.5% rate)
|
|
- Low credit score rejections
|
|
- Blacklisted customer rejections
|
|
- Validation error handling (empty names, invalid amounts)
|
|
|
|
**Interactive Mode:**
|
|
|
|
After automated tests complete, you can enter interactive mode with these commands:
|
|
- `hello <name>` - Test Hello World service
|
|
- `register <name>` - Register a regular customer
|
|
- `blacklist <name>` - Register a blacklisted customer
|
|
- `loan <name> <amount> <credit_score>` - Process loan application
|
|
- `quit` - Exit
|
|
|
|
**Example output:**
|
|
```
|
|
================================================================================
|
|
JAX-WS UNIFIED TEST CLIENT
|
|
================================================================================
|
|
Testing all services and operations
|
|
|
|
Checking services availability...
|
|
|
|
Hello World Service: Service is accessible
|
|
Loan Approval Service: Service is accessible
|
|
|
|
================================================================================
|
|
AUTOMATED TEST SUITE
|
|
================================================================================
|
|
|
|
--------------------------------------------------------------------------------
|
|
1. Testing Hello World Service
|
|
--------------------------------------------------------------------------------
|
|
✓ PASS | getHelloWorld('John') - Should return greeting
|
|
Hello World, John!
|
|
|
|
✓ PASS | getHelloWorld('Alice') - Should return greeting
|
|
Hello World, Alice!
|
|
|
|
--------------------------------------------------------------------------------
|
|
2. Testing Customer Registration Service
|
|
--------------------------------------------------------------------------------
|
|
✓ PASS | registerNewCustomer('Alice Johnson', blacklisted=False) - Register regular customer
|
|
Registration Successful
|
|
|
|
✓ PASS | registerNewCustomer('Charlie Brown', blacklisted=True) - Register blacklisted customer
|
|
Registration Successful
|
|
|
|
✓ PASS | registerNewCustomer('Alice Johnson', blacklisted=False) - Duplicate registration (should fail)
|
|
Error: Customer already exists
|
|
|
|
--------------------------------------------------------------------------------
|
|
3. Testing Loan Application Processing Service
|
|
--------------------------------------------------------------------------------
|
|
✓ PASS | processLoanApplication('Alice Johnson', $50000, score=750) - High credit score
|
|
approved: True
|
|
approvedRate: 3.5
|
|
message: Loan approved with excellent rate
|
|
|
|
✓ PASS | processLoanApplication('Charlie Brown', $40000, score=700) - Blacklisted customer
|
|
approved: False
|
|
rejectionReason: Applicant is blacklisted
|
|
message: Loan application rejected
|
|
|
|
================================================================================
|
|
TEST SUMMARY
|
|
================================================================================
|
|
Total Tests: 20
|
|
Passed: 20
|
|
Failed: 0
|
|
Success Rate: 100.0%
|
|
|
|
Would you like to enter interactive mode? (y/n):
|
|
```
|
|
|
|
## Python Test Scripts
|
|
|
|
### Prerequisites
|
|
|
|
- Python 3.6 or higher
|
|
- pip (Python package installer)
|
|
|
|
### Installation
|
|
|
|
1. **Install Python dependencies:**
|
|
|
|
**Windows:**
|
|
```cmd
|
|
cd scripts
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
**Linux/Mac:**
|
|
```bash
|
|
cd scripts
|
|
pip3 install -r requirements.txt
|
|
```
|
|
|
|
### Running the Test Script
|
|
|
|
Make sure the JAX-WS service is running (using Docker or traditional setup).
|
|
|
|
**Windows:**
|
|
```cmd
|
|
python test_hello_world.py
|
|
```
|
|
|
|
**Linux/Mac:**
|
|
```bash
|
|
python3 test_hello_world.py
|
|
# OR
|
|
chmod +x test_hello_world.py
|
|
./test_hello_world.py
|
|
```
|
|
|
|
### What the Script Does
|
|
|
|
The `test_hello_world.py` script:
|
|
|
|
1. **Checks WSDL availability** - Verifies the service is running
|
|
2. **Tests with multiple names** - Calls the service with predefined test cases
|
|
3. **Interactive mode** - Allows you to enter custom names and see responses in real-time
|
|
|
|
### Example Output
|
|
|
|
```
|
|
============================================================
|
|
JAX-WS Hello World Service Test Client
|
|
============================================================
|
|
|
|
1. Checking WSDL availability...
|
|
WSDL is accessible
|
|
|
|
2. Testing Hello World Service...
|
|
|
|
Calling service with name: 'World'
|
|
Response: Hello World, World!
|
|
|
|
Calling service with name: 'Python Client'
|
|
Response: Hello World, Python Client!
|
|
|
|
Calling service with name: 'JAX-WS User'
|
|
Response: Hello World, JAX-WS User!
|
|
|
|
Calling service with name: 'Docker'
|
|
Response: Hello World, Docker!
|
|
|
|
3. Interactive Mode
|
|
--------------------------------------------------------
|
|
Enter a name (or 'quit' to exit): John
|
|
Response: Hello World, John!
|
|
|
|
Enter a name (or 'quit' to exit): quit
|
|
|
|
============================================================
|
|
Test completed!
|
|
============================================================
|
|
```
|
|
|
|
## Using the HelloWorldClient Class
|
|
|
|
You can also use the `HelloWorldClient` class in your own Python scripts:
|
|
|
|
```python
|
|
from test_hello_world import HelloWorldClient
|
|
|
|
# Create client
|
|
client = HelloWorldClient()
|
|
|
|
# Check if service is available
|
|
is_available, message = client.check_wsdl()
|
|
print(message)
|
|
|
|
# Call the service
|
|
response = client.call_hello_world("Your Name")
|
|
print(response) # Output: Hello World, Your Name!
|
|
```
|
|
|
|
## Customer Registration Test Script
|
|
|
|
### Running the Customer Registration Test
|
|
|
|
Make sure the JAX-WS service is running (using Docker or traditional setup).
|
|
|
|
**Windows:**
|
|
```cmd
|
|
python test_register_customer.py
|
|
```
|
|
|
|
**Linux/Mac:**
|
|
```bash
|
|
python3 test_register_customer.py
|
|
# OR
|
|
chmod +x test_register_customer.py
|
|
./test_register_customer.py
|
|
```
|
|
|
|
### What the Script Does
|
|
|
|
The `test_register_customer.py` script:
|
|
|
|
1. **Checks WSDL availability** - Verifies the LoanApprovalService is running
|
|
2. **Tests customer registration** - Registers multiple customers with different scenarios
|
|
3. **Tests blacklist functionality** - Registers both regular and blacklisted customers
|
|
4. **Tests duplicate registration** - Verifies that duplicate registrations are handled correctly
|
|
5. **Interactive mode** - Allows you to register customers interactively
|
|
|
|
### Example Output
|
|
|
|
```
|
|
======================================================================
|
|
Customer Registration Service Test Client
|
|
======================================================================
|
|
|
|
1. Checking WSDL availability...
|
|
WSDL is accessible
|
|
|
|
2. Testing Customer Registration...
|
|
|
|
Test 1: Regular customer
|
|
Customer Name: John Doe
|
|
Blacklisted: False
|
|
Result: Registration Successful
|
|
|
|
Test 2: Regular customer
|
|
Customer Name: Jane Smith
|
|
Blacklisted: False
|
|
Result: Registration Successful
|
|
|
|
Test 3: Blacklisted customer
|
|
Customer Name: Bad Actor
|
|
Blacklisted: True
|
|
Result: Registration Successful
|
|
|
|
Test 4: Duplicate registration (should fail)
|
|
Customer Name: John Doe
|
|
Blacklisted: False
|
|
Result: Error: Customer already exists
|
|
|
|
3. Interactive Mode
|
|
------------------------------------------------------------------
|
|
Commands:
|
|
- register <name>: Register a regular customer
|
|
- blacklist <name>: Register a blacklisted customer
|
|
- quit: Exit
|
|
|
|
> register Alice Smith
|
|
Result: Registration Successful
|
|
|
|
> blacklist Evil Corp
|
|
Result: Registration Successful
|
|
|
|
> quit
|
|
|
|
======================================================================
|
|
Test completed!
|
|
======================================================================
|
|
```
|
|
|
|
### Using the CustomerRegistrationClient Class
|
|
|
|
You can also use the `CustomerRegistrationClient` class in your own Python scripts:
|
|
|
|
```python
|
|
from test_register_customer import CustomerRegistrationClient
|
|
|
|
# Create client
|
|
client = CustomerRegistrationClient()
|
|
|
|
# Check if service is available
|
|
is_available, message = client.check_wsdl()
|
|
print(message)
|
|
|
|
# Register a regular customer
|
|
response = client.register_customer("John Doe", is_blacklisted=False)
|
|
print(response) # Output: Registration Successful
|
|
|
|
# Register a blacklisted customer
|
|
response = client.register_customer("Bad Actor", is_blacklisted=True)
|
|
print(response) # Output: Registration Successful
|
|
|
|
# Try to register duplicate
|
|
response = client.register_customer("John Doe", is_blacklisted=False)
|
|
print(response) # Output: Error: Customer already exists
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Service Not Available
|
|
|
|
If you get a connection error:
|
|
|
|
1. Make sure the Docker container is running:
|
|
```bash
|
|
docker ps | grep jaxws
|
|
```
|
|
|
|
2. Check if the service is accessible:
|
|
```bash
|
|
curl http://localhost:8080/jaxws-hello-world/hello?wsdl
|
|
```
|
|
|
|
3. Restart the service:
|
|
```bash
|
|
docker-compose restart
|
|
```
|
|
|
|
### Python Not Found
|
|
|
|
If you get "python: command not found":
|
|
|
|
- **Windows**: Use `python` or `py` command
|
|
- **Linux/Mac**: Use `python3` command
|
|
|
|
### Dependencies Not Installing
|
|
|
|
If pip install fails:
|
|
|
|
1. Make sure pip is up to date:
|
|
```bash
|
|
python -m pip install --upgrade pip
|
|
```
|
|
|
|
2. Try installing with sudo (Linux/Mac only):
|
|
```bash
|
|
sudo pip3 install -r requirements.txt
|
|
```
|
|
|
|
3. Use a virtual environment:
|
|
```bash
|
|
python3 -m venv venv
|
|
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
pip install -r requirements.txt
|
|
```
|