# (DD14) 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 verifies the owner detail display path for the Petclinic owner management screen. It exercises the HTTP GET request to `/owners/{ownerId}` and confirms that the application returns the expected owner detail view with the correct business profile data populated into the model. The method acts as a behavioral contract for the owner inquiry flow, ensuring that the controller can retrieve an existing owner and render a stable presentation for the UI.

From a business perspective, the test validates a read-only customer master inquiry scenario: the owner’s name, address, phone number, pet collection, and visit history are all expected to be available in the returned model. The method does not branch into multiple business service types itself; instead, it asserts the output of the controller’s display routing and object population behavior. In the larger system, this test serves as a regression guard for the owner detail screen and the controller-to-repository lookup chain behind it.

## 2. Processing Pattern (Detailed Business Logic)

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

    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) | - | This test method is parameterless. It validates the owner detail retrieval flow using test fixtures and framework-managed request execution rather than explicit inputs. |

Instance fields and external state read by the method:
- `mockMvc` — test HTTP client used to execute the GET request and validate the response.
- `TEST_OWNER_ID` — fixture owner identifier used to target the owner record under test.
- Static matcher infrastructure from Spring Test and Hamcrest — used to assert response status, model attributes, and view selection.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `mockMvc.perform(get("/owners/{ownerId}", TEST_OWNER_ID))` | N/A | Owner detail endpoint / controller model | Executes a read-style HTTP request that retrieves an owner detail page for the specified owner identifier. |
| R | `status().isOk()` | N/A | HTTP response | Verifies that the owner inquiry completed successfully and returned a normal response. |
| R | `model().attribute("owner", ...)` | N/A | `Owner` model object | Confirms that the returned model contains the expected owner master data and nested pet information. |
| R | `view().name("owners/ownerDetails")` | N/A | View template `owners/ownerDetails` | Verifies that the controller routed to the owner detail presentation page. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Controller test runner / JUnit | `OwnerControllerTests.showOwner()` | `mockMvc.perform(get("/owners/{ownerId}", TEST_OWNER_ID)) [R] Owner detail endpoint` |
| 2 | Screen: owner detail request | `HTTP GET /owners/{ownerId}` -> `OwnerController.showOwner(int)` -> `owners.findById(ownerId)` | `findById [R] Owner` |

## 6. Per-Branch Detail Blocks

**Block 1** — SEQUENCE `(test assertion chain)` (L217-L228)

> This block validates the owner detail response end-to-end through the controller’s public web contract.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `mockMvc.perform(get("/owners/{ownerId}", TEST_OWNER_ID))` // execute the GET request for the target owner |
| 2 | CALL | `.andExpect(status().isOk())` // verify the response status is successful |
| 3 | CALL | `.andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin"))))` // verify owner last name |
| 4 | CALL | `.andExpect(model().attribute("owner", hasProperty("firstName", is("George"))))` // verify owner first name |
| 5 | CALL | `.andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St."))))` // verify owner address |
| 6 | CALL | `.andExpect(model().attribute("owner", hasProperty("city", is("Madison"))))` // verify owner city |
| 7 | CALL | `.andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023"))))` // verify owner telephone |
| 8 | CALL | `.andExpect(model().attribute("owner", hasProperty("pets", not(empty()))))` // verify the owner has at least one pet |
| 9 | CALL | `.andExpect(model().attribute("owner", hasProperty("pets", hasItem(hasProperty("visits", hasSize(greaterThan(0)))))))` // verify at least one pet has visit history |
| 10 | CALL | `.andExpect(view().name("owners/ownerDetails"))` // verify the owner detail view is rendered |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `mockMvc` | Test tool | Spring MVC test client used to simulate browser requests against the controller without starting a full web server. |
| `TEST_OWNER_ID` | Test fixture | Predefined owner identifier used to target a specific owner record in the test dataset. |
| `owner` | Model attribute | The owner master record returned by the controller and exposed to the view layer. |
| `ownerDetails` | View name | Owner detail presentation page that shows the selected owner and related pet information. |
| `pets` | Business collection | The set of pets associated with the owner. |
| `visits` | Business collection | The set of medical or service visits associated with a pet. |
| GET | HTTP method | Read-only web request used to retrieve a resource without modifying data. |
| JUnit | Test framework | Unit and integration test framework used to execute the verification method. |
| Spring MVC | Web framework | Framework that routes HTTP requests to controllers and binds model data for rendering. |
| Hamcrest | Assertion library | Matcher library used to express readable expectations about response contents. |
| `OwnerController.showOwner(int)` | Controller method | Web handler that loads a single owner and returns the owner detail page. |
| `findById` | Repository operation | Read operation that looks up an owner record by its identifier. |
