---
# (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 update-owner entry point from the perspective of the web layer. It confirms that a GET request to `/owners/{ownerId}/edit` returns the owner maintenance form used for editing an existing owner record. The business expectation is that the user is routed to the same owner creation/update screen that supports both initial registration and subsequent correction of owner information. The assertions validate that the page is opened successfully, that the model contains the `owner` object, and that the object is pre-populated with the persisted owner’s identity and contact details. In other words, this test safeguards the edit-screen contract: the controller must expose the correct view and preserve the current owner profile data for review and modification. The method itself is a routing-oriented integration test and does not transform domain data; it functions as a regression guard for the update form display workflow.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["initUpdateOwnerForm() test"])
    REQUEST(["Perform GET /owners/{ownerId}/edit with TEST_OWNER_ID"])
    STATUS(["Assert HTTP status is 200 OK"])
    MODEL(["Assert model contains owner attribute"])
    LAST_NAME(["Assert owner.lastName = Franklin"])
    FIRST_NAME(["Assert owner.firstName = George"])
    ADDRESS(["Assert owner.address = 110 W. Liberty St."])
    CITY(["Assert owner.city = Madison"])
    TELEPHONE(["Assert owner.telephone = 6085551023"])
    VIEW(["Assert view = owners/createOrUpdateOwnerForm"])
    END_NODE(["End"])

    START --> REQUEST
    REQUEST --> STATUS
    STATUS --> MODEL
    MODEL --> LAST_NAME
    LAST_NAME --> FIRST_NAME
    FIRST_NAME --> ADDRESS
    ADDRESS --> CITY
    CITY --> TELEPHONE
    TELEPHONE --> VIEW
    VIEW --> END_NODE
```

## 3. Parameter Analysis

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

External state used by this test:
- `TEST_OWNER_ID` - the owner identifier used to target the edit screen for a specific existing customer record.
- MockMvc response state - the test inspects HTTP status, model attributes, and resolved view name.
- Persisted owner fixture data - the assertions depend on an owner already stored with the expected name, address, city, and telephone values.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `get("/owners/{ownerId}/edit")` via MVC test | N/A | `Owner` view model | Reads the edit form for an existing owner and verifies the controller returns the current owner profile for display. |

The method under test does not invoke application service components directly. Its only observable business dependency is the controller endpoint that loads the owner edit form.

## 5. Dependency Trace

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

The only caller found in the codebase is the test itself, which drives the controller endpoint through MockMvc. The test is therefore a web-layer verification entry point rather than a downstream business caller.

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE] `(MockMvc request and assertions)` (L171-L177)

> This block covers the single linear verification path executed by the test.

| # | 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"))` |

**Block 2** — [END] `(successful web-layer verification)` (L178)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `void` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|-------------------|
| `owner` | Field / Model attribute | The owner profile displayed and edited in the pet clinic application. |
| `ownerId` | Field | Unique identifier for an existing owner record. |
| `TEST_OWNER_ID` | Test constant | Predefined owner identifier used to target a known persisted owner fixture. |
| `lastName` | Field | Owner family name shown on the edit form. |
| `firstName` | Field | Owner given name shown on the edit form. |
| `address` | Field | Owner street address shown on the edit form. |
| `city` | Field | Owner city of residence shown on the edit form. |
| `telephone` | Field | Owner contact number shown on the edit form. |
| `MockMvc` | Technical term | Spring test utility used to simulate HTTP requests against the web layer. |
| `Model` | Technical term | Container holding data made available to the view template. |
| `owners/createOrUpdateOwnerForm` | View | Shared owner maintenance screen used for both creating and updating owner records. |
| `HTTP GET` | Protocol term | Read-only web request used to fetch the edit form page. |
| `owner maintenance form` | Business term | User interface used to review and modify owner master data. |
