-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathRestateTest.java
More file actions
79 lines (75 loc) · 2.66 KB
/
Copy pathRestateTest.java
File metadata and controls
79 lines (75 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
//
// This file is part of the Restate Java SDK,
// which is released under the MIT license.
//
// You can find a copy of the license in file LICENSE in the root
// directory of this repository or package, or at
// https://github.com/restatedev/sdk-java/blob/main/LICENSE
package dev.restate.sdk.testing;
import java.lang.annotation.*;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
/**
* Annotation to enable the Restate extension for JUnit 5. The annotation will bootstrap a Restate
* environment using TestContainers, and will automatically register all services field of the class
* annotated with {@link BindService}.
*
* <p>Example:
*
* <pre>
* // Annotate the class as RestateTest to start a Restate environment
* {@code @RestateTest}
* class CounterTest {
*
* // Annotate the service to bind
* {@code @BindService} private final Counter counter = new Counter();
*
* // Inject the client to send requests
* {@code @Test}
* void testGreet({@code @RestateClient} Client ingressClient) {
* var client = CounterClient.fromClient(ingressClient, "my-counter");
*
* long response = client.get();
* assertThat(response).isEqualTo(0L);
* }
* }
* </pre>
*
* <p>The runner will deploy the services locally, execute Restate as container using <a
* href="https://java.testcontainers.org/">Testcontainers</a>, and register the services.
*
* <p>This extension is scoped per test class, meaning that the restate runner will be shared among
* test methods. Because of this behaviour, the extension sets the {@link TestInstance} as {@link
* TestInstance.Lifecycle#PER_CLASS} automatically.
*
* <p>Use the annotations {@link RestateClient}, {@link RestateURL} and {@link RestateAdminURL} to
* interact with the deployed environment:
*
* <pre>
* {@code @Test}
* void initialCountIsZero({@code @RestateClient} Client client) {
* var client = CounterClient.fromClient(ingressClient, "my-counter");
*
* // Use client as usual
* long response = client.get();
* assertThat(response).isEqualTo(0L);
* }</pre>
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@ExtendWith(RestateExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public @interface RestateTest {
/**
* Environment variables in form {@literal key=value} that should be added to the deployed Restate
* container.
*
* @return the environment variables to add
*/
String[] environment() default {};
/** Restate container image to use */
String containerImage() default "docker.io/restatedev/restate:latest";
}