|
| 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