Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » JUnit Test on JET Transform
JUnit Test on JET Transform [message #106726] |
Thu, 10 January 2008 19:18  |
Eclipse User |
|
|
|
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 #108115 is a reply to message #107841] |
Thu, 24 January 2008 11:30  |
Eclipse User |
|
|
|
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
>
|
|
|
Re: JUnit Test on JET Transform [message #613979 is a reply to message #106726] |
Thu, 10 January 2008 19:21  |
Eclipse User |
|
|
|
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 #614041 is a reply to message #106849] |
Thu, 17 January 2008 18:06  |
Eclipse User |
|
|
|
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 #614052 is a reply to message #107594] |
Mon, 21 January 2008 11:12  |
Eclipse User |
|
|
|
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 #614059 is a reply to message #107742] |
Tue, 22 January 2008 14:28  |
Eclipse User |
|
|
|
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 #614078 is a reply to message #107841] |
Thu, 24 January 2008 11:30  |
Eclipse User |
|
|
|
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
>
|
|
|
Goto Forum:
Current Time: Thu Jul 03 03:26:16 EDT 2025
Powered by FUDForum. Page generated in 0.19806 seconds
|