Skip to content

Commit 7091cd4

Browse files
author
Jerjou Cheng
committed
Add skeleton UJ tests to all bookshelf steps.
This is necessary to let the automatic pre- and post-integration start/stop of jetty to work correctly (otherwise it doesn't shutdown correctly or something, leaving it bound to the port so the next test can't start).
1 parent d90b60d commit 7091cd4

16 files changed

Lines changed: 582 additions & 27 deletions

File tree

bookshelf-standard/2-structured-data/pom.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ Copyright 2016 Google Inc.
134134
<groupId>org.seleniumhq.selenium</groupId>
135135
<artifactId>selenium-server</artifactId>
136136
</dependency>
137-
137+
<dependency>
138+
<groupId>org.seleniumhq.selenium</groupId>
139+
<artifactId>selenium-chrome-driver</artifactId>
140+
</dependency>
138141
</dependencies>
139142

140143
<build>

bookshelf-standard/3-binary-data/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ Copyright 2016 Google Inc.
148148
<groupId>org.seleniumhq.selenium</groupId>
149149
<artifactId>selenium-server</artifactId>
150150
</dependency>
151+
<dependency>
152+
<groupId>org.seleniumhq.selenium</groupId>
153+
<artifactId>selenium-chrome-driver</artifactId>
154+
</dependency>
151155
</dependencies>
152156

153157
<build>

bookshelf-standard/4-auth/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ Copyright 2016 Google Inc.
148148
<groupId>org.seleniumhq.selenium</groupId>
149149
<artifactId>selenium-server</artifactId>
150150
</dependency>
151+
<dependency>
152+
<groupId>org.seleniumhq.selenium</groupId>
153+
<artifactId>selenium-chrome-driver</artifactId>
154+
</dependency>
151155
</dependencies>
152156

153157
<build>

bookshelf-standard/5-logging/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ Copyright 2016 Google Inc.
148148
<groupId>org.seleniumhq.selenium</groupId>
149149
<artifactId>selenium-server</artifactId>
150150
</dependency>
151+
<dependency>
152+
<groupId>org.seleniumhq.selenium</groupId>
153+
<artifactId>selenium-chrome-driver</artifactId>
154+
</dependency>
151155
</dependencies>
152156

153157
<build>

bookshelf/2-structured-data/pom.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,10 @@ Copyright 2016 Google Inc.
161161
<groupId>org.seleniumhq.selenium</groupId>
162162
<artifactId>selenium-server</artifactId>
163163
</dependency>
164-
<!-- selenium / guava chokes without this for some reason. -->
165-
<dependency>
166-
<groupId>org.apache.httpcomponents</groupId>
167-
<artifactId>httpclient</artifactId>
168-
<version>4.3.5</version>
169-
</dependency>
164+
<dependency>
165+
<groupId>org.seleniumhq.selenium</groupId>
166+
<artifactId>selenium-chrome-driver</artifactId>
167+
</dependency>
170168
</dependencies>
171169

172170
<build>

bookshelf/3-binary-data/pom.xml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Copyright 2016 Google Inc.
4747
<!-- [END config] -->
4848

4949
<appengine.maven.plugin>1.0.0</appengine.maven.plugin>
50-
<jetty.maven.plugin>9.3.8.v20160314</jetty.maven.plugin>
50+
<jetty.maven.plugin>9.4.3.v20170317</jetty.maven.plugin>
5151

5252
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5353
<maven.compiler.source>1.8</maven.compiler.source> <!-- REQUIRED -->
@@ -98,6 +98,12 @@ Copyright 2016 Google Inc.
9898
<groupId>com.google.api-client</groupId>
9999
<artifactId>google-api-client</artifactId>
100100
<version>1.22.0</version>
101+
<exclusions>
102+
<exclusion>
103+
<groupId>com.google.guava</groupId>
104+
<artifactId>guava-jdk5</artifactId>
105+
</exclusion>
106+
</exclusions>
101107
</dependency>
102108

103109
<dependency> <!-- Google+ API Client Library for Java -->
@@ -113,9 +119,9 @@ Copyright 2016 Google Inc.
113119
</dependency>
114120

115121
<dependency> <!-- Google Core Libraries for Java -->
116-
<groupId>com.google.guava</groupId>
117-
<artifactId>guava</artifactId> <!-- https://github.com/google/guava/wiki -->
118-
<version>21.0</version>
122+
<groupId>com.google.guava</groupId>
123+
<artifactId>guava</artifactId> <!-- https://github.com/google/guava/wiki -->
124+
<version>21.0</version>
119125
</dependency>
120126

121127
<dependency> <!-- http://www.joda.org/joda-time/ -->
@@ -148,6 +154,19 @@ Copyright 2016 Google Inc.
148154
<version>4.1.0</version>
149155
</dependency>
150156

157+
<!-- Test dependencies -->
158+
<dependency>
159+
<groupId>junit</groupId>
160+
<artifactId>junit</artifactId>
161+
</dependency>
162+
<dependency>
163+
<groupId>org.seleniumhq.selenium</groupId>
164+
<artifactId>selenium-server</artifactId>
165+
</dependency>
166+
<dependency>
167+
<groupId>org.seleniumhq.selenium</groupId>
168+
<artifactId>selenium-chrome-driver</artifactId>
169+
</dependency>
151170
</dependencies>
152171

153172
<build>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2017 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.getstarted.basicactions;
18+
19+
import com.google.cloud.datastore.Batch;
20+
import com.google.cloud.datastore.Datastore;
21+
import com.google.cloud.datastore.DatastoreOptions;
22+
import com.google.cloud.datastore.Key;
23+
import com.google.cloud.datastore.Query;
24+
import com.google.cloud.datastore.QueryResults;
25+
import com.google.cloud.datastore.StructuredQuery;
26+
27+
import org.junit.After;
28+
import org.junit.AfterClass;
29+
import org.junit.Before;
30+
import org.junit.BeforeClass;
31+
import org.junit.Test;
32+
import org.junit.runner.RunWith;
33+
import org.junit.runners.JUnit4;
34+
35+
import org.openqa.selenium.WebDriver;
36+
import org.openqa.selenium.chrome.ChromeDriverService;
37+
import org.openqa.selenium.remote.DesiredCapabilities;
38+
import org.openqa.selenium.remote.RemoteWebDriver;
39+
import org.openqa.selenium.remote.service.DriverService;
40+
41+
@RunWith(JUnit4.class)
42+
@SuppressWarnings("checkstyle:abbreviationaswordinname")
43+
public class UserJourneyTestIT {
44+
45+
private static final String TITLE = "mytitle";
46+
private static final String AUTHOR = "myauthor";
47+
private static final String PUBLISHED_DATE = "1984-02-27";
48+
private static final String DESCRIPTION = "mydescription";
49+
50+
private static DriverService service;
51+
private WebDriver driver;
52+
53+
@BeforeClass
54+
public static void setupClass() throws Exception {
55+
service = ChromeDriverService.createDefaultService();
56+
service.start();
57+
}
58+
59+
@AfterClass
60+
public static void tearDownClass() {
61+
service.stop();
62+
63+
// Clear the datastore
64+
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
65+
Batch batch = datastore.newBatch();
66+
StructuredQuery<Key> query = Query.newKeyQueryBuilder()
67+
.setKind("Book3").build();
68+
for (QueryResults<Key> keys = datastore.run(query); keys.hasNext(); ) {
69+
batch.delete(keys.next());
70+
}
71+
batch.submit();
72+
}
73+
74+
@Before
75+
public void setup() {
76+
driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());
77+
}
78+
79+
@After
80+
public void tearDown() {
81+
driver.quit();
82+
}
83+
84+
@Test
85+
public void userJourney() throws Exception {
86+
driver.get("http://localhost:8080");
87+
}
88+
}

bookshelf/4-auth/pom.xml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Copyright 2016 Google Inc.
5555
<!-- [END config] -->
5656

5757
<appengine.maven.plugin>1.0.0</appengine.maven.plugin>
58-
<jetty.maven.plugin>9.3.8.v20160314</jetty.maven.plugin>
58+
<jetty.maven.plugin>9.4.3.v20170317</jetty.maven.plugin>
5959

6060
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6161
<maven.compiler.source>1.8</maven.compiler.source> <!-- REQUIRED -->
@@ -117,6 +117,12 @@ Copyright 2016 Google Inc.
117117
<groupId>com.google.api-client</groupId>
118118
<artifactId>google-api-client</artifactId>
119119
<version>1.22.0</version>
120+
<exclusions>
121+
<exclusion>
122+
<groupId>com.google.guava</groupId>
123+
<artifactId>guava-jdk5</artifactId>
124+
</exclusion>
125+
</exclusions>
120126
</dependency>
121127

122128
<dependency> <!-- Google+ API Client Library for Java -->
@@ -132,9 +138,9 @@ Copyright 2016 Google Inc.
132138
</dependency>
133139

134140
<dependency> <!-- Google Core Libraries for Java -->
135-
<groupId>com.google.guava</groupId>
136-
<artifactId>guava</artifactId> <!-- https://github.com/google/guava/wiki -->
137-
<version>21.0</version>
141+
<groupId>com.google.guava</groupId>
142+
<artifactId>guava</artifactId> <!-- https://github.com/google/guava/wiki -->
143+
<version>21.0</version>
138144
</dependency>
139145

140146
<dependency> <!-- http://www.joda.org/joda-time/ -->
@@ -167,6 +173,19 @@ Copyright 2016 Google Inc.
167173
<version>4.1.0</version>
168174
</dependency>
169175

176+
<!-- Test dependencies -->
177+
<dependency>
178+
<groupId>junit</groupId>
179+
<artifactId>junit</artifactId>
180+
</dependency>
181+
<dependency>
182+
<groupId>org.seleniumhq.selenium</groupId>
183+
<artifactId>selenium-server</artifactId>
184+
</dependency>
185+
<dependency>
186+
<groupId>org.seleniumhq.selenium</groupId>
187+
<artifactId>selenium-chrome-driver</artifactId>
188+
</dependency>
170189
</dependencies>
171190

172191
<build>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2017 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.getstarted.basicactions;
18+
19+
import com.google.cloud.datastore.Batch;
20+
import com.google.cloud.datastore.Datastore;
21+
import com.google.cloud.datastore.DatastoreOptions;
22+
import com.google.cloud.datastore.Key;
23+
import com.google.cloud.datastore.Query;
24+
import com.google.cloud.datastore.QueryResults;
25+
import com.google.cloud.datastore.StructuredQuery;
26+
27+
import org.junit.After;
28+
import org.junit.AfterClass;
29+
import org.junit.Before;
30+
import org.junit.BeforeClass;
31+
import org.junit.Test;
32+
import org.junit.runner.RunWith;
33+
import org.junit.runners.JUnit4;
34+
35+
import org.openqa.selenium.WebDriver;
36+
import org.openqa.selenium.chrome.ChromeDriverService;
37+
import org.openqa.selenium.remote.DesiredCapabilities;
38+
import org.openqa.selenium.remote.RemoteWebDriver;
39+
import org.openqa.selenium.remote.service.DriverService;
40+
41+
@RunWith(JUnit4.class)
42+
@SuppressWarnings("checkstyle:abbreviationaswordinname")
43+
public class UserJourneyTestIT {
44+
45+
private static final String TITLE = "mytitle";
46+
private static final String AUTHOR = "myauthor";
47+
private static final String PUBLISHED_DATE = "1984-02-27";
48+
private static final String DESCRIPTION = "mydescription";
49+
50+
private static DriverService service;
51+
private WebDriver driver;
52+
53+
@BeforeClass
54+
public static void setupClass() throws Exception {
55+
service = ChromeDriverService.createDefaultService();
56+
service.start();
57+
}
58+
59+
@AfterClass
60+
public static void tearDownClass() {
61+
service.stop();
62+
63+
// Clear the datastore
64+
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
65+
Batch batch = datastore.newBatch();
66+
StructuredQuery<Key> query = Query.newKeyQueryBuilder()
67+
.setKind("Book4").build();
68+
for (QueryResults<Key> keys = datastore.run(query); keys.hasNext(); ) {
69+
batch.delete(keys.next());
70+
}
71+
batch.submit();
72+
}
73+
74+
@Before
75+
public void setup() {
76+
driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());
77+
}
78+
79+
@After
80+
public void tearDown() {
81+
driver.quit();
82+
}
83+
84+
@Test
85+
public void userJourney() throws Exception {
86+
driver.get("http://localhost:8080");
87+
}
88+
}

0 commit comments

Comments
 (0)