Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Re: JUnit Test on JET Transform
Re: JUnit Test on JET Transform [message #39196] Fri, 11 January 2008 00:21 Go to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Roshan,

Please use the M2T newsgroup for JET2 questions. I've added it to the
"to" list of the reply so there's no need to repost.


Roshan Soni wrote:
> Hi,
>
> I want to run a JUnit test on a JET2 template by running the
> transform, but whenever I try to run the transform inside of my test i.e.
> -JET2Platform.runTransformOnObject(...)
> -Compare results with expected output
> -assertTrue
>
> The problem is that the transformation is not being run. I tried to
> run it within a Job, but I still had no luck. Any ideas would be
> greatly appreciated:
>
> Job job = new Job("SD .NET Generation") {
> protected IStatus run(final IProgressMonitor monitor) {
> Map variablesMap = initializeInputs();
> JET2Platform.runTransformOnObject("project.transform", null,
> variablesMap, monitor);
>
> return Status.OK_STATUS;
> }
> };
>
Re: JUnit Test on JET Transform [message #39814 is a reply to message #39196] Tue, 15 January 2008 14:42 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Roshan:

JET runs some JET transformations as part of its JUnit suite. Take a look
at.

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.m2t/org .eclipse.jet/tests/org.eclipse.jet.tests/src/org/eclipse/jet /tests/parser/resources/ResourceTemplateInputTest.java?revis ion=1.1&root=Modeling_Project&view=markup

.... and then ask more questions ;-)

Paul

"Ed Merks" <merks@ca.ibm.com> wrote in message
news:fm6ctg$hl8$2@build.eclipse.org...
> Roshan,
>
> Please use the M2T newsgroup for JET2 questions. I've added it to the
> "to" list of the reply so there's no need to repost.
>
>
> Roshan Soni wrote:
>> Hi,
>>
>> I want to run a JUnit test on a JET2 template by running the transform,
>> but whenever I try to run the transform inside of my test i.e.
>> -JET2Platform.runTransformOnObject(...)
>> -Compare results with expected output
>> -assertTrue
>>
>> The problem is that the transformation is not being run. I tried to run
>> it within a Job, but I still had no luck. Any ideas would be greatly
>> appreciated:
>>
>> Job job = new Job("SD .NET Generation") {
>> protected IStatus run(final IProgressMonitor monitor) {
>> Map variablesMap = initializeInputs();
>> JET2Platform.runTransformOnObject("project.transform", null,
>> variablesMap, monitor);
>> return Status.OK_STATUS;
>> }
>> };
>>
Re: JUnit Test on JET Transform [message #40300 is a reply to message #39814] Thu, 17 January 2008 23:06 Go to previous messageGo to next message
Roshan S. is currently offline Roshan S.Friend
Messages: 125
Registered: July 2009
Senior Member
Thanks Paul,

This is the type of test I want to run, but cannot get it to work. I have
a test class that runs this code as the test (I'll make it more robust
once I can get the transformation working in the test). When I run this
test I get the exception below. If I run my transform normally through my
launch file I do not receive any errors and I have output generated.

public void testTransform() throws Exception
{
Map variablesMap = initializeInputs();
IStatus status = JET2Platform.runTransformOnObject("com.tools.transform",
null, variablesMap, new NullProgressMonitor());

assertTrue("setUpAllTests", status.isOK());

try {
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
// TODO Auto-generated method stub

}}, new NullProgressMonitor());
} catch (CoreException e) {
fail(e.getMessage());
}
}



java.lang.ExceptionInInitializerError
at com.tools.test.AttachEventTest.testTransform(AttachEventTest .java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:130)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
Caused by: java.lang.NullPointerException
at org.eclipse.jet.JET2Platform.<clinit>(JET2Platform.java:76)
... 19 more
Re: JUnit Test on JET Transform [message #40485 is a reply to message #40300] Mon, 21 January 2008 16:12 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Roshan:

A quick look at the NPE suggests it happens if the JET plug-in has not been
started by Eclipse. How are you launching your JUnits?

You should be using an Eclipse launch configuration of type "JUnit Plug-in
Test".

Paul

"Roshan Soni" <roshan.soni1@gmail.com> wrote in message
news:7a10174e4db0877148ecce9616b7be55$1@www.eclipse.org...
> Thanks Paul,
> This is the type of test I want to run, but cannot get it to work. I have
> a test class that runs this code as the test (I'll make it more robust
> once I can get the transformation working in the test). When I run this
> test I get the exception below. If I run my transform normally through my
> launch file I do not receive any errors and I have output generated.
>
> public void testTransform() throws Exception {
> Map variablesMap = initializeInputs();
> IStatus status = JET2Platform.runTransformOnObject("com.tools.transform",
> null, variablesMap, new NullProgressMonitor());
>
> assertTrue("setUpAllTests", status.isOK());
>
> try {
> ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
> public void run(IProgressMonitor monitor) throws CoreException {
> // TODO Auto-generated method stub
>
> }}, new NullProgressMonitor());
> } catch (CoreException e) {
> fail(e.getMessage());
> } }
>
>
>
> java.lang.ExceptionInInitializerError
> at com.tools.test.AttachEventTest.testTransform(AttachEventTest .java:26)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at junit.framework.TestCase.runTest(TestCase.java:164)
> at junit.framework.TestCase.runBare(TestCase.java:130)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:120)
> at junit.framework.TestSuite.runTest(TestSuite.java:230)
> at junit.framework.TestSuite.run(TestSuite.java:225)
> at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestRefer ence.run(JUnit3TestReference.java:130)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
> Caused by: java.lang.NullPointerException
> at org.eclipse.jet.JET2Platform.<clinit>(JET2Platform.java:76)
> ... 19 more
>
>
>
Re: JUnit Test on JET Transform [message #40761 is a reply to message #40485] Tue, 22 January 2008 19:28 Go to previous messageGo to next message
Roshan S. is currently offline Roshan S.Friend
Messages: 125
Registered: July 2009
Senior Member
You're right it was a problem with my launch configuration and when I
properly setup my launch to run the correct plugin. I was orignally
running the same transform as my project and so my unit tests were not
running, but changing it to run the org.eclipse.sdk.ide product runs my
transformation and test.

Now I have a different question. On the basis of unit testing I want to
test my xpath. what would you say is a good test for the xpath in the
template snippet below? I was want to use XMLUnit to test because all of
my output is xml.

<c:when test="string($someControl/@attribute1) != 'true'">
<c:setVariable select="$composite_widget/@attribute1" var="myParent" />
</c:when>

Thanks,
Roshan
Re: JUnit Test on JET Transform [message #41011 is a reply to message #40761] Thu, 24 January 2008 16:30 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Roshan:

I'm not an XMLUnit expert, but here's a suggestion on JUnit testing JET
transformation results...

1) Run the JET transformation using a TestSetup extension. See:

http://junit.sourceforge.net/javadoc/junit/extensions/TestSe tup.html

JET uses this technique in some if its JUnits:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.m2t/org .eclipse.jet/tests/org.eclipse.jet.tests/src/org/eclipse/jet /tests/parser/resources/ResourceTemplateInputTest.java?revis ion=1.1&root=Modeling_Project&view=markup

2) With a TestSetup, individual tests in the JUnit class can than verify
individual file contents. If you have XML content to verify, the XMLUnit
would be a handy tool.

3) For Unit testing your XPath expressions, one possibility is to create a
template (and a ws:file action) that writes calculated values, and then
write a JUnit test to verify these values. If you don't want this template
run in normal circumstances, you could run it only if a particular XPath
variable is defined, and define that variable when you run the JUnit test.

Paul

"Roshan Soni" <roshan.soni1@gmail.com> wrote in message
news:288c21f6c2cc29d097162f4a2fafe771$1@www.eclipse.org...
> You're right it was a problem with my launch configuration and when I
> properly setup my launch to run the correct plugin. I was orignally
> running the same transform as my project and so my unit tests were not
> running, but changing it to run the org.eclipse.sdk.ide product runs my
> transformation and test.
>
> Now I have a different question. On the basis of unit testing I want to
> test my xpath. what would you say is a good test for the xpath in the
> template snippet below? I was want to use XMLUnit to test because all of
> my output is xml.
>
> <c:when test="string($someControl/@attribute1) != 'true'">
> <c:setVariable select="$composite_widget/@attribute1" var="myParent" />
> </c:when>
>
> Thanks,
> Roshan
>
Previous Topic:Run generate method for a single JET2 template
Next Topic:minimal jet plugin
Goto Forum:
  


Current Time: Thu Nov 14 09:57:09 GMT 2024

Powered by FUDForum. Page generated in 0.03268 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top