13
13
package gust .backend .driver .firestore ;
14
14
15
15
16
+ import com .google .api .gax .core .NoCredentialsProvider ;
17
+ import com .google .cloud .NoCredentials ;
18
+ import com .google .cloud .firestore .FirestoreOptions ;
19
+ import com .google .cloud .firestore .v1 .stub .FirestoreStubSettings ;
20
+ import com .google .cloud .grpc .GrpcTransportOptions ;
16
21
import com .google .common .util .concurrent .ListeningScheduledExecutorService ;
17
22
import com .google .common .util .concurrent .MoreExecutors ;
18
23
import gust .backend .model .GenericPersistenceAdapterTest ;
19
24
import gust .backend .model .PersonRecord .Person ;
20
25
import gust .backend .model .PersonRecord .PersonKey ;
21
26
import org .junit .jupiter .api .AfterAll ;
22
- import org .junit .jupiter .api .BeforeAll ;
27
+ import org .junit .jupiter .api .BeforeEach ;
28
+ import org .testcontainers .containers .FirestoreEmulatorContainer ;
29
+ import org .testcontainers .junit .jupiter .Container ;
30
+ import org .testcontainers .junit .jupiter .Testcontainers ;
31
+ import org .testcontainers .utility .DockerImageName ;
23
32
24
33
import javax .annotation .Nonnull ;
25
34
import java .util .concurrent .Executors ;
29
38
30
39
31
40
/** Tests for the {@link FirestoreAdapter}. */
41
+ @ Testcontainers
32
42
@ SuppressWarnings ("UnstableApiUsage" )
33
43
public final class FirestoreAdapterTest extends GenericPersistenceAdapterTest <FirestoreAdapter <PersonKey , Person >> {
34
44
private static ListeningScheduledExecutorService executorService ;
35
45
private static FirestoreAdapter <PersonKey , Person > personAdapter ;
46
+ private static final String firestoreVersion = System .getProperty (
47
+ "e2e.firestoreVersion" , "349.0.0-emulators" );
36
48
37
- @ BeforeAll
38
- static void initExecutor () {
49
+ @ Container
50
+ public FirestoreEmulatorContainer firestore = new FirestoreEmulatorContainer (
51
+ DockerImageName .parse ("gcr.io/google.com/cloudsdktool/cloud-sdk:" + firestoreVersion )
52
+ ).withNetworkAliases ("firestore" );
53
+
54
+ @ BeforeEach
55
+ void initExecutor () {
39
56
executorService = MoreExecutors .listeningDecorator (Executors .newScheduledThreadPool (3 ));
57
+ var creds = NoCredentialsProvider .create ();
58
+
59
+ var stubSettings = FirestoreStubSettings .newBuilder ()
60
+ .setEndpoint (firestore .getEmulatorEndpoint ())
61
+ .setCredentialsProvider (creds );
62
+
40
63
personAdapter = FirestoreAdapter .acquire (
64
+ FirestoreOptions .newBuilder ()
65
+ .setProjectId ("test-project" )
66
+ .setHost (firestore .getEmulatorEndpoint ())
67
+ .setEmulatorHost (firestore .getEmulatorEndpoint ())
68
+ .setCredentials (NoCredentials .getInstance ())
69
+ .setCredentialsProvider (NoCredentialsProvider .create ()),
70
+ stubSettings .getTransportChannelProvider ()
71
+ .withEndpoint (firestore .getEmulatorEndpoint ())
72
+ .withCredentials (NoCredentials .getInstance ()),
73
+ stubSettings .getCredentialsProvider (),
74
+ GrpcTransportOptions .newBuilder ().build (),
75
+ executorService ,
41
76
PersonKey .getDefaultInstance (),
42
- Person .getDefaultInstance (),
43
- executorService );
77
+ Person .getDefaultInstance ()
78
+ );
44
79
}
45
80
46
81
@ AfterAll
@@ -60,10 +95,6 @@ static void shutdownExecutor() throws InterruptedException {
60
95
/** {@inheritDoc} */
61
96
@ Override
62
97
protected void acquireDriver () {
63
- FirestoreAdapter <PersonKey , Person > personAdapter = FirestoreAdapter .acquire (
64
- PersonKey .getDefaultInstance (),
65
- Person .getDefaultInstance (),
66
- executorService );
67
98
assertNotNull (personAdapter , "should not get `null` for adapter acquire" );
68
99
}
69
100
}
0 commit comments