PT #158345230: Added tests for javadoc from Eclipse client
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.springframework.tooling.ls.eclipse.commons.test</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -0,0 +1,14 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Test
|
||||
Bundle-SymbolicName: org.springframework.tooling.ls.eclipse.commons.test
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Automatic-Module-Name: org.springframework.tooling.ls.eclipse.commons.test
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Require-Bundle: org.junit,
|
||||
org.eclipse.core.runtime,
|
||||
org.eclipse.core.resources,
|
||||
org.springframework.tooling.ls.eclipse.commons,
|
||||
org.eclipse.jdt.core,
|
||||
org.apache.commons.io,
|
||||
org.springframework.tooling.jdt.ls.commons
|
||||
@@ -0,0 +1,4 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
@@ -0,0 +1,82 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>eclipse-test-plugin</packaging>
|
||||
<artifactId>org.springframework.tooling.ls.eclipse.commons.test</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>org.springframework.tooling.ls.eclipse.commons.test</name>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot.ide</groupId>
|
||||
<artifactId>org.springframework.boot.ide.servers</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<test.argLine></test.argLine>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>osx</id>
|
||||
<activation>
|
||||
<os>
|
||||
<family>mac</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<test.argLine>-XstartOnFirstThread</test.argLine>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>target-platform-configuration</artifactId>
|
||||
<configuration>
|
||||
<dependency-resolution>
|
||||
<extraRequirements>
|
||||
<requirement>
|
||||
<type>eclipse-feature</type>
|
||||
<id>org.eclipse.jdt</id>
|
||||
<versionRange>0.0.0</versionRange>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<type>eclipse-feature</type>
|
||||
<id>org.eclipse.platform</id>
|
||||
<versionRange>0.0.0</versionRange>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<type>eclipse-feature</type>
|
||||
<id>org.eclipse.rcp</id>
|
||||
<versionRange>0.0.0</versionRange>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<type>eclipse-feature</type>
|
||||
<id>org.eclipse.m2e.feature</id>
|
||||
<versionRange>0.0.0</versionRange>
|
||||
</requirement>
|
||||
</extraRequirements>
|
||||
</dependency-resolution>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>tycho-surefire-plugin</artifactId>
|
||||
<version>${tycho-version}</version>
|
||||
<configuration>
|
||||
<forkedProcessTimeoutInSeconds>200</forkedProcessTimeoutInSeconds>
|
||||
<includes>**/*Test.java</includes>
|
||||
<useUIHarness>true</useUIHarness>
|
||||
<argLine>${test.argLine}</argLine>
|
||||
<trimStackTrace>false</trimStackTrace>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,86 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, 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:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jdt.core.IField;
|
||||
import org.eclipse.jdt.core.IJavaProject;
|
||||
import org.eclipse.jdt.core.IMethod;
|
||||
import org.eclipse.jdt.core.IType;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.tooling.jdt.ls.commons.javadoc.JavadocResponse;
|
||||
import org.springframework.tooling.ls.eclipse.commons.JavadocParams;
|
||||
import org.springframework.tooling.ls.eclipse.commons.STS4LanguageClientImpl;
|
||||
|
||||
public class JavadocTest {
|
||||
|
||||
private static STS4LanguageClientImpl client = new STS4LanguageClientImpl();
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TestUtils.deleteAllProjects();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void classJavadoc() throws Exception {
|
||||
IJavaProject project = TestUtils.createTestProject("simple-java-project");
|
||||
assertNotNull(project);
|
||||
IType type = project.findType("com.sample.SampleJavadoc");
|
||||
assertNotNull(type);
|
||||
|
||||
String expectedBindingKey = "Lcom/sample/SampleJavadoc;";
|
||||
assertEquals(expectedBindingKey, type.getKey());
|
||||
|
||||
JavadocParams params = new JavadocParams(project.getProject().getLocation().toFile().toURI().toString(), expectedBindingKey);
|
||||
JavadocResponse response = client.javadoc(params).get(1, TimeUnit.SECONDS);
|
||||
assertEquals("**Sample class**", response.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldJavadoc() throws Exception {
|
||||
IJavaProject project = TestUtils.createTestProject("simple-java-project");
|
||||
assertNotNull(project);
|
||||
IType type = project.findType("com.sample.SampleJavadoc");
|
||||
assertNotNull(type);
|
||||
IField field = type.getField("number");
|
||||
assertNotNull(field);
|
||||
|
||||
String expectedBindingKey = "Lcom/sample/SampleJavadoc;.number";
|
||||
assertEquals(expectedBindingKey, field.getKey());
|
||||
|
||||
JavadocParams params = new JavadocParams(project.getProject().getLocation().toFile().toURI().toString(), expectedBindingKey);
|
||||
JavadocResponse response = client.javadoc(params).get(1, TimeUnit.SECONDS);
|
||||
assertEquals("**Sample field**", response.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methodJavadoc() throws Exception {
|
||||
IJavaProject project = TestUtils.createTestProject("simple-java-project");
|
||||
assertNotNull(project);
|
||||
IType type = project.findType("com.sample.SampleJavadoc");
|
||||
assertNotNull(type);
|
||||
IMethod method = type.getMethod("getNumber", new String[0]);
|
||||
assertNotNull(method);
|
||||
|
||||
String expectedBindingKey = "Lcom/sample/SampleJavadoc;.getNumber()V";
|
||||
assertEquals(expectedBindingKey, method.getKey());
|
||||
|
||||
JavadocParams params = new JavadocParams(project.getProject().getLocation().toFile().toURI().toString(), expectedBindingKey);
|
||||
JavadocResponse response = client.javadoc(params).get(1, TimeUnit.SECONDS);
|
||||
assertEquals("**Sample getter**", response.getContent());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, 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:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.tooling.ls.eclipse.commons.test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IncrementalProjectBuilder;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.FileLocator;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.jdt.core.IJavaProject;
|
||||
import org.eclipse.jdt.core.JavaCore;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
public static IJavaProject createTestProject(String name) throws Exception {
|
||||
File testProjectSourceLocation = new File(FileLocator.toFileURL(Platform.getBundle("org.springframework.tooling.ls.eclipse.commons.test").getEntry("test-projects/"+name)).toURI());
|
||||
File targetWorkspace = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
|
||||
|
||||
FileUtils.copyDirectory(testProjectSourceLocation, new File(targetWorkspace, name));
|
||||
|
||||
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
|
||||
project.create(null);
|
||||
project.open(null);
|
||||
project.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
|
||||
assertTrue(project.hasNature(JavaCore.NATURE_ID));
|
||||
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
|
||||
|
||||
return JavaCore.create(project);
|
||||
}
|
||||
|
||||
public static void deleteAllProjects() throws Exception {
|
||||
IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
||||
for (IProject project : allProjects) {
|
||||
project.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
project.close(null);
|
||||
deleteProject(project);
|
||||
}
|
||||
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
|
||||
}
|
||||
|
||||
private static void deleteProject(IProject project) throws Exception {
|
||||
int retryCount = 10; // wait 1 minute at most
|
||||
Exception lastException = null;
|
||||
while (project.exists() && --retryCount >= 0) {
|
||||
try {
|
||||
project.delete(true, true, new NullProgressMonitor());
|
||||
lastException = null;
|
||||
} catch (Exception e) {
|
||||
lastException = e;
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch (InterruptedException e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lastException!=null) {
|
||||
throw lastException;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.sample;
|
||||
|
||||
/**
|
||||
* <b>Sample class</b>
|
||||
*/
|
||||
public class SampleJavadoc {
|
||||
|
||||
/**
|
||||
* <b>Sample field</b>
|
||||
*/
|
||||
public int number;
|
||||
|
||||
/**
|
||||
* <b>Sample getter</b>
|
||||
*/
|
||||
public int getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
<modules>
|
||||
<module>../headless-services/jdt-ls-extension</module>
|
||||
<module>org.springframework.tooling.ls.eclipse.commons</module>
|
||||
<module>org.springframework.tooling.ls.eclipse.commons.test</module>
|
||||
|
||||
<module>org.springframework.tooling.cloudfoundry.manifest.ls</module>
|
||||
<module>org.springframework.tooling.cloudfoundry.manifest.ls.feature</module>
|
||||
|
||||
Reference in New Issue
Block a user