Re: Testing Harness Strange Behavior - Gotcha

2006-12-07 Thread Steve Loughran

Ole Ersoy wrote:

OK - Got it.

Apparently Eclipse EMF likes
each resourceSet = createResourceSet()

method inside each test case.

Cheers,
- Ole


you should do all junit setup in setUp() , not the ctor. JUnit creates 
all instances in advance and stores them somewhere. This is a fact you 
can abuse, but which can also hurt you.


-steve

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Testing Harness Strange Behavior - Gotcha

2006-12-07 Thread Ole Ersoy
OK - Got it.

Apparently Eclipse EMF likes
each resourceSet = createResourceSet()

method inside each test case.

Cheers,
- Ole


--- Ole Ersoy <[EMAIL PROTECTED]> wrote:

> Hey Guys,
> 
> I'm seeing some really strange JUnit behavior in
> combination with the testing harness and Eclipse
> EMF. 
> 
> 
> Someone from the JUnit list suspected that it might
> be
> due to a static in the harness setup.
> 
> Here's the scenario:
> 
> I'm testing a method, testLoadPomResource()
> 
> When I have the method by itself it tests fine.
> 
> When I put another test in front of it like this:
> public void testCreateResourceSet() {
> //Stub
> assertTrue(true);
> }
> 
> I get an exception like this:
> java.lang.ExceptionInInitializerError
> at
>
org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl.eStaticClass(AnyTypeImpl.java:83)
> at
>
org.eclipse.emf.ecore.impl.EObjectImpl.eClass(EObjectImpl.java:210)
> 
> 
> 
> I get the same exception when
> running JUnit with Maven or Eclipse,
> so I know it is localized to
> JUnit/TestHarness/EMF/Java(build 1.5.0_09-b01).
> 
> I'll paste the full test case below, in case anyone
> wants to look at it further.
> 
> Cheers,
> - Ole
> 
> 
> package org.jpackage.test;
> 
> import java.io.File;
> import java.io.IOException;
> 
> import org.apache.maven.artifact.Artifact;
> import
> org.apache.maven.artifact.factory.ArtifactFactory;
> import
>
org.apache.maven.artifact.repository.ArtifactRepository;
> import
>
org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
> import
>
org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
> import
> org.apache.maven.plugin.MojoExecutionException;
> import
>
org.apache.maven.plugin.testing.AbstractMojoTestCase;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import
> org.jpackage.impl.JPackageMojoHelperBufferImpl;
> import org.jpackage.impl.JPackageMojoImpl;
> import org.jpackage.JPackageMojoConstants;
> import org.jpackage.impl.JPackageMojoHelperImpl;
> 
> import
> com.pyramidetechnologies.emf.utils.EMFUtilities;
> 
> public class JPackageMojoHelperTest extends
> AbstractMojoTestCase implements
> JPackageMojoConstants
> {
> 
> private JPackageMojoImpl mojo = null;
> private ArtifactRepository artifactRepository =
> null;
> private ResourceSet resourceSet = null;
> protected void setUp() throws Exception {
> 
> // required for mojo lookups to work
> super.setUp();
> 
> File pluginXml = new File(getBasedir(),
> "src/test/resources/plugin-config.xml");
> mojo = (JPackageMojoImpl) lookupMojo(
> "xml2spec.mojo", "org.jpackage", "1.0-SNAPSHOT",
> "generate", pluginXml, false);
> 
> resourceSet =
> JPackageMojoHelperImpl.createResourceSet();
> }
> 
> public void testCreateResourceSet() {
> //Stub
> assertTrue(true);
> }
> 
> public void testLoadPomResource() throws
> MojoExecutionException
> {
> String artifactId = "apacheds-server-main";
> String groupId = "org.apache.directory.server";
> String version = "1.5.0-SNAPSHOT";
> 
> ArtifactFactory artifactFactory =
> mojo.getArtifactFactory();
> assertNotNull(artifactFactory);
> 
> Artifact pomArtifact =
> artifactFactory.createArtifact(groupId, artifactId,
> version, null, "pom");
> assertNotNull(pomArtifact);
> 
> String path = pathOf(pomArtifact);
> File file = new File(path);
> assertTrue(file.exists());
> 
> pomArtifact.setFile(file);
> 
> Resource resource = null;
> resource =
> JPackageMojoHelperImpl.loadPomResource(pomArtifact,
> resourceSet);
> 
> assertNotNull(resource);
> }
> 
> private static String pathOf(Artifact artifact)
> {
> ArtifactRepositoryLayout artifactRepositoryLayout =
> new DefaultRepositoryLayout();
> String artifactPath =
> artifactRepositoryLayout.pathOf(artifact);
> return REPOSITORY_BASE_DIRECTORY + artifactPath;
> }
> 
> private static String REPOSITORY_BASE_DIRECTORY =
> "/home/ole/.m2/repository/";
> 
> }
> 
> 
>  
>

> Want to start your own business?
> Learn how on Yahoo! Small Business.
> http://smallbusiness.yahoo.com/r-index
> 
>
-
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 



 

Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]