/*
 * Copyright (c) 2012-2018 Red Hat, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Red Hat, Inc. - initial API and implementation
 */
package org.eclipse.che.selenium.opendeclaration;

import static org.testng.Assert.fail;

import com.google.inject.Inject;
import java.net.URL;
import java.nio.file.Paths;
import org.eclipse.che.commons.lang.NameGenerator;
import org.eclipse.che.selenium.core.client.TestProjectServiceClient;
import org.eclipse.che.selenium.core.project.ProjectTemplates;
import org.eclipse.che.selenium.core.workspace.TestWorkspace;
import org.eclipse.che.selenium.pageobject.CodenvyEditor;
import org.eclipse.che.selenium.pageobject.Ide;
import org.eclipse.che.selenium.pageobject.ProjectExplorer;
import org.openqa.selenium.Keys;
import org.openqa.selenium.TimeoutException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

/**
 * @author Maxim Musienko
 * @author Aleksandr Shmaraev
 */
public class Eclipse0121Test {

  private static final String PATH_TO_PACKAGE_PREFIX = "/src/main/java/org/eclipse/qa/examples/";
  private static final String PROJECT_NAME =
      NameGenerator.generate(Eclipse0121Test.class.getSimpleName(), 4);

  @Inject private TestWorkspace ws;
  @Inject private Ide ide;
  @Inject private ProjectExplorer projectExplorer;
  @Inject private CodenvyEditor editor;
  @Inject private TestProjectServiceClient testProjectServiceClient;

  @BeforeClass
  public void prepare() throws Exception {
    URL resource = getClass().getResource("/projects/resolveTests_1_5_t0121");
    testProjectServiceClient.importProject(
        ws.getId(), Paths.get(resource.toURI()), PROJECT_NAME, ProjectTemplates.MAVEN_SPRING);
    ide.open(ws);
  }

  @Test
  public void test0121() throws Exception {
    projectExplorer.waitProjectExplorer();
    projectExplorer.waitItem(PROJECT_NAME);
    projectExplorer.quickExpandWithJavaScript();
    projectExplorer.openItemByPath(PROJECT_NAME + PATH_TO_PACKAGE_PREFIX + "Test.java");
    editor.waitActive();
    editor.goToCursorPositionVisible(15, 43);
    editor.typeTextIntoEditor(Keys.F4.toString());

    try {
      editor.waitTabIsPresent("Collections");
    } catch (TimeoutException ex) {
      // remove try-catch block after issue has been resolved
      fail("Known issue https://github.com/eclipse/che/issues/7161", ex);
    }

    editor.waitSpecifiedValueForLineAndChar(14, 35);
  }
}

@@ -1021,16 +1021,73 @@
 eption;%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import o
@@ -1121,16 +1121,16 @@
 eClass;%0A
-
 import o
@@ -1352,16 +1352,100 @@
 ples/%22;%0A
+  private static final Logger LOG = LoggerFactory.getLogger(Eclipse0121Test.class);%0A
   privat
@@ -2569,16 +2569,115 @@
 n ex) %7B%0A
+      logExternalLibraries();%0A      logProjectTypeChecking();%0A      logProjectLanguageChecking();%0A%0A
       //
@@ -2811,16 +2811,16 @@
 %0A    %7D%0A%0A
-
     edit
@@ -2867,11 +2867,743 @@
 35);%0A  %7D
+%0A%0A  private void logExternalLibraries() throws Exception %7B%0A    testProjectServiceClient%0A        .getExternalLibraries(ws.getId(), PROJECT_NAME)%0A        .forEach(library -%3E LOG.info(%22project external library:  %7B%7D%22, library));%0A  %7D%0A%0A  private void logProjectTypeChecking() throws Exception %7B%0A    LOG.info(%0A        %22Project type of the %7B%7D project is %5C%22maven%5C%22 - %7B%7D%22,%0A        PROJECT_NAME,%0A        testProjectServiceClient.checkProjectType(ws.getId(), PROJECT_NAME, %22maven%22));%0A  %7D%0A%0A  private void logProjectLanguageChecking() throws Exception %7B%0A    LOG.info(%0A        %22Project language of the %7B%7D project is %5C%22java%5C%22 - %7B%7D%22,%0A        PROJECT_NAME,%0A        testProjectServiceClient.checkProjectLanguage(ws.getId(), PROJECT_NAME, %22java%22));%0A  %7D
 %0A%7D%0A

Store list of external libraries, project type and project language for investigate #7161 bug (#8696)