atg.adapter.gsa.AccessibleTableColumns Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of atgdust Show documentation
Show all versions of atgdust Show documentation
ATG DUST is a framework for building JUnit tests for
applications built on the ATG Dynamo platform. This framework allows
one to quickly write test code that depends up Nucleus or ATG
Repositories. By using this framework one can drastically cut down
on development time. It takes only a few seconds to start up a test
with a repository, but it may take multiple minutes to start up an
application server. To get started with DUST, take a look at
http://atgdust.sourceforge.net/first-test.html. This page will walk
you through the process of running a basic test which starts
Nucleus. After that, read the other getting started guides to
describe how to create standalone Junit tests which can startup
repositories and use the DynamoHttpServletResponse classes.
For only ATG10 and tested.
The newest version!
package atg.adapter.gsa;
import java.lang.reflect.Field;
import java.util.List;
import org.apache.log4j.Logger;
/**
* This class uses reflection to allow access to private member variables
* withing a GSA Table class.
*
* @author adamb
*/
public class AccessibleTableColumns {
public Logger mLogger = Logger.getLogger(this.getClass());
public TableColumns mTableColumns;
public AccessibleTableColumns(TableColumns pTable) {
mTableColumns = pTable;
}
// ------------------------
/**
* Returns the mHead field of the Table class passed to the constructor of
* this class.
*
* @return
*/
public ColumnDefinitionNode getHead() {
String fieldName = "mHead";
ColumnDefinitionNode node = (ColumnDefinitionNode) getPrivateField(fieldName);
return node;
}
// ------------------------
/**
* Returns the mTail field of the Table class passed to the constructor of
* this class.
*
* @return
*/
public ColumnDefinitionNode getTail() {
String fieldName = "mTail";
ColumnDefinitionNode node = (ColumnDefinitionNode) getPrivateField(fieldName);
return node;
}
// ------------------------
/**
* Returns the mPrimaryKeys field of the Table class passed to the constructor of
* this class.
*
* @return
*/
public List getPrimaryKeys() {
String fieldName = "mPrimaryKeys";
List node = (List) getPrivateField(fieldName);
return node;
}
//------------------------
/**
* Returns the mForeignKeys field of the Table class passed to the constructor of
* this class.
*
* @return
*/
public List getForeignKeys() {
String fieldName = "mForeignKeys";
List node = (List) getPrivateField(fieldName);
return node;
}
// ------------------------
/**
* Returns the mMultiColumnName field of the Table class passed to the
* constructor of this class.
*
* @return
*/
public String getMultiColumnName() {
String fieldName = "mMultiColumnName";
String node = (String) getPrivateField(fieldName);
return node;
}
// ------------------------
public Object getPrivateField(String fieldName) {
Field columnDefinitionNode = null;
Object field = null;
try {
columnDefinitionNode = mTableColumns.getClass().getDeclaredField(
fieldName);
columnDefinitionNode.setAccessible(true);
field = columnDefinitionNode.get(mTableColumns);
} catch (SecurityException e) {
mLogger.error(e);
} catch (NoSuchFieldException e) {
mLogger.error(e);
} catch (IllegalArgumentException e) {
mLogger.error(e);
} catch (IllegalAccessException e) {
mLogger.error(e);
}
return field;
}
}