### Eclipse Workspace Patch 1.0 #P org.eclipse.equinox.p2.tests Index: src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java =================================================================== RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java,v retrieving revision 1.1 diff -u -r1.1 MetadataMirrorApplicationTest.java --- src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java 30 Sep 2008 21:02:48 -0000 1.1 +++ src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java 1 Oct 2008 20:42:40 -0000 @@ -74,9 +74,9 @@ } /** - * runs default mirror. source is the source repo, destination is the destination repo + * runs the mirror application with arguments args */ - private void basicRunMirrorApplication(String message, final URL source, final URL destination, final boolean append) throws Exception { + private void runMirrorApplication(String message, final String[] args) throws Exception { MirrorApplication application = new MirrorApplication(); application.start(new IApplicationContext() { @@ -86,7 +86,7 @@ public Map getArguments() { Map arguments = new HashMap(); - arguments.put(IApplicationContext.APPLICATION_ARGS, new String[] {"-source", source.toExternalForm(), "-destination", destination.toExternalForm(), append ? "-append" : ""}); + arguments.put(IApplicationContext.APPLICATION_ARGS, args); return arguments; } @@ -118,6 +118,16 @@ } /** + * runs mirror application with default arguments. source is the source repo, destination is the destination repo, append is if the "-append" argument is needed + */ + private void basicRunMirrorApplication(String message, URL source, URL destination, boolean append) throws Exception { + //set the default arguments + String[] args = new String[] {"-source", source.toExternalForm(), "-destination", destination.toExternalForm(), append ? "-append" : ""}; + //run the mirror application + runMirrorApplication(message, args); + } + + /** * just a wrapper method for compatibility */ private void runMirrorApplication(String message, File source, File destination, boolean append) { @@ -754,4 +764,68 @@ fail("20.6", e); } } + + /** + * Tests how mirror application handles an unspecified source + */ + public void testArtifactMirrorNullSource() { + String[] args = null; + try { + //create arguments without a "-source" + args = new String[] {"-destination", destRepoLocation.toURL().toExternalForm()}; + } catch (MalformedURLException e) { + fail("21.0", e); + } + + try { + runMirrorApplication("21.1", args); + //We expect the IllegalStateException to be thrown + fail("21.3 IllegalStateException not thrown"); + } catch (IllegalStateException e) { + return; //expected type of exception has been thrown + } catch (Exception e) { + fail("21.2", e); + } + } + + /** + * Tests how mirror application handles an unspecified destination + */ + public void testArtifactMirrorNullDestination() { + String[] args = null; + try { + //create arguments without a "-destination" + args = new String[] {"-source", sourceRepoLocation.toURL().toExternalForm()}; + } catch (MalformedURLException e) { + fail("22.0", e); + } + + try { + runMirrorApplication("22.1", args); + //We expect the IllegalStateException to be thrown + fail("22.3 IllegalStateException not thrown"); + } catch (IllegalStateException e) { + return; //expected type of exception has been thrown + } catch (Exception e) { + fail("22.2", e); + } + } + + /** + * Tests how mirror application handles both an unspecified source and an unspecified destination + */ + public void testArtifactMirrorNullBoth() { + //create arguments with neither "-destination" nor "-source" + String[] args = new String[] {}; + + try { + runMirrorApplication("23.0", args); + //We expect the IllegalStateException to be thrown + fail("23.2 IllegalStateException not thrown"); + } catch (IllegalStateException e) { + return; //expected type of exception has been thrown + } catch (Exception e) { + fail("23.1", e); + } + } } Index: src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java =================================================================== RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java,v retrieving revision 1.1 diff -u -r1.1 ArtifactMirrorApplicationTest.java --- src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java 30 Sep 2008 21:02:48 -0000 1.1 +++ src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java 1 Oct 2008 20:42:40 -0000 @@ -71,9 +71,9 @@ } /** - * runs default mirror. source is the source repo, destination is the destination repo + * runs the mirror application with arguments args */ - private void basicRunMirrorApplication(final String message, final URL source, final URL destination, final boolean append) throws Exception { + private void runMirrorApplication(String message, final String[] args) throws Exception { MirrorApplication application = new MirrorApplication(); application.start(new IApplicationContext() { @@ -83,7 +83,7 @@ public Map getArguments() { Map arguments = new HashMap(); - arguments.put(IApplicationContext.APPLICATION_ARGS, new String[] {"-source", source.toExternalForm(), "-destination", destination.toExternalForm(), append ? "-append" : ""}); + arguments.put(IApplicationContext.APPLICATION_ARGS, args); return arguments; } @@ -115,6 +115,16 @@ } /** + * runs mirror application with default arguments. source is the source repo, destination is the destination repo, append is if the "-append" argument is needed + */ + private void basicRunMirrorApplication(String message, URL source, URL destination, boolean append) throws Exception { + //set the default arguments + String[] args = new String[] {"-source", source.toExternalForm(), "-destination", destination.toExternalForm(), append ? "-append" : ""}; + //run the mirror application + runMirrorApplication(message, args); + } + + /** * just a wrapper method for compatibility */ private void runMirrorApplication(String message, File source, File destination, boolean append) { @@ -542,7 +552,7 @@ //we expect a provision exception to be thrown. We should never get here. fail("13.0 ProvisionExpection not thrown"); } catch (ProvisionException e) { - return; //correct type fo exception has been thrown + return; //correct type of exception has been thrown } catch (Exception e) { fail("13.2", e); } @@ -580,9 +590,9 @@ //Setup: create a URL pointing to an unmodifiable place URL invalidDestRepository = new URL("http://foobar.com/abcdefg"); basicRunMirrorApplication("15.1", invalidRepository.toURL(), invalidDestRepository, true); - //We expect the ProvisionException to be thrown BEFORE an UnsupportedOperationException - fail("15.0 ProvisionExpection not thrown"); - } catch (ProvisionException e) { + //We expect the UnsupportedOperationException to be thrown + fail("15.0 UnsupportedOperationException not thrown"); + } catch (UnsupportedOperationException e) { return; //correct type of exception was thrown } catch (Exception e) { fail("15.2", e); @@ -731,4 +741,68 @@ fail("20.6", e); } } + + /** + * Tests how mirror application handles an unspecified source + */ + public void testArtifactMirrorNullSource() { + String[] args = null; + try { + //create arguments without a "-source" + args = new String[] {"-destination", destRepoLocation.toURL().toExternalForm()}; + } catch (MalformedURLException e) { + fail("21.0", e); + } + + try { + runMirrorApplication("21.1", args); + //We expect the IllegalStateException to be thrown + fail("21.3 IllegalStateException not thrown"); + } catch (IllegalStateException e) { + return; //expected type of exception has been thrown + } catch (Exception e) { + fail("21.2", e); + } + } + + /** + * Tests how mirror application handles an unspecified destination + */ + public void testArtifactMirrorNullDestination() { + String[] args = null; + try { + //create arguments without a "-destination" + args = new String[] {"-source", sourceRepoLocation.toURL().toExternalForm()}; + } catch (MalformedURLException e) { + fail("22.0", e); + } + + try { + runMirrorApplication("22.1", args); + //We expect the IllegalStateException to be thrown + fail("22.3 IllegalStateException not thrown"); + } catch (IllegalStateException e) { + return; //expected type of exception has been thrown + } catch (Exception e) { + fail("22.2", e); + } + } + + /** + * Tests how mirror application handles both an unspecified source and an unspecified destination + */ + public void testArtifactMirrorNullBoth() { + //create arguments with neither "-destination" nor "-source" + String[] args = new String[] {}; + + try { + runMirrorApplication("23.0", args); + //We expect the IllegalStateException to be thrown + fail("23.2 IllegalStateException not thrown"); + } catch (IllegalStateException e) { + return; //expected type of exception has been thrown + } catch (Exception e) { + fail("23.1", e); + } + } } #P org.eclipse.equinox.p2.artifact.repository Index: src/org/eclipse/equinox/internal/p2/artifact/mirror/MirrorApplication.java =================================================================== RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/MirrorApplication.java,v retrieving revision 1.12 diff -u -r1.12 MirrorApplication.java --- src/org/eclipse/equinox/internal/p2/artifact/mirror/MirrorApplication.java 1 Oct 2008 15:19:38 -0000 1.12 +++ src/org/eclipse/equinox/internal/p2/artifact/mirror/MirrorApplication.java 1 Oct 2008 20:42:41 -0000 @@ -73,17 +73,17 @@ } private void setupRepositories() throws ProvisionException { + if (destinationLocation == null || sourceLocation == null) + throw new IllegalStateException("Must specify a source and destination"); //$NON-NLS-1$ + //Check if repositories are already loaded //TODO modify the contains statement once the API is available sourceLoaded = getManager().contains(sourceLocation); //TODO modify the contains statement once the API is available destinationLoaded = getManager().contains(destinationLocation); + destination = initializeDestination(); source = getManager().loadRepository(sourceLocation, null); - if (destinationLocation == null) - destination = source; - else - destination = initializeDestination(); } private IArtifactRepository initializeDestination() throws ProvisionException {