1 package org.apache.maven.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;
27 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
30 public class FilenameParserTest
33 public void testNameExtensionJar()
35 FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
37 assertEquals( "maven-test-plugin-1.8.3", parser.getName() );
38 assertEquals( "jar", parser.getExtension() );
41 public void testNameExtensionTarGz()
43 FilenameParser parser = new FilenameParser( "archiva-1.0-beta-2-bin.tar.gz" );
45 assertEquals( "archiva-1.0-beta-2-bin", parser.getName() );
46 assertEquals( "tar.gz", parser.getExtension() );
49 public void testNameExtensionTarBz2()
51 FilenameParser parser = new FilenameParser( "archiva-1.0-SNAPSHOT-src.tar.bz2" );
53 assertEquals( "archiva-1.0-SNAPSHOT-src", parser.getName() );
54 assertEquals( "tar.bz2", parser.getExtension() );
57 public void testNameExtensionCapitolizedTarGz()
59 FilenameParser parser = new FilenameParser( "ARCHIVA-1.0-BETA-2-BIN.TAR.GZ" );
61 assertEquals( "ARCHIVA-1.0-BETA-2-BIN", parser.getName() );
62 assertEquals( "TAR.GZ", parser.getExtension() );
65 public void testNext()
67 FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
69 assertEquals( "maven-test-plugin-1.8.3", parser.getName() );
70 assertEquals( "jar", parser.getExtension() );
72 assertEquals( "maven", parser.next() );
73 assertEquals( "test", parser.next() );
74 assertEquals( "plugin", parser.next() );
75 assertEquals( "1.8.3", parser.next() );
76 assertNull( parser.next() );
79 public void testExpect()
81 FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
83 assertEquals( "maven-test-plugin-1.8.3", parser.getName() );
84 assertEquals( "jar", parser.getExtension() );
86 assertEquals( "maven-test-plugin", parser.expect( "maven-test-plugin" ) );
87 assertEquals( "1.8.3", parser.expect( "1.8.3" ) );
88 assertNull( parser.expect( "jar" ) );
91 public void testExpectWithRemaining()
93 FilenameParser parser = new FilenameParser( "ganymede-ssh2-build250-sources.jar" );
95 assertEquals( "ganymede-ssh2-build250-sources", parser.getName() );
96 assertEquals( "jar", parser.getExtension() );
98 assertEquals( "ganymede-ssh2", parser.expect( "ganymede-ssh2" ) );
99 assertEquals( "build250", parser.expect( "build250" ) );
100 assertEquals( '-', parser.seperator() );
101 assertEquals( "sources", parser.remaining() );
103 assertNull( parser.expect( "jar" ) );
106 public void testExpectWithRemainingDualExtensions()
108 FilenameParser parser = new FilenameParser( "example-presentation-3.2.xml.zip" );
110 assertEquals( "example-presentation-3.2.xml", parser.getName() );
111 assertEquals( "zip", parser.getExtension() );
113 assertEquals( "example-presentation", parser.expect( "example-presentation" ) );
114 assertEquals( "3.2", parser.expect( "3.2" ) );
115 assertEquals( '.', parser.seperator() );
116 assertEquals( "xml", parser.remaining() );
120 public void testNextNonVersion()
122 FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
124 assertEquals( "maven-test-plugin", parser.nextNonVersion() );
125 assertEquals( "1.8.3", parser.remaining() );
128 public void testNextArbitraryNonVersion()
130 FilenameParser parser = new FilenameParser( "maven-jdk-1.4-plugin-1.0-20070828.123456-42.jar" );
132 assertEquals( "maven-jdk-1.4-plugin", parser.nextNonVersion() );
133 assertEquals( "1.0-20070828.123456-42", parser.remaining() );
136 public void testNextJython()
138 FilenameParser parser = new FilenameParser( "jython-20020827-no-oro.jar" );
140 assertEquals( "jython", parser.nextNonVersion() );
141 assertEquals( "20020827", parser.nextVersion() );
142 assertEquals( "no-oro", parser.remaining() );
145 public void testLongExtension()
147 FilenameParser parser = new FilenameParser( "libfobs4jmf-0.4.1.4-20080217.211715-4.jnilib" );
149 assertEquals( "libfobs4jmf-0.4.1.4-20080217.211715-4", parser.getName() );
150 assertEquals( "jnilib", parser.getExtension() );
153 public void testInterveningVersion()
155 FilenameParser parser = new FilenameParser( "artifact-id-1.0-abc-1.1-20080221.062205-9.pom" );
157 assertEquals( "artifact-id", parser.nextNonVersion() );
158 assertEquals( "1.0-abc-1.1-20080221.062205-9", parser.expect( "1.0-abc-1.1-SNAPSHOT" ) );
159 assertNull( null, parser.remaining() );
160 assertEquals( "artifact-id-1.0-abc-1.1-20080221.062205-9", parser.getName() );
161 assertEquals( "pom", parser.getExtension() );
164 public void testExpectWrongSnapshot()
166 FilenameParser parser = new FilenameParser( "artifact-id-1.0-20080221.062205-9.pom" );
168 assertEquals( "artifact-id", parser.nextNonVersion() );
169 assertNull( parser.expect( "2.0-SNAPSHOT" ) );
172 public void testClassifier()
174 FilenameParser parser = new FilenameParser( "artifact-id-1.0-20070219.171202-34-test-sources.jar" );
176 assertEquals( "artifact-id", parser.nextNonVersion() );
177 assertEquals( "1.0-20070219.171202-34", parser.nextVersion() );
178 assertEquals( "test-sources", parser.remaining() );
179 assertEquals( "artifact-id-1.0-20070219.171202-34-test-sources", parser.getName() );
180 assertEquals( "jar", parser.getExtension() );
183 public void testNoExtension()
185 FilenameParser parser = new FilenameParser( "foo_bar" );
186 assertNull( parser.getExtension() );