1 package org.apache.archiva.repository.maven.metadata;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import junit.framework.TestCase;
22 import org.apache.archiva.model.ArchivaRepositoryMetadata;
23 import org.apache.archiva.repository.metadata.base.RepositoryMetadataWriter;
24 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.xmlunit.assertj.XmlAssert;
29 import java.io.StringWriter;
30 import java.net.URISyntaxException;
31 import java.nio.charset.Charset;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
36 * RepositoryMetadataWriterTest
38 @RunWith ( ArchivaBlockJUnit4ClassRunner.class )
39 public class RepositoryMetadataWriterTest
42 private Path getRepositoryPath(String repoName) {
45 return Paths.get( Thread.currentThread( ).getContextClassLoader( ).getResource( "repositories/" + repoName ).toURI( ) );
47 catch ( URISyntaxException e )
49 throw new RuntimeException( "Could not resolve repository path " + e.getMessage( ), e );
54 public void testWriteSimple()
57 Path defaultRepoDir = getRepositoryPath( "default-repository" );
58 Path expectedFile = defaultRepoDir.resolve( "org/apache/maven/shared/maven-downloader/maven-metadata.xml" );
59 String expectedContent = org.apache.archiva.common.utils.FileUtils.readFileToString( expectedFile, Charset.defaultCharset() );
61 ArchivaRepositoryMetadata metadata = new ArchivaRepositoryMetadata();
63 metadata.setGroupId( "org.apache.maven.shared" );
64 metadata.setArtifactId( "maven-downloader" );
65 metadata.setVersion( "1.0" );
66 metadata.setReleasedVersion( "1.1" );
67 metadata.getAvailableVersions().add( "1.0" );
68 metadata.getAvailableVersions().add( "1.1" );
69 metadata.setLastUpdated( "20061212214311" );
71 StringWriter actual = new StringWriter();
72 RepositoryMetadataWriter.write( metadata, actual );
74 XmlAssert.assertThat( actual.toString() ).and( expectedContent ).areIdentical();