forked from shrinkwrap/resolver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SHRINKRES-104 Honoring programmatic offline flag, new local repositor…
…y tests
- Loading branch information
Showing
5 changed files
with
227 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
...st/java/org/jboss/shrinkwrap/resolver/impl/maven/integration/LocalRepositoryTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat Middleware LLC, and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.shrinkwrap.resolver.impl.maven.integration; | ||
|
||
import java.io.File; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.jboss.shrinkwrap.resolver.api.NoResolvedResultException; | ||
import org.jboss.shrinkwrap.resolver.api.maven.Maven; | ||
import org.jboss.shrinkwrap.resolver.impl.maven.bootstrap.MavenSettingsBuilder; | ||
import org.jboss.shrinkwrap.resolver.impl.maven.util.TestFileUtil; | ||
import org.jboss.shrinkwrap.resolver.impl.maven.util.ValidationUtil; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Ensures that artifact is correctly resolved from local repository. | ||
* This test will fail outside the presence of an internet connection and access to repo1.maven.org | ||
* | ||
* @author <a href="mailto:kpiwko@redhat.com">Karel Piwko</a> | ||
*/ | ||
public class LocalRepositoryTestCase { | ||
|
||
private static final String LOCAL_REPOSITORY = "target/local-only-repository"; | ||
private static final String REMOTE_ENABLED_SETTINGS = "target/settings/profiles/settings.xml"; | ||
private static final String CENTRAL_ONLY_SETTINGS = "target/settings/profiles/settings-central.xml"; | ||
|
||
@BeforeClass | ||
public static void setRemoteRepository() { | ||
System.setProperty(MavenSettingsBuilder.ALT_LOCAL_REPOSITORY_LOCATION, LOCAL_REPOSITORY); | ||
} | ||
|
||
/** | ||
* Cleanup, remove the repositories from previous tests | ||
*/ | ||
@Before | ||
@After | ||
// For debugging you might want to temporarily remove the @After lifecycle call just to sanity-check for yourself | ||
// the repo | ||
public void cleanup() throws Exception { | ||
TestFileUtil.removeDirectory(new File(LOCAL_REPOSITORY)); | ||
} | ||
|
||
/** | ||
* Ensures that we can contact Maven Central (as a control test) | ||
*/ | ||
@Test | ||
public void resolveFromLocalRepository() throws Exception { | ||
|
||
// fixture | ||
prepareLocalRepository(); | ||
|
||
// now, we need to remove Maven repository checks | ||
// https://cwiki.apache.org/confluence/display/MAVEN/Maven+3.x+Compatibility+Notes#Maven3.xCompatibilityNotes-ResolutionfromLocalRepository | ||
// this behavior can be switched using non-tracking LocalRepositoryManager | ||
// the other way is to ensure | ||
TestFileUtil.removeFilesRecursively(new File(LOCAL_REPOSITORY), "_maven.repositories"); | ||
|
||
// now, we disable remote repository and rely only on what's available in local repository | ||
File[] filesLocal = Maven.configureResolver().fromFile(CENTRAL_ONLY_SETTINGS) | ||
.resolve("org.jboss.shrinkwrap.test:test-deps-c:1.0.0") | ||
.withTransitivity().as(File.class); | ||
|
||
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c.tree")).validate( | ||
filesLocal); | ||
} | ||
|
||
/** | ||
* Ensures that we can contact Maven Central (as a control test) | ||
*/ | ||
@Test | ||
public void resolveFromLocalRepositoryOffline() throws Exception { | ||
|
||
// fixture | ||
prepareLocalRepository(); | ||
|
||
// now, we disable remote repository and rely only on what's available in local repository | ||
// test will work in offline mode, so it won't touch remote repositories | ||
File[] filesLocal = Maven.configureResolver().fromFile(CENTRAL_ONLY_SETTINGS).offline() | ||
.resolve("org.jboss.shrinkwrap.test:test-deps-c:1.0.0") | ||
.withTransitivity().as(File.class); | ||
|
||
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c.tree")).validate( | ||
filesLocal); | ||
} | ||
|
||
/** | ||
* Ensures that we can contact Maven Central (as a control test) | ||
*/ | ||
@Test(expected = NoResolvedResultException.class) | ||
public void resolveFromLocalRepositoryTrackingRemotes() throws Exception { | ||
|
||
// fixture | ||
prepareLocalRepository(); | ||
|
||
// now, following will fail because remote repository is no longer available and tracking remotes will reject locally | ||
// cached dependencies | ||
Maven.configureResolver().fromFile(CENTRAL_ONLY_SETTINGS) | ||
.resolve("org.jboss.shrinkwrap.test:test-deps-c:1.0.0") | ||
.withTransitivity().as(File.class); | ||
|
||
Assert.fail("Maven 3 is tracking artifact remote repositories origin by default, which should cause test to fail."); | ||
} | ||
|
||
private void prepareLocalRepository() { | ||
|
||
// ensure we get an artifact from remote repository | ||
File[] filesRemote = Maven.configureResolver().fromFile(REMOTE_ENABLED_SETTINGS) | ||
.resolve("org.jboss.shrinkwrap.test:test-deps-c:1.0.0") | ||
.withTransitivity().as(File.class); | ||
|
||
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c.tree")).validate( | ||
filesRemote); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.