1 package org.apache.archiva.repository.maven.content;
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.test.utils.ArchivaBlockJUnit4ClassRunner;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
31 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
32 public class FilenameParserTest
36 public void testNameExtensionJar()
38 FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
40 assertEquals( "maven-test-plugin-1.8.3", parser.getName() );
41 assertEquals( "jar", parser.getExtension() );
45 public void testNameExtensionTarGz()
47 FilenameParser parser = new FilenameParser( "archiva-1.0-beta-2-bin.tar.gz" );
49 assertEquals( "archiva-1.0-beta-2-bin", parser.getName() );
50 assertEquals( "tar.gz", parser.getExtension() );
54 public void testNameExtensionTarBz2()
56 FilenameParser parser = new FilenameParser( "archiva-1.0-SNAPSHOT-src.tar.bz2" );
58 assertEquals( "archiva-1.0-SNAPSHOT-src", parser.getName() );
59 assertEquals( "tar.bz2", parser.getExtension() );
63 public void testNameExtensionCapitolizedTarGz()
65 FilenameParser parser = new FilenameParser( "ARCHIVA-1.0-BETA-2-BIN.TAR.GZ" );
67 assertEquals( "ARCHIVA-1.0-BETA-2-BIN", parser.getName() );
68 assertEquals( "TAR.GZ", parser.getExtension() );
72 public void testNext()
74 FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
76 assertEquals( "maven-test-plugin-1.8.3", parser.getName() );
77 assertEquals( "jar", parser.getExtension() );
79 assertEquals( "maven", parser.next() );
80 assertEquals( "test", parser.next() );
81 assertEquals( "plugin", parser.next() );
82 assertEquals( "1.8.3", parser.next() );
83 assertNull( parser.next() );
87 public void testExpect()
89 FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
91 assertEquals( "maven-test-plugin-1.8.3", parser.getName() );
92 assertEquals( "jar", parser.getExtension() );
94 assertEquals( "maven-test-plugin", parser.expect( "maven-test-plugin" ) );
95 assertEquals( "1.8.3", parser.expect( "1.8.3" ) );
96 assertNull( parser.expect( "jar" ) );
100 public void testExpectWithRemaining()
102 FilenameParser parser = new FilenameParser( "ganymede-ssh2-build250-sources.jar" );
104 assertEquals( "ganymede-ssh2-build250-sources", parser.getName() );
105 assertEquals( "jar", parser.getExtension() );
107 assertEquals( "ganymede-ssh2", parser.expect( "ganymede-ssh2" ) );
108 assertEquals( "build250", parser.expect( "build250" ) );
109 assertEquals( '-', parser.seperator() );
110 assertEquals( "sources", parser.remaining() );
112 assertNull( parser.expect( "jar" ) );
116 public void testExpectWithRemainingDualExtensions()
118 FilenameParser parser = new FilenameParser( "example-presentation-3.2.xml.zip" );
120 assertEquals( "example-presentation-3.2.xml", parser.getName() );
121 assertEquals( "zip", parser.getExtension() );
123 assertEquals( "example-presentation", parser.expect( "example-presentation" ) );
124 assertEquals( "3.2", parser.expect( "3.2" ) );
125 assertEquals( '.', parser.seperator() );
126 assertEquals( "xml", parser.remaining() );
131 public void testNextNonVersion()
133 FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
135 assertEquals( "maven-test-plugin", parser.nextNonVersion() );
136 assertEquals( "1.8.3", parser.remaining() );
140 public void testNextArbitraryNonVersion()
142 FilenameParser parser = new FilenameParser( "maven-jdk-1.4-plugin-1.0-20070828.123456-42.jar" );
144 assertEquals( "maven-jdk-1.4-plugin", parser.nextNonVersion() );
145 assertEquals( "1.0-20070828.123456-42", parser.remaining() );
149 public void testNextJython()
151 FilenameParser parser = new FilenameParser( "jython-20020827-no-oro.jar" );
153 assertEquals( "jython", parser.nextNonVersion() );
154 assertEquals( "20020827", parser.nextVersion() );
155 assertEquals( "no-oro", parser.remaining() );
159 public void testLongExtension()
161 FilenameParser parser = new FilenameParser( "libfobs4jmf-0.4.1.4-20080217.211715-4.jnilib" );
163 assertEquals( "libfobs4jmf-0.4.1.4-20080217.211715-4", parser.getName() );
164 assertEquals( "jnilib", parser.getExtension() );
168 public void testInterveningVersion()
170 FilenameParser parser = new FilenameParser( "artifact-id-1.0-abc-1.1-20080221.062205-9.pom" );
172 assertEquals( "artifact-id", parser.nextNonVersion() );
173 assertEquals( "1.0-abc-1.1-20080221.062205-9", parser.expect( "1.0-abc-1.1-SNAPSHOT" ) );
174 assertNull( null, parser.remaining() );
175 assertEquals( "artifact-id-1.0-abc-1.1-20080221.062205-9", parser.getName() );
176 assertEquals( "pom", parser.getExtension() );
180 public void testExpectWrongSnapshot()
182 FilenameParser parser = new FilenameParser( "artifact-id-1.0-20080221.062205-9.pom" );
184 assertEquals( "artifact-id", parser.nextNonVersion() );
185 assertNull( parser.expect( "2.0-SNAPSHOT" ) );
189 public void testExpectWrongSnapshot2()
191 // tests parsing axiom snapshots without exceptions
192 FilenameParser parser = new FilenameParser( "axiom-20080221.062205-9.pom" );
194 assertEquals( "axiom", parser.nextNonVersion() );
195 assertNull( parser.expect( "SNAPSHOT" ) );
199 public void testClassifier()
201 FilenameParser parser = new FilenameParser( "artifact-id-1.0-20070219.171202-34-test-sources.jar" );
203 assertEquals( "artifact-id", parser.nextNonVersion() );
204 assertEquals( "1.0-20070219.171202-34", parser.nextVersion() );
205 assertEquals( "test-sources", parser.remaining() );
206 assertEquals( "artifact-id-1.0-20070219.171202-34-test-sources", parser.getName() );
207 assertEquals( "jar", parser.getExtension() );
211 public void testNoExtension()
213 FilenameParser parser = new FilenameParser( "foo_bar" );
214 assertNull( parser.getExtension() );