Running Annotator unit test gives Cannot resolve symbol 'String' for basic JDK classes

Hi

I have problem with testing my Annotator because checkHighlighting report errors on basic JDK classes like 'String'. 

Is there way to setup the LightCodeInsightFixtureTestCase to use a JDK it run the inspecting test or what are my options?

public void testAnnotatorUnknownOptionWithConsumerAnnotationValidation() {
myFixture.configureByText("AnnotatorTestData.java", getJavaUnknownOptionsConsumerAnnotationTestData());
myFixture.checkHighlighting(false, false, true, true);
}
private String getJavaUnknownOptionsConsumerAnnotationTestData() {
return "public class MyRouteBuilder extends RouteBuilder {\n"
+ " @Consumer(file:test?allowNullBody=true&<error descr=\"Unknown option\">foo</error>=bar);"
+ " public void onCheese(String name) {}"
+ " }";
}

The full test case can be viewed here https://github.com/davsclaus/camel-idea-plugin/blob/master/camel-idea-plugin/src/test/java/org/apache/camel/idea/annotator/CamelAnnotatorTestIT.java 

Thanks

Flemming

0
7 comments
Official comment

Please set property idea.home.path property correctly, it must point to IJ community sources to find corresponding mockJDKs (see IdeaTestUtil)

Avatar
Permanently deleted user

I'm still not able to get it work, still the same issue

I follow the SDK guide "Tests Prerequisites" http://www.jetbrains.org/intellij/sdk/docs/tutorials/writing_tests_for_plugins/tests_prerequisites.html and set the idea.home.path to point to my IJ

-ea
-Xbootclasspath/p:../out/classes/production/boot
-XX:+HeapDumpOnOutOfMemoryError
-Xmx512m
-XX:MaxPermSize=320m
-Didea.system.path=target/test-system
-Didea.config.path=target/test-config
-Didea.test.group=ALL_EXCLUDE_DEFINED
-Didea.load.plugins.id=org.apache.camel
-Didea.home.path="C:/Program Files (x86)/JetBrains/IntelliJ IDEA Community Edition 2016.3.2/"

1

it must point to checked out IJ community sources, not the installation

2
Avatar
Permanently deleted user

Thanks, I missed that part in your previous comment

It's works now :-)

0
Avatar
Permanently deleted user

The code news it's working for JDK classes now, but after that I got the same problem for 3 party libraries.

public void testAnnotatorCamelPredicateValidation() {
myFixture.configureByText("AnnotatorTestData.java", getJavaWithCamelPredicate());
myFixture.checkHighlighting(false, false, false, true);
}

private String getJavaWithCamelPredicate() {
return "import org.apache.camel.builder.RouteBuilder;\n"
+ "public class MyRouteBuilder extends RouteBuilder {\n"
+ " public void configure() throws Exception {\n"
+ " from(\"direct:start\")\n"
+ " .loopDoWhile(simple(\"${body.length} <error descr=\"Unexpected token !\">=!=</error> 12\"))\n"
+ " .to(\"mock:loop\")\n"
+ " .transform(body().append(\"A\"))\n"
+ " .end()\n"
+ " .to(\"mock:result\");"
+ " }\n"
+ " }";
}

I have added the camel-core lib to myModule, but it still fail with "Cannot resolve symbol" for Apache Camel classes

import <error descr="Cannot resolve symbol 'org'">org</error>.apache.camel.builder.RouteBuilder;
public class MyRouteBuilder extends <error descr="Cannot resolve symbol 'RouteBuilder'">RouteBuilder</error> {
public void configure() throws <error descr="Cannot resolve symbol 'Exception'">Exception</error> {
<error descr="Cannot resolve method 'from(java.lang.String)'">from</error>("direct:start")
.loopDoWhile(<error descr="Cannot resolve method 'simple(java.lang.String)'">simple</error>("${body.length} =!= 12"))
.to("mock:loop")
.transform(<error descr="Cannot resolve method 'body()'">body</error>().append("A"))
.end()
.to("mock:result"); }
}
File[] mavenArtifacts = getMavenArtifacts(CAMEL_CORE_MAVEN_ARTIFACT);
VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(mavenArtifacts[0]);
PsiTestUtil.addProjectLibrary(myModule, "Maven: " + CAMEL_CORE_MAVEN_ARTIFACT, virtualFile);
final LibraryTable projectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myModule.getProject());

ApplicationManager.getApplication().runWriteAction(() -> {
Library library = projectLibraryTable.createLibrary("Maven: " + CAMEL_CORE_MAVEN_ARTIFACT);
final Library.ModifiableModel libraryModifiableModel = library.getModifiableModel();
libraryModifiableModel.addRoot(virtualFile, OrderRootType.CLASSES);
libraryModifiableModel.commit();
ModuleRootModificationUtil.addDependency(myModule, library);
});

How do you make it aware of 3 party libs in my test?

Thanks

 

0

Please use com.intellij.testFramework.PsiTestUtil to add libraries and perform other test project modifications.

 

0
Avatar
Permanently deleted user

Thanks!!!!

With the insight your provided, I was able to solve it by adding the library in the "getProjectDescription" method

@Override
protected LightProjectDescriptor getProjectDescriptor() {

return new DefaultLightProjectDescriptor() {
@Override
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
super.configureModule(module, model, contentEntry);
File[] mavenArtifacts;
try {
mavenArtifacts = getMavenArtifacts(CAMEL_CORE_MAVEN_ARTIFACT);
PsiTestUtil.addLibrary(module, model, "Maven: " + CAMEL_CORE_MAVEN_ARTIFACT, mavenArtifacts[0].getParent(), mavenArtifacts[0].getName());
} catch (IOException e) {
e.printStackTrace();
}

}
};
}

 

0

Please sign in to leave a comment.