Skip to content

Commit 4236fdd

Browse files
committed
Add system tests to pubsub quickstart.
1 parent 1f0c8a5 commit 4236fdd

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

pubsub/cloud-client/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Getting Started with Cloud Pub/Sub and the Google Cloud Client libraries
2+
3+
[Google Cloud Pub/Sub][pubsub] is a fully-managed real-time messaging service that allows you to
4+
send and receive messages between independent applications.
5+
These sample Java applications demonstrate how to access the Pub/Sub API using
6+
the [Google Cloud Client Library for Java][google-cloud-java].
7+
8+
[pubsub]: https://cloud.google.com/pubsub/
9+
[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java
10+
11+
## Quickstart
12+
13+
Install [Maven](http://maven.apache.org/).
14+
15+
Build your project with:
16+
17+
mvn clean package -DskipTests
18+
19+
You can then run a given `ClassName` via:
20+
21+
mvn exec:java -Dexec.mainClass=com.example.pubsub.ClassName \
22+
-DpropertyName=propertyValue \
23+
-Dexec.args="any arguments to the app"
24+
25+
### Creating a new topic (using the quickstart sample)
26+
27+
mvn exec:java -Dexec.mainClass=com.example.pubsub.QuickstartSample

pubsub/cloud-client/pom.xml

+14
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,19 @@
3939
<artifactId>google-cloud-pubsub</artifactId>
4040
<version>0.4.0</version>
4141
</dependency>
42+
43+
<!-- Test dependencies -->
44+
<dependency>
45+
<groupId>junit</groupId>
46+
<artifactId>junit</artifactId>
47+
<version>4.12</version>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>com.google.truth</groupId>
52+
<artifactId>truth</artifactId>
53+
<version>0.30</version>
54+
<scope>test</scope>
55+
</dependency>
4256
</dependencies>
4357
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Copyright 2016, 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.pubsub;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import com.google.cloud.pubsub.PubSub;
22+
import com.google.cloud.pubsub.PubSubOptions;
23+
import org.junit.After;
24+
import org.junit.Before;
25+
import org.junit.Test;
26+
import org.junit.runner.RunWith;
27+
import org.junit.runners.JUnit4;
28+
29+
import java.io.ByteArrayOutputStream;
30+
import java.io.PrintStream;
31+
32+
/**
33+
* Tests for quickstart sample.
34+
*/
35+
@RunWith(JUnit4.class)
36+
@SuppressWarnings("checkstyle:abbreviationaswordinname")
37+
public class QuickstartSampleIT {
38+
private ByteArrayOutputStream bout;
39+
private PrintStream out;
40+
41+
private static final void deleteTestTopic() {
42+
PubSub pubsub = PubSubOptions.defaultInstance().service();
43+
String topicName = "my-new-topic";
44+
pubsub.deleteTopic(topicName);
45+
}
46+
47+
@Before
48+
public void setUp() {
49+
deleteTestTopic();
50+
51+
bout = new ByteArrayOutputStream();
52+
out = new PrintStream(bout);
53+
System.setOut(out);
54+
}
55+
56+
@After
57+
public void tearDown() {
58+
System.setOut(null);
59+
deleteTestTopic();
60+
}
61+
62+
@Test
63+
public void testQuickstart() throws Exception {
64+
QuickstartSample.main();
65+
String got = bout.toString();
66+
assertThat(got).contains("Topic my-new-topic created.");
67+
}
68+
}
69+
// [END datastore_quickstart]

0 commit comments

Comments
 (0)