use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testV3PomConvertWithRelocation.
@Test
public void testV3PomConvertWithRelocation() throws Exception {
Artifact artifact = createArtifact("test", "relocated-v3artifact", "1.0.0");
ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata(artifact);
Path artifactMetadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(artifactMetadata));
Files.deleteIfExists(artifactMetadataFile);
ArtifactMetadata versionMetadata = new SnapshotArtifactRepositoryMetadata(artifact);
Path versionMetadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(versionMetadata));
Files.deleteIfExists(versionMetadataFile);
artifactConverter.convert(artifact, targetRepository);
// checkSuccess(); --> commented until MNG-2100 is fixed
Path artifactFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
assertTrue("Check if relocated artifact created", Files.exists(artifactFile));
assertTrue("Check if relocated artifact matches", FileUtils.contentEquals(artifactFile.toFile(), artifact.getFile()));
Artifact pomArtifact = createArtifact("relocated-test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom");
Path pomFile = getTestFile("src/test/expected-files/" + targetRepository.pathOf(pomArtifact));
Path testFile = getTestFile("target/test-target-repository/" + targetRepository.pathOf(pomArtifact));
compareFiles(pomFile, testFile);
Artifact orig = createArtifact("test", "relocated-v3artifact", "1.0.0", "1.0.0", "pom");
artifactFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(orig));
assertTrue("Check if relocation artifact pom is created", Files.exists(artifactFile));
testFile = getTestFile("src/test/expected-files/" + targetRepository.pathOf(orig));
compareFiles(artifactFile, testFile);
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testIncorrectSourceChecksumMd5.
@Test
public void testIncorrectSourceChecksumMd5() throws Exception {
// test that it fails when the source md5 is wrong
Artifact artifact = createArtifact("test", "incorrectMd5Artifact", "1.0.0");
Path file = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
Files.deleteIfExists(file);
artifactConverter.convert(artifact, targetRepository);
checkWarnings(artifactConverter, 2);
assertHasWarningReason(artifactConverter, Messages.getString("failure.incorrect.md5"));
assertFalse("Check artifact not created", Files.exists(file));
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact);
Path metadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(metadata));
assertFalse("Check metadata not created", Files.exists(metadataFile));
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testInvalidSourceSnapshotMetadata.
@Test
public void testInvalidSourceSnapshotMetadata() throws Exception {
// test artifact is not converted when source snapshot metadata is invalid and returns failure
createModernSourceRepository();
Artifact artifact = createArtifact("test", "incorrectSnapshotMetadata", "1.0.0-20060102.030405-6");
Path file = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
Files.deleteIfExists(file);
artifactConverter.convert(artifact, targetRepository);
checkWarnings(artifactConverter, 2);
assertHasWarningReason(artifactConverter, Messages.getString("failure.incorrect.snapshotMetadata.snapshot"));
assertFalse("Check artifact not created", Files.exists(file));
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact);
Path metadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(metadata));
assertFalse("Check metadata not created", Files.exists(metadataFile));
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testDryRunSuccess.
@Test
public void testDryRunSuccess() throws Exception {
// test dry run does nothing on a run that will be successful, and returns success
artifactConverter = applicationContext.getBean("artifactConverter#dryrun-repository-converter", ArtifactConverter.class);
Artifact artifact = createArtifact("test", "dryrun-artifact", "1.0.0");
Artifact pomArtifact = createPomArtifact(artifact);
Path sourceFile = Paths.get(sourceRepository.getBasedir(), sourceRepository.pathOf(artifact));
Path sourcePomFile = Paths.get(sourceRepository.getBasedir(), sourceRepository.pathOf(pomArtifact));
Path targetFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
Path targetPomFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(pomArtifact));
// clear warning before test related to MRM-1638
artifactConverter.clearWarnings();
artifactConverter.convert(artifact, targetRepository);
checkSuccess(artifactConverter);
assertTrue("Check source file exists", Files.exists(sourceFile));
assertTrue("Check source POM exists", Files.exists(sourcePomFile));
assertFalse("Check target file doesn't exist", Files.exists(targetFile));
assertFalse("Check target POM doesn't exist", Files.exists(targetPomFile));
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact);
Path metadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(metadata));
assertFalse("Check metadata not created", Files.exists(metadataFile));
}
use of org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata in project archiva by apache.
the class LegacyToDefaultConverterTest method testModifedArtifactFails.
@Test
public void testModifedArtifactFails() throws Exception {
// test that it fails when the source artifact has changed and is different to the existing artifact in the
// target repository
Artifact artifact = createArtifact("test", "modified-artifact", "1.0.0");
Artifact pomArtifact = createPomArtifact(artifact);
Path sourceFile = Paths.get(sourceRepository.getBasedir(), sourceRepository.pathOf(artifact));
Path sourcePomFile = Paths.get(sourceRepository.getBasedir(), sourceRepository.pathOf(pomArtifact));
Path targetFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(artifact));
Path targetPomFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOf(pomArtifact));
assertTrue("Check target file exists", Files.exists(targetFile));
assertTrue("Check target POM exists", Files.exists(targetPomFile));
Files.setLastModifiedTime(sourceFile, FileTime.from(System.currentTimeMillis(), TimeUnit.MILLISECONDS));
Files.setLastModifiedTime(sourcePomFile, FileTime.from(System.currentTimeMillis(), TimeUnit.MILLISECONDS));
long origTime = Files.getLastModifiedTime(targetFile).toMillis();
long origPomTime = Files.getLastModifiedTime(targetPomFile).toMillis();
// Need to guarantee last modified is not equal
Thread.sleep(SLEEP_MILLIS);
artifactConverter.convert(artifact, targetRepository);
checkWarnings(artifactConverter, 2);
assertHasWarningReason(artifactConverter, Messages.getString("failure.target.already.exists"));
assertEquals("Check unmodified", origTime, Files.getLastModifiedTime(targetFile).toMillis());
assertEquals("Check unmodified", origPomTime, Files.getLastModifiedTime(targetPomFile).toMillis());
ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata(artifact);
Path metadataFile = Paths.get(targetRepository.getBasedir(), targetRepository.pathOfRemoteRepositoryMetadata(metadata));
assertFalse("Check metadata not created", Files.exists(metadataFile));
}
Aggregations