Skip to content

Commit 8017980

Browse files
committed
fix: testing java 17 for samples
1 parent fedc857 commit 8017980

File tree

11 files changed

+49
-132
lines changed

11 files changed

+49
-132
lines changed

samples/spring-eventsourced-customer-registry/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
1717
<mainClass>customer.Main</mainClass>
1818

19-
<jdk.target>11</jdk.target>
19+
<jdk.target>17</jdk.target>
2020
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2121

2222
<kalix-sdk.version>1.0.8</kalix-sdk.version>
@@ -123,7 +123,7 @@
123123
<name>${dockerImage}:%l</name>
124124
<build>
125125
<!-- Base Docker image which contains jre-->
126-
<from>docker.io/library/adoptopenjdk:${jdk.target}-jre-hotspot</from>
126+
<from>docker.io/library/eclipse-temurin:${jdk.target}-alpine</from>
127127
<createImageOptions>
128128
<platform>linux/amd64</platform>
129129
</createImageOptions>

samples/spring-eventsourced-customer-registry/src/it/java/customer/api/CustomerIntegrationTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class CustomerIntegrationTest extends KalixIntegrationTestKitSupport {
3434
private Duration timeout = Duration.of(5, SECONDS);
3535

3636
@Test
37-
public void create() throws InterruptedException {
37+
public void create() {
3838
String id = UUID.randomUUID().toString();
3939
Customer customer = new Customer(id, "[email protected]", "Johanna", null);
4040

@@ -47,11 +47,11 @@ public void create() throws InterruptedException {
4747
.block(timeout);
4848

4949
Assertions.assertEquals(HttpStatus.OK, response.getStatusCode());
50-
Assertions.assertEquals("Johanna", getCustomerById(id).name);
50+
Assertions.assertEquals("Johanna", getCustomerById(id).name());
5151
}
5252

5353
@Test
54-
public void changeName() throws InterruptedException {
54+
public void changeName() {
5555
String id = UUID.randomUUID().toString();
5656
Customer customer = new Customer(id, "[email protected]", "Johanna", null);
5757

@@ -74,11 +74,11 @@ public void changeName() throws InterruptedException {
7474

7575

7676
Assertions.assertEquals(HttpStatus.OK, resUpdate.getStatusCode());
77-
Assertions.assertEquals("Katarina", getCustomerById(id).name);
77+
Assertions.assertEquals("Katarina", getCustomerById(id).name());
7878
}
7979

8080
@Test
81-
public void changeAddress() throws InterruptedException {
81+
public void changeAddress() {
8282
String id = UUID.randomUUID().toString();
8383
Customer customer = new Customer(id, "[email protected]", "Johanna", null);
8484

@@ -103,12 +103,12 @@ public void changeAddress() throws InterruptedException {
103103

104104

105105
Assertions.assertEquals(HttpStatus.OK, resUpdate.getStatusCode());
106-
Assertions.assertEquals("Elm st. 5", getCustomerById(id).address.street);
106+
Assertions.assertEquals("Elm st. 5", getCustomerById(id).address().street());
107107
}
108108

109109

110110
@Test
111-
public void findByName() throws Exception {
111+
public void findByName() {
112112
String id = UUID.randomUUID().toString();
113113
Customer customer = new Customer(id, "[email protected]", "Foo", null);
114114
ResponseEntity<String> response =
@@ -131,13 +131,13 @@ public void findByName() throws Exception {
131131
.retrieve()
132132
.bodyToMono(CustomerView.class)
133133
.block(timeout)
134-
.name,
134+
.name(),
135135
new IsEqual("Foo")
136136
);
137137
}
138138

139139
@Test
140-
public void findByEmail() throws Exception {
140+
public void findByEmail() {
141141
String id = UUID.randomUUID().toString();
142142
Customer customer = new Customer(id, "[email protected]", "Bar", null);
143143
ResponseEntity<String> response =
@@ -160,7 +160,7 @@ public void findByEmail() throws Exception {
160160
.retrieve()
161161
.bodyToMono(CustomerView.class)
162162
.block(timeout)
163-
.name,
163+
.name(),
164164
new IsEqual("Bar")
165165
);
166166
}

samples/spring-eventsourced-customer-registry/src/main/java/customer/api/Address.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,4 @@
33
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
44
*/
55

6-
import com.fasterxml.jackson.annotation.JsonCreator;
7-
import com.fasterxml.jackson.annotation.JsonProperty;
8-
9-
public class Address {
10-
public String street;
11-
public String city;
12-
13-
@JsonCreator
14-
public Address(@JsonProperty("street") String street, @JsonProperty("city") String city) {
15-
this.street = street;
16-
this.city = city;
17-
}
18-
}
6+
public record Address(String street, String city) {}

samples/spring-eventsourced-customer-registry/src/main/java/customer/api/AddressChanged.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

samples/spring-eventsourced-customer-registry/src/main/java/customer/api/Customer.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,7 @@
33
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
44
*/
55

6-
import com.fasterxml.jackson.annotation.JsonCreator;
7-
import com.fasterxml.jackson.annotation.JsonProperty;
8-
9-
public class Customer {
10-
public String customerId;
11-
public String email;
12-
public String name;
13-
public Address address;
14-
15-
// TODO: remove JsonCreator and JsonProperty
16-
// this should not be needed and it's not when running the application
17-
// however, the integration tests seems to need it.
18-
// Probably related to how the compiler is configured for the tests?
19-
@JsonCreator
20-
public Customer(@JsonProperty("customerId") String customerId,
21-
@JsonProperty("email") String email,
22-
@JsonProperty("name") String name,
23-
@JsonProperty("address") Address address) {
24-
this.customerId = customerId;
25-
this.email = email;
26-
this.name = name;
27-
this.address = address;
28-
}
29-
6+
public record Customer(String customerId, String email, String name, Address address) {
307

318
public Customer withName(String newName) {
329
return new Customer(customerId, email, newName, address);

samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerCreated.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEntity.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818

1919
import kalix.javasdk.eventsourcedentity.EventSourcedEntity;
2020
import kalix.javasdk.eventsourcedentity.EventSourcedEntityContext;
21-
import kalix.javasdk.valueentity.ValueEntity;
2221
import kalix.springsdk.annotations.Entity;
2322
import kalix.springsdk.annotations.EventHandler;
2423
import org.springframework.web.bind.annotation.*;
2524

25+
import static customer.api.CustomerEvent.*;
26+
2627
@Entity(entityKey = "id", entityType = "customer")
2728
@RequestMapping("/customer/{id}")
2829
public class CustomerEntity extends EventSourcedEntity<Customer> {
@@ -41,13 +42,13 @@ public Effect<Customer> getCustomer() {
4142
@PostMapping("/create")
4243
public Effect<String> create(@RequestBody Customer customer) {
4344
return effects()
44-
.emitEvent(new CustomerCreated(customer.email, customer.name, customer.address))
45+
.emitEvent(new CustomerCreated(customer.email(), customer.name(), customer.address()))
4546
.thenReply(__ -> "OK");
4647
}
4748

4849
@EventHandler
4950
public Customer onEvent(CustomerCreated created) {
50-
return new Customer(entityId, created.email, created.name, created.address);
51+
return new Customer(entityId, created.email(), created.name(), created.address());
5152
}
5253

5354

@@ -61,7 +62,7 @@ public Effect<String> changeName(@PathVariable String newName) {
6162

6263
@EventHandler
6364
public Customer onEvent(NameChanged nameChanged) {
64-
return currentState().withName(nameChanged.newName);
65+
return currentState().withName(nameChanged.newName());
6566
}
6667

6768

@@ -73,7 +74,7 @@ public Effect<String> changeAddress(@RequestBody Address newAddress) {
7374
}
7475

7576
@EventHandler
76-
public Customer onEvents(AddressChanged addressChanged){
77-
return currentState().withAddress(addressChanged.address);
77+
public Customer onEvents(AddressChanged addressChanged) {
78+
return currentState().withAddress(addressChanged.address());
7879
}
7980
}

samples/spring-eventsourced-customer-registry/src/main/java/customer/api/CustomerEvent.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,23 @@
44
import com.fasterxml.jackson.annotation.JsonSubTypes;
55
import com.fasterxml.jackson.annotation.JsonTypeInfo;
66

7+
import static customer.api.CustomerEvent.*;
8+
79
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
810
@JsonSubTypes(
911
{
1012
@JsonSubTypes.Type(value = CustomerCreated.class, name = "customer-created"),
1113
@JsonSubTypes.Type(value = NameChanged.class, name = "name-changed"),
1214
@JsonSubTypes.Type(value = AddressChanged.class, name = "address-changed")
1315
})
14-
public interface CustomerEvent {
16+
public sealed interface CustomerEvent {
17+
18+
record CustomerCreated(String email, String name, Address address) implements CustomerEvent {
19+
}
20+
21+
record NameChanged(String newName) implements CustomerEvent {
22+
}
23+
24+
record AddressChanged(Address address) implements CustomerEvent {
25+
}
1526
}

samples/spring-eventsourced-customer-registry/src/main/java/customer/api/NameChanged.java

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11
package customer.view;
22

3-
import com.fasterxml.jackson.annotation.JsonCreator;
4-
import com.fasterxml.jackson.annotation.JsonProperty;
5-
import customer.api.*;
3+
import customer.api.Address;
4+
import customer.api.CustomerEvent;
65

76
import java.util.Optional;
87

9-
public class CustomerView {
10-
final public String email;
11-
final public String name;
12-
final public Address address;
13-
14-
@JsonCreator
15-
public CustomerView(@JsonProperty("email") String email, @JsonProperty("name") String name, @JsonProperty("address") Address address) {
16-
this.email = email;
17-
this.name = name;
18-
this.address = address;
19-
}
8+
import static customer.api.CustomerEvent.*;
209

10+
public record CustomerView(String email, String name, Address address) {
2111

2212
public CustomerView withName(String newName) {
23-
return new CustomerView( email, newName, address);
13+
return new CustomerView(email, newName, address);
2414
}
2515

2616
public CustomerView withAddress(Address newAddress) {
27-
return new CustomerView( email, name, newAddress);
17+
return new CustomerView(email, name, newAddress);
2818
}
2919

3020
/**
@@ -35,25 +25,20 @@ public static Optional<CustomerView> onEvent(CustomerView state, CustomerEvent e
3525

3626
if (state == null) {
3727
// the only event we can receive when state is null is the CustomerCreated
38-
if (event instanceof CustomerCreated) {
39-
CustomerCreated created = (CustomerCreated) event;
40-
return Optional.of(new CustomerView(created.email, created.name, created.address));
28+
if (event instanceof CustomerCreated created) {
29+
return Optional.of(new CustomerView(created.email(), created.name(), created.address()));
4130
}
4231
} else {
4332
// when not null, we can receive the other events
44-
if (event instanceof NameChanged) {
45-
NameChanged nameChanged = (NameChanged) event;
46-
return Optional.of(state.withName(nameChanged.newName));
47-
} else if (event instanceof AddressChanged) {
48-
AddressChanged addressChanged = (AddressChanged) event;
49-
return Optional.of(state.withAddress(addressChanged.address));
33+
if (event instanceof NameChanged nameChanged) {
34+
return Optional.of(state.withName(nameChanged.newName()));
35+
} else if (event instanceof AddressChanged addressChanged) {
36+
return Optional.of(state.withAddress(addressChanged.address()));
5037
}
5138
}
5239

5340
// If state is null, and we receive anything different from CustomerCreated we will end-up here.
5441
// That case won't happen as the delivery ordering is guaranteed, but we need to keep the compiler happy
5542
return Optional.empty();
5643
}
57-
58-
5944
}

0 commit comments

Comments
 (0)