Skip to content
This repository has been archived by the owner on Jun 13, 2020. It is now read-only.

Commit

Permalink
add test for StrutsConfigsSearcher
Browse files Browse the repository at this point in the history
  • Loading branch information
yann.cebron committed Feb 19, 2008
1 parent ad0d99b commit 1ac80ff
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* Copyright 2008 The authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.intellij.struts2.facet.ui;

import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.facet.Facet;
import com.intellij.facet.ui.FacetEditorContext;
import com.intellij.ide.util.projectWizard.ModuleBuilder;
import com.intellij.ide.util.projectWizard.WizardContext;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleRootModel;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.struts2.BasicHighlightingTestCase;
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Map;

/**
* Tests for {@link com.intellij.struts2.facet.ui.StrutsConfigsSearcher}.
*
* @author Yann CŽbron
*/
public class StrutsConfigsSearcherTestCase extends BasicHighlightingTestCase<JavaModuleFixtureBuilder> {

protected LocalInspectionTool[] getHighlightingInspections() {
return new LocalInspectionTool[0];
}

protected String getTestDataLocation() {
return "configsSearcher";
}

protected void configureModule(final JavaModuleFixtureBuilder moduleBuilder) throws Exception {
super.configureModule(moduleBuilder);
addStrutsJars(moduleBuilder);
}


private final FacetEditorContext myFacetEditorContext = new FacetEditorContext() {

@Nullable
public Project getProject() {
return myProject;
}

@Nullable
public Library findLibrary(@NotNull final String name) {
return null;
}

@Nullable
public ModuleBuilder getModuleBuilder() {
return null;
}

@Nullable
public Facet getFacet() {
return null;
}

@Nullable
public Facet getParentFacet() {
return null;
}

@NotNull
public FacetsProvider getFacetsProvider() {
throw new UnsupportedOperationException("'getFacetsProvider' not implemented in " + getClass().getName());
}

@NotNull
public ModulesProvider getModulesProvider() {
throw new UnsupportedOperationException("'getModulesProvider' not implemented in " + getClass().getName());
}

@Nullable
public ModifiableRootModel getModifiableRootModel() {
return null;
}

@Nullable
public ModuleRootModel getRootModel() {
return null;
}

public boolean isNewFacet() {
return false;
}

@Nullable
public Module getModule() {
return myModule;
}

public Library[] getLibraries() {
return new Library[0];
}

@Nullable
public WizardContext getWizardContext() {
return null;
}

public Library createProjectLibrary(final String name, final VirtualFile[] roots, final VirtualFile[] sources) {
throw new UnsupportedOperationException("'createProjectLibrary' not implemented in " + getClass().getName());
}

public VirtualFile[] getLibraryFiles(final Library library, final OrderRootType rootType) {
return VirtualFile.EMPTY_ARRAY;
}

@NotNull
public String getFacetName() {
return "";
}

public <T> T getUserData(final Key<T> key) {
return null;
}

public <T> void putUserData(final Key<T> key, final T value) {
}
};

public void testSearch() throws Exception {
final StrutsConfigsSearcher configsSearcher = new StrutsConfigsSearcher(myFacetEditorContext);
configsSearcher.search();

final Map<Module, List<PsiFile>> map = configsSearcher.getFilesByModules();
assertEquals(map.size(), 1);
assertEquals(map.get(myModule).size(), 1); // /src/struts.xml

final Map<VirtualFile, List<PsiFile>> configsInJars = configsSearcher.getJars();
assertEquals(configsInJars.size(), 2); // default-xxx.xml in struts2-core.jar & xwork.jar
}

}
9 changes: 9 additions & 0 deletions plugin/testData/configsSearcher/src/struts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<!-- empty struts.xml to be found by StrutsConfigsSearcher -->
<struts>
</struts>

0 comments on commit 1ac80ff

Please sign in to comment.