01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.util;
19:
20: import java.util.HashMap;
21: import java.util.Map;
22:
23: import junit.framework.TestCase;
24:
25: import org.apache.ivy.core.IvyPatternHelper;
26:
27: public class IvyPatternHelperTest extends TestCase {
28: public void testSubstitute() {
29: String pattern = "[organisation]/[module]/build/archives/[type]s/[artifact]-[revision].[ext]";
30: assertEquals("apache/Test/build/archives/jars/test-1.0.jar",
31: IvyPatternHelper.substitute(pattern, "apache", "Test",
32: "1.0", "test", "jar", "jar"));
33: }
34:
35: public void testCyclicSubstitute() {
36: String pattern = "${var}";
37: Map variables = new HashMap();
38: variables.put("var", "${othervar}");
39: variables.put("othervar", "${var}");
40: try {
41: IvyPatternHelper.substituteVariables(pattern, variables);
42: fail("cyclic var should raise an exception");
43: } catch (Exception ex) {
44: // ok
45: } catch (Error er) {
46: fail("cyclic var shouldn't raise an error: " + er);
47: }
48: }
49:
50: public void testOptionalSubstitute() {
51: Map tokens = new HashMap();
52: tokens.put("token", "");
53: tokens.put("othertoken", "myval");
54: assertEquals("test-myval", IvyPatternHelper.substituteTokens(
55: "test(-[token])(-[othertoken])", tokens));
56: tokens.put("token", "val");
57: assertEquals("test-val-myval", IvyPatternHelper
58: .substituteTokens("test(-[token])(-[othertoken])",
59: tokens));
60: }
61:
62: public void testOrganization() {
63: String pattern = "[organization]/[module]/build/archives/[type]s/[artifact]-[revision].[ext]";
64: assertEquals("apache/Test/build/archives/jars/test-1.0.jar",
65: IvyPatternHelper.substitute(pattern, "apache", "Test",
66: "1.0", "test", "jar", "jar"));
67: }
68:
69: }
|