use of org.eclipse.jst.jsp.core.internal.java.IJSPTranslation in project webtools.sourceediting by eclipse.
the class JSPJavaTranslatorCoreTest method testVariablesFromIncludedFragments.
public void testVariablesFromIncludedFragments() throws Exception {
String testName = "testVariablesFromIncludedFragments";
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
synchronized (creationLock) {
if (!project.isAccessible()) {
// Create new project
project = BundleResourceUtil.createSimpleProject(testName, null, null);
assertTrue(project.exists());
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
}
}
IFile main = project.getFile("/WebContent/main.jsp");
assertTrue("sample test file not accessible", main.isAccessible());
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(main);
ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
IJSPTranslation translation = translationAdapter.getJSPTranslation();
assertNotNull("no Java translation found", translation);
assertTrue("String variableFromHeader1 not found", translation.getJavaText().indexOf("String variableFromHeader1") > 0);
assertTrue("header1 contents not included", translation.getJavaText().indexOf("String variableFromHeader1 = \"initialized in header 1\";") > 0);
assertTrue("header2 contents not included", translation.getJavaText().indexOf("variableFromHeader1 = \"reassigned in header 2\";") > 0);
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.jst.jsp.core.internal.java.IJSPTranslation in project webtools.sourceediting by eclipse.
the class JSPJavaTranslatorCoreTest method test_preludes.
public void test_preludes() throws Exception {
String testName = "testPreludeAndCodas";
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
synchronized (creationLock) {
if (!project.isAccessible()) {
// Create new project
project = BundleResourceUtil.createSimpleProject(testName, null, null);
assertTrue(project.exists());
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
}
}
IFile main = project.getFile("/web stuff/prelude-user/test.jsp");
assertTrue("sample test file not accessible", main.isAccessible());
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(main);
ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
IJSPTranslation translation = translationAdapter.getJSPTranslation();
assertNotNull("no Java translation found", translation);
assertTrue("prelude0 contents not included", translation.getJavaText().indexOf("int prelude0") > 0);
assertTrue("prelude1 contents not included", translation.getJavaText().indexOf("int prelude1") > 0);
assertTrue("import statement not found", translation.getJavaText().indexOf("import java.lang.ref.Reference") > 0);
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.jst.jsp.core.internal.java.IJSPTranslation in project webtools.sourceediting by eclipse.
the class JSPTranslatorPersistenceTest method testCreateTranslationAdapter.
/**
* <p>This test case follows the general pattern of how a translation is created, then can be
* externalized when the workspace is closed, then reloaded when its opened again.</p>
*
* @throws Exception
*/
public void testCreateTranslationAdapter() throws Exception {
String outFileName = "testCreateTranslationAdapter.obj";
IStructuredModel structModel = null;
try {
structModel = getModelForRead("Test1.jsp");
// verify there is not already an existing translation adapter
IDOMDocument domDoc = ((IDOMModel) structModel).getDocument();
INodeAdapter existingAdapter = domDoc.getAdapterFor(IJSPTranslation.class);
assertNull("There should be no existing adapter for IJSPTranslation", existingAdapter);
// create a translator and externalize it, then load the externalized translator
JSPTranslator originalTranslator = writeTranslator(structModel, outFileName);
JSPTranslator externalizedTranslator = (JSPTranslator) readObject(outFileName);
// create an adaptr from the loaded externalized translator and add it to the doc
JSPTranslationAdapter restoredAdapter = new JSPTranslationAdapter((IDOMModel) structModel, externalizedTranslator);
domDoc.addAdapter(restoredAdapter);
// verify we can retrieve the adapter we just set
existingAdapter = domDoc.getAdapterFor(IJSPTranslation.class);
assertNotNull("There should now be an existing adapter for IJSPTranslation", existingAdapter);
assertTrue("Expected " + existingAdapter + " to be an instance of JSPTranslationAdapter", existingAdapter instanceof JSPTranslationAdapter);
JSPTranslationAdapter retrievedAdapter = (JSPTranslationAdapter) existingAdapter;
JSPTranslationExtension jspTranslationExtension = retrievedAdapter.getJSPTranslation();
/* verify that the original translation is equal to that of the
* retrieved adapter created from the previously externalized translator
*/
assertEquals("The original translation should be the same as the restored externalized translation", originalTranslator.getTranslation().toString(), jspTranslationExtension.getJavaText());
} finally {
if (structModel != null) {
structModel.releaseFromRead();
}
}
}
Aggregations