# (DD06) Business Logic — OwnerControllerTests.initUpdateOwnerForm() [12 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.initUpdateOwnerForm()

This test verifies the read-path behavior of the owner edit screen entry point. It performs a business-level validation that the owner update form is reachable through the `/owners/{ownerId}/edit` URL and that the controller responds with the expected HTTP status, view name, and pre-populated owner profile data. The method does not mutate business state; instead, it asserts that the controller correctly exposes the existing owner record for editing, which is a standard CRUD update workflow for the Owner domain.

From a testing-pattern perspective, the method implements a UI contract test around request routing, model population, and view resolution. It confirms that the controller returns the owner form view and that the model contains the correct owner identity and contact attributes used by the screen. In the larger system, this test protects the update-owner user journey by ensuring that the edit action continues to serve the same business form with stable field values for an existing owner.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["initUpdateOwnerForm() test"])
    STEP1(["Send GET request to /owners/{ownerId}/edit using TEST_OWNER_ID"])
    STEP2(["Expect HTTP status 200 OK"])
    STEP3(["Verify model contains owner attribute"])
    STEP4(["Verify owner.lastName equals Franklin"])
    STEP5(["Verify owner.firstName equals George"])
    STEP6(["Verify owner.address equals 110 W. Liberty St."])
    STEP7(["Verify owner.city equals Madison"])
    STEP8(["Verify owner.telephone equals 6085551023"])
    STEP9(["Verify view name is owners/createOrUpdateOwnerForm"])
    END_NODE(["Test completes"])

    START --> STEP1
    STEP1 --> STEP2
    STEP2 --> STEP3
    STEP3 --> STEP4
    STEP4 --> STEP5
    STEP5 --> STEP6
    STEP6 --> STEP7
    STEP7 --> STEP8
    STEP8 --> STEP9
    STEP9 --> END_NODE
```

## 3. Parameter Analysis

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

Instance fields and external state used by the test:

- `mockMvc`: Spring MVC test harness used to simulate the owner edit request and inspect the controller response.
- `TEST_OWNER_ID`: Test fixture owner identifier that selects the owner record for the update form scenario.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `mockMvc.perform(get("/owners/{ownerId}/edit", TEST_OWNER_ID))` | N/A | Owner screen model | Reads the owner edit page by simulating an HTTP GET request to the controller entry point |
| R | `status().isOk()` | N/A | HTTP response | Verifies that the controller returns a successful response for the read-only edit form request |
| R | `model().attributeExists("owner")` | N/A | Owner model attribute | Confirms that the response model contains the owner record required by the edit form |
| R | `model().attribute("owner", hasProperty(...))` | N/A | Owner model attribute | Verifies that the returned owner data contains the expected persisted profile values |
| R | `view().name("owners/createOrUpdateOwnerForm")` | N/A | View template | Confirms that the request resolves to the owner create-or-update form view |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:Owner edit flow | `OwnerController.initUpdateOwnerForm` -> `OwnerControllerTests.initUpdateOwnerForm` | `GET /owners/{ownerId}/edit [R] Owner model` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENTIAL] `(test setup and request execution)` (L171-L181)

> This block validates the update-owner entry screen through a single GET request and a sequence of response assertions.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `mockMvc.perform(get("/owners/{ownerId}/edit", TEST_OWNER_ID))` |
| 2 | CALL | `.andExpect(status().isOk())` |
| 3 | CALL | `.andExpect(model().attributeExists("owner"))` |
| 4 | CALL | `.andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin"))))` |
| 5 | CALL | `.andExpect(model().attribute("owner", hasProperty("firstName", is("George"))))` |
| 6 | CALL | `.andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St."))))` |
| 7 | CALL | `.andExpect(model().attribute("owner", hasProperty("city", is("Madison"))))` |
| 8 | CALL | `.andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023"))))` |
| 9 | CALL | `.andExpect(view().name("owners/createOrUpdateOwnerForm"))` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `Owner` | Domain entity | A pet owner record in the Petclinic system, including identity and contact details |
| `owner` | Model attribute | The owner data object placed into the MVC model for rendering the edit form |
| `ownerId` | Path variable / identifier | The unique identifier used to locate the owner whose profile is being edited |
| `TEST_OWNER_ID` | Test fixture | Predefined owner identifier used by the test to target a known owner record |
| `lastName` | Field | Owner family name shown on the edit form |
| `firstName` | Field | Owner given name shown on the edit form |
| `address` | Field | Mailing address associated with the owner profile |
| `city` | Field | City portion of the owner mailing address |
| `telephone` | Field | Contact phone number displayed and edited in the owner form |
| `mockMvc` | Technical term | Spring MVC test client used to simulate web requests without starting a full server |
| `GET` | HTTP method | Read-only web request used to retrieve the owner edit form |
| `CRUD` | Acronym | Create, Read, Update, Delete — standard data operation categories |
| `view` | MVC term | The rendered UI template returned to the browser |
| `owners/createOrUpdateOwnerForm` | View name | Screen template used for both creating and updating owner records |
