1 package com.eviware.soapui.impl.wsdl; 2 3 import com.eviware.soapui.impl.wsdl.support.PathUtils; 4 import com.eviware.soapui.support.Tools; 5 6 import junit.framework.TestCase; 7 8 public class ResolveContextTest extends TestCase 9 { 10 public void testRelativizePath() 11 { 12 testFilePath( "test.txt", "c://dir//test.txt", "c://dir" ); 13 testFilePath( "dir2//test.txt", "c://dir//dir2//test.txt", "c://dir" ); 14 testFilePath( "..//test.txt", "c://dir//dir2//test.txt", "c://dir//dir2//dir3" ); 15 testFilePath( "dir//test.txt", "c://dir//test.txt", "c://" ); 16 testFilePath( "..//test.txt", "c://dir//test.txt", "c://dir//anotherDir" ); 17 testFilePath( "..//dir2//test.txt", "c://dir//dir2//test.txt", "c://dir//anotherDir" ); 18 19 testUrl( "test.txt", "http://www.test.com/dir/test.txt", "http://www.test.com/dir" ); 20 testUrl( "dir2/test.txt", "http://www.test.com/dir/dir2/test.txt", "http://www.test.com/dir" ); 21 testUrl( "../test.txt?test", "http://www.test.com/dir/dir2/test.txt?test", "http://www.test.com/dir/dir2/dir3" ); 22 } 23 24 private void testFilePath( String relativePath, String absolutePath, String rootPath ) 25 { 26 assertEquals( relativePath, PathUtils.relativize( absolutePath, rootPath )); 27 28 if( !rootPath.endsWith( "//" )) 29 rootPath += "//"; 30 31 assertEquals( absolutePath, Tools.joinRelativeUrl( rootPath, relativePath )); 32 } 33 34 private void testUrl( String relativePath, String absolutePath, String rootPath ) 35 { 36 assertEquals( relativePath, PathUtils.relativize( absolutePath, rootPath )); 37 38 if( !rootPath.endsWith( "/" )) 39 rootPath += "/"; 40 41 assertEquals( absolutePath, Tools.joinRelativeUrl( rootPath , relativePath )); 42 } 43 }