use of org.eclipse.persistence.mappings.TypedAssociation in project eclipselink by eclipse-ee4j.
the class VariableOneToOneMapping2 method runTests.
public void runTests() {
/**
***********************************************************************
*/
mapping.addClassIndicator(Employee.class, null);
if (mapping.getClassIndicatorAssociations().isEmpty()) {
testFailures += "addClassIndicator = null did not add a null wrapper type indicator";
} else {
Enumeration e = mapping.getClassIndicatorAssociations().elements();
while (e.hasMoreElements()) {
TypedAssociation association = (TypedAssociation) e.nextElement();
if (association.getKey() == Employee.class) {
if (!(association.getValue() instanceof Helper)) {
testFailures += "addClassIndicator = null, type indicator does not = Helper class";
}
}
}
}
/**
***********************************************************************
*/
Vector vectorIn = new Vector();
vectorIn.add(new Association(Actor.class, new String("ASHLEY JUDD")));
vectorIn.add(new Association(Secretary.class, new String("DARTH VADER")));
vectorIn.add(new Association(Broadcastor.class, new String("RED KELLY")));
mapping.setClassIndicatorAssociations(vectorIn);
Vector vectorOut = mapping.getClassIndicatorAssociations();
if (vectorOut.size() != 3) {
testFailures += "setClassIndicatorAssociations - the set failed";
} else {
int foundCount = 0;
for (int i = 0; i < vectorOut.size(); i++) {
Association ass = (Association) vectorOut.elementAt(i);
if (ass.getKey() == Actor.class.getName() && ass.getValue().equals("ASHLEY JUDD")) {
foundCount++;
}
if (ass.getKey() == Secretary.class.getName() && ass.getValue().equals("DARTH VADER")) {
foundCount++;
}
if (ass.getKey() == Broadcastor.class.getName() && ass.getValue().equals("RED KELLY")) {
foundCount++;
}
}
if (foundCount != 3) {
testFailures += "setClassIndicatorAssociations - association values not found";
}
}
/**
***********************************************************************
*/
Association assoc = new Association(new String("key"), new String("value"));
Vector in = new Vector();
in.add(assoc);
mapping.setSourceToTargetQueryKeyFieldAssociations(in);
Vector out = mapping.getSourceToTargetQueryKeyFieldAssociations();
if (out.size() != 1) {
testFailures += "setSourceToTargetQueryFieldAssociations - the set failed";
} else {
Association a = (Association) out.elementAt(0);
if (!(a.getKey().equals("key") && a.getValue().equals("value"))) {
testFailures += "setSourceToTargetQueryFieldAssociations - value in the set failed";
}
}
/**
***********************************************************************
*/
Vector foreignKeyNames = new Vector();
foreignKeyNames.add("fkey1");
foreignKeyNames.add("fkey2");
foreignKeyNames.add("fkey3");
mapping.setForeignKeyFieldNames(foreignKeyNames);
Vector fieldNames = mapping.getForeignKeyFieldNames();
if (!(mapping.getForeignKeyFieldNames().contains("fkey1"))) {
testFailures += "addForeignQueryKeyName - fkey1";
}
if (!(mapping.getForeignKeyFieldNames().contains("fkey2"))) {
testFailures += "addForeignQueryKeyName - fkey2";
}
if (!(mapping.getForeignKeyFieldNames().contains("fkey3"))) {
testFailures += "addForeignQueryKeyName - fkey3";
}
/**
***********************************************************************
*/
mapping.setTypeFieldName("doesNotExist");
if (!mapping.getTypeFieldName().equals("doesNotExist")) {
testFailures += "setTypeFieldName failed";
}
/**
***********************************************************************
*/
// tests done through the wrapper
/**
***********************************************************************
*/
/**
***********************************************************************
*/
VariableOneToOneMapping2 wrappedMapping = new VariableOneToOneMapping2();
wrappedMapping.setTypeField(null);
if (wrappedMapping.getTypeFieldName() != null) {
testFailures += "setTypeField - set to null failed";
}
/**
***********************************************************************
*/
wrappedMapping.addClassIndicator(Employee.class, null);
if (wrappedMapping.getTypeForImplementor(Employee.class) != null) {
testFailures += "getTypeForImplementor failed";
}
if (wrappedMapping.getImplementorForType(null, getSession()) != Employee.class) {
testFailures += "getImplementorForType failed";
}
}
use of org.eclipse.persistence.mappings.TypedAssociation in project eclipselink by eclipse-ee4j.
the class InheritancePolicy method getClassIndicatorAssociations.
/**
* INTERNAL:
* Return the class indicator associations for XML.
* List of class-name/value associations.
*/
public Vector<Association> getClassIndicatorAssociations() {
Vector<Association> associations = new Vector<>(getClassNameIndicatorMapping().size() / 2);
Iterator classesEnum = getClassNameIndicatorMapping().keySet().iterator();
Iterator valuesEnum = getClassNameIndicatorMapping().values().iterator();
while (classesEnum.hasNext()) {
Object className = classesEnum.next();
// If the project was built in runtime is a class, MW is a string.
if (className instanceof Class) {
className = ((Class<?>) className).getName();
}
Object value = valuesEnum.next();
associations.addElement(new TypedAssociation(className, value));
}
return associations;
}
Aggregations