Skip to content

Commit 13b4130

Browse files
authored
Add tests for Cloud Tasks app engine targets (GoogleCloudPlatform#1493)
* Add tests for cloud tasks app engine targets * Update env variable * Update queue location * Clean up tests * add scope to test dep
1 parent 693368c commit 13b4130

File tree

4 files changed

+73
-4
lines changed

4 files changed

+73
-4
lines changed

.kokoro/tests/run_tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ if [[ "$SCRIPT_DEBUG" != "true" ]]; then
5353
# Setup required env variables
5454
export GOOGLE_CLOUD_PROJECT=java-docs-samples-testing
5555
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-acct.json
56+
export QUEUE_ID=my-appengine-queue
57+
export LOCATION_ID=us-east1
5658
source "${KOKORO_GFILE_DIR}/aws-secrets.sh"
5759
source "${KOKORO_GFILE_DIR}/storage-hmac-credentials.sh"
5860
source "${KOKORO_GFILE_DIR}/dlp_secrets.txt"

appengine-java11/tasks/pom.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,22 @@ Copyright 2019 Google LLC
4545
<dependency>
4646
<groupId>com.google.cloud</groupId>
4747
<artifactId>google-cloud-tasks</artifactId>
48-
<version>1.6.0</version>
49-
<scope>provided</scope>
48+
<version>1.3.0</version>
5049
</dependency>
5150
<!-- [END gae_java11_task_pom] -->
51+
<!-- Test dependencies -->
52+
<dependency>
53+
<groupId>junit</groupId>
54+
<artifactId>junit</artifactId>
55+
<version>4.13-beta-2</version>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>com.google.truth</groupId>
60+
<artifactId>truth</artifactId>
61+
<version>0.44</version>
62+
<scope>test</scope>
63+
</dependency>
5264
</dependencies>
5365

5466
<build>

appengine-java11/tasks/src/main/java/com/example/task/CreateTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
import java.time.Instant;
3030

3131
public class CreateTask {
32-
public static void main(String[] args) throws Exception {
32+
public static void main(String... args) throws Exception {
3333
// Instantiates a client.
3434
try (CloudTasksClient client = CloudTasksClient.create()) {
3535
// Variables provided by system variables.
36-
String projectId = System.getenv("PROJECT_ID");
36+
String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
3737
String queueName = System.getenv("QUEUE_ID");
3838
String location = System.getenv("LOCATION_ID");
3939
// Optional variables.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2019 Google LLC
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.task;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import java.io.ByteArrayOutputStream;
22+
import java.io.PrintStream;
23+
import org.junit.After;
24+
import org.junit.Before;
25+
import org.junit.Rule;
26+
import org.junit.Test;
27+
import org.junit.rules.Timeout;
28+
import org.junit.runner.RunWith;
29+
import org.junit.runners.JUnit4;
30+
31+
/** Tests for creating Tasks with App Engine targets. */
32+
@RunWith(JUnit4.class)
33+
public class CreateTaskIT {
34+
private ByteArrayOutputStream bout;
35+
private PrintStream out;
36+
37+
@Before
38+
public void setUp() {
39+
bout = new ByteArrayOutputStream();
40+
out = new PrintStream(bout);
41+
System.setOut(out);
42+
}
43+
44+
@After
45+
public void tearDown() {
46+
System.setOut(null);
47+
}
48+
49+
@Test
50+
public void testCreateTask() throws Exception {
51+
CreateTask.main();
52+
String got = bout.toString();
53+
assertThat(got).contains("Task created:");
54+
}
55+
}

0 commit comments

Comments
 (0)