From 3a30e7520927a50b8457dd5ceea9700407a17e69 Mon Sep 17 00:00:00 2001 From: Mridula <66699525+mpeddada1@users.noreply.github.com> Date: Wed, 27 Apr 2022 14:33:34 -0400 Subject: [PATCH] fix(java): rename test to be picked up by native profile (#723) * fix(java): rename test to be picked up by native profile --- datastore-v1-proto-client/pom.xml | 15 +- .../native-image/native-image.properties | 1 + .../META-INF/native-image/reflect-config.json | 32 ++++ ...toreTest.java => DatastoreClientTest.java} | 164 +++++++++++------- ...TDatastoreTest.java => DatastoreTest.java} | 2 +- 5 files changed, 138 insertions(+), 76 deletions(-) create mode 100644 datastore-v1-proto-client/src/main/resources/META-INF/native-image/native-image.properties create mode 100644 datastore-v1-proto-client/src/main/resources/META-INF/native-image/reflect-config.json rename datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/{DatastoreTest.java => DatastoreClientTest.java} (76%) rename google-cloud-datastore/src/test/java/com/google/cloud/datastore/{ITDatastoreTest.java => DatastoreTest.java} (99%) diff --git a/datastore-v1-proto-client/pom.xml b/datastore-v1-proto-client/pom.xml index 6507d7446..dcb521be9 100644 --- a/datastore-v1-proto-client/pom.xml +++ b/datastore-v1-proto-client/pom.xml @@ -109,24 +109,11 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M5 - - - **/*SmokeTest.java - **/IT*.java - - sponge_log -Xmx2048m - - - org.apache.maven.surefire - surefire-junit47 - 3.0.0-M5 - - + diff --git a/datastore-v1-proto-client/src/main/resources/META-INF/native-image/native-image.properties b/datastore-v1-proto-client/src/main/resources/META-INF/native-image/native-image.properties new file mode 100644 index 000000000..0b5b2e18c --- /dev/null +++ b/datastore-v1-proto-client/src/main/resources/META-INF/native-image/native-image.properties @@ -0,0 +1 @@ +Args = --enable-url-protocols=https,http \ No newline at end of file diff --git a/datastore-v1-proto-client/src/main/resources/META-INF/native-image/reflect-config.json b/datastore-v1-proto-client/src/main/resources/META-INF/native-image/reflect-config.json new file mode 100644 index 000000000..32b27f5d9 --- /dev/null +++ b/datastore-v1-proto-client/src/main/resources/META-INF/native-image/reflect-config.json @@ -0,0 +1,32 @@ +[ + { + "name":"com.google.datastore.v1.client.Datastore", + "methods":[ + {"name":"allocateIds","parameterTypes":["com.google.datastore.v1.AllocateIdsRequest"] }, + {"name":"beginTransaction","parameterTypes":["com.google.datastore.v1.BeginTransactionRequest"] }, + {"name":"commit","parameterTypes":["com.google.datastore.v1.CommitRequest"] }, + {"name":"lookup","parameterTypes":["com.google.datastore.v1.LookupRequest"] }, + {"name":"reserveIds","parameterTypes":["com.google.datastore.v1.ReserveIdsRequest"] }, + {"name":"rollback","parameterTypes":["com.google.datastore.v1.RollbackRequest"] }, + {"name":"runQuery","parameterTypes":["com.google.datastore.v1.RunQueryRequest"] } + ] + }, + { + "name":"com.google.api.client.http.HttpRequest", + "allDeclaredFields":true, + "allPublicFields":true, + "allDeclaredMethods":true, + "allPublicMethods":true, + "allDeclaredConstructors" : true, + "allPublicConstructors" : true + }, + { + "name":"com.google.api.client.http.HttpHeaders", + "allDeclaredFields":true, + "allPublicFields":true, + "allDeclaredMethods":true, + "allPublicMethods":true, + "allDeclaredConstructors" : true, + "allPublicConstructors" : true + } +] \ No newline at end of file diff --git a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreTest.java b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java similarity index 76% rename from datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreTest.java rename to datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java index ca4fcc449..d8376dc29 100644 --- a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreTest.java +++ b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.fail; import com.google.api.client.auth.oauth2.Credential; @@ -62,108 +63,144 @@ import java.lang.reflect.Method; import java.net.SocketTimeoutException; import java.util.List; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** Tests for {@link DatastoreFactory} and {@link Datastore}. */ @RunWith(JUnit4.class) -public class DatastoreTest { +public class DatastoreClientTest { private static final String PROJECT_ID = "project-id"; - @Rule public ExpectedException thrown = ExpectedException.none(); - private DatastoreFactory factory = new MockDatastoreFactory(); private DatastoreOptions.Builder options = new DatastoreOptions.Builder().projectId(PROJECT_ID).credential(new MockCredential()); @Test - public void options_NoProjectIdOrProjectEndpoint() throws Exception { - options = new DatastoreOptions.Builder(); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Either project ID or project endpoint must be provided"); + public void options_NoProjectIdOrProjectEndpoint() { + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> factory.create(new DatastoreOptions.Builder().build())); + assertThat(exception) + .hasMessageThat() + .contains("Either project ID or project endpoint must be provided"); factory.create(options.build()); } @Test public void options_ProjectIdAndProjectEndpoint() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Cannot set both project endpoint and project ID"); - options = - new DatastoreOptions.Builder() - .projectId(PROJECT_ID) - .projectEndpoint("http://localhost:1234/datastore/v1beta42/projects/project-id"); + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> + new DatastoreOptions.Builder() + .projectId(PROJECT_ID) + .projectEndpoint( + "http://localhost:1234/datastore/v1beta42/projects/project-id")); + assertThat(exception) + .hasMessageThat() + .contains("Cannot set both project endpoint and project ID"); } @Test public void options_LocalHostAndProjectEndpoint() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Can set at most one of project endpoint, host, and local host"); - options = - new DatastoreOptions.Builder() - .localHost("localhost:8080") - .projectEndpoint("http://localhost:1234/datastore/v1beta42/projects/project-id"); + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> + new DatastoreOptions.Builder() + .localHost("localhost:8080") + .projectEndpoint( + "http://localhost:1234/datastore/v1beta42/projects/project-id")); + assertThat(exception) + .hasMessageThat() + .contains("Can set at most one of project endpoint, host, and local host"); } @Test public void options_HostAndProjectEndpoint() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Can set at most one of project endpoint, host, and local host"); - options = - new DatastoreOptions.Builder() - .host("foo-datastore.googleapis.com") - .projectEndpoint("http://localhost:1234/datastore/v1beta42/projects/project-id"); + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> + new DatastoreOptions.Builder() + .host("foo-datastore.googleapis.com") + .projectEndpoint( + "http://localhost:1234/datastore/v1beta42/projects/project-id")); + assertThat(exception) + .hasMessageThat() + .contains("Can set at most one of project endpoint, host, and local host"); } @Test public void options_HostAndLocalHost() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Can set at most one of project endpoint, host, and local host"); - options = - new DatastoreOptions.Builder() - .host("foo-datastore.googleapis.com") - .localHost("localhost:8080"); + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> + new DatastoreOptions.Builder() + .host("foo-datastore.googleapis.com") + .localHost("localhost:8080")); + assertThat(exception) + .hasMessageThat() + .contains("Can set at most one of project endpoint, host, and local host"); } @Test public void options_InvalidLocalHost() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Illegal character"); - factory.create( - new DatastoreOptions.Builder() - .projectId(PROJECT_ID) - .localHost("!not a valid url!") - .build()); + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> + factory.create( + new DatastoreOptions.Builder() + .projectId(PROJECT_ID) + .localHost("!not a valid url!") + .build())); + assertThat(exception).hasMessageThat().contains("Illegal character"); } @Test public void options_SchemeInLocalHost() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Local host \"http://localhost:8080\" must not include scheme"); - new DatastoreOptions.Builder().localHost("http://localhost:8080"); + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> new DatastoreOptions.Builder().localHost("http://localhost:8080")); + assertThat(exception) + .hasMessageThat() + .contains("Local host \"http://localhost:8080\" must not include scheme"); } @Test - public void options_InvalidHost() throws Exception { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Illegal character"); - factory.create( - new DatastoreOptions.Builder().projectId(PROJECT_ID).host("!not a valid url!").build()); + public void options_InvalidHost() { + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> + factory.create( + new DatastoreOptions.Builder() + .projectId(PROJECT_ID) + .host("!not a valid url!") + .build())); + assertThat(exception).hasMessageThat().contains("Illegal character"); } @Test public void options_SchemeInHost() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Host \"http://foo-datastore.googleapis.com\" must not include scheme"); - new DatastoreOptions.Builder().host("http://foo-datastore.googleapis.com"); + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> new DatastoreOptions.Builder().host("http://foo-datastore.googleapis.com")); + + assertThat(exception) + .hasMessageThat() + .contains("Host \"http://foo-datastore.googleapis.com\" must not include scheme."); } @Test public void create_NullOptions() throws Exception { - thrown.expect(NullPointerException.class); - factory.create(null); + assertThrows(NullPointerException.class, () -> factory.create(null)); } @Test @@ -223,14 +260,19 @@ public void create_ProjectEndpoint() { @Test public void create_ProjectEndpointNoScheme() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage( - "Project endpoint \"localhost:1234/datastore/v1beta42/projects/project-id\" must" - + " include scheme."); - factory.create( - new DatastoreOptions.Builder() - .projectEndpoint("localhost:1234/datastore/v1beta42/projects/project-id") - .build()); + IllegalArgumentException exception = + assertThrows( + IllegalArgumentException.class, + () -> + factory.create( + new DatastoreOptions.Builder() + .projectEndpoint("localhost:1234/datastore/v1beta42/projects/project-id") + .build())); + assertThat(exception) + .hasMessageThat() + .contains( + "Project endpoint \"localhost:1234/datastore/v1beta42/projects/project-id\" must" + + " include scheme."); } @Test diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ITDatastoreTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java similarity index 99% rename from google-cloud-datastore/src/test/java/com/google/cloud/datastore/ITDatastoreTest.java rename to google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java index 5a3bc7e00..0a532b176 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ITDatastoreTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java @@ -78,7 +78,7 @@ import org.threeten.bp.Duration; @RunWith(JUnit4.class) -public class ITDatastoreTest { +public class DatastoreTest { private static LocalDatastoreHelper helper = LocalDatastoreHelper.create(1.0); private static final DatastoreOptions options = helper.getOptions();