1 package org.apache.maven.plugin.ant;
2
3 /*
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
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
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
19 * under the License.
20 */
21
22 import junit.framework.TestCase;
23
24 import java.io.File;
25
26 /**
27 * Tests <code>AntBuildWriter</code>.
28 *
29 * @author Benjamin Bentmann
30 * @version $Id: AntBuildWriterTest.java 1517969 2013-08-27 20:14:02Z krosenvold $
31 */
32 public class AntBuildWriterTest
33 extends TestCase
34 {
35
36 public void testGetProjectRepoDirectory()
37 {
38 String basedir = new File( System.getProperty( "java.io.tmpdir" ) ).getPath();
39
40 // non-project rooted repo URLs
41 assertEquals( null, AntBuildWriter.getProjectRepoDirectory( "http://maven.apache.org/", basedir ) );
42 assertEquals( null, AntBuildWriter.getProjectRepoDirectory( "file:///just-some-test-directory", basedir ) );
43
44 // RFC-compliant URLs
45 assertEquals( "", AntBuildWriter.getProjectRepoDirectory( new File( basedir ).toURI().toString(), basedir ) );
46 assertEquals( "dir", AntBuildWriter.getProjectRepoDirectory( new File( basedir, "dir" ).toURI().toString(),
47 basedir ) );
48 assertEquals( "dir/subdir",
49 AntBuildWriter.getProjectRepoDirectory( new File( basedir, "dir/subdir" ).toURI().toString(),
50 basedir ) );
51
52 // not so strict URLs
53 assertEquals( "", AntBuildWriter.getProjectRepoDirectory( "file://" + basedir, basedir ) );
54 assertEquals( "dir", AntBuildWriter.getProjectRepoDirectory( "file://" + basedir + "/dir", basedir ) );
55 assertEquals( "dir/subdir",
56 AntBuildWriter.getProjectRepoDirectory( "file://" + basedir + "/dir/subdir", basedir ) );
57
58 // URLs with encoded characters
59 assertEquals( "some dir",
60 AntBuildWriter.getProjectRepoDirectory( new File( basedir, "some dir" ).toURI().toString(),
61 basedir ) );
62 }
63
64 }