@@ -0,0 +1,3189 @@
+/*%0A * Copyright 2019 Google LLC%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     https://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.google.cloud.dialogflow.v2;%0A%0Aimport com.google.common.base.Preconditions;%0Aimport com.google.common.collect.Lists;%0Aimport com.google.protobuf.Value;%0Aimport java.io.IOException;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.UUID;%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger;%0Aimport org.junit.Test;%0A%0Apublic class ContextManagementSmokeTest %7B%0A  private static final String PROJECT_ENV_NAME = %22GOOGLE_CLOUD_PROJECT%22;%0A  private static final String LEGACY_PROJECT_ENV_NAME = %22GCLOUD_PROJECT%22;%0A  private static String SESSION_ID = UUID.randomUUID().toString();%0A%0A  public static void main(String args%5B%5D) %7B%0A    Logger.getLogger(%22%22).setLevel(Level.WARNING);%0A    try %7B%0A      listContexts(SESSION_ID, getProjectId());%0A      System.out.println(%22OK%22);%0A    %7D catch (IOException e) %7B%0A      System.err.println(%22Failed with exception:%22);%0A      e.printStackTrace(System.err);%0A      System.exit(1);%0A    %7D%0A  %7D%0A%0A  @Test%0A  public void run() %7B%0A    main(null);%0A  %7D%0A%0A  /**%0A   * Lists contexts%0A   *%0A   * @param sessionId Identifier of the DetectIntent session.%0A   * @param projectId Project/Agent Id.%0A   * @return List of Contexts found.%0A   */%0A  public static List%3CContext%3E listContexts(String sessionId, String projectId) throws IOException %7B%0A    List%3CContext%3E contexts = Lists.newArrayList();%0A    // Instantiates a client%0A    try (ContextsClient contextsClient = ContextsClient.create()) %7B%0A      // Set the session name using the sessionId (UUID) and projectId (my-project-id)%0A      SessionName session = SessionName.of(projectId, sessionId);%0A%0A      // Performs the list contexts request%0A      for (Context context : contextsClient.listContexts(session).iterateAll()) %7B%0A        System.out.format(%22Context name: %25s%5Cn%22, context.getName());%0A        System.out.format(%22Lifespan Count: %25d%5Cn%22, context.getLifespanCount());%0A        System.out.format(%22Fields:%5Cn%22);%0A        for (Map.Entry%3CString, Value%3E entry : context.getParameters().getFieldsMap().entrySet()) %7B%0A          if (entry.getValue().hasStructValue()) %7B%0A            System.out.format(%22%5Ct%25s: %25s%5Cn%22, entry.getKey(), entry.getValue());%0A          %7D%0A        %7D%0A%0A        contexts.add(context);%0A      %7D%0A    %7D%0A    return contexts;%0A  %7D%0A%0A  private static String getProjectId() %7B%0A    String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME));%0A    if (projectId == null) %7B%0A      projectId =%0A          System.getProperty(LEGACY_PROJECT_ENV_NAME, System.getenv(LEGACY_PROJECT_ENV_NAME));%0A    %7D%0A    Preconditions.checkArgument(projectId != null, %22A project ID is required.%22);%0A    return projectId;%0A  %7D%0A%7D%0A

Add ContextManagementSmokeTest (#6086)