Curious, why would a junit test act upon or need information about
another artifact?

Thank you very much for your feedback. Yes, I agree that it would seem
strange on why someone would need access to an artifact from outside a
Mojo. The use case I was running into is the design of a SDK that
allows developers to integration test OSGi bundles.

For instance, here is your previous example given with the org.junit bundle ....

public class BundleTest extends OsgiTestCase {

   @Test
   public void testSuccessfulJunitBundleInstall(){
       try{
           Resource location = ArtifactLocator.locateArtifact("org.junit")
           getBundleContext().installBundle(location.getPath());
       } catch (BundleException installationException) {
           fail("Bundle could not be installed.");
       }
   }

}

On 7/14/07, Timothy Reilly <[EMAIL PROTECTED]> wrote:
> Alexander Horn wrote:
> However, what do I need to do to determine the local file
> system location of an artifact from outside a Mojo (i.e. a

Just IMO, it would be better if your TestCase's had no knowledge of
Maven
or the execution environment they're running in.
Personally, I would locate the URL using the classloader's getResource()
method.
(Of course, you need to know a class or marker file to search for.)
Not sure if this good enough for your scenario?

An example:
To get the location of junit's jar I would look for
junit.framework.TestCase.class


import java.net.URL;
import junit.framework.TestCase;

public class ResourceUrlTest extends TestCase {
        public ResourceUrlTest(String name) {
                super(name);
        }
        public void resourceLocationTest() {
                URL loc =
Thread.currentThread().getContextClassLoader().getResource("junit/framew
ork/TestCase.class");
                fail(loc.toExternalForm());
        }
}

Outputs the following in the Surefire log:

junit.framework.AssertionFailedError:
jar:file:/C:/Documents%20and%20Settings/treilly/.m2/repository/junit/jun
it/3.8.1/junit-3.8.1.jar!/junit/framework/TestCase.class

Curious, why would a junit test act upon or need information about
another artifact?
(I think this is probably a topic for the user list, any dev's feel free
to correct me.)

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




--
Alexander Horn
http://www2.truman.edu/~ah428

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

Reply via email to