---
# (DD10) Business Logic — OwnerControllerTests.processCreationFormHasErrors() [10 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `org.springframework.samples.petclinic.owner.OwnerControllerTests` |
| Layer | Controller Test |
| Module | `owner` (Package: `org.springframework.samples.petclinic.owner`) |

## 1. Role

### OwnerControllerTests.processCreationFormHasErrors()

This test method verifies the failure path of the owner creation flow when the submitted registration form does not satisfy validation rules. In business terms, it simulates a user attempting to create a new pet owner profile with only partial contact information and confirms that the system rejects the submission instead of persisting the record.

The method exercises the controller’s form-validation behavior for the owner onboarding use case. It focuses on required-field validation for the owner’s address and telephone data, while still allowing the request to reach the controller endpoint and return the same maintenance screen for correction. This is a request/response verification pattern typical of MVC controller tests: submit form data, observe validation errors, and assert that the user remains on the owner form view.

In the larger system, this method safeguards the data-entry experience for the owner registration screen by ensuring that incomplete submissions are handled gracefully. It acts as a regression test for the controller’s binding and validation contract, especially the business rule that an owner cannot be created without a complete address and telephone number. No branching business logic is implemented inside the test itself; rather, it validates the branch selection performed by the controller under error conditions.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["processCreationFormHasErrors()"])
    REQ(["Build POST request to /owners/new with firstName=Joe, lastName=Bloggs, city=London"])
    EXEC(["mockMvc.perform(request)"])
    OK(["Assert HTTP status is 200 OK"])
    ERR(["Assert model has validation errors for owner"])
    ADDR(["Assert model has field error on owner.address"])
    TEL(["Assert model has field error on owner.telephone"])
    VIEW(["Assert returned view is owners/createOrUpdateOwnerForm"])
    END_NODE(["Return / Next"])

    START --> REQ
    REQ --> EXEC
    EXEC --> OK
    OK --> ERR
    ERR --> ADDR
    ADDR --> TEL
    TEL --> VIEW
    VIEW --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | - |

**Instance fields / external state read by the method:** None directly inside the method body. The test relies on the autowired `MockMvc` infrastructure and the Spring MVC test context to execute the request and inspect the controller response.

## 4. CRUD Operations / Called Services

This method does not invoke application CRUD services directly. It calls the web-layer testing harness to submit an HTTP request and then inspects the controller response. The underlying CRUD behavior is indirect: the controller endpoint is expected not to create a new owner record when validation fails.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|-----------------------|
| R | `MockMvc.perform` | N/A | N/A | Sends a simulated HTTP POST request to the owner creation endpoint for validation testing |
| R | `status().isOk` | N/A | N/A | Verifies that the controller returns a successful page response instead of redirecting after validation failure |
| R | `model().attributeHasErrors` | N/A | N/A | Verifies that the MVC model contains validation errors for the owner form object |
| R | `model().attributeHasFieldErrors` | N/A | N/A | Verifies field-level validation failures for `address` and `telephone` |
| R | `view().name` | N/A | N/A | Verifies that the user remains on the owner maintenance form view |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:OwnerControllerTests | `OwnerControllerTests.processCreationFormHasErrors` | `MockMvc POST /owners/new [R]` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE] `(test setup and execution)` (L124-L130)

> This block validates the owner creation failure path when required contact details are missing.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `mockMvc.perform(post("/owners/new").param("firstName", "Joe").param("lastName", "Bloggs").param("city", "London"));` |
| 2 | CALL | `.andExpect(status().isOk());` |
| 3 | CALL | `.andExpect(model().attributeHasErrors("owner"));` |
| 4 | CALL | `.andExpect(model().attributeHasFieldErrors("owner", "address"));` |
| 5 | CALL | `.andExpect(model().attributeHasFieldErrors("owner", "telephone"));` |
| 6 | CALL | `.andExpect(view().name("owners/createOrUpdateOwnerForm"));` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `MockMvc` | Technical term | Spring MVC test harness used to simulate HTTP requests against controller endpoints without starting a full server |
| `owner` | Domain object | Owner form/model attribute representing a pet owner being registered or edited |
| `owners/new` | Endpoint | Web route for the owner creation form submission |
| `address` | Field | Owner street address, required contact information for a complete owner profile |
| `telephone` | Field | Owner phone number, required contact information for a complete owner profile |
| `firstName` | Field | Owner given name used as part of the owner identity |
| `lastName` | Field | Owner family name used as part of the owner identity |
| `city` | Field | City portion of the owner address used to complete the contact profile |
| `owners/createOrUpdateOwnerForm` | View | Thymeleaf/JSP-style maintenance page used to display owner create and edit forms |
| validation errors | Business term | Input rule violations that prevent the system from accepting incomplete or incorrect owner data |
| MVC model | Technical term | Server-side data container returned to the view so the form can be redisplayed with errors |
| request/response test | Technical term | Test pattern that submits a web request and asserts the resulting status, model, and view |
