From 44933a4d5d38b7bf6a11ee0c139a120563ef9d6b Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski <24374337+tomboc@users.noreply.github.com> Date: Fri, 4 Jun 2021 08:42:34 -0600 Subject: [PATCH] Remove the test for Java client generation. (#201) Java client generation feature depends on an external server, which takes an OpenAPI spec and returns a Java client library. The server has been turned down. Remove the test, which depends on the server. Actual error: Execution failed for task ':test-compat:appengineEndpointsGetClientLibs'. > There was an error running endpoints command get-client-lib: 404 Not Found --- test-compat/build.gradle | 8 - .../com/google/testapi/TictactoeTest.java | 94 ------ .../java/com/google/util/TestUtils.java | 67 ----- .../java/com/google/waxapi/WaxTest.java | 268 ------------------ 4 files changed, 437 deletions(-) delete mode 100644 test-compat/src/testlib/java/com/google/testapi/TictactoeTest.java delete mode 100644 test-compat/src/testlib/java/com/google/util/TestUtils.java delete mode 100644 test-compat/src/testlib/java/com/google/waxapi/WaxTest.java diff --git a/test-compat/build.gradle b/test-compat/build.gradle index 819725cb..ccfa58a9 100644 --- a/test-compat/build.gradle +++ b/test-compat/build.gradle @@ -62,7 +62,6 @@ allprojects { } test { - dependsOn += ':test-compat:appengineEndpointsInstallClientLibs' } // This is necessary because otherwise gradle check runs the dev server, but since there are no @@ -88,7 +87,6 @@ def testAllConfigs = task('testAllConfigs', type: Test) { description = 'runs tests for all environments' group = 'Compatibility testing' testClassesDir = sourceSets.test.output.classesDir - dependsOn += ':test-compat:appengineEndpointsInstallClientLibs' } testConfigs.each { cfg -> @@ -127,12 +125,6 @@ dependencies { compile group: 'javax.servlet', name: 'servlet-api', version: servletVersion compileOnly group: 'com.google.appengine', name: 'appengine-endpoints', version: appengineVersion - testlibCompile(group: 'com.compat_tests', name: 'wax', version: 'v1-+') { - exclude group: 'com.google.guava', module: 'guava-jdk5' - } - testlibCompile(group: 'com.compat_tests', name: 'tictactoe', version: 'v1-+') { - exclude group: 'com.google.guava', module: 'guava-jdk5' - } testlibCompile group: 'junit', name: 'junit', version: junitVersion testlibCompile group: 'com.google.truth', name: 'truth', version: truthVersion testlibCompile group: 'javax.servlet', name: 'servlet-api', version: servletVersion diff --git a/test-compat/src/testlib/java/com/google/testapi/TictactoeTest.java b/test-compat/src/testlib/java/com/google/testapi/TictactoeTest.java deleted file mode 100644 index 8c27f813..00000000 --- a/test-compat/src/testlib/java/com/google/testapi/TictactoeTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.testapi; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.api.client.http.javanet.NetHttpTransport; -import com.google.api.client.json.jackson.JacksonFactory; -import com.google.api.client.util.DateTime; -import com.google.util.TestUtils; - -import com.compat_tests.tictactoe.Tictactoe; -import com.compat_tests.tictactoe.model.FieldContainer; - -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; - -/** - * End-to-end tests for {@link TestEndpoint}, which implements a tictactoe api (in name only). - */ -public class TictactoeTest { - private static final int INT = 1234; - private static final long LONG = 1234L; - private static final float FLOAT = 1.5f; - private static final double DOUBLE = 5.2; - private static final String STRING = "中文"; - private static final DateTime SIMPLE_DATE = new DateTime("2016-01-26"); - private static final DateTime DATE_TIME = new DateTime("2016-01-26T11:46:00Z"); - private static final DateTime JAVA_DATE = new DateTime("2016-01-26T11:52:00Z"); - private static final String ENUM_VALUE = "VALUE1"; - - private Tictactoe api; - - @Before - public void setUp() { - api = TestUtils.configureApiClient( - new Tictactoe.Builder(new NetHttpTransport(), new JacksonFactory(), null)).build(); - } - - @Test - public void test() throws IOException { - assertThat(api.testEndpoint().test().execute().getValue()).isEqualTo("x"); - } - - @Test - public void echo() throws IOException { - assertThat(api.testEndpoint().echo("test").execute().getValue()).isEqualTo("test"); - } - - @Test - public void testParamsPath() throws IOException { - checkResponse(api.testEndpoint().testParamsPath(INT, LONG, FLOAT, DOUBLE, true, "中文", - SIMPLE_DATE, DATE_TIME, JAVA_DATE, ENUM_VALUE).execute()); - } - - @Test - public void testParamsQuery() throws IOException { - checkResponse(api.testEndpoint().testParamsQuery(true, JAVA_DATE, DATE_TIME, DOUBLE, FLOAT, - LONG, ENUM_VALUE, INT, SIMPLE_DATE, STRING).execute()); - } - - @Test - public void testPathParamCollision() throws IOException { - assertThat(api.testEndpoint().getCollidingPath("test").execute().getValue()).isEqualTo("test"); - assertThat(api.testEndpoint().putCollidingPath("test").execute().getValue()).isEqualTo("test"); - } - - private void checkResponse(FieldContainer ret) { - assertThat(ret.getAnInt()).isEqualTo(INT); - assertThat(ret.getALong()).isEqualTo(LONG); - assertThat(ret.getAFloat()).isWithin(0.0f).of(FLOAT); - assertThat(ret.getADouble()).isWithin(0.0).of(DOUBLE); - assertThat(ret.getABoolean()).isTrue(); - assertThat(ret.getAString()).isEqualTo(STRING); - assertThat(ret.getASimpleDate()).isEqualTo(SIMPLE_DATE); - assertThat(ret.getADateAndTime()).isEqualTo(DATE_TIME); - assertThat(ret.getAnEnum()).isEqualTo(ENUM_VALUE); - } -} diff --git a/test-compat/src/testlib/java/com/google/util/TestUtils.java b/test-compat/src/testlib/java/com/google/util/TestUtils.java deleted file mode 100644 index 31f2329b..00000000 --- a/test-compat/src/testlib/java/com/google/util/TestUtils.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.util; - -import com.google.api.client.googleapis.services.AbstractGoogleClient; -import com.google.api.client.googleapis.services.AbstractGoogleClientRequest; -import com.google.api.client.googleapis.services.GoogleClientRequestInitializer; -import com.google.api.client.http.HttpRequest; -import com.google.api.client.http.HttpRequestInitializer; -import com.google.api.client.http.HttpResponse; -import com.google.api.client.http.HttpUnsuccessfulResponseHandler; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; - -/** - * Miscellaneous utilities for end-to-end tests. - */ -public class TestUtils { - private static final String TEST_BACKEND_URL_PROPERTY = "test.backend.url"; - - public static T configureApiClient(T builder) { - builder - .setRootUrl(System.getProperty(TEST_BACKEND_URL_PROPERTY)) - .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() { - @Override - public void initialize(AbstractGoogleClientRequest request) throws IOException { - request.setDisableGZipContent(true); - } - }) - .setHttpRequestInitializer(new HttpRequestInitializer() { - @Override - public void initialize(HttpRequest request) throws IOException { - request.setUnsuccessfulResponseHandler(new ErrorHandler()); - } - }); - return builder; - } - - private static class ErrorHandler implements HttpUnsuccessfulResponseHandler { - @Override - public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) - throws IOException { - System.out.println(response.getStatusCode()); - BufferedReader in = new BufferedReader(new InputStreamReader(response.getContent())); - String line; - while ((line = in.readLine()) != null) { - System.out.println(line); - } - return false; - } - } -} diff --git a/test-compat/src/testlib/java/com/google/waxapi/WaxTest.java b/test-compat/src/testlib/java/com/google/waxapi/WaxTest.java deleted file mode 100644 index 1c390278..00000000 --- a/test-compat/src/testlib/java/com/google/waxapi/WaxTest.java +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.waxapi; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.fail; - -import com.google.api.client.googleapis.json.GoogleJsonResponseException; -import com.google.api.client.http.javanet.NetHttpTransport; -import com.google.api.client.json.jackson.JacksonFactory; -import com.google.common.truth.IntegerSubject; -import com.google.util.TestUtils; - -import com.compat_tests.wax.Wax; -import com.compat_tests.wax.model.WaxDataItem; -import com.compat_tests.wax.model.WaxDataItemCollection; -import com.compat_tests.wax.model.WaxNewSessionRequest; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -import java.io.IOException; -import java.util.List; - -import javax.servlet.http.HttpServletResponse; - -/** - * End-to-end tests using the Wax API. - */ -@RunWith(JUnit4.class) -public class WaxTest { - private static final WaxDataItem ITEM_A = new WaxDataItem().setId("A").setName("Item A"); - private static final WaxDataItem ITEM_B = new WaxDataItem().setId("B").setName("Item B"); - private static final WaxDataItem ITEM_C = new WaxDataItem().setId("C").setName("Item C"); - private Wax wax; - - @Before - public void setUp() { - wax = TestUtils.configureApiClient( - new Wax.Builder(new NetHttpTransport(), new JacksonFactory(), null)).build(); - } - - @Test - public void newSession() throws IOException { - String sessionId = createSession(); - // We just care that this doesn't return an error. - wax.items().list(sessionId).execute(); - } - - @Test - public void newSession_invalidSessionId() throws IOException { - try { - wax.sessions() - .create(new WaxNewSessionRequest().setSessionName("").setDurationInMillis(1L)) - .execute(); - } catch (GoogleJsonResponseException e) { - assertThatResponseCode(e).isEqualTo(HttpServletResponse.SC_BAD_REQUEST); - } - } - - @Test - public void removeSession() throws IOException { - String sessionId = createSession(); - // Make sure success is returned, but we don't care what the items are. - wax.items().list(sessionId).execute(); - wax.sessions().remove(sessionId).execute(); - try { - wax.items().list(sessionId); - } catch (GoogleJsonResponseException e) { - assertThatResponseCode(e).isEqualTo(HttpServletResponse.SC_NOT_FOUND); - } - } - - @Test - public void removeSession_invalidSession() throws IOException { - try { - wax.sessions().remove("not a real id").execute(); - } catch (GoogleJsonResponseException e) { - // 500 is translated to 503 by default. - assertThatResponseCode(e).isEqualTo(HttpServletResponse.SC_SERVICE_UNAVAILABLE); - } - } - - @Test - public void listSessionItems() throws IOException { - String sessionId = createSession(); - WaxDataItemCollection items = wax.items().list(sessionId).execute(); - assertThat(stripMetadata(items.getItems())).containsExactly(ITEM_A, ITEM_B); - } - - @Test - public void listSessionItems_invalidSession() throws IOException { - try { - wax.items().list("not a real id").execute(); - fail("expected exception"); - } catch (GoogleJsonResponseException e) { - assertThatResponseCode(e).isEqualTo(HttpServletResponse.SC_NOT_FOUND); - } - } - - @Test - public void addSessionItem() throws IOException { - String sessionId = createSession(); - WaxDataItem item = wax.items().insert(sessionId, ITEM_C).execute(); - WaxDataItemCollection items = wax.items().list(sessionId).execute(); - assertThat(stripMetadata(item)).isEqualTo(ITEM_C); - assertThat(stripMetadata(items.getItems())).containsExactly(ITEM_A, ITEM_B, ITEM_C); - } - - @Test - public void addSessionItem_invalidSession() throws IOException { - try { - wax.items().insert("not a real id", ITEM_C).execute(); - fail("expected exception"); - } catch (GoogleJsonResponseException e) { - assertThatResponseCode(e).isEqualTo(HttpServletResponse.SC_NOT_FOUND); - } - } - - @Test - public void addSessionItem_invalidItem() throws IOException { - try { - String sessionId = createSession(); - wax.items().insert(sessionId, ITEM_A).execute(); - fail("expected exception"); - } catch (GoogleJsonResponseException e) { - assertThatResponseCode(e).isEqualTo(HttpServletResponse.SC_BAD_REQUEST); - } - } - - @Test - public void removeSessionItem() throws Exception { - String sessionId = createSession(); - wax.items().delete(sessionId, ITEM_B.getId()).execute(); - WaxDataItemCollection items = wax.items().list(sessionId).execute(); - assertThat(stripMetadata(items.getItems())).containsExactly(ITEM_A); - } - - @Test - public void removeSessionItem_invalidSession() throws IOException { - try { - wax.items().delete("not a real id", ITEM_B.getId()).execute(); - fail("expected exception"); - } catch (GoogleJsonResponseException e) { - assertThatResponseCode(e).isEqualTo(HttpServletResponse.SC_NOT_FOUND); - } - } - - @Test - public void removeSessionItem_invalidItem() throws IOException { - try { - String sessionId = createSession(); - wax.items().delete(sessionId, "not a real id").execute(); - fail("expected exception"); - } catch (GoogleJsonResponseException e) { - assertThatResponseCode(e).isEqualTo(HttpServletResponse.SC_NOT_FOUND); - } - } - - @Test - public void updateSessionItem() throws IOException { - String sessionId = createSession(); - WaxDataItem newItemB = new WaxDataItem().setId("B").setName("New Item B"); - WaxDataItem item = wax.items().update(sessionId, newItemB.getId(), newItemB).execute(); - WaxDataItemCollection items = wax.items().list(sessionId).execute(); - assertThat(stripMetadata(item)).isEqualTo(newItemB); - assertThat(stripMetadata(items.getItems())).containsExactly(ITEM_A, newItemB); - } - - @Test - public void updateSessionItem_invalidSession() throws IOException { - try { - wax.items().update("not a real id", ITEM_B.getId(), ITEM_B).execute(); - fail("expected exception"); - } catch (GoogleJsonResponseException e) { - assertThatResponseCode(e).isEqualTo(HttpServletResponse.SC_NOT_FOUND); - } - } - - @Test - public void updateSessionItem_invalidItem() throws IOException { - try { - String sessionId = createSession(); - wax.items().update(sessionId, ITEM_C.getId(), ITEM_C).execute(); - fail("expected exception"); - } catch (GoogleJsonResponseException e) { - assertThatResponseCode(e).isEqualTo(HttpServletResponse.SC_NOT_FOUND); - } - } - - @Test - public void updateSessionItem_invalidItemIdChange() throws IOException { - try { - String sessionId = createSession(); - wax.items().update(sessionId, ITEM_B.getId(), ITEM_C).execute(); - fail("expected exception"); - } catch (GoogleJsonResponseException e) { - assertThatResponseCode(e).isEqualTo(HttpServletResponse.SC_BAD_REQUEST); - } - } - - @Test - public void getSessionItem() throws IOException { - String sessionId = createSession(); - WaxDataItem item = wax.items().get(sessionId, ITEM_B.getId()).execute(); - assertThat(stripMetadata(item)).isEqualTo(ITEM_B); - } - - @Test - public void getSessionItem_invalidSession() throws IOException { - try { - wax.items().get("not a real id", ITEM_B.getId()).execute(); - fail("expected exception"); - } catch (GoogleJsonResponseException e) { - assertThatResponseCode(e).isEqualTo(HttpServletResponse.SC_NOT_FOUND); - } - } - - @Test - public void getSessionItem_invalidItem() throws IOException { - try { - String sessionId = createSession(); - wax.items().get(sessionId, ITEM_C.getId()).execute(); - fail("expected exception"); - } catch (GoogleJsonResponseException e) { - assertThatResponseCode(e).isEqualTo(HttpServletResponse.SC_NOT_FOUND); - } - } - - private String createSession() throws IOException { - return wax.sessions() - .create(new WaxNewSessionRequest().setSessionName("test").setDurationInMillis(1L)) - .execute() - .getNewSessionId(); - } - - private static IntegerSubject assertThatResponseCode(GoogleJsonResponseException e) { - return assertThat(e.getStatusCode()); - } - - public List stripMetadata(List items) { - for (WaxDataItem item : items) { - stripMetadata(item); - } - return items; - } - - public WaxDataItem stripMetadata(WaxDataItem item) { - item.remove("kind"); - item.remove("etag"); - return item; - } -}