Skip to content

Commit 3439c96

Browse files
authored
Add tests to Cloud Tasks Quickstart (#1497)
1 parent 7517dd7 commit 3439c96

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

appengine-java8/tasks/pom.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,27 @@ Copyright 2018 Google LLC
5252
<dependency>
5353
<groupId>com.google.cloud</groupId>
5454
<artifactId>google-cloud-tasks</artifactId>
55-
<version>1.6.0</version>
55+
<version>1.3.0</version>
5656
</dependency>
5757
<dependency>
5858
<groupId>commons-cli</groupId>
5959
<artifactId>commons-cli</artifactId>
6060
<version>1.4</version>
6161
<scope>compile</scope>
6262
</dependency>
63+
<!-- Test dependencies -->
64+
<dependency>
65+
<groupId>junit</groupId>
66+
<artifactId>junit</artifactId>
67+
<version>4.13-beta-2</version>
68+
<scope>test</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>com.google.truth</groupId>
72+
<artifactId>truth</artifactId>
73+
<version>0.44</version>
74+
<scope>test</scope>
75+
</dependency>
6376
</dependencies>
6477

6578
<build>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
private String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
38+
private String location = System.getenv("LOCATION_ID");
39+
private String queueName = System.getenv("QUEUE_ID");
40+
41+
@Before
42+
public void setUp() {
43+
bout = new ByteArrayOutputStream();
44+
out = new PrintStream(bout);
45+
System.setOut(out);
46+
}
47+
48+
@After
49+
public void tearDown() {
50+
System.setOut(null);
51+
}
52+
53+
@Test
54+
public void testCreateTask() throws Exception {
55+
CreateTask.main(
56+
new String[] {
57+
"--project-id", projectId,
58+
"--queue", queueName,
59+
"--location", location,
60+
}
61+
);
62+
String got = bout.toString();
63+
assertThat(got).contains("Task created:");
64+
}
65+
}

0 commit comments

Comments
 (0)