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( "sources", parser.remaining() );
102 assertNull( parser.expect( "jar" ) );
105 public void testNextNonVersion()
107 FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
109 assertEquals("maven-test-plugin", parser.nextNonVersion() );
110 assertEquals("1.8.3", parser.remaining() );
113 public void testNextArbitraryNonVersion()
115 FilenameParser parser = new FilenameParser( "maven-jdk-1.4-plugin-1.0-20070828.123456-42.jar" );
117 assertEquals("maven-jdk-1.4-plugin", parser.nextNonVersion() );
118 assertEquals("1.0-20070828.123456-42", parser.remaining() );
121 public void testNextJython()
123 FilenameParser parser = new FilenameParser( "jython-20020827-no-oro.jar" );
125 assertEquals("jython", parser.nextNonVersion() );
126 assertEquals("20020827", parser.nextVersion() );
127 assertEquals("no-oro", parser.remaining() );