値クラスと値マネージャー

以下のコード例は、いくつかの値クラスと値マネージャーを示しています。

値クラス

値クラスとは、データを含む Java™ または .Net のクラスのことです。これにより対話が行いやすくなります。 値クラスのインスタンスは持続可能で、同じクラスの別のインスタンスとの比較を行うことができます。 これはすべての値クラスの基本機能です。

以下のサンプル・コードは、Java の値クラスを示しています。

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+")";
	}
}

以下のサンプル・コードは、.Net の値クラスを示しています。

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+")";
		}
	}

}

値マネージャー

値マネージャーは値クラスと対話を行い、値クラスのオブジェクトを直列化、比較、および持続できるようにします。 サポートされるマネージャーのセットに対して値マネージャーのクラスを動的に追加することができます。 新規マネージャーが登録された後、新たにサポートされる値クラスのプロパティーはすべて、テスト・オブジェクトに関連付けられるプロパティーのセットで自動的に表現されます。

以下のサンプル・コードは、Java の値マネージャーを示しています。

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;
	}
	
}

以下のサンプル・コードは、.Net の値マネージャーを示しています。

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;
		}
	}
}

フィードバック