package modTransf.model.extension;
import junit.framework.TestCase;
import java.io.IOException;
import modTransf.model.java.JavaObjectModelHelper;
import modTransf.model.ModelHelper;
import modTransf.model.ModelException;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
/**
* Test case for SimpleMultiModelHelper.
*/
public class ConceptExtensionMngrTest extends ExtensionTestCase
{
protected ConceptExtensionMngr mngr;
protected ModelHelper model1;
public ConceptExtensionMngrTest(String name)
{
super(name);
}
/**
* Initialize the context for a new test.
* This method is called befor each test
* @throws IOException
*/
public void setUp()
throws IOException
{
super.setUp();
// create models
try
{
model1 = new JavaObjectModelHelper();
model1.createInstance("java.lang.Object");
}
catch(InstantiationException ex)
{
throw new Error(ex);
}
// create context.
mngr = new ConceptExtensionMngr(model1);
}
/**
* Tear down the test.
* This method is called after each test.
*/
public void tearDown()
{
super.tearDown();
model1 = null;
mngr = null;
}
/**
* Check registration, retrieval by name and by member.
*/
public void testRegistration()
throws ModelException
{
// Define a property on a String
ConceptPropertyExtension p1 = createPropertyExtension("p1", "java.lang.String",
"java.lang.String", null);
mngr.registerPropertyExtension(p1);
String bean = new String();
// Test on internal implementation.
// These tests should be removed if the implementation change.
assertNotNull("mngr internal created", mngr.propertyExtensions);
assertNotNull("mngr internal pool created", mngr.propertyExtensions.get("p1"));
// Test registration
ConceptPropertyExtension res = mngr.getPropertyExtension(bean, "p1");
assertEquals("get registered extension", p1, res);
// Define another property p1 on an Object
ConceptPropertyExtension p2 = createPropertyExtension("p1", "java.lang.String",
"java.util.List", null);
mngr.registerPropertyExtension(p2);
// Test registration
res = mngr.getPropertyExtension(bean, "p1");
assertEquals("get registered extension", p1, res);
// Define a property on a String
ConceptPropertyExtension p3 = createPropertyExtension("p3", "java.lang.String",
"java.lang.String", null);
mngr.registerPropertyExtension(p3);
// Test retrieving
res = mngr.getPropertyExtension(bean, "p3");
assertEquals("get registered extension", p3, res);
}
/**
* Check registration, retrieval by name and by member.
* Register in reverse order, and check that the retrieval by (name,concept)
* works.
*/
public void testRegistration2()
throws ModelException
{
// Define another property p1 on an Object
ConceptPropertyExtension p2 = createPropertyExtension("p1", "java.lang.String",
"java.util.List", null);
mngr.registerPropertyExtension(p2);
// Define a property on a String
ConceptPropertyExtension p1 = createPropertyExtension("p1", "java.lang.String",
"java.lang.String", null);
mngr.registerPropertyExtension(p1);
// Test retrieving for a String
String bean = new String();
ConceptPropertyExtension res = mngr.getPropertyExtension(bean, "p1");
assertEquals("get registered extension", p1, res);
}
/**
* Check the getProperty on regular property and on registered property.
*/
public void testGet()
throws ModelException
{
// Define a property on a String
ConceptPropertyExtension p1 = createPropertyExtension("size2", "java.lang.Integer",
"java.lang.String", new Integer(5) );
mngr.registerPropertyExtension(p1);
// Test registration
String bean = new String("abc");
Object res = mngr.getProperty(bean, "size2");
assertEquals("Returned value", new Integer(5), res);
}
}