1 7 package fr.jayasoft.ivy.util; 8 9 import java.util.HashMap ; 10 import java.util.Map ; 11 12 import junit.framework.TestCase; 13 14 public class IvyPatternHelperTest extends TestCase { 15 public void testSubstitute() { 16 String pattern = "[organisation]/[module]/build/archives/[type]s/[artifact]-[revision].[ext]"; 17 assertEquals( 18 "jayasoft/Test/build/archives/jars/test-1.0.jar", 19 IvyPatternHelper.substitute(pattern, "jayasoft", "Test", "1.0", "test", "jar", "jar")); 20 } 21 22 public void testCyclicSubstitute() { 23 String pattern = "${var}"; 24 Map variables = new HashMap (); 25 variables.put("var", "${othervar}"); 26 variables.put("othervar", "${var}"); 27 try { 28 IvyPatternHelper.substituteVariables(pattern, variables); 29 fail("cyclic var should raise an exception"); 30 } catch (Exception ex) { 31 } catch (Error er) { 33 fail("cyclic var shouldn't raise an error: "+er); 34 } 35 } 36 37 public void testOptionalSubstitute() { 38 Map tokens = new HashMap (); 39 tokens.put("token", ""); 40 tokens.put("othertoken", "myval"); 41 assertEquals("test-myval", IvyPatternHelper.substituteTokens("test(-[token])(-[othertoken])", tokens)); 42 tokens.put("token", "val"); 43 assertEquals("test-val-myval", IvyPatternHelper.substituteTokens("test(-[token])(-[othertoken])", tokens)); 44 } 45 46 public void testOrganization() { 47 String pattern = "[organization]/[module]/build/archives/[type]s/[artifact]-[revision].[ext]"; 48 assertEquals( 49 "jayasoft/Test/build/archives/jars/test-1.0.jar", 50 IvyPatternHelper.substitute(pattern, "jayasoft", "Test", "1.0", "test", "jar", "jar")); 51 } 52 53 } 54 | Popular Tags |