Update of /cvsroot/asterisk-java/asterisk-java/src/test/net/sf/asterisk/manager
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23034/src/test/net/sf/asterisk/manager
Added Files:
ActionBuilderTest.java
Log Message:
Added test case for ActionBuilder
--- NEW FILE: ActionBuilderTest.java ---
/*
* Copyright 2004-2005 Stefan Reuter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package net.sf.asterisk.manager;
import junit.framework.TestCase;
import net.sf.asterisk.manager.action.ManagerAction;
public class ActionBuilderTest extends TestCase
{
private ActionBuilder actionBuilder;
public void setUp()
{
this.actionBuilder = new ActionBuilder();
}
public void testBuildAction()
{
MyAction myAction;
String actual;
myAction = new MyAction();
myAction.setFirstProperty("first value");
myAction.setSecondProperty(new Integer(2));
myAction.setNonPublicProperty("private");
actual = actionBuilder.buildAction(myAction);
assertTrue("Action name missing", actual.indexOf("action: My\r\n") >= 0);
assertTrue("First property missing", actual.indexOf("firstproperty: first value\r\n") >= 0);
assertTrue("Second property missing", actual.indexOf("secondproperty: 2\r\n") >= 0);
assertTrue("Missing trailing CRNL CRNL", actual.endsWith("\r\n\r\n"));
assertEquals("Incorrect length", 61, actual.length());
}
public void testBuildActionWithNullValue()
{
MyAction myAction;
String actual;
myAction = new MyAction();
myAction.setFirstProperty("first value");
actual = actionBuilder.buildAction(myAction);
assertTrue("Action name missing", actual.indexOf("action: My\r\n") >= 0);
assertTrue("First property missing", actual.indexOf("firstproperty: first value\r\n") >= 0);
assertTrue("Missing trailing CRNL CRNL", actual.endsWith("\r\n\r\n"));
assertEquals("Incorrect length", 42, actual.length());
}
class MyAction extends ManagerAction
{
private static final long serialVersionUID = 3257568425345102641L;
private String firstProperty;
private Integer secondProperty;
private String nonPublicProperty;
public String getAction()
{
return "My";
}
public String getFirstProperty()
{
return firstProperty;
}
public void setFirstProperty(String firstProperty)
{
this.firstProperty = firstProperty;
}
public Integer getSecondProperty()
{
return secondProperty;
}
public void setSecondProperty(Integer secondProperty)
{
this.secondProperty = secondProperty;
}
protected String getNonPublicProperty()
{
return nonPublicProperty;
}
protected void setNonPublicProperty(String privateProperty)
{
this.nonPublicProperty = privateProperty;
}
public String get()
{
return "This method must not be considered a getter";
}
public String getIndexedProperty(int i)
{
return "This method must not be considered a getter relevant for building the action";
}
}
}
|