|
| 1 | +/* |
| 2 | + * Copyright 2021 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.contactcenterinsights; |
| 18 | + |
| 19 | +import static com.google.common.truth.Truth.assertThat; |
| 20 | +import static junit.framework.TestCase.assertNotNull; |
| 21 | + |
| 22 | +import com.google.cloud.contactcenterinsights.v1.ContactCenterInsightsClient; |
| 23 | +import com.google.cloud.contactcenterinsights.v1.Settings; |
| 24 | +import com.google.cloud.contactcenterinsights.v1.SettingsName; |
| 25 | +import com.google.protobuf.Duration; |
| 26 | +import com.google.protobuf.FieldMask; |
| 27 | +import java.io.ByteArrayOutputStream; |
| 28 | +import java.io.IOException; |
| 29 | +import java.io.PrintStream; |
| 30 | +import org.junit.After; |
| 31 | +import org.junit.Before; |
| 32 | +import org.junit.BeforeClass; |
| 33 | +import org.junit.Test; |
| 34 | +import org.junit.runner.RunWith; |
| 35 | +import org.junit.runners.JUnit4; |
| 36 | + |
| 37 | +@RunWith(JUnit4.class) |
| 38 | +public class SetProjectTtlIT { |
| 39 | + |
| 40 | + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); |
| 41 | + private ByteArrayOutputStream bout; |
| 42 | + private PrintStream out; |
| 43 | + |
| 44 | + private static void requireEnvVar(String varName) { |
| 45 | + assertNotNull(String.format(varName), String.format(varName)); |
| 46 | + } |
| 47 | + |
| 48 | + @BeforeClass |
| 49 | + public static void checkRequirements() { |
| 50 | + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); |
| 51 | + requireEnvVar("GOOGLE_CLOUD_PROJECT"); |
| 52 | + } |
| 53 | + |
| 54 | + @Before |
| 55 | + public void setUp() { |
| 56 | + bout = new ByteArrayOutputStream(); |
| 57 | + out = new PrintStream(bout); |
| 58 | + System.setOut(out); |
| 59 | + } |
| 60 | + |
| 61 | + @After |
| 62 | + public void tearDown() throws IOException { |
| 63 | + try (ContactCenterInsightsClient client = ContactCenterInsightsClient.create()) { |
| 64 | + // Clear project-level TTL. |
| 65 | + SettingsName name = SettingsName.of(PROJECT_ID, "us-central1"); |
| 66 | + Settings settings = |
| 67 | + Settings.newBuilder() |
| 68 | + .setName(name.toString()) |
| 69 | + .setConversationTtl(Duration.newBuilder().build()) |
| 70 | + .build(); |
| 71 | + |
| 72 | + FieldMask updateMask = FieldMask.newBuilder().addPaths("conversation_ttl").build(); |
| 73 | + |
| 74 | + Settings response = client.updateSettings(settings, updateMask); |
| 75 | + } |
| 76 | + System.setOut(null); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void testSetProjecTtl() throws IOException { |
| 81 | + SetProjectTtl.setProjectTtl(PROJECT_ID); |
| 82 | + assertThat(bout.toString()).contains("Set TTL for all incoming conversations to 1 day"); |
| 83 | + } |
| 84 | +} |
0 commit comments