Skip to main content
summaryrefslogtreecommitdiffstats
blob: cd44d1b5b23c83f2c18226c166d82790e19d39d8 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/**
 * 
 */
package org.eclipse.jst.ws.tests.unittest;

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

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
import org.eclipse.jst.ws.internal.common.J2EEUtils;
import org.eclipse.jst.ws.internal.common.ResourceUtils;
import org.eclipse.jst.ws.internal.consumption.command.common.AssociateModuleWithEARCommand;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;

/**
 * @author sengpl
 *
 */
public class J2EEUtilsTests extends TestCase implements WSJUnitConstants{

    private IProject project1 = null;
    private IProject project2 = null;
    private IProject ejbProject = null;
    
    private String comp1 = webComponentName;
    private String comp2 = webComponent2Name;
    private String comp3 = webComp3Name;
    private String comp4 = webComp4Name;
	
	protected void setUp() throws Exception {
		super.setUp();
		
		// Project and component names initialized here!
		project1 = ProjectUtilities.getProject(webProjectName);
		assertNotNull(project1);
		
		project2 = ProjectUtilities.getProject(webProject2Name);
		assertNotNull(project2);
    
        ejbProject = ProjectUtilities.getProject(ejbProjectName);
        assertNotNull(ejbProject);
		
	}

	protected void tearDown() throws Exception {
		super.tearDown();
		// TODO Clear the workspace
		
	}

	 public static Test suite()
	  {
	    return new TestSuite(J2EEUtilsTests.class);
	  }
	 
	  public void testComponentsExist(){
		  System.out.println("< BEGIN: testComponentExists ...");
		  IVirtualComponent vc1 = J2EEUtils.getVirtualComponent(project1, comp1);
		  IVirtualComponent vc2 = J2EEUtils.getVirtualComponent(project2.getName(), comp3);
		  
		  assertTrue(vc1.exists());
		  assertTrue(J2EEUtils.exists(project1, comp1));
		  assertTrue(vc2.exists());
		  assertTrue(J2EEUtils.exists(project2.getName(), comp3));
		  System.out.println("< END: testComponentExists ...");
	  }
	  
	  public void testLocationGetterMethods(){
		  
		  System.out.println("< BEGIN: testLocationGetterMethods ...");
		  IPath loc1 = J2EEUtils.getWebContentPath(project1,comp1);
		  System.out.println("WebContentPath of comp1 = "+loc1);
		  IResource res = ResourceUtils.getWorkspaceRoot().findMember(loc1);
		  assertTrue(res.exists());
		  assertTrue(res.toString().endsWith("WebContent"));
		  
		  IPath loc2 = J2EEUtils.getWebContentPath(project2,comp3);
		  System.out.println("WebContentPath of comp1 = "+loc2);
		  IResource res2 = ResourceUtils.getWorkspaceRoot().findMember(loc2);
		  assertTrue(res2.exists());
		  assertTrue(res2.toString().endsWith("WebContent"));		  
		  
		  IPath loc3 = J2EEUtils.getWebInfPath(project1, comp2);
		  System.out.println("Web-INF path = "+loc3);
		  IResource res3 = ResourceUtils.getWorkspaceRoot().findMember(loc3);
		  assertTrue(res3.exists());
		  assertTrue(res3.toString().endsWith("WEB-INF"));
		  
		  IContainer container = J2EEUtils.getWebContentContainer(project2, comp3);
		  IResource res4 = ResourceUtils.getWorkspaceRoot().findMember(container.getFullPath());
		  assertEquals(res2, res4);
		  
		  System.out.println("< END: testLocationGetterMethods ...");
		  
	  }
	  
	  public void testJ2EEVersionMethods(){
		  
		  System.out.println("< BEGIN: testJ2EEVersionMethods ...");
	  
		  int j1 = J2EEUtils.getJ2EEVersion(project2, comp4);
		  
		  IVirtualComponent vc2 = J2EEUtils.getVirtualComponent(project1, comp2);
		  int j2 = J2EEUtils.getJ2EEVersion(vc2);
		  System.out.println("J2EEVersions p1: "+j2);
		  System.out.println("J2EEVersions p2: "+j1);		  
		  assertEquals(j1, j2);
		  
		  String j3 = J2EEUtils.getJ2EEVersionAsString(project1, comp1);
		  System.out.println("J2EEVersion p1 as String: "+j3);
		  assertEquals(j3, J2EEVersionConstants.VERSION_1_4_TEXT);
		  
		  System.out.println("< ENG: testJ2EEVersionMethods ...");
	  }

	  public void testComponentGetterMethods(){
		  
		  System.out.println("< BEGIN: testComponentGetterMethods ...");
		  
		  IVirtualComponent[] vcs = J2EEUtils.getAllComponents();
		  checkVirtualComponentsExists(vcs);
		  
		  IVirtualComponent[] vcs2 = J2EEUtils.getAllEARComponents();
		  checkVirtualComponentsExists(vcs2);
		  
		  IVirtualComponent[] vcs3 = J2EEUtils.getAllWebComponents();
		  checkVirtualComponentsExists(vcs3);
		  
		  IVirtualComponent[] vcs4 = J2EEUtils.getWebComponents(project1);
		  checkVirtualComponentsExists(vcs4);
		  
		  String[] names = J2EEUtils.getWebComponentNames(project2);
		  printNameStrings(names);
		  
		  String[] names2 = J2EEUtils.toComponentNamesArray(J2EEUtils.getComponentsByType(project1, J2EEUtils.WEB | J2EEUtils.EJB));
		  printNameStrings(names2);
		  
		  IProject[] projects = J2EEUtils.getAllFlexibleProjects();
		  for (int i=0;i<projects.length;i++){
			  System.out.println("Flex project "+i+" = "+projects[i]);
		  }
		  
		  System.out.println("< END: testComponentGetterMethods ...");
	  }
	  
	  private void checkVirtualComponentsExists(IVirtualComponent[] vcs){
		  if (vcs.length == 0)
			  System.out.println("Empty....");
		  
		  for (int i=0; i<vcs.length;i++){
			  IVirtualComponent vc = vcs[i];
			  System.out.println("VC: Project = "+vc.getProject()+" Name = "+vc.getName());
			  assertTrue(vc.exists());
			  
		  }
	  }
	  
	  private void printNameStrings(String[] names){
		  for (int i=0;i<names.length;i++){
			  System.out.println("Name"+i+" = "+names[i]);
		  }
	  }
	  
      public void testAssociateComponentCommand(){
        
        System.out.println("< BEGIN: testAssociateComponentCommand ...");
        
        AssociateModuleWithEARCommand amwe = new AssociateModuleWithEARCommand();
        amwe.setEar(earCompName);
        amwe.setEARProject(webProjectName);
        amwe.setModule(comp1);
        amwe.setProject(webProjectName);
        amwe.execute(null);
        
        System.out.println("< END: testAssociateComponentCommand ...");     
      }
    
	  public void testReferencingGetterMethods(){
		  
		  System.out.println("< BEGIN: testReferencingGetterMethods ...");
		  
		  System.out.println("isComponentAssociated ..");
		  J2EEUtils.isComponentAssociated(project1, earCompName, project1, comp1);
		
		  String[] names = J2EEUtils.toComponentNamesArray(J2EEUtils.getReferencingEARComponents(project1, comp1));
		  printNameStrings(names);
		  String[] names2 = J2EEUtils.toComponentNamesArray(J2EEUtils.getReferencingEARComponents(project2, comp3));
		  printNameStrings(names2);
		  
		  String[] names3 = J2EEUtils.toComponentNamesArray(J2EEUtils.getReferencingWebComponentsFromEAR(project1, earCompName));
		  printNameStrings(names3);
		  
		  System.out.println("< END: testReferencingGetterMethods ...");
	  }
	  
	  public void testIsComponentMethods(){
		
		  System.out.println("< BEGIN: testIsComponentMethods ...");
		  
		  //assertFalse(J2EEUtils.isEJB20Component(ejbProject, ejbComponentName));
		  assertTrue(J2EEUtils.isEJB20Component(ejbProject, ejbComponentName));
		  
		  System.out.println("< END: testIsComponentMethods ...");
	  }
	  

	  
}

Back to the top