blob: f1a886f6ac0853cb50244bcd8112fe98d5b1d0e0 [file] [log] [blame]
package org.eclipse.jst.j2ee.classpath.tests;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jst.j2ee.classpath.tests.util.ClasspathDependencyTestUtil;
import org.eclipse.jst.j2ee.classpathdep.UpdateClasspathAttributeUtil;
import org.eclipse.jst.j2ee.dependency.tests.util.ProjectUtil;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* Tests creation of classpath component dependencies via addition of the
* classpath entry attribute.
*/
public class ClasspathDependencyCreationTests extends AbstractTests {
private ClasspathDependencyCreationTests(final String name) {
super(name);
}
public static Test suite(){
final TestSuite suite = new TestSuite();
suite.setName("Classpath Component Dependency Creation Tests" );
suite.addTest(new ClasspathDependencyCreationTests("testNoClasspathDependencies"));
suite.addTest(new ClasspathDependencyCreationTests("testAddRemoveClasspathDependency"));
suite.addTest(new ClasspathDependencyCreationTests("testLibraryClasspathDependency"));
return suite;
}
public void testNoClasspathDependencies() throws Exception {
final IProject project = ProjectUtil.createUtilityProject("TestUtil", "TestEAR");
final IJavaProject javaProject = JavaCore.create(project);
final IVirtualComponent comp = ComponentCore.createComponent(project);
ClasspathDependencyTestUtil.verifyNoClasspathAttributes(javaProject);
ClasspathDependencyTestUtil.verifyNoPotentialClasspathEntries(javaProject);
ClasspathDependencyTestUtil.verifyNoClasspathDependencies(comp);
}
public void testAddRemoveClasspathDependency() throws Exception {
final IProject project = ProjectUtil.createUtilityProject("TestUtil", "TestEAR");
final IJavaProject javaProject = JavaCore.create(project);
final IVirtualComponent comp = ComponentCore.createComponent(project);
ClasspathDependencyTestUtil.verifyNoClasspathAttributes(javaProject);
ClasspathDependencyTestUtil.verifyNoPotentialClasspathEntries(javaProject);
ClasspathDependencyTestUtil.verifyNoClasspathDependencies(comp);
ClasspathDependencyTestUtil.addCustomClasspathContainer(javaProject);
final Set entryPaths = new HashSet();
entryPaths.add(ClasspathDependencyTestUtil.CUSTOM_CLASSPATH_CONTAINER);
List entries = ClasspathDependencyTestUtil.verifyPotentialClasspathEntries(javaProject, entryPaths);
ClasspathDependencyTestUtil.verifyNoClasspathAttributes(javaProject);
ClasspathDependencyTestUtil.verifyNoClasspathDependencies(comp);
IClasspathEntry entry = (IClasspathEntry) entries.get(0);
UpdateClasspathAttributeUtil.addDependencyAttribute(null, project.getName(), entry);
ClasspathDependencyTestUtil.verifyNoPotentialClasspathEntries(javaProject);
ClasspathDependencyTestUtil.verifyClasspathAttributes(javaProject, entryPaths);
final Set archiveNames = new HashSet();
archiveNames.add(ClasspathDependencyTestUtil.TEST1_JAR);
archiveNames.add(ClasspathDependencyTestUtil.TEST2_JAR);
ClasspathDependencyTestUtil.verifyClasspathDependencies(comp, archiveNames);
UpdateClasspathAttributeUtil.removeDependencyAttribute(null, project.getName(), entry);
ClasspathDependencyTestUtil.verifyPotentialClasspathEntries(javaProject, entryPaths);
ClasspathDependencyTestUtil.verifyNoClasspathAttributes(javaProject);
ClasspathDependencyTestUtil.verifyNoClasspathDependencies(comp);
}
public void testLibraryClasspathDependency() throws Exception {
final IProject project = ProjectUtil.createWebProject("TestWeb", "TestEAR");
final IJavaProject javaProject = JavaCore.create(project);
final IVirtualComponent comp = ComponentCore.createComponent(project);
ClasspathDependencyTestUtil.verifyNoClasspathAttributes(javaProject);
ClasspathDependencyTestUtil.verifyNoPotentialClasspathEntries(javaProject);
ClasspathDependencyTestUtil.verifyNoClasspathDependencies(comp);
ClasspathDependencyTestUtil.addLibraryEntry(javaProject, ClasspathDependencyTestUtil.TEST3_JAR_PATH, true);
final Set entryPaths = new HashSet();
entryPaths.add(ClasspathDependencyTestUtil.TEST3_JAR_PATH);
List entries = ClasspathDependencyTestUtil.verifyPotentialClasspathEntries(javaProject, entryPaths);
ClasspathDependencyTestUtil.verifyNoClasspathAttributes(javaProject);
ClasspathDependencyTestUtil.verifyNoClasspathDependencies(comp);
IClasspathEntry entry = (IClasspathEntry) entries.get(0);
UpdateClasspathAttributeUtil.addDependencyAttribute(null, project.getName(), entry);
ClasspathDependencyTestUtil.verifyNoPotentialClasspathEntries(javaProject);
ClasspathDependencyTestUtil.verifyClasspathAttributes(javaProject, entryPaths);
final Set archiveNames = new HashSet();
archiveNames.add(ClasspathDependencyTestUtil.TEST3_JAR);
ClasspathDependencyTestUtil.verifyClasspathDependencies(comp, archiveNames);
}
}