Value classes and value managers
The following code examples show several value classes and value managers.
Value classes
A value class is a Java™ or .Net class containing data that is useful to interact with. An instance of a value class can persist and can be compared to other instances of the same class. This is a basic capability of all value classes.
This example code shows a Java value class:
package sdk.sample.value;
public class SimpleValue
{
String data = null;
public SimpleValue(String data)
{
this.data = data;
}
public String getValue()
{
return this.data;
}
public String toString()
{
return "SimpleValue("+data+")";
}
}
This example code shows a .Net value class:
using System;
namespace SDK.Sample.Value
{
public class SimpleValue
{
private String data = null;
public SimpleValue(String data)
{
this.data = data;
}
public String GetValue()
{
return this.data;
}
public override String ToString()
{
return "SimpleValue("+data+")";
}
}
}
Value Managers
Value managers interact with value classes so that value class objects can be serialized and compared and made to persist. Value manager classes can be dynamically added to the set of supported managers. After a new manager has been registered, any property of the newly supported value class is automatically expressed in the set of properties associated with a test object.
This example code shows a Java value manager:
package sdk.sample.value;
import com.rational.test.ft.value.managers.*;
public class SimpleValueManager implements IManageValueClass, IStringTableLookup
{
private static final String CLASSNAME = "sdk.sample.value.SimpleValue";
private static final String CANONICALNAME = ".simple_value";
private static final String DATA = "Data";
public void persistOut(Object theObject, IPersistOut persist,
IAuxiliaryDataManager auxData)
{
SimpleValue simple = (SimpleValue)theObject;
persist.write(DATA, simple.getValue());
}
public Object persistIn(IPersistIn persist,
IAuxiliaryDataManager auxData)
{
String data = (String)persist.read(0);
return new SimpleValue(data);
}
public Object persistIn(IPersistInNamed persist,
IAuxiliaryDataManager auxData)
{
String data = (String)persist.read(DATA);
return new SimpleValue(data);
}
public int compare(Object left, Object right, ICompareValueClass nested)
{
if ( left = null || right = null )
return ( left = right ? 100 : 0 );
if ( !(right instanceof SimpleValue) ) return 0;
SimpleValue l = (SimpleValue)left;
SimpleValue r = (SimpleValue)right;
return ( l.equals(r) ? 100 : 0 );
}
public Object createValue(Object sourceToCopy)
{
if ( sourceToCopy instanceof SimpleValue )
return new SimpleValue(((SimpleValue)sourceToCopy).getValue());
return null;
}
public String getCanonicalName()
{
return CANONICALNAME;
}
public String getClassName()
{
return CLASSNAME;
}
public String doLookup(Object lookup)
{
String retVal = null;
if (lookup instanceof SimpleValue && lookup != null)
{
retVal = com.rational.test.ft.services.StringTableService.getString(
((SimpleValue)lookup).getValue());
// If they are the same return null so we won't bother changing VP data, etc.
if (retVal = ((SimpleValue)lookup).getValue())
{
retVal = null;
}
}
return retVal;
}
}
This example code shows a .Net value manager:
using System;
using Rational.Test.Ft.Value.Managers;
namespace SDK.Sample.Value
{
public class SimpleValueManager: IManageValueClass
{
private const System.String CLASSNAME = "SDK.Sample.Value.SimpleValue";
private const System.String CANONICALNAME = ".simpe_value";
private const System.String DATA = "Data";
public virtual void PersistOut(System.Object theObject, IPersistOut persist, IAuxiliaryDataManager auxData)
{
SimpleValue simple = (SimpleValue)theObject;
persist.Write(DATA, simple.GetValue());
}
public virtual System.Object PersistIn(IPersistIn persist, IAuxiliaryDataManager auxData)
{
String data = (String)persist.Read(0);
return new SimpleValue(data);
}
public virtual System.Object PersistIn(IPersistInNamed persist, IAuxiliaryDataManager auxData)
{
String data = (String)persist.Read(DATA);
return new SimpleValue(data);
}
public virtual int Compare(System.Object left, System.Object right, ICompareValueClass nested)
{
if ( left = null || right = null )
return ( left = right ? 100 : 0 );
if ( !(right is SimpleValue) ) return 0;
SimpleValue l = (SimpleValue)left;
SimpleValue r = (SimpleValue)right;
return ( l.Equals(r) ? 100 : 0 );
}
public virtual System.Object CreateValue(System.Object sourceToCopy)
{
if ( sourceToCopy is SimpleValue )
return new SimpleValue(((SimpleValue)sourceToCopy).GetValue());
return null;
}
public virtual System.String GetCanonicalName()
{
return CANONICALNAME;
}
public virtual System.String GetClassName()
{
return CLASSNAME;
}
}
}