# (DD03) Business Logic — OwnerControllerTests.showOwner() [14 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `org.springframework.samples.petclinic.owner.OwnerControllerTests` |
| Layer | Test / Controller |
| Module | `owner` (Package: `org.springframework.samples.petclinic.owner`) |

## 1. Role

### OwnerControllerTests.showOwner()

This test verifies the owner detail display use case in the Petclinic owner domain. It exercises the controller endpoint that renders an owner profile page for a specific owner ID and confirms that the returned model contains the expected owner identity, contact, and pet-related information. In business terms, the method validates that a customer service representative or clinic user can open an owner record and see the owner's personal details together with at least one associated pet and visit history. The test follows an HTTP request/response verification pattern: it sends a GET request to the owner detail URL, checks for a successful response, inspects the model attribute named `owner`, and confirms that the application uses the `owners/ownerDetails` view. Because this is a controller test, it does not perform domain mutation; instead, it protects the read path for the owner inquiry screen and ensures the presentation contract stays stable.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["showOwner(ownerId)"])
    REQUEST["Perform GET request to /owners/{ownerId}"]
    STATUS_OK{"HTTP status is OK"}
    CHECK_OWNER_LAST["Assert model attribute owner.lastName = Franklin"]
    CHECK_OWNER_FIRST["Assert model attribute owner.firstName = George"]
    CHECK_OWNER_ADDRESS["Assert model attribute owner.address = 110 W. Liberty St."]
    CHECK_OWNER_CITY["Assert model attribute owner.city = Madison"]
    CHECK_OWNER_PHONE["Assert model attribute owner.telephone = 6085551023"]
    CHECK_OWNER_PETS["Assert owner.pets is not empty"]
    CHECK_OWNER_VISITS["Assert at least one pet has visits"]
    CHECK_VIEW["Assert view name is owners/ownerDetails"]
    END_NODE(["Test completes"])

    START --> REQUEST
    REQUEST --> STATUS_OK
    STATUS_OK --> CHECK_OWNER_LAST
    CHECK_OWNER_LAST --> CHECK_OWNER_FIRST
    CHECK_OWNER_FIRST --> CHECK_OWNER_ADDRESS
    CHECK_OWNER_ADDRESS --> CHECK_OWNER_CITY
    CHECK_OWNER_CITY --> CHECK_OWNER_PHONE
    CHECK_OWNER_PHONE --> CHECK_OWNER_PETS
    CHECK_OWNER_PETS --> CHECK_OWNER_VISITS
    CHECK_OWNER_VISITS --> CHECK_VIEW
    CHECK_VIEW --> END_NODE
```

**CRITICAL — Constant Resolution:**
No application constants are referenced in this test method. The assertions use literal expected values embedded in the test data.

## 3. Parameter Analysis

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

This test method does not accept parameters. It reads instance-level test fixtures and framework state instead, including `mockMvc`, the preloaded `TEST_OWNER_ID`, and the configured owner test data used by the controller test slice.

## 4. CRUD Operations / Called Services

Analyze all method calls within this method and classify each as a CRUD operation.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `mockMvc.perform(get("/owners/{ownerId}", TEST_OWNER_ID))` | N/A | Owner controller endpoint | Issues an HTTP read request for the owner detail page using the target owner identifier. |
| R | `status().isOk()` | N/A | HTTP response | Verifies the read request completed successfully with a 200 OK response. |
| R | `model().attribute("owner", hasProperty("lastName", is("Franklin")))` | N/A | Owner model | Confirms the returned owner model contains the expected last name. |
| R | `model().attribute("owner", hasProperty("firstName", is("George")))` | N/A | Owner model | Confirms the returned owner model contains the expected first name. |
| R | `model().attribute("owner", hasProperty("address", is("110 W. Liberty St.")))` | N/A | Owner model | Confirms the returned owner model contains the expected street address. |
| R | `model().attribute("owner", hasProperty("city", is("Madison")))` | N/A | Owner model | Confirms the returned owner model contains the expected city. |
| R | `model().attribute("owner", hasProperty("telephone", is("6085551023")))` | N/A | Owner model | Confirms the returned owner model contains the expected telephone number. |
| R | `model().attribute("owner", hasProperty("pets", not(empty())))` | N/A | Pet collection in owner model | Confirms the owner detail page includes at least one associated pet. |
| R | `model().attribute("owner", hasProperty("pets", hasItem(hasProperty("visits", hasSize(greaterThan(0))))))` | N/A | Pet visit collection | Confirms at least one pet has one or more visit records available for display. |
| R | `view().name("owners/ownerDetails")` | N/A | View template | Confirms the read operation routes to the owner detail view template. |

## 5. Dependency Trace

Trace who calls this method and what this method ultimately calls.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:KKSV0004 / Controller test | `OwnerControllerTests.showOwner` | `mockMvc.perform(get(...)) [R] Owner controller endpoint` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE] `(test setup and HTTP GET request)` (L217)

> Verifies that the owner details endpoint responds correctly for a known owner.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `mockMvc.perform(get("/owners/{ownerId}", TEST_OWNER_ID))` |
| 2 | CALL | `.andExpect(status().isOk())` |

**Block 2** — [SEQUENCE] `(model assertions for owner identity and contact data)` (L218-L222)

> Confirms that the controller populates the owner summary fields required by the view.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `.andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin"))))` |
| 2 | CALL | `.andExpect(model().attribute("owner", hasProperty("firstName", is("George"))))` |
| 3 | CALL | `.andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St."))))` |
| 4 | CALL | `.andExpect(model().attribute("owner", hasProperty("city", is("Madison"))))` |
| 5 | CALL | `.andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023"))))` |

**Block 3** — [SEQUENCE] `(model assertions for pet collection and visit history)` (L223-L227)

> Confirms that related pet records are available and that the page can show visit details for at least one pet.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `.andExpect(model().attribute("owner", hasProperty("pets", not(empty()))))` |
| 2 | CALL | `.andExpect(model().attribute("owner", hasProperty("pets", hasItem(hasProperty("visits", hasSize(greaterThan(0)))))))` |

**Block 4** — [SEQUENCE] `(view resolution)` (L228)

> Verifies that the correct detail view is selected for rendering.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `.andExpect(view().name("owners/ownerDetails"))` |

**Block 5** — [RETURN] `(test completion)` (L229)

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

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `mockMvc` | Technical term | Spring MVC test client used to simulate an HTTP request to the controller endpoint. |
| `ownerId` | Field | Unique identifier for the owner record being displayed. |
| `owner` | Model attribute | The owner domain object exposed to the UI for detail display. |
| `lastName` | Field | Owner family name shown on the detail page. |
| `firstName` | Field | Owner given name shown on the detail page. |
| `address` | Field | Owner street address shown for contact purposes. |
| `city` | Field | Owner city shown on the detail page. |
| `telephone` | Field | Owner contact telephone number. |
| `pets` | Field / Collection | List of pets belonging to the owner. |
| `visits` | Field / Collection | Visit records associated with a pet. |
| `ownerDetails` | View name | UI template used to render the owner detail screen. |
| `GET` | HTTP method | Read-only request used to retrieve a resource from the server. |
| `ModelAndView` | Technical term | Spring MVC return object that combines model data with a view name. |
| `Petclinic` | Application name | Sample veterinary clinic domain application used to demonstrate CRUD-style owner and pet management. |
