📄 jbrequesttest.java
字号:
/*
* OPIAM Suite
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package opiam.admin.faare.unittests.struts.service.beans;
import opiam.admin.faare.PropertiesManager;
import opiam.admin.faare.struts.service.beans.JBRequest;
import opiam.admin.faare.struts.service.beans.JBRessourceRequest;
import opiam.admin.faare.unittests.TestResult;
import opiam.admin.faare.unittests.TestUtils;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.log4j.Logger;
import java.util.HashMap;
import java.util.Map;
/**
* Test of the JBRequest class.
*/
public class JBRequestTest extends TestCase
{
/** Instance of logger. */
private static Logger _logger = Logger.getLogger(JBRequestTest.class);
/** Instance of the trace class. */
private static TestUtils _test = new TestUtils(_logger);
/** Instance of JBRequest. */
private JBRequest jbRequest = new JBRequest();
/**
* Creates a new JBRequestTest object.
*
* @param arg0 Parameter.
*/
public JBRequestTest(String arg0)
{
super(arg0);
try
{
PropertiesManager.getInstance();
}
catch (Exception e)
{
StringBuffer msg = new StringBuffer();
msg.append("JBRequestTest constructor error");
msg.append(TestUtils.NEXT);
msg.append(e.toString());
_test.displayResultError(msg.toString());
}
}
/**
* Method of the tests suite.
*
* @return Tests result.
*/
public static Test suite()
{
TestSuite suite = new TestSuite();
suite.addTest(new JBRequestTest("testBegin"));
suite.addTest(new JBRequestTest("testGetName"));
suite.addTest(new JBRequestTest("testAddRessourceRequest"));
suite.addTest(new JBRequestTest("testFindRessourceRequestByName"));
suite.addTest(new JBRequestTest("testEnd"));
return suite;
}
/**
* Main method of the test class.
*
* @param args Sets of the parameters.
*/
public static void main(String[] args)
{
junit.textui.TestRunner.run(suite());
}
/**
* Method to indicate the beginning of the class test.
*
*/
public static void testBegin()
{
// To initialize the tests statement
TestResult.getInstance().setInitiator("JBRequestTest");
_test.displayHeaderClass("JBRequestTest");
assertTrue(true);
}
/**
* Method to indicate the end of the class test.
*
*/
public static void testEnd()
{
_test.displayFooterClass(null);
assertTrue(true);
// To display the tests statement
_test.displayTestStatement("JBRequestTest");
}
/**
* Test the methods: setName and getName.
*
*/
public void testGetName()
{
_test.displayHeaderMethod("testGetName");
try
{
String expected = "jbRessourceRequest";
jbRequest.setName("jbRessourceRequest");
String result = jbRequest.getName();
if (expected.equals(result))
{
_test.displayResultSuccess(null);
}
else
{
_test.displayResultFailure(null);
}
}
catch (Exception ex)
{
StringBuffer msg = new StringBuffer();
msg.append("Exception : ");
msg.append(TestUtils.NEXT);
msg.append(ex.toString());
_test.displayResultError(msg.toString());
}
_test.displayFooterMethod("testGetName");
}
/**
* Test the methods: addRessourceRequest and getRessourceRequestMap.
*
*/
public void testAddRessourceRequest()
{
_test.displayHeaderMethod("testAddRessourceRequest");
try
{
Map expectedRessourceRequestMap = new HashMap();
Map resultRessourceRequestMap = new HashMap();
JBRessourceRequest jbRessourceRequest1 = new JBRessourceRequest();
jbRessourceRequest1.setName("jbRessourceRequest1");
int expectedSize1 = expectedRessourceRequestMap.size();
expectedRessourceRequestMap.put("jbRessourceRequest1",
jbRessourceRequest1);
int expectedSize2 = expectedRessourceRequestMap.size();
int resultSize1 = resultRessourceRequestMap.size();
jbRequest.addRessourceRequest(jbRessourceRequest1);
resultRessourceRequestMap = jbRequest.getRessourceRequestMap();
int resultSize2 = resultRessourceRequestMap.size();
if (expectedSize2 == resultSize2)
{
_test.displayResultSuccess(null);
}
else
{
_test.displayResultFailure(null);
}
}
catch (Exception ex)
{
StringBuffer msg = new StringBuffer();
msg.append("Exception : ");
msg.append(TestUtils.NEXT);
msg.append(ex.toString());
_test.displayResultError(msg.toString());
}
_test.displayFooterMethod("testAddRessourceRequest");
}
/**
* Test the method: findRessourceRequestByName.
*
*/
public void testFindRessourceRequestByName()
{
_test.displayHeaderMethod("testFindRessourceRequestByName");
try
{
JBRessourceRequest jbRessourceRequest1 = new JBRessourceRequest();
JBRessourceRequest jbRessourceRequest2 = new JBRessourceRequest();
jbRessourceRequest1.setName("field1");
jbRequest.addRessourceRequest(jbRessourceRequest1);
jbRessourceRequest2 = jbRequest.findRessourceRequestByName("field1");
if (jbRessourceRequest1.getName().equals(jbRessourceRequest2.getName()))
{
_test.displayResultSuccess(null);
}
else
{
_test.displayResultFailure(null);
}
}
catch (Exception ex)
{
StringBuffer msg = new StringBuffer();
msg.append("Exception : ");
msg.append(TestUtils.NEXT);
msg.append(ex.toString());
_test.displayResultError(msg.toString());
}
_test.displayFooterMethod("testFindRessourceRequestByName");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -