Java to Python Test Suite
Verification-first test infrastructure for secure, dependency-aware Java to Python translation services.
Executive Summary
This project uses a Python + pytest stack because it maximizes test expressiveness, async API coverage, and security-focused validation in one cohesive framework. The suite is intentionally built around comparison and traceability: each major requirement is represented in marker groups, assertion patterns, dependency ordering tests, and visual models.
Why This Stack, How It Is Used, and Benefits
| Technology |
Why Used |
How Used in This Suite |
Benefit Over Alternatives |
| Python 3.11+ |
Fast iteration and excellent testing ecosystem |
Executes all test layers and fixture logic |
Lower friction than Java/JUnit for mixed async + security test authoring |
| pytest |
Marker-based structure and fixture system |
Separates unit/integration/correctness/negative/adversarial pipelines |
Better parametrization and fixture ergonomics than unittest |
| pytest-asyncio |
Native async compatibility |
Runs async endpoint tests without custom event-loop wrappers |
Cleaner than ad-hoc loop management |
| httpx + ASGITransport |
In-process API contract testing |
Calls API endpoints with dependency overrides and mock backends |
Faster and more deterministic than external server + requests |
| cryptography + PyJWT |
Realistic auth-path verification |
Generates RSA keys and signs test JWTs at runtime |
Stronger coverage than static token-only tests |
| javalang |
Java structure awareness in validation workflows |
Supports parser-oriented assertions in unit tests |
More reliable than regex-only Java parsing checks |
[!IMPORTANT]
The suite verifies not only correctness, but also translation safety and dependency order requirements, including base-class-before-subclass guarantees through topological sorting tests.
Table of Contents
Overview
This repository is a dedicated test harness for a Java-to-Python translation service. It validates parser behavior, method/type fidelity, API contract integrity, authorization controls, guardrail enforcement, and adversarial resilience. It is designed for teams that need reproducible quality and security checks before releasing translation features.
[!IMPORTANT]
The suite assumes an external orchestrator source path and environment variables are available as configured in conftest.py.
Core value for this project:
- Confirms required behavior with explicit assertions (not heuristic checks only).
- Compares expected ordering and output properties against actual responses.
- Detects failures in dependency ordering and cycle handling early.
- Verifies that translation order favors reusable base components before dependents.
(back to top)
Requirements to Validation Mapping
| Requirement |
Implementation Focus |
Evidence in Test Suite |
Outcome Verified |
| Parse Java artifacts safely |
Parser and class-info extraction paths |
tests/unit/test_java_parsing.py |
AST/data extraction is stable for normal and malformed inputs |
| Build dependency graph correctly |
Intra-project edge construction |
tests/unit/test_dependency_graph.py |
No self-loops, no JDK noise, valid class map |
| Sort translation order by dependency |
Topological ordering logic |
tests/unit/test_topological_sort.py |
Dependencies appear before dependent classes |
| Translate base classes before subclasses |
Ordering invariant in project translation plan |
tests/unit/test_topological_sort.py and tests/integration/test_project_translate_api.py |
Base abstractions precede concrete subclasses/services |
| Detect cycles without dropping files |
Cycle fallback behavior |
tests/adversarial/test_circular_dependencies.py and unit cycle tests |
had_cycle is true and all files remain represented |
| Block unsafe or manipulative input |
Input guardrails |
tests/adversarial/test_prompt_injection.py and tests/unit/test_guardrails.py |
Injection/secret patterns rejected before model path |
| Enforce RBAC and policy boundaries |
JWT + permission checks |
tests/negative/test_rbac_enforcement.py |
Unauthorized roles/actions are denied |
(back to top)
Requirements Verification and Validation
This suite applies both verification and validation:
- Verification asks: are we building the system right against explicit requirements?
- Validation asks: are we building the right behavior for secure translation operations?
V&V Strategy Matrix
| Requirement Area |
Verification Method |
Validation Method |
Pass Criteria |
Primary Evidence |
| Dependency graph correctness |
Unit assertions on graph edges and node invariants |
Integration checks of API dependency output |
No self-loops, no missing files, dependency-first order |
tests/unit/test_dependency_graph.py, tests/integration/test_project_translate_api.py |
| Topological ordering (base before subclass) |
Unit invariant checks for order index relationships |
Project-level translate API response order checks |
For every edge A depends on B, index(B) < index(A) |
tests/unit/test_topological_sort.py, tests/integration/test_project_translate_api.py |
| Cycle detection robustness |
Unit and adversarial cycle test scenarios |
End-to-end circular project request handling |
had_cycle true on cyclic input, all files retained in output |
tests/adversarial/test_circular_dependencies.py, tests/unit/test_topological_sort.py |
| Security guardrails |
Unit and adversarial pattern blocking tests |
API-level blocked request behavior checks |
Injection and credential patterns rejected before unsafe processing |
tests/unit/test_guardrails.py, tests/adversarial/test_prompt_injection.py |
| RBAC and auth correctness |
Negative role/permission tests |
Unauthorized API paths return denied responses |
Role permissions enforced with no privilege escalation |
tests/negative/test_rbac_enforcement.py, integration auth tests |
| Output structure fidelity |
Correctness tests over syntax/import/signatures |
Workflow-level usage consistency checks |
Outputs remain parseable and structurally aligned to expectations |
tests/correctness/*.py |
Verification Pipeline
flowchart TD
A[Requirements] --> B[Unit Verification]
B --> C[Integration Verification]
C --> D[Negative and Adversarial Verification]
D --> E[Validation Against Runtime Behaviors]
E --> F[Release Confidence Decision]
Validation Acceptance Gates
| Gate |
Scope |
Command Pattern |
Minimum Acceptance |
| Gate 1 |
Core logic verification |
pytest -m unit -q |
All dependency/order/parser tests pass |
| Gate 2 |
API contract verification |
pytest -m integration -q |
Endpoint contract fields and ordering checks pass |
| Gate 3 |
Security validation |
pytest -m negative -q && pytest -m adversarial -q |
RBAC, injection, and egress/model policy checks pass |
| Gate 4 |
Output quality validation |
pytest -m correctness -q |
Output syntax/structure/import quality checks pass |
| Gate 5 |
Full-system confidence |
pytest -q |
No regressions across all marker groups |
Traceability Notes
- Requirement-to-test traceability is explicit through marker groups and targeted modules.
- Visualization-to-requirement traceability is captured by architecture, object model, and dependency diagrams.
- Algorithm-to-requirement traceability is captured by Kahn ordering assertions that enforce base-before-subclass translation.
[!NOTE]
V&V is strongest when failures are triaged by marker group first, then by requirement area, so remediation stays requirement-focused rather than only test-focused.
(back to top)
Architecture
flowchart LR
A[Fixture Corpus: Java Inputs] --> B[Pytest Marker Groups]
B --> C[Unit Validations]
B --> D[Integration Endpoint Contracts]
B --> E[Negative Security and RBAC]
B --> F[Adversarial Guardrail Tests]
C --> G[Dependency Graph + Topological Sort Validation]
D --> H[Translate and Translate-Project API Behavior]
E --> H
F --> H
G --> I[Confidence in Ordering and Requirements]
H --> I
Architecture intent:
- Marker groups isolate concerns so each risk area is testable independently.
- Unit tests validate deterministic algorithmic behavior (graph and order).
- Integration tests confirm API contract fields like
dependency_order and had_cycle.
- Security suites ensure unsafe requests fail fast and auditable paths stay intact.
(back to top)
Object Model
classDiagram
class FileEntry {
+string filename
+string source
+class_info
+set dependencies
+int order
}
class ProjectTranslationPlan {
+list ordered_files
+map class_map
+bool had_cycle
}
class JavaClassInfo {
+string name
+bool is_interface
+bool is_abstract
+set imports
+set methods
}
ProjectTranslationPlan "1" --> "many" FileEntry : contains
FileEntry --> JavaClassInfo : parsed_from
How this model helps:
- Makes ordering state explicit (
order, dependencies, had_cycle).
- Supports comparison between parsed structure and output expectations.
- Enables requirement-level assertions that are easy to reason about in tests.
(back to top)
Dependency Graph and Topological Sort
The translation planner builds a directed dependency graph where each node is a class/file and edges represent prerequisite relationships (for example, subclass depends on base class).
flowchart TD
A[AbstractProcessor] --> B[PaymentProcessor]
C[Order] --> D[OrderService]
E[IRepository] --> F[OrderRepository]
C --> F
The expected translation order is dependency-first:
- Base abstractions and interfaces.
- Core domain models.
- Concrete implementations and services.
This is why tests verify examples such as Order before OrderService and AbstractProcessor before PaymentProcessor.
Dependency ordering checkpoints used by the suite
| Ordering Check |
Why It Matters |
Test Evidence |