# (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 validates the owner creation flow when the submitted form does not satisfy the domain validation rules. In business terms, it simulates a user attempting to register a new pet owner with only partial identity and address data, and verifies that the controller rejects the submission instead of creating a persisted owner record. The test specifically confirms that the application surfaces validation failures on the owner aggregate, with field-level errors for the address and telephone attributes, which are mandatory for a valid owner profile in this workflow.

The method plays the role of a web-layer acceptance check for negative-path form handling. It uses the MockMvc testing pattern to drive the controller through an HTTP POST request, then asserts the returned model and view state rather than calling any business service directly. Because the method is a test, it does not implement routing or persistence itself; instead, it verifies that the controller's validation-and-return pattern behaves correctly when submitted data is incomplete. The business branch covered here is the error branch of owner creation: the controller must keep the user on the owner form page and expose validation messages rather than proceeding to successful save behavior.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START["processCreationFormHasErrors()"]
    REQUEST["HTTP POST /owners/new with firstName=Joe, lastName=Bloggs, city=London"]
    VALIDATE["Controller validates owner creation form"]
    ERRORS["Binding result contains validation errors"]
    ADDRESS["Field error - address is required or derived from input"]
    TELEPHONE["Field error - telephone is required or derived from input"]
    VIEW["Return view owners/createOrUpdateOwnerForm"]
    END_NODE["Test assertions complete"]
    START --> REQUEST
    REQUEST --> VALIDATE
    VALIDATE --> ERRORS
    ERRORS --> ADDRESS
    ERRORS --> TELEPHONE
    ADDRESS --> VIEW
    TELEPHONE --> VIEW
    VIEW --> END_NODE
```

## 3. Parameter Analysis

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

This method declares no parameters. Its behavior is driven entirely by the fixed MockMvc request payload embedded in the test body and by the controller's validation state. The method also relies on test fixture state managed by the test class, including the configured MockMvc instance and the MVC model returned by the controller under test.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `mockMvc.perform(post(...))` | N/A | HTTP request / MVC controller | Sends a form submission into the web layer to exercise controller validation behavior. |
| R | `status().isOk()` | N/A | HTTP response | Verifies the controller returned a successful HTTP 200 response for the validation-error path. |
| R | `model().attributeHasErrors("owner")` | N/A | MVC model `owner` | Confirms the owner model object carries validation errors after the failed submission. |
| R | `model().attributeHasFieldErrors("owner", "address")` | N/A | MVC model `owner.address` | Confirms the address field is rejected by validation. |
| R | `model().attributeHasFieldErrors("owner", "telephone")` | N/A | MVC model `owner.telephone` | Confirms the telephone field is rejected by validation. |
| R | `view().name("owners/createOrUpdateOwnerForm")` | N/A | MVC view `owners/createOrUpdateOwnerForm` | Verifies the user remains on the owner form view to correct validation errors. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Test runner / JUnit | `OwnerControllerTests.processCreationFormHasErrors` | `mockMvc.perform(post("/owners/new")) [R] HTTP MVC request` |

## 6. Per-Branch Detail Blocks

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

| # | Type | Code |
|---|------|------|
| 1 | CALL | `mockMvc.perform(post("/owners/new").param("firstName", "Joe").param("lastName", "Bloggs").param("city", "London"));` // submits incomplete owner registration form |
| 2 | CALL | `.andExpect(status().isOk());` // expects controller to stay on the page with HTTP 200 |
| 3 | CALL | `.andExpect(model().attributeHasErrors("owner"));` // verifies the owner aggregate has validation errors |
| 4 | CALL | `.andExpect(model().attributeHasFieldErrors("owner", "address"));` // verifies address validation failure |
| 5 | CALL | `.andExpect(model().attributeHasFieldErrors("owner", "telephone"));` // verifies telephone validation failure |
| 6 | CALL | `.andExpect(view().name("owners/createOrUpdateOwnerForm"));` // verifies the form view is re-displayed for correction |
| 7 | RETURN | `return;` // test method ends after assertions complete |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `owner` | Domain object | Pet owner record being created through the registration form. |
| `address` | Field | Owner mailing or residence address required for a complete owner profile. |
| `telephone` | Field | Owner contact phone number required for a complete owner profile. |
| `firstName` | Field | Owner given name supplied by the user during registration. |
| `lastName` | Field | Owner family name supplied by the user during registration. |
| `city` | Field | City portion of the owner's address input. |
| `MockMvc` | Technical component | Spring MVC test harness used to simulate HTTP requests and assert controller responses. |
| `BindingResult` | Technical component | Validation result container that holds field and object-level form errors. |
| `validation error` | Business term | Rule violation that prevents an owner registration from being accepted. |
| `owners/createOrUpdateOwnerForm` | View | Owner maintenance form shown for create and edit workflows, including error correction. |
| HTTP 200 / `isOk()` | Technical term | Successful response status used here to indicate the form was re-rendered with validation messages instead of failing with an error page. |
| JUnit | Technical term | Unit test execution framework running the method as part of the test suite. |
| Controller | Layer | Web-layer component that accepts form submissions and drives validation feedback to the user. |
