|
| 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.logging; |
| 18 | + |
| 19 | +import static com.google.common.truth.Truth.assertThat; |
| 20 | + |
| 21 | +import com.google.cloud.logging.Logging; |
| 22 | +import com.google.cloud.logging.LoggingOptions; |
| 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 | + |
| 39 | + private ByteArrayOutputStream bout; |
| 40 | + private PrintStream out; |
| 41 | + |
| 42 | + private static final void deleteMyLog() { |
| 43 | + Logging logging = LoggingOptions.getDefaultInstance().getService(); |
| 44 | + |
| 45 | + logging.deleteLog("my-log"); |
| 46 | + } |
| 47 | + |
| 48 | + @Before |
| 49 | + public void setUp() { |
| 50 | + deleteMyLog(); |
| 51 | + |
| 52 | + bout = new ByteArrayOutputStream(); |
| 53 | + out = new PrintStream(bout); |
| 54 | + System.setOut(out); |
| 55 | + } |
| 56 | + |
| 57 | + @After |
| 58 | + public void tearDown() { |
| 59 | + System.setOut(null); |
| 60 | + deleteMyLog(); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testQuickstart() throws Exception { |
| 65 | + QuickstartSample.main("my-log"); |
| 66 | + String got = bout.toString(); |
| 67 | + assertThat(got).contains("Logged: Hello, world!"); |
| 68 | + } |
| 69 | +} |
0 commit comments