# (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 negative path of the owner creation workflow in the Petclinic owner management screen. It submits a POST request to `/owners/new` using a deliberately incomplete owner profile: first name, last name, and city are provided, but the form omits the owner address and telephone number. The business purpose of the test is to confirm that the controller rejects an incomplete registration request and redisplays the owner entry form instead of allowing the creation flow to continue.

From a domain perspective, the method validates that mandatory customer master data is enforced before a new owner record can be accepted into the system. This is an input-validation test rather than a data-processing routine, and it exercises the controller's form-binding and Bean Validation behavior. The test represents a standard request/response assertion pattern in Spring MVC: send a form submission, let validation execute, and inspect the model and view returned by the controller. Its role in the larger system is to protect the owner onboarding process from invalid registrations and to ensure the user receives the same maintenance screen with field-level error feedback.

The method has one effective business branch: when validation fails, the controller must keep the user on `owners/createOrUpdateOwnerForm` and expose errors on the `owner` model attribute, specifically for `address` and `telephone`. There is no successful-create branch in this method; that path is covered by other tests. This method therefore documents and guards the error-handling behavior of the owner creation screen.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["processCreationFormHasErrors()"])
    REQ(["Send POST /owners/new with firstName=Joe, lastName=Bloggs, city=London"])
    BIND(["Spring MVC binds request parameters to Owner form object"])
    VALIDATE(["Bean Validation checks required address and telephone fields"])
    ERRORS{"Binding result has validation errors?"}
    ERRORS_YES(["Yes - owner form is invalid"])
    ASSERT_MODEL_ERRORS(["Assert model contains errors for owner"])
    ASSERT_ADDRESS(["Assert field error on address"])
    ASSERT_TELEPHONE(["Assert field error on telephone"])
    ASSERT_VIEW(["Assert returned view is owners/createOrUpdateOwnerForm"])
    END_NODE(["Return / Next"])

    START --> REQ
    REQ --> BIND
    BIND --> VALIDATE
    VALIDATE --> ERRORS
    ERRORS -->|"Yes"| ERRORS_YES
    ERRORS_YES --> ASSERT_MODEL_ERRORS
    ASSERT_MODEL_ERRORS --> ASSERT_ADDRESS
    ASSERT_ADDRESS --> ASSERT_TELEPHONE
    ASSERT_TELEPHONE --> ASSERT_VIEW
    ASSERT_VIEW --> END_NODE
```

## 3. Parameter Analysis

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

This method does not declare any parameters. It relies on local test setup through `mockMvc` and externally defined Spring MVC validation rules. The method reads the following instance state: the `mockMvc` test fixture configured for the owner controller test slice.

## 4. CRUD Operations / Called Services

The method is a test harness for controller validation behavior and does not directly invoke repository or service CRUD methods. Its only observable operations are framework-level request execution and response assertions.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|-----------------------|
| R | `mockMvc.perform` | Spring MVC Test | HTTP request / response | Submits the owner creation request to exercise the controller's validation path |
| R | `andExpect(status().isOk())` | Spring MVC Test | HTTP status | Verifies the controller returns a successful response while redisplaying the form |
| R | `andExpect(model().attributeHasErrors("owner"))` | Spring MVC Test | Model attribute `owner` | Verifies the form model contains validation errors |
| R | `andExpect(model().attributeHasFieldErrors("owner", "address"))` | Spring MVC Test | Model field `address` | Verifies the address field is rejected by validation |
| R | `andExpect(model().attributeHasFieldErrors("owner", "telephone"))` | Spring MVC Test | Model field `telephone` | Verifies the telephone field is rejected by validation |
| R | `andExpect(view().name("owners/createOrUpdateOwnerForm"))` | Spring MVC Test | View `owners/createOrUpdateOwnerForm` | Verifies the validation failure returns the owner maintenance form |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Test: `OwnerControllerTests` | `OwnerControllerTests.processCreationFormHasErrors()` | `Spring MVC Test assertions [R] HTTP response and model` |

This method is a JUnit test entry point, so there are no business callers in the application flow. It is invoked by the test runner as part of the `OwnerControllerTests` class execution. The method itself does not call downstream business services; instead, it verifies controller behavior through MockMvc and response matchers.

## 6. Per-Branch Detail Blocks

**Block 1** — **EXEC** `(build POST request and perform controller submission)` (L124)
> Submits the invalid owner creation form to the controller under test.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `mockMvc.perform(post("/owners/new").param("firstName", "Joe").param("lastName", "Bloggs").param("city", "London"))` // submit incomplete owner registration form |

**Block 2** — **EXEC** `(assert HTTP response status)` (L125)
> Confirms the controller accepts the request but does not complete creation.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `.andExpect(status().isOk())` // expect normal form redisplay after validation failure |

**Block 3** — **EXEC** `(assert model contains validation errors)` (L126-L127)
> Verifies that the owner model object is flagged as invalid.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `.andExpect(model().attributeHasErrors("owner"))` // owner form must contain validation errors |
| 2 | CALL | `.andExpect(model().attributeHasFieldErrors("owner", "address"))` // address must be rejected |
| 3 | CALL | `.andExpect(model().attributeHasFieldErrors("owner", "telephone"))` // telephone must be rejected |

**Block 4** — **EXEC** `(assert validation failure view)` (L128)
> Confirms the user is returned to the owner maintenance screen for correction.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `.andExpect(view().name("owners/createOrUpdateOwnerForm"))` // redisplay the create or update owner form |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `mockMvc` | Technical term | Spring MVC test harness used to simulate HTTP requests and verify controller responses |
| `POST /owners/new` | Endpoint | Owner creation submission endpoint used to register a new owner record |
| `owner` | Domain object | Owner form-backed model attribute representing the person being registered in Petclinic |
| `address` | Field | Owner mailing/contact address; required data for owner registration |
| `telephone` | Field | Owner contact telephone number; required data for owner registration |
| `owners/createOrUpdateOwnerForm` | View | Owner maintenance page used to display validation errors and allow corrections |
| `Bean Validation` | Framework term | Declarative validation mechanism that checks required fields and form constraints |
| `Model` | Technical term | Spring MVC container that carries form data and validation errors to the view |
| `JUnit` | Framework term | Unit test framework executing the test method |
| `Spring MVC` | Framework term | Web framework handling request binding, validation, and view rendering |
