Added JUnit exmaple test.

It test creation of MLocation records.
This commit is contained in:
trifonnt 2007-05-15 23:19:30 +00:00
parent fc4b40d2bc
commit 3774af4050
4 changed files with 126 additions and 0 deletions

View File

@ -5,5 +5,6 @@
<classpathentry kind="src" path="/base"/>
<classpathentry kind="src" path="/tools"/>
<classpathentry kind="src" path="/looks"/>
<classpathentry kind="lib" path="/tools/lib/junit.jar"/>
<classpathentry kind="output" path="build"/>
</classpath>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="test.MLocationTest"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="extend"/>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
</launchConfiguration>

View File

@ -0,0 +1,109 @@
//MLocationTest.java
package test;
import java.io.FileInputStream;
import java.util.Properties;
import java.util.logging.Level;
import junit.framework.TestCase;
import org.compiere.model.MLocation;
import org.compiere.util.CLogMgt;
import org.compiere.util.DB;
import org.compiere.util.Ini;
public class MLocationTest extends TestCase {
// Test: General
private Properties testProperties = null;
private Properties m_Ctx = null;
private String fileName_DefaultValue = "J:/Trifon-CD-0.3/workspace/adempiere-trunk/adempiere/Adempiere/Adempiere.properties";
private String fileName_Key = "AdempiereProperties";
private String fileName_Value = "";
private String isClient_DefaultValue = "Y";
private String isClient_Key = "isClient";
private boolean isClient_Value = true;
private String AD_User_ID_DefaultValue = "0";
private String AD_User_ID_Key = "AD_User_ID";
private int AD_User_ID_Value = 0;
// Test: Specific variables
private MLocation location = null;
@Override
protected void setUp() throws Exception {
super.setUp();
testProperties = new Properties();
testProperties.load(new FileInputStream("test.properties"));
fileName_Value = testProperties.getProperty(fileName_Key, fileName_DefaultValue);
isClient_Value = "Y".equals( testProperties.getProperty(isClient_Key, isClient_DefaultValue) );
AD_User_ID_Value = Integer.parseInt(testProperties.getProperty(AD_User_ID_Key, AD_User_ID_DefaultValue) );
m_Ctx = new Properties();
m_Ctx.setProperty("#AD_User_ID", new Integer(AD_User_ID_Value).toString());
System.out.println("m_Ctx: " + m_Ctx);
if (fileName_Value.length() < 1) {
assertEquals("Please specify path to Adempiere.properties file!", true, false);
}
System.setProperty("PropertyFile", fileName_Value);
Ini.setClient (isClient_Value);
org.compiere.Adempiere.startup(isClient_Value);
// Force connection if there are enough parameters. Else we work with Adempiere.properties
// if (args.length >= 6) {
// CConnection cc = CConnection.get(Database.DB_ORACLE, args[1], Integer.valueOf(args[2]).intValue(), args[3], args[4], args[5]);
// System.out.println("DB UserID:"+cc.getDbUid());
// DB.setDBTarget(cc);
// }
CLogMgt.setLevel(Level.FINEST);
/* Available levels:
Level.OFF, Level.SEVERE, Level.WARNING, Level.INFO,
Level.CONFIG, Level.FINE, Level.FINER, Level.FINEST, Level.ALL
*/
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
testProperties = null;
m_Ctx = null;
}
public void testMLocationCreation() {
location = new MLocation(m_Ctx, 0, "test");
// location.loadDefaults();
location.setC_Country_ID(100);
location.setC_Region_ID(103);
location.setCity("Windsor");
location.setAddress1("nyb");
location.setAddress2("");
location.setPostal("95492");
location.setPostal_Add("95492");
// location.setAD_Client_ID(0);
location.setAD_Org_ID(0);
boolean saveResult = location.save();
if (!saveResult) {
assertEquals("Location not updated!", true, saveResult);
} else {
System.out.println("location.getC_Location_ID: " + location.getC_Location_ID());
try {
DB.commit(true, "test");
} catch (Exception e) {
assertEquals("Location not updated!", true, false);
}
}
assertTrue("TestExample", true);
}
}

View File

@ -0,0 +1,3 @@
AdempiereProperties=C:/Adempiere/Adempiere.properties
isClient=Y
AD_User_ID=0