summaryrefslogtreecommitdiff
path: root/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImportWizardTest.java
blob: bbf0d4acfa67f2b9bc46aa1c21821f5196c524f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 * Copyright 2000-2012 JetBrains s.r.o.
 *
 * 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 org.jetbrains.idea.eclipse;

import com.intellij.ide.projectWizard.ProjectWizardTestCase;
import com.intellij.ide.util.projectWizard.ImportFromSourcesProvider;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.idea.eclipse.importWizard.EclipseImportBuilder;
import org.jetbrains.idea.eclipse.importWizard.EclipseProjectImportProvider;

import java.io.File;
import java.io.IOException;

/**
 * @author Dmitry Avdeev
 *         Date: 11/7/12
 */
public class EclipseImportWizardTest extends ProjectWizardTestCase {

  public void testImportProject() throws Exception {
    Module module = doTest(".project");
    assertEquals("root", module.getName());
  }

  public void testImportClasspath() throws Exception {
    Module module = doTest(".classpath");
    assertEquals("root", module.getName());
  }

  public void testImportFromDirectory() throws Exception {
    Module module = doTest("");
    assertEquals("root", module.getName());
  }

  private Module doTest(final String fileName) throws IOException {
    copyTestData();
    return importProjectFrom(getProject().getBaseDir().getPath() + "/" + fileName, null,
                                      new EclipseProjectImportProvider(new EclipseImportBuilder()));
  }

  private void copyTestData() throws IOException {
    final File testRoot = new File(PluginPathManager.getPluginHomePath("eclipse") + "/testData", "import");
    FileUtil.copyDir(testRoot, new File(getProject().getBaseDir().getPath()));
  }

  public void testImportingFromTwoProviders() throws Exception {
    File file = createTempFile("Foo.java", "class Foo {}");
    Module module = importProjectFrom(file.getParent(), null, new ImportFromSourcesProvider(),
                                      new EclipseProjectImportProvider(new EclipseImportBuilder()));
    VirtualFile[] sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots();
    assertEquals(1, sourceRoots.length);
    assertEquals(LocalFileSystem.getInstance().findFileByIoFile(file.getParentFile()), sourceRoots[0]);
  }
}