# (DD50) Business Logic — ProcessCreationFormHasErrors.processCreationFormWithBlankName() [12 LOC]

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

## 1. Role

### ProcessCreationFormHasErrors.processCreationFormWithBlankName()

This test method validates the pet creation screen behavior when a user submits a blank pet name while creating a new pet for an existing owner. Its business purpose is to confirm that the web layer rejects empty or whitespace-only names, preserves the owner context, and returns the user to the pet form with a field-level validation error. In functional terms, it exercises the “create pet” flow at the point where form validation must protect data quality before persistence occurs.

The method acts as a controller acceptance test rather than a business service. It dispatches a POST request to the pet creation endpoint, submits a valid birth date, and intentionally leaves the name field blank by sending only whitespace. The test then verifies that the owner aggregate does not receive validation errors, the pet form object does receive validation errors, the `name` field specifically reports the `required` validation code, and the response remains on the same creation form view with HTTP 200 OK. This establishes that the application follows a validation-first, user-correction pattern instead of attempting to create an invalid pet record.

In the larger system, this test protects the integrity of the owner/pet CRUD flow by ensuring that the controller, form binding, and Bean Validation integration are aligned. It is part of a shared regression suite for the web layer and specifically guards against accidental changes that would let blank pet names pass through the creation process.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["processCreationFormWithBlankName()"])
    BUILD_REQUEST(["Build POST request to /owners/{ownerId}/pets/new with whitespace-only name and birthDate"])
    PERFORM_REQUEST(["Execute MockMvc.perform(post(...))"])
    ASSERT_OWNER(["Assert model attribute owner has no errors"])
    ASSERT_PET_ERRORS(["Assert model attribute pet has errors"])
    ASSERT_NAME_ERROR(["Assert pet.name has field error"])
    ASSERT_REQUIRED_CODE(["Assert pet.name error code equals required"])
    ASSERT_STATUS(["Assert HTTP status is 200 OK"])
    ASSERT_VIEW(["Assert view name is pets/createOrUpdatePetForm"])
    END_NODE(["Test completes"])

    START --> BUILD_REQUEST
    BUILD_REQUEST --> PERFORM_REQUEST
    PERFORM_REQUEST --> ASSERT_OWNER
    ASSERT_OWNER --> ASSERT_PET_ERRORS
    ASSERT_PET_ERRORS --> ASSERT_NAME_ERROR
    ASSERT_NAME_ERROR --> ASSERT_REQUIRED_CODE
    ASSERT_REQUIRED_CODE --> ASSERT_STATUS
    ASSERT_STATUS --> ASSERT_VIEW
    ASSERT_VIEW --> END_NODE
```

## 3. Parameter Analysis

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

External state read by the method:
- `TEST_OWNER_ID` — identifies the owner whose pet creation form is being validated.
- The MockMvc test fixture and Spring MVC request mapping configured for the pet creation endpoint.
- The Bean Validation rules attached to the pet form model, especially the required-name constraint.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|-----------------------|
| R | `MockMvc.perform(post("/owners/{ownerId}/pets/new"...))` | N/A | `Owner`, `Pet` form model | Submits a create request into the controller layer so validation can be evaluated before any persistence step. |
| R | `model().attributeHasNoErrors("owner")` | N/A | `Owner` | Reads the owner form binding result and confirms no owner-level validation failures occurred. |
| R | `model().attributeHasErrors("pet")` | N/A | `Pet` | Reads the pet binding result and confirms validation rejected the submitted form. |
| R | `model().attributeHasFieldErrors("pet", "name")` | N/A | `Pet.name` | Reads the field-level validation outcome for the pet name input. |
| R | `model().attributeHasFieldErrorCode("pet", "name", "required")` | N/A | `Pet.name` | Reads the exact validation code emitted for the blank-name failure. |
| R | `status().isOk()` | N/A | HTTP response | Reads the response status to confirm the controller returned a normal form-rendering result instead of a redirect or error response. |
| R | `view().name("pets/createOrUpdatePetForm")` | N/A | View template | Reads the rendered view name to confirm the user is returned to the pet creation form. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen: `PetControllerTests` | `PetControllerTests.processCreationFormWithBlankName()` | `MockMvc.perform(...) [R] Pet form binding` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE] `(test setup and request execution)` (L107-L118)

> This block validates the negative path for pet creation when the name is blank or whitespace-only.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `mockMvc.perform(post("/owners/{ownerId}/pets/new", TEST_OWNER_ID).param("name", "\t 
").param("birthDate", "2015-02-12"))` // Send a create-pet request with blank name input |
| 2 | EXEC | `.andExpect(model().attributeHasNoErrors("owner"))` // Confirm the owner model remains valid |
| 3 | EXEC | `.andExpect(model().attributeHasErrors("pet"))` // Confirm the pet model is rejected |
| 4 | EXEC | `.andExpect(model().attributeHasFieldErrors("pet", "name"))` // Confirm the name field is the source of the validation error |
| 5 | EXEC | `.andExpect(model().attributeHasFieldErrorCode("pet", "name", "required"))` // Confirm the validation rule is the required-name rule |
| 6 | EXEC | `.andExpect(status().isOk())` // Confirm the controller re-renders the form instead of redirecting |
| 7 | EXEC | `.andExpect(view().name("pets/createOrUpdatePetForm"))` // Confirm the original pet form is shown again |
| 8 | RETURN | `void` // Test method completes with no returned value |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `TEST_OWNER_ID` | Field | Identifier of the owner used to drive the pet creation scenario. |
| `MockMvc` | Technical term | Spring MVC test harness used to simulate HTTP requests against the controller layer. |
| `owner` | Domain model | The owner aggregate whose existing data must remain valid during pet creation. |
| `pet` | Domain model | The pet form/model being validated in the create flow. |
| `birthDate` | Field | Pet date of birth submitted along with the form. |
| `name` | Field | Pet name entered by the user; must not be blank. |
| `required` | Validation code | Bean Validation error code emitted when a mandatory field is empty or whitespace-only. |
| `pets/createOrUpdatePetForm` | View name | Thymeleaf form used to create or edit a pet. |
| CRUD | Acronym | Create, Read, Update, Delete — standard lifecycle operations for business data. |
| Bean Validation | Technical term | JSR 380 validation mechanism used to enforce form-field constraints before persistence. |
| POST | HTTP method | Web request method used to submit form data for server-side processing. |
