# (DD50) 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 verifies the negative path of the owner creation flow in the Petclinic owner module. Business-wise, it confirms that when a user submits a new owner registration form without all mandatory contact data, the web layer rejects the submission and returns the owner creation screen with validation feedback instead of proceeding to persistence or redirecting to a success page. The method specifically exercises the form-processing branch where address and telephone information are missing, which are treated as required business fields for a valid owner record.

The test acts as a guardrail for the controller’s validation contract: it proves that the controller preserves the invalid form state, exposes field-level errors, and keeps the user on the same create/update page so the data can be corrected. It follows a request/response verification pattern using MockMvc rather than invoking business services directly, so its role is to validate MVC behavior, binding, and server-side validation rules at the boundary of the application. In the broader system, it supports the owner onboarding journey by ensuring incomplete customer data is not accepted as a finalized owner profile.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["processCreationFormHasErrors()"])
    POST_REQUEST(["POST /owners/new with firstName, lastName, city only"])
    BIND_OWNER(["Spring binds request parameters to owner form object"])
    VALIDATE(["Validate owner form using controller validation rules"])
    HAS_ERRORS{"Binding result has validation errors"}
    SHOW_FORM(["Return owners/createOrUpdateOwnerForm with error model"])
    END_NODE(["End"])
    START --> POST_REQUEST
    POST_REQUEST --> BIND_OWNER
    BIND_OWNER --> VALIDATE
    VALIDATE --> HAS_ERRORS
    HAS_ERRORS -->|Yes| SHOW_FORM
    SHOW_FORM --> END_NODE
    HAS_ERRORS -->|No| END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This is a zero-argument JUnit test method. All business input is embedded in the MockMvc request payload, where the submitted owner form intentionally omits required contact fields to trigger validation errors. |

External state read by the method:
- `mockMvc` — the configured MockMvc test client used to send the POST request and assert the HTTP response.
- Spring MVC validation and binding configuration associated with `OwnerController` and the owner form.

## 4. CRUD Operations / Called Services

This method does not call application CRUD services directly. It validates controller behavior through MockMvc assertions only.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `mockMvc.perform(...)` | N/A | HTTP request/response boundary | Submits the owner creation form as an HTTP POST so the controller can execute its validation and binding logic. |
| R | `status().isOk()` | N/A | HTTP response status | Confirms the controller returns a successful 200 response for the invalid form submission path. |
| R | `model().attributeHasErrors("owner")` | N/A | MVC model `owner` | Verifies that the submitted owner object contains validation errors. |
| R | `model().attributeHasFieldErrors("owner", "address")` | N/A | MVC model field `address` | Verifies that the address field is marked invalid because it was omitted from the request. |
| R | `model().attributeHasFieldErrors("owner", "telephone")` | N/A | MVC model field `telephone` | Verifies that the telephone field is marked invalid because it was omitted from the request. |
| R | `view().name("owners/createOrUpdateOwnerForm")` | N/A | View template `owners/createOrUpdateOwnerForm` | Confirms the controller returns the owner form view for correction instead of redirecting to the success flow. |

## 5. Dependency Trace

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

## 6. Per-Branch Detail Blocks

**Block 1** — **EXEC** `(test setup and request submission)` (L124-L129)

> This block drives the invalid owner creation scenario by posting an incomplete owner form to the controller.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `mockMvc.perform(post("/owners/new").param("firstName", "Joe").param("lastName", "Bloggs").param("city", "London"))` // submit incomplete owner form |
| 2 | EXEC | `.andExpect(status().isOk())` // expect the controller to stay on the same page |
| 3 | EXEC | `.andExpect(model().attributeHasErrors("owner"))` // verify owner-level validation errors |
| 4 | EXEC | `.andExpect(model().attributeHasFieldErrors("owner", "address"))` // verify address is required |
| 5 | EXEC | `.andExpect(model().attributeHasFieldErrors("owner", "telephone"))` // verify telephone is required |
| 6 | EXEC | `.andExpect(view().name("owners/createOrUpdateOwnerForm"))` // return the correction form view |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `owner` | Domain object | Owner registration form model representing a pet owner being created in the system. |
| `address` | Field | Owner mailing address — a mandatory contact field for a valid owner profile. |
| `telephone` | Field | Owner phone number — a mandatory contact field for a valid owner profile. |
| `firstName` | Field | Owner given name captured during new owner registration. |
| `lastName` | Field | Owner family name captured during new owner registration. |
| `city` | Field | Owner city of residence captured during new owner registration. |
| MockMvc | Technical term | Spring MVC test client used to simulate HTTP requests against controller endpoints. |
| validation errors | Business term | Field-level rejection messages produced when required form data is missing or invalid. |
| owners/createOrUpdateOwnerForm | View | Owner data entry page used for both creation and correction of owner information. |
| POST /owners/new | Endpoint | HTTP entry point used to submit a new owner registration. |
