001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.tools.common;
019:
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import org.junit.Assert;
024: import org.junit.Test;
025:
026: public class ProcessorEnvironmentTest extends Assert {
027: @Test
028: public void testGet() {
029: Map<String, Object> map = new HashMap<String, Object>();
030: map.put("k1", "v1");
031: ToolContext env = new ToolContext();
032: env.setParameters(map);
033: String value = (String) env.get("k1");
034: assertEquals("v1", value);
035: }
036:
037: @Test
038: public void testPut() {
039: Map<String, Object> map = new HashMap<String, Object>();
040: map.put("k1", "v1");
041: ToolContext env = new ToolContext();
042: env.setParameters(map);
043: env.put("k2", "v2");
044: String value = (String) env.get("k2");
045: assertEquals("v2", value);
046: }
047:
048: @Test
049: public void testRemove() {
050: Map<String, Object> map = new HashMap<String, Object>();
051: map.put("k1", "v1");
052: ToolContext env = new ToolContext();
053: env.setParameters(map);
054: env.put("k2", "v2");
055: String value = (String) env.get("k2");
056: assertEquals("v2", value);
057: env.remove("k1");
058: assertNull(env.get("k1"));
059: }
060:
061: @Test
062: public void testContainsKey() {
063: Map<String, Object> map = new HashMap<String, Object>();
064: map.put("k1", "v1");
065: ToolContext env = new ToolContext();
066: env.setParameters(map);
067: assertTrue(env.containsKey("k1"));
068: }
069:
070: @Test
071: public void testGetDefaultValue() {
072: Map<String, Object> map = new HashMap<String, Object>();
073: map.put("k1", "v1");
074: ToolContext env = new ToolContext();
075: env.setParameters(map);
076:
077: String k1 = (String) env.get("k1", "v2");
078: assertEquals("v1", k1);
079: String k2 = (String) env.get("k2", "v2");
080: assertEquals("v2", k2);
081: }
082:
083: @Test
084: public void testOptionSet() {
085: Map<String, Object> map = new HashMap<String, Object>();
086: map.put("k1", "true");
087: ToolContext env = new ToolContext();
088: env.setParameters(map);
089:
090: assertTrue(env.optionSet("k1"));
091: assertFalse(env.optionSet("k2"));
092: }
093:
094: @Test
095: public void testGetBooleanValue() {
096: Map<String, Object> map = new HashMap<String, Object>();
097: map.put("k1", "true");
098: ToolContext env = new ToolContext();
099: env.setParameters(map);
100:
101: Boolean k1 = Boolean.valueOf((String) env.get("k1"));
102: assertTrue(k1);
103: Boolean k2 = Boolean.valueOf((String) env.get("k2", "true"));
104: assertTrue(k2);
105: Boolean k3 = Boolean.valueOf((String) env.get("k3", "yes"));
106: assertFalse(k3);
107: }
108:
109: }
|