Search in sources :

Example 1 with Helper

use of org.eclipse.persistence.internal.helper.Helper 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";
    }
}
Also used : Helper(org.eclipse.persistence.internal.helper.Helper) Enumeration(java.util.Enumeration) TypedAssociation(org.eclipse.persistence.mappings.TypedAssociation) Association(org.eclipse.persistence.mappings.Association) TypedAssociation(org.eclipse.persistence.mappings.TypedAssociation) Vector(java.util.Vector)

Aggregations

Enumeration (java.util.Enumeration)1 Vector (java.util.Vector)1 Helper (org.eclipse.persistence.internal.helper.Helper)1 Association (org.eclipse.persistence.mappings.Association)1 TypedAssociation (org.eclipse.persistence.mappings.TypedAssociation)1