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
|
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*
*******************************************************************************/
package org.eclipse.jst.jsp.core.tests.model;
import junit.framework.TestCase;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration;
import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation;
import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter;
import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapterFactory;
import org.eclipse.jst.jsp.core.tests.taglibindex.BundleResourceUtil;
import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
import org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.w3c.dom.Element;
/**
* Tests for JSP include directives
*/
public class TestModelIncludes extends TestCase {
String wtp_autotest_noninteractive = null;
protected void setUp() throws Exception {
super.setUp();
String noninteractive = System.getProperty("wtp.autotest.noninteractive");
if (noninteractive != null)
wtp_autotest_noninteractive = noninteractive;
System.setProperty("wtp.autotest.noninteractive", "true");
}
protected void tearDown() throws Exception {
super.tearDown();
if (wtp_autotest_noninteractive != null)
System.setProperty("wtp.autotest.noninteractive", wtp_autotest_noninteractive);
}
/**
* Tests the custom tag content model when single line fragments are used
* without trailing white space
*
* @throws Exception
*/
public void testContentModelSingleLineIncludedFileWithNoSpacesButWithTaglibInInclude() throws Exception {
String projectName = "prj119576_a";
BundleResourceUtil.createSimpleProject(projectName, null, null);
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + projectName, "/" + projectName);
assertTrue("project could not be created", ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).exists());
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/prj119576_a/WebContent/body2.jsp"));
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(file);
assertTrue("model has no content", model.getStructuredDocument().getLength() > 0);
Element element = (Element) model.getIndexedRegion(75);
CMElementDeclaration ed = ModelQueryUtil.getModelQuery(model).getCMElementDeclaration(element);
assertTrue("not a wrapping content model element declaration: " + ed.getNodeName(), ed instanceof CMNodeWrapper);
assertTrue("not a taglib content model element declaration: " + ed.getNodeName(), ((CMNodeWrapper) ed).getOriginNode() instanceof TLDElementDeclaration);
String tagClassName = ((TLDElementDeclaration) ((CMNodeWrapper) ed).getOriginNode()).getTagclass();
assertNotNull("no tag class name found", tagClassName);
}
finally {
if (model != null)
model.releaseFromRead();
}
}
/**
* Verify included files are translated properly when they contain a
* multiple lines
*
* @throws Exception
*/
public void testTranslateMultiLineIncludedFileWithSpacesAndScriptletInInclude() throws Exception {
String projectName = "prj119576_c";
BundleResourceUtil.createSimpleProject(projectName, null, null);
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + projectName, "/" + projectName);
assertTrue("project could not be created", ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).exists());
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/" + projectName + "/WebContent/body3.jsp"));
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(file);
assertTrue("model has no content", model.getStructuredDocument().getLength() > 0);
JSPTranslationAdapterFactory factory = new JSPTranslationAdapterFactory();
model.getFactoryRegistry().addFactory(factory);
JSPTranslationAdapter adapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
String source = adapter.getJSPTranslation().getJavaText();
assertTrue("scriptlet with variable declaration not found\n" + source, source.indexOf("java.util.Date headerDate") > -1);
}
finally {
if (model != null)
model.releaseFromRead();
}
}
/**
* Verify included files are translated properly when they contain a
* single line and document region and no trailing white space.
*
* @throws Exception
*/
public void testTranslateSingleLineIncludedFileWithNoSpacesButScriptletInInclude() throws Exception {
String projectName = "prj119576_b";
BundleResourceUtil.createSimpleProject(projectName, null, null);
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + projectName, "/" + projectName);
assertTrue("project could not be created", ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).exists());
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/" + projectName + "/WebContent/body3.jsp"));
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(file);
assertTrue("model has no content", model.getStructuredDocument().getLength() > 0);
JSPTranslationAdapterFactory factory = new JSPTranslationAdapterFactory();
model.getFactoryRegistry().addFactory(factory);
JSPTranslationAdapter adapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
String source = adapter.getJSPTranslation().getJavaText();
assertTrue("scriptlet with variable declaration not found", source.indexOf("java.util.Date headerDate") > -1);
}
finally {
if (model != null)
model.releaseFromRead();
}
}
}
|