Skip to content

Commit

Permalink
Add support for java record serialization - move test code to google-…
Browse files Browse the repository at this point in the history
…cloud-firestore module by adding a test-jdk17 directory and a java17 profile, and eliminate google-cloud-firestore-jdk17 module
  • Loading branch information
eranl committed Nov 3, 2023
1 parent de25226 commit 53aabf5
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 181 deletions.
121 changes: 0 additions & 121 deletions google-cloud-firestore-jdk17/pom.xml

This file was deleted.

44 changes: 44 additions & 0 deletions google-cloud-firestore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,49 @@
</dependency>
</dependencies>
</profile>
<profile>
<!-- And different set up for JDK 17 -->
<id>java17</id>
<activation>
<jdk>17</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test-jdk17/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<!-- Enable Java 17 for all sources so that Intellij picks the right language level -->
<source>17</source>
<release>17</release>
<compilerArgs>
<arg>-parameters</arg>
<arg>--add-opens=java.base/java.lang=ALL-UNNAMED</arg>
<arg>--add-opens=java.base/java.util=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.cloud.firestore;

import static com.google.cloud.firestore.jdk17.LocalFirestoreHelper.*;
import static com.google.cloud.firestore.record.LocalFirestoreHelper.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doAnswer;
Expand All @@ -25,28 +25,29 @@
import com.google.api.gax.rpc.ResponseObserver;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.firestore.jdk17.LocalFirestoreHelper;
import com.google.cloud.firestore.spi.v1.FirestoreRpc;
import com.google.firestore.v1.BatchGetDocumentsRequest;
import com.google.firestore.v1.CommitRequest;
import com.google.firestore.v1.CommitResponse;
import com.google.firestore.v1.Value;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.Captor;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RunWith(MockitoJUnitRunner.class)
public class RecordDocumentReferenceTest {
Expand Down Expand Up @@ -75,7 +76,7 @@ public void serializeBasicTypes() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
commitCapture.capture(), ArgumentMatchers.<UnaryCallable<CommitRequest, CommitResponse>>any());

documentReference.set(ALL_SUPPORTED_TYPES_OBJECT).get();

Expand Down Expand Up @@ -127,7 +128,7 @@ public void doesNotDeserializeAdvancedNumberTypes() throws Exception {
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
Matchers.<ServerStreamingCallable>any());
ArgumentMatchers.<ServerStreamingCallable>any());

var snapshot = documentReference.get().get();
try {
Expand All @@ -148,7 +149,7 @@ public void createDocument() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
commitCapture.capture(), ArgumentMatchers.<UnaryCallable<CommitRequest, CommitResponse>>any());

documentReference.create(SINGLE_COMPONENT_OBJECT).get();

Expand All @@ -163,9 +164,9 @@ public void createWithServerTimestamp() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
commitCapture.capture(), ArgumentMatchers.<UnaryCallable<CommitRequest, CommitResponse>>any());

documentReference.create(LocalFirestoreHelper.SERVER_TIMESTAMP_OBJECT).get();
documentReference.create(SERVER_TIMESTAMP_OBJECT).get();

var create =
commit(
Expand All @@ -181,9 +182,9 @@ public void setWithServerTimestamp() throws Exception {
doReturn(FIELD_TRANSFORM_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
commitCapture.capture(), ArgumentMatchers.<UnaryCallable<CommitRequest, CommitResponse>>any());

documentReference.set(LocalFirestoreHelper.SERVER_TIMESTAMP_OBJECT).get();
documentReference.set(SERVER_TIMESTAMP_OBJECT).get();

var set =
commit(
Expand All @@ -199,10 +200,10 @@ public void mergeWithServerTimestamps() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
commitCapture.capture(), ArgumentMatchers.<UnaryCallable<CommitRequest, CommitResponse>>any());

documentReference
.set(LocalFirestoreHelper.SERVER_TIMESTAMP_OBJECT, SetOptions.mergeFields("inner.bar"))
.set(SERVER_TIMESTAMP_OBJECT, SetOptions.mergeFields("inner.bar"))
.get();

var set =
Expand All @@ -219,7 +220,7 @@ public void setDocumentWithMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
commitCapture.capture(), ArgumentMatchers.<UnaryCallable<CommitRequest, CommitResponse>>any());

documentReference.set(SINGLE_COMPONENT_OBJECT, SetOptions.merge()).get();
documentReference.set(ALL_SUPPORTED_TYPES_OBJECT, SetOptions.mergeFields("foo")).get();
Expand All @@ -244,7 +245,7 @@ public void setDocumentWithNestedMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
commitCapture.capture(), ArgumentMatchers.<UnaryCallable<CommitRequest, CommitResponse>>any());

documentReference.set(NESTED_RECORD_OBJECT, SetOptions.mergeFields("first.foo")).get();
documentReference
Expand Down Expand Up @@ -273,7 +274,7 @@ public void setMultipleFieldsWithMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
commitCapture.capture(), ArgumentMatchers.<UnaryCallable<CommitRequest, CommitResponse>>any());

documentReference
.set(
Expand Down Expand Up @@ -301,7 +302,7 @@ public void setNestedMapWithMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
commitCapture.capture(), ArgumentMatchers.<UnaryCallable<CommitRequest, CommitResponse>>any());

documentReference.set(NESTED_RECORD_OBJECT, SetOptions.mergeFields("first", "second")).get();

Expand All @@ -321,7 +322,7 @@ public void extractFieldMaskFromMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
commitCapture.capture(), ArgumentMatchers.<UnaryCallable<CommitRequest, CommitResponse>>any());

documentReference.set(NESTED_RECORD_OBJECT, SetOptions.merge()).get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@

package com.google.cloud.firestore;

import com.google.cloud.firestore.annotation.DocumentId;
import com.google.cloud.firestore.annotation.PropertyName;
import com.google.cloud.firestore.annotation.ThrowOnExtraProperties;
import com.google.cloud.firestore.spi.v1.FirestoreRpc;
import com.google.common.collect.ImmutableList;
import com.google.firestore.v1.DatabaseRootName;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
Expand All @@ -28,22 +40,12 @@
import java.util.Map;
import java.util.Set;

import com.google.cloud.firestore.annotation.DocumentId;
import com.google.cloud.firestore.annotation.PropertyName;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.Spy;

import com.google.cloud.firestore.annotation.ThrowOnExtraProperties;
import com.google.cloud.firestore.spi.v1.FirestoreRpc;
import com.google.common.collect.ImmutableList;
import com.google.firestore.v1.DatabaseRootName;
import org.mockito.junit.MockitoJUnitRunner;

import static com.google.cloud.firestore.jdk17.LocalFirestoreHelper.fromSingleQuotedString;
import static com.google.cloud.firestore.jdk17.LocalFirestoreHelper.mapAnyType;
import static org.junit.Assert.*;
import static com.google.cloud.firestore.record.LocalFirestoreHelper.fromSingleQuotedString;
import static com.google.cloud.firestore.record.LocalFirestoreHelper.mapAnyType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

@SuppressWarnings({"unused", "WeakerAccess", "SpellCheckingInspection"})
@RunWith(MockitoJUnitRunner.class)
Expand Down
Loading

0 comments on commit 53aabf5

Please sign in to comment.