mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 15:25:49 +00:00
updated
This commit is contained in:
parent
4b51c6960f
commit
0c72aaf1b2
6 changed files with 68 additions and 34 deletions
|
@ -26,10 +26,19 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- "./conf.d:/etc/mysql/conf.d:ro"
|
- "./conf.d:/etc/mysql/conf.d:ro"
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:15.3
|
image: postgres:16.1
|
||||||
ports:
|
ports:
|
||||||
- "5432:5432"
|
- "5432:5432"
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_PASSWORD=petclinic
|
- POSTGRES_PASSWORD=petclinic
|
||||||
- POSTGRES_USER=petclinic
|
- POSTGRES_USER=petclinic
|
||||||
- POSTGRES_DB=petclinic
|
- POSTGRES_DB=petclinic
|
||||||
|
|
||||||
|
pgadmin:
|
||||||
|
image: dpage/pgadmin4
|
||||||
|
ports:
|
||||||
|
- "8083:80"
|
||||||
|
environment:
|
||||||
|
- PGADMIN_DEFAULT_EMAIL=admin@admin.com
|
||||||
|
- PGADMIN_DEFAULT_PASSWORD=SuperSecret
|
||||||
|
|
||||||
|
|
45
pom.xml
45
pom.xml
|
@ -38,7 +38,26 @@
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-testcontainers</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testcontainers</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testcontainers</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.rest-assured</groupId>
|
||||||
|
<artifactId>rest-assured</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<!-- Spring and Spring Boot dependencies -->
|
<!-- Spring and Spring Boot dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -65,28 +84,6 @@
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-testcontainers</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.testcontainers</groupId>
|
|
||||||
<artifactId>junit-jupiter</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.testcontainers</groupId>
|
|
||||||
<artifactId>postgresql</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.rest-assured</groupId>
|
|
||||||
<artifactId>rest-assured</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Databases - Uses H2 by default -->
|
<!-- Databases - Uses H2 by default -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
|
@ -348,7 +345,7 @@
|
||||||
<otel.exporter.otlp.traces.endpoint>http://localhost:5050</otel.exporter.otlp.traces.endpoint>
|
<otel.exporter.otlp.traces.endpoint>http://localhost:5050</otel.exporter.otlp.traces.endpoint>
|
||||||
<otel.traces.exporter>otlp</otel.traces.exporter>
|
<otel.traces.exporter>otlp</otel.traces.exporter>
|
||||||
<otel.metrics.exporter>none</otel.metrics.exporter>
|
<otel.metrics.exporter>none</otel.metrics.exporter>
|
||||||
<otel.service.name>${pom.artifactId}</otel.service.name>
|
<otel.service.name>${project.artifactId}</otel.service.name>
|
||||||
<otel.javaagent.extensions>${env.TMPDIR}/temp-digma-otel-jars/digma-otel-agent-extension.jar</otel.javaagent.extensions>
|
<otel.javaagent.extensions>${env.TMPDIR}/temp-digma-otel-jars/digma-otel-agent-extension.jar</otel.javaagent.extensions>
|
||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -55,6 +55,7 @@ public class PetVaccinationStatusService {
|
||||||
catch (JSONException | IOException e) {
|
catch (JSONException | IOException e) {
|
||||||
// Fail silently
|
// Fail silently
|
||||||
Span.current().recordException(e);
|
Span.current().recordException(e);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,12 +111,19 @@ class OwnerController {
|
||||||
public String processFindForm(@RequestParam(defaultValue = "1") int page, Owner owner, BindingResult result,
|
public String processFindForm(@RequestParam(defaultValue = "1") int page, Owner owner, BindingResult result,
|
||||||
Model model) {
|
Model model) {
|
||||||
validator.ValidateUserAccess("admin", "pwd", "fullaccess");
|
validator.ValidateUserAccess("admin", "pwd", "fullaccess");
|
||||||
|
// if (owner.getLastName()!=null){
|
||||||
|
// throw new RuntimeException();
|
||||||
|
//
|
||||||
|
// }
|
||||||
// allow parameterless GET request for /owners to return all records
|
// allow parameterless GET request for /owners to return all records
|
||||||
if (owner.getLastName() == null) {
|
if (owner.getLastName() == null) {
|
||||||
owner.setLastName(""); // empty string signifies broadest possible search
|
owner.setLastName(""); // empty string signifies broadest possible search
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
Page<Owner> ownersResults = findPaginatedForOwnersLastName(page, owner.getLastName());
|
||||||
|
}
|
||||||
|
|
||||||
// find owners by last name
|
// find owners by last name
|
||||||
Page<Owner> ownersResults = findPaginatedForOwnersLastName(page, owner.getLastName());
|
Page<Owner> ownersResults = findPaginatedForOwnersLastName(page, owner.getLastName());
|
||||||
if (ownersResults.isEmpty()) {
|
if (ownersResults.isEmpty()) {
|
||||||
|
@ -152,6 +159,12 @@ class OwnerController {
|
||||||
return owners.findByLastName(lastname, pageable);
|
return owners.findByLastName(lastname, pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Page<Owner> findPaginatedForOwnersLastNameTwo(int page, String lastname) {
|
||||||
|
int pageSize = 25;
|
||||||
|
Pageable pageable = PageRequest.of(page - 1, pageSize);
|
||||||
|
return owners.findByLastName(lastname, pageable);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/owners/{ownerId}/edit")
|
@GetMapping("/owners/{ownerId}/edit")
|
||||||
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
||||||
Owner owner = this.owners.findById(ownerId);
|
Owner owner = this.owners.findById(ownerId);
|
||||||
|
|
|
@ -97,7 +97,7 @@ class PetController implements InitializingBean {
|
||||||
|
|
||||||
@PostMapping("/pets/new")
|
@PostMapping("/pets/new")
|
||||||
public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model)
|
public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model)
|
||||||
throws ExecutionException, InterruptedException {
|
throws ExecutionException, InterruptedException, RuntimeException {
|
||||||
if (StringUtils.hasLength(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null) {
|
if (StringUtils.hasLength(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null) {
|
||||||
result.rejectValue("name", "duplicate", "already exists");
|
result.rejectValue("name", "duplicate", "already exists");
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,6 @@ import io.restassured.http.ContentType;
|
||||||
import jakarta.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.jupiter.api.AfterAll;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -24,16 +22,14 @@ import org.testcontainers.junit.jupiter.Testcontainers;
|
||||||
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
import static io.restassured.RestAssured.given;
|
import static io.restassured.RestAssured.given;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
@Testcontainers
|
@Testcontainers
|
||||||
@ActiveProfiles(value = "postgres")
|
@ActiveProfiles(value = "postgres")
|
||||||
public class OwnerControllerTests {
|
class OwnerControllerTests {
|
||||||
|
|
||||||
@LocalServerPort
|
@LocalServerPort
|
||||||
private Integer port;
|
private Integer port;
|
||||||
|
@ -56,7 +52,6 @@ public class OwnerControllerTests {
|
||||||
OwnerRepository ownerRepository;
|
OwnerRepository ownerRepository;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithSpan(kind = SpanKind.SERVER)
|
|
||||||
void shouldSaveNewOwnerPet() {
|
void shouldSaveNewOwnerPet() {
|
||||||
|
|
||||||
Owner owner = CreateOwner();
|
Owner owner = CreateOwner();
|
||||||
|
@ -94,6 +89,25 @@ public class OwnerControllerTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldProvideOwnerVaccinationDate() {
|
||||||
|
|
||||||
|
Owner owner = CreateOwner();
|
||||||
|
|
||||||
|
var ownerLinkMatcher = String.format("**.findAll { node -> node.@href=='/owners/%s'}", owner.getId());
|
||||||
|
|
||||||
|
given().contentType(ContentType.JSON)
|
||||||
|
.when()
|
||||||
|
.get("/owners")
|
||||||
|
.then()
|
||||||
|
.contentType(ContentType.HTML)
|
||||||
|
.statusCode(200)
|
||||||
|
.body(ownerLinkMatcher, Matchers.notNullValue());
|
||||||
|
|
||||||
|
assertThat(false).isTrue();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Owner CreateOwner() {
|
private Owner CreateOwner() {
|
||||||
var owner = new Owner();
|
var owner = new Owner();
|
||||||
|
|
Loading…
Reference in a new issue