# (DD03) Business Logic — OwnerControllerTests.showOwner() [14 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.showOwner()

This test method verifies the business-facing behavior of the owner detail display endpoint in the PetClinic owner management flow. In domain terms, it confirms that requesting an owner profile by identifier returns the expected owner record, renders the owner details screen, and exposes the correct customer-facing attributes such as name, address, contact number, and associated pet list. The method does not perform business processing itself; instead, it validates that the controller’s read-only lookup path correctly supports the “view owner profile” use case end to end.

The test represents a presentation-layer acceptance check for the owner inquiry feature. It ensures that the controller behaves as a routing/dispatch entry point from the `/owners/{ownerId}` URL to the `owners/ownerDetails` view and that the model contains a fully populated owner aggregate suitable for UI rendering. Because the method is a test, it validates the read branch only; there are no update, create, or delete branches inside this method. Its role in the larger system is to safeguard the user experience for owner lookup and to prevent regressions in the model-to-view contract.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START["showOwner() test"]
    A["Perform GET /owners/{ownerId} using TEST_OWNER_ID"]
    B["Expect HTTP 200 OK"]
    C["Assert model contains owner.lastName = Franklin"]
    D["Assert model contains owner.firstName = George"]
    E["Assert model contains owner.address = 110 W. Liberty St."]
    F["Assert model contains owner.city = Madison"]
    G["Assert model contains owner.telephone = 6085551023"]
    H["Assert owner.pets is not empty"]
    I["Assert at least one pet has visits with size greater than 0"]
    J["Assert view name = owners/ownerDetails"]
    END_NODE["Test completed"]
    START --> A
    A --> B
    B --> C
    C --> D
    D --> E
    E --> F
    F --> G
    G --> H
    H --> I
    I --> J
    J --> END_NODE
```

## 3. Parameter Analysis

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

External state read by the method:
- `mockMvc` — the configured MVC test client used to invoke the controller endpoint.
- `TEST_OWNER_ID` — the owner identifier used as the lookup key for the read-only request.
- The test fixture data behind the owner repository, which must contain the expected owner profile and associated pets/visits for the assertions to pass.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `owners.findById(ownerId)` | N/A | `Owner` | Reads the owner record by primary key so the details page can be rendered with the correct customer profile and pet associations. |

The method under documentation is a test, so its only direct business dependency is the controller’s read path. The actual read operation is executed by `OwnerController.showOwner(int ownerId)`, which calls the `owners.findById(ownerId)` repository lookup. No create, update, or delete business action is triggered by this test method.

## 5. Dependency Trace

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

The only caller context that can be confirmed from the code is the MVC route `/owners/{ownerId}` exercised through the controller’s show-owner handler. This test method itself is an assertion harness and does not initiate additional downstream application services.

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE] `(display owner details test flow)` (L217–229)

> Validates that the owner detail endpoint returns the correct view and model content for the selected owner ID.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `mockMvc.perform(get("/owners/{ownerId}", TEST_OWNER_ID));` // issue HTTP GET request against the owner detail route |
| 2 | EXEC | `.andExpect(status().isOk());` // verify the response succeeds |
| 3 | EXEC | `.andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin"))));` // verify owner last name |
| 4 | EXEC | `.andExpect(model().attribute("owner", hasProperty("firstName", is("George"))));` // verify owner first name |
| 5 | EXEC | `.andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St."))));` // verify street address |
| 6 | EXEC | `.andExpect(model().attribute("owner", hasProperty("city", is("Madison"))));` // verify city |
| 7 | EXEC | `.andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023"))));` // verify telephone |
| 8 | EXEC | `.andExpect(model().attribute("owner", hasProperty("pets", not(empty()))));` // verify owner has at least one pet |
| 9 | EXEC | `.andExpect(model().attribute("owner", hasProperty("pets", hasItem(hasProperty("visits", hasSize(greaterThan(0)))))));` // verify at least one pet has visit history |
| 10 | EXEC | `.andExpect(view().name("owners/ownerDetails"));` // verify the owner details view is rendered |
| 11 | RETURN | `void` // test ends after all expectations pass |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `Owner` | Domain entity | Pet owner master record containing identity and contact details used in the clinic system. |
| `ownerId` | Field | Unique owner identifier used to locate a specific customer record. |
| `lastName` | Field | Owner family name displayed in the owner profile. |
| `firstName` | Field | Owner given name displayed in the owner profile. |
| `address` | Field | Owner street address used for contact and correspondence. |
| `city` | Field | Owner city used for the contact profile. |
| `telephone` | Field | Owner phone number used for contact communication. |
| `pets` | Field/Collection | Set of pets belonging to the owner; displayed on the owner details page. |
| `visits` | Field/Collection | Medical visit history associated with a pet. |
| `mockMvc` | Technical component | Spring MVC test harness used to simulate HTTP requests against controller endpoints. |
| `GET` | HTTP method | Read-only web request used to retrieve the owner detail screen. |
| `ModelAndView` | Technical component | MVC return object that carries both model data and the target view name. |
| `owners/ownerDetails` | View name | UI page that renders the owner profile and related pets. |
| `Franklin` | Test data value | Expected owner last name in the fixture data. |
| `George` | Test data value | Expected owner first name in the fixture data. |
| `110 W. Liberty St.` | Test data value | Expected street address in the fixture data. |
| `Madison` | Test data value | Expected city in the fixture data. |
| `6085551023` | Test data value | Expected telephone number in the fixture data. |
