|
| 1 | +/* |
| 2 | + * Copyright (c) 2017 Google Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | + * in compliance with the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | + * or implied. See the License for the specific language governing permissions and limitations under |
| 12 | + * the License. |
| 13 | + */ |
| 14 | + |
| 15 | +package com.example; |
| 16 | + |
| 17 | +import static com.google.common.truth.Truth.assertThat; |
| 18 | + |
| 19 | +import org.junit.AfterClass; |
| 20 | +import org.junit.Before; |
| 21 | +import org.junit.BeforeClass; |
| 22 | +import org.junit.Test; |
| 23 | +import org.junit.runner.RunWith; |
| 24 | +import org.junit.runners.JUnit4; |
| 25 | + |
| 26 | +import java.io.ByteArrayOutputStream; |
| 27 | +import java.io.PrintStream; |
| 28 | + |
| 29 | +/** |
| 30 | + * Integration (system) tests for {@link Quickstart}. |
| 31 | + */ |
| 32 | +@RunWith(JUnit4.class) |
| 33 | +@SuppressWarnings("checkstyle:abbreviationaswordinname") |
| 34 | +public class QuickstartIT { |
| 35 | + |
| 36 | + private ByteArrayOutputStream bout; |
| 37 | + private PrintStream out; |
| 38 | + |
| 39 | + @BeforeClass |
| 40 | + public static void setUpClass() throws Exception { |
| 41 | + SnippetsIT.setUpClass(); |
| 42 | + ByteArrayOutputStream bout = new ByteArrayOutputStream(); |
| 43 | + PrintStream out = new PrintStream(bout); |
| 44 | + System.setOut(out); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Destroys all the keys created during this test run. |
| 49 | + */ |
| 50 | + @AfterClass |
| 51 | + public static void tearDownClass() throws Exception { |
| 52 | + SnippetsIT.tearDownClass(); |
| 53 | + } |
| 54 | + |
| 55 | + @Before |
| 56 | + public void setUp() throws Exception { |
| 57 | + bout = new ByteArrayOutputStream(); |
| 58 | + out = new PrintStream(bout); |
| 59 | + System.setOut(out); |
| 60 | + |
| 61 | + Snippets.createCryptoKeyVersion( |
| 62 | + SnippetsIT.PROJECT_ID, SnippetsIT.KEY_RING_ID, SnippetsIT.CRYPTO_KEY_ID); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void listKeyRings_printsKeyRing() throws Exception { |
| 67 | + Quickstart.main(SnippetsIT.PROJECT_ID); |
| 68 | + |
| 69 | + assertThat(bout.toString()).contains(String.format("keyRings/%s", SnippetsIT.KEY_RING_ID)); |
| 70 | + } |
| 71 | +} |
0 commit comments