1 package org.apache.archiva.repository.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
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import junit.framework.TestCase;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.junit.runners.JUnit4;
32 @RunWith( JUnit4.class )
33 public class FilenameParserTest
37 public void testNameExtensionJar()
39 FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
41 assertEquals( "maven-test-plugin-1.8.3", parser.getName() );
42 assertEquals( "jar", parser.getExtension() );
46 public void testNameExtensionTarGz()
48 FilenameParser parser = new FilenameParser( "archiva-1.0-beta-2-bin.tar.gz" );
50 assertEquals( "archiva-1.0-beta-2-bin", parser.getName() );
51 assertEquals( "tar.gz", parser.getExtension() );
55 public void testNameExtensionTarBz2()
57 FilenameParser parser = new FilenameParser( "archiva-1.0-SNAPSHOT-src.tar.bz2" );
59 assertEquals( "archiva-1.0-SNAPSHOT-src", parser.getName() );
60 assertEquals( "tar.bz2", parser.getExtension() );
64 public void testNameExtensionCapitolizedTarGz()
66 FilenameParser parser = new FilenameParser( "ARCHIVA-1.0-BETA-2-BIN.TAR.GZ" );
68 assertEquals( "ARCHIVA-1.0-BETA-2-BIN", parser.getName() );
69 assertEquals( "TAR.GZ", parser.getExtension() );
73 public void testNext()
75 FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
77 assertEquals( "maven-test-plugin-1.8.3", parser.getName() );
78 assertEquals( "jar", parser.getExtension() );
80 assertEquals( "maven", parser.next() );
81 assertEquals( "test", parser.next() );
82 assertEquals( "plugin", parser.next() );
83 assertEquals( "1.8.3", parser.next() );
84 assertNull( parser.next() );
88 public void testExpect()
90 FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
92 assertEquals( "maven-test-plugin-1.8.3", parser.getName() );
93 assertEquals( "jar", parser.getExtension() );
95 assertEquals( "maven-test-plugin", parser.expect( "maven-test-plugin" ) );
96 assertEquals( "1.8.3", parser.expect( "1.8.3" ) );
97 assertNull( parser.expect( "jar" ) );
101 public void testExpectWithRemaining()
103 FilenameParser parser = new FilenameParser( "ganymede-ssh2-build250-sources.jar" );
105 assertEquals( "ganymede-ssh2-build250-sources", parser.getName() );
106 assertEquals( "jar", parser.getExtension() );
108 assertEquals( "ganymede-ssh2", parser.expect( "ganymede-ssh2" ) );
109 assertEquals( "build250", parser.expect( "build250" ) );
110 assertEquals( '-', parser.seperator() );
111 assertEquals( "sources", parser.remaining() );
113 assertNull( parser.expect( "jar" ) );
117 public void testExpectWithRemainingDualExtensions()
119 FilenameParser parser = new FilenameParser( "example-presentation-3.2.xml.zip" );
121 assertEquals( "example-presentation-3.2.xml", parser.getName() );
122 assertEquals( "zip", parser.getExtension() );
124 assertEquals( "example-presentation", parser.expect( "example-presentation" ) );
125 assertEquals( "3.2", parser.expect( "3.2" ) );
126 assertEquals( '.', parser.seperator() );
127 assertEquals( "xml", parser.remaining() );
132 public void testNextNonVersion()
134 FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
136 assertEquals( "maven-test-plugin", parser.nextNonVersion() );
137 assertEquals( "1.8.3", parser.remaining() );
141 public void testNextArbitraryNonVersion()
143 FilenameParser parser = new FilenameParser( "maven-jdk-1.4-plugin-1.0-20070828.123456-42.jar" );
145 assertEquals( "maven-jdk-1.4-plugin", parser.nextNonVersion() );
146 assertEquals( "1.0-20070828.123456-42", parser.remaining() );
150 public void testNextJython()
152 FilenameParser parser = new FilenameParser( "jython-20020827-no-oro.jar" );
154 assertEquals( "jython", parser.nextNonVersion() );
155 assertEquals( "20020827", parser.nextVersion() );
156 assertEquals( "no-oro", parser.remaining() );
160 public void testLongExtension()
162 FilenameParser parser = new FilenameParser( "libfobs4jmf-0.4.1.4-20080217.211715-4.jnilib" );
164 assertEquals( "libfobs4jmf-0.4.1.4-20080217.211715-4", parser.getName() );
165 assertEquals( "jnilib", parser.getExtension() );
169 public void testInterveningVersion()
171 FilenameParser parser = new FilenameParser( "artifact-id-1.0-abc-1.1-20080221.062205-9.pom" );
173 assertEquals( "artifact-id", parser.nextNonVersion() );
174 assertEquals( "1.0-abc-1.1-20080221.062205-9", parser.expect( "1.0-abc-1.1-SNAPSHOT" ) );
175 assertNull( null, parser.remaining() );
176 assertEquals( "artifact-id-1.0-abc-1.1-20080221.062205-9", parser.getName() );
177 assertEquals( "pom", parser.getExtension() );
181 public void testExpectWrongSnapshot()
183 FilenameParser parser = new FilenameParser( "artifact-id-1.0-20080221.062205-9.pom" );
185 assertEquals( "artifact-id", parser.nextNonVersion() );
186 assertNull( parser.expect( "2.0-SNAPSHOT" ) );
190 public void testExpectWrongSnapshot2()
192 // tests parsing axiom snapshots without exceptions
193 FilenameParser parser = new FilenameParser( "axiom-20080221.062205-9.pom" );
195 assertEquals( "axiom", parser.nextNonVersion() );
196 assertNull( parser.expect( "SNAPSHOT" ) );
200 public void testClassifier()
202 FilenameParser parser = new FilenameParser( "artifact-id-1.0-20070219.171202-34-test-sources.jar" );
204 assertEquals( "artifact-id", parser.nextNonVersion() );
205 assertEquals( "1.0-20070219.171202-34", parser.nextVersion() );
206 assertEquals( "test-sources", parser.remaining() );
207 assertEquals( "artifact-id-1.0-20070219.171202-34-test-sources", parser.getName() );
208 assertEquals( "jar", parser.getExtension() );
212 public void testNoExtension()
214 FilenameParser parser = new FilenameParser( "foo_bar" );
215 assertNull( parser.getExtension() );