Skip to main content
summaryrefslogtreecommitdiffstats
blob: 69b8ef3f2a9536ee3537ac35c1963946fdfa4887 (plain) (blame)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package org.eclipse.jst.ws.tests.unittest;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
import org.eclipse.jst.ws.internal.common.ResourceUtils;
import org.eclipse.jst.ws.tests.util.JUnitUtils;
import org.eclipse.wst.command.internal.env.context.PersistentResourceContext;
import org.eclipse.wst.command.internal.env.eclipse.EclipseEnvironment;
import org.eclipse.wst.command.internal.env.ui.eclipse.EclipseStatusHandler;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;

/**
 * JUnit tests for selective ResourceUtils methods.  Calls which return a simple String or rely on a IResource
 * API need not be tested.  The focus is mainly to exercise Component and Flexible project APIs. 
 * 
 */
public class ResourceUtilsTests extends TestCase implements WSJUnitConstants{


	public static Test suite(){
		return new TestSuite(ResourceUtilsTests.class);
	}
	
	public void testComponentType(){
		IProject project = ProjectUtilities.getProject(projectName);
		String componentType = ResourceUtils.getComponentType(project);
		assertEquals(IModuleConstants.JST_WEB_MODULE, componentType);
	}
	
	public void testComponentOf(){
		IProject project = ProjectUtilities.getProject(projectName);
        IPath destPath = ResourceUtils.getJavaSourceLocation(project);
        IFolder folder = (IFolder)ResourceUtils.findResource(destPath);
        try {
            PersistentResourceContext  resourceContext = PersistentResourceContext.getInstance();
            EclipseStatusHandler       handler         = new EclipseStatusHandler();
            EclipseEnvironment         env     = new EclipseEnvironment( null, resourceContext, handler );

            IFile file = folder.getFile(new Path("foo/Echo.java"));
            if (!file.exists()) {
              JUnitUtils.copyTestData("BUJava/src", folder, env, null );
            }
        }
        catch (Exception ex){
        	ex.printStackTrace();
        }

        IPath javaFilePath = folder.getFile(new Path("foo/Echo.java")).getFullPath();
        IVirtualComponent vc = ResourceUtils.getComponentOf(javaFilePath);
        assertTrue(vc.exists());
        
		
	}
	
	public void testJavaSourceLocation(){
		IProject project = ProjectUtilities.getProject(projectName);
		String javaSourceLoc = ResourceUtils.getJavaSourceLocation(project).toString();
		System.out.println("Java source location = "+javaSourceLoc);
		assertTrue(javaSourceLoc.endsWith("src"));
		
		// get all the JavaSourceLocations via the VirtualComponent
		IVirtualComponent vc1 = ComponentCore.createComponent(project);
		IVirtualComponent vc2 = ComponentCore.createComponent(project);
		IVirtualComponent[] vcs = new IVirtualComponent[]{vc1, vc2};
		IPath[] paths = ResourceUtils.getAllJavaSourceLocations(vcs);
		
		// verify first folder exists
		IPath path1 = (IPath)paths[0];
		IResource resource  = ResourceUtils.findResource(path1);
		if (resource.exists()){
			assertEquals(IResource.FOLDER, resource.getType());
		}

		// verify second folder exists
		IPath path2 = (IPath)paths[1];
		IResource resource2  = ResourceUtils.findResource(path2);
		if (resource2.exists()){
			assertEquals(IResource.FOLDER, resource2.getType());
		}		
	}
	
	public void testWebComponentServerRoot() {
		IProject project = ProjectUtilities.getProject(projectName);
		IFolder folder = ResourceUtils.getWebComponentServerRoot(project);
		assertTrue(folder.exists());
	
	}
	
}

Back to the top