001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.engine; 016 017 import org.apache.tapestry.BaseComponentTestCase; 018 import org.apache.tapestry.util.QueryParameterMap; 019 import org.testng.annotations.Test; 020 021 import java.util.HashMap; 022 import java.util.Map; 023 024 /** 025 * Tests for {@link org.apache.tapestry.engine.ServiceEncodingImpl}. 026 * 027 * @author Howard M. Lewis Ship 028 */ 029 @Test 030 public class TestServiceEncoding extends BaseComponentTestCase 031 { 032 public void testSetServletPath() 033 { 034 ServiceEncodingImpl se = new ServiceEncodingImpl("/bar"); 035 036 assertEquals("/bar", se.getServletPath()); 037 assertEquals(false, se.isModified()); 038 039 se.setServletPath("/foo"); 040 041 assertEquals("/foo", se.getServletPath()); 042 assertEquals(true, se.isModified()); 043 } 044 045 public void testCreateWithExistingMap() 046 { 047 Map parameters = new HashMap(); 048 049 ServiceEncodingImpl se = new ServiceEncodingImpl("/foo", new QueryParameterMap(parameters)); 050 051 se.setParameterValue("foo", "bar"); 052 053 assertEquals("bar", parameters.get("foo")); 054 } 055 056 public void testGetParameterValue() 057 { 058 ServiceEncodingImpl se = new ServiceEncodingImpl("/foo"); 059 060 se.setParameterValue("foo", "bar"); 061 062 assertEquals(true, se.isModified()); 063 064 assertEquals("bar", se.getParameterValue("foo")); 065 066 se.setParameterValues("flintstone", new String[] 067 { "fred", "wilma", "dino" }); 068 069 assertEquals("fred", se.getParameterValue("flintstone")); 070 071 assertNull(se.getParameterValue("unknown")); 072 } 073 074 public void testGetParameterValues() 075 { 076 ServiceEncodingImpl se = new ServiceEncodingImpl("/foo"); 077 se.setParameterValues("flintstone", new String[] 078 { "fred", "wilma", "dino" }); 079 080 assertListEquals(new String[] 081 { "fred", "wilma", "dino" }, se.getParameterValues("flintstone")); 082 083 assertEquals(true, se.isModified()); 084 085 se.setParameterValue("foo", "bar"); 086 087 assertListEquals(new String[] 088 { "bar" }, se.getParameterValues("foo")); 089 090 assertNull(se.getParameterValue("unknown")); 091 } 092 093 public void testResetModified() 094 { 095 ServiceEncodingImpl se = new ServiceEncodingImpl("/bar"); 096 097 assertEquals(false, se.isModified()); 098 099 se.setServletPath("/foo"); 100 101 assertEquals(true, se.isModified()); 102 103 se.resetModified(); 104 105 assertEquals(false, se.isModified()); 106 } 107 108 public void testGetParameterNames() 109 { 110 ServiceEncodingImpl se = new ServiceEncodingImpl("/foo"); 111 112 se.setParameterValue("foo", "bar"); 113 se.setParameterValue("alpha", "beta"); 114 115 assertListEquals(new String[] 116 { "alpha", "foo" }, se.getParameterNames()); 117 } 118 }