public void testNonImplementorsHaveNoIndicatorValuesProblem() {
    String problem = ProblemConstants.MAPPING_CLASS_INDICATOR_VALUES_INVALID;

    SimpleContactProject project = new SimpleContactProject();
    MWVariableOneToOneMapping mapping =
        (MWVariableOneToOneMapping) project.getPersonImplDescriptor().mappingNamed("contact");

    assertTrue(
        "The mapping should not have the problem: " + problem, !hasProblem(problem, mapping));

    MWRelationalClassIndicatorFieldPolicy policy = mapping.getClassIndicatorPolicy();
    try {
      MWClassIndicatorValue value =
          (MWClassIndicatorValue)
              ClassTools.attemptNewInstance(
                  MWClassIndicatorValue.class,
                  new Class[] {
                    MWClassIndicatorFieldPolicy.class, MWMappingDescriptor.class, Object.class
                  },
                  new Object[] {policy, project.getPersonImplDescriptor(), "I"});
      value.setInclude(true);
      Collection indicatorValues =
          (Collection) ClassTools.attemptToGetFieldValue(policy, "classIndicatorValues");
      indicatorValues.add(value);
    } catch (NoSuchFieldException exception) {
      // test will fail
    } catch (NoSuchMethodException exception) {
      // test will fail
    }

    assertTrue("The mapping should have the problem: " + problem, hasProblem(problem, mapping));
  }
  public void testIndicatorFieldNotNullProblem() {
    String problem = ProblemConstants.MAPPING_CLASS_INDICATOR_FIELD_NOT_SPECIFIED;

    SimpleContactProject project = new SimpleContactProject();
    MWVariableOneToOneMapping mapping =
        (MWVariableOneToOneMapping) project.getPersonImplDescriptor().mappingNamed("contact");

    assertTrue(
        "The mapping should not have the problem: " + problem,
        !hasProblem(problem, mapping.getClassIndicatorPolicy()));

    Iterator associations = mapping.columnQueryKeyPairs();

    mapping.getClassIndicatorPolicy().setField(null);
    assertTrue(
        "The mapping should not have the problem: " + problem,
        !hasProblem(problem, mapping.getClassIndicatorPolicy()));

    while (associations.hasNext()) {
      MWColumnQueryKeyPair association = (MWColumnQueryKeyPair) associations.next();
      association.getColumn().setPrimaryKey(false);
      association.getColumn().setUnique(false);
    }

    assertTrue(
        "The mapping should have the problem: " + problem,
        hasProblem(problem, mapping.getClassIndicatorPolicy()));
  }
  public void testMultipleWriteableMappingsProblem() {
    String problem = "0106";

    SimpleContactProject project = new SimpleContactProject();
    MWVariableOneToOneMapping mapping =
        (MWVariableOneToOneMapping) project.getPersonImplDescriptor().mappingNamed("contact");

    assertTrue(
        "The mapping's parent descriptor should not have the problem: " + problem,
        !hasProblem(problem, mapping.getParentDescriptor()));
    assertTrue(
        "The mapping's parent descriptor should not have the problem: " + problem,
        !hasProblem(
            ProblemConstants.DESCRIPTOR_PRIMARY_KEY_FIELD_UNMAPPED, mapping.getParentDescriptor()));

    MWDirectToFieldMapping idMapping =
        (MWDirectToFieldMapping)
            mapping
                .getParentDescriptor()
                .addDirectMapping(mapping.getParentDescriptor().getMWClass().attributeNamed("id"));
    idMapping.setColumn(
        ((MWTableDescriptor) mapping.getParentDescriptor()).getPrimaryTable().columnNamed("ID"));

    assertTrue(
        "The mapping's parent descriptor should have the problem: " + problem,
        hasProblem(problem, mapping.getParentDescriptor()));

    mapping.getParentDescriptor().removeMapping(idMapping);
    mapping.removeColumnQueryKeyPair((MWColumnQueryKeyPair) mapping.columnQueryKeyPairs().next());

    assertTrue(
        "The mapping's parent descriptor  should have the problem: " + problem,
        hasProblem(
            ProblemConstants.DESCRIPTOR_PRIMARY_KEY_FIELD_UNMAPPED, mapping.getParentDescriptor()));
  }
  public void testMWVariableOneToOneMapping() {
    SimpleContactProject simpleContactProject = new SimpleContactProject();
    MWVariableOneToOneMapping original =
        (MWVariableOneToOneMapping)
            simpleContactProject.getPersonImplDescriptor().mappingNamed("contact");

    assertCommonAttributesEqual(original, original.asMWOneToOneMapping());

    assertCommonAttributesEqual(original, original.asMWOneToManyMapping());
  }
  public void testForeignKeysAreSpecifiedProblem() {
    String problem = ProblemConstants.MAPPING_QUERY_KEY_ASSOCIATIONS_INCOMPLETE;

    SimpleContactProject project = new SimpleContactProject();
    MWVariableOneToOneMapping mapping =
        (MWVariableOneToOneMapping) project.getPersonImplDescriptor().mappingNamed("contact");

    assertTrue(
        "The mapping should not have the problem: " + problem, !hasProblem(problem, mapping));

    mapping.addColumnQueryKeyPair(null, "getThatQuery");

    assertTrue("The mapping should have the problem: " + problem, hasProblem(problem, mapping));
  }
  public void testMappingAndVariableUseIndirectionProblem() {
    String problem =
        ProblemConstants.MAPPING_VALUE_HOLDER_INDIRECTION_WITHOUT_VALUE_HOLDER_ATTRIBUTE;

    SimpleContactProject project = new SimpleContactProject();
    MWVariableOneToOneMapping mapping =
        (MWVariableOneToOneMapping) project.getPersonImplDescriptor().mappingNamed("contact");

    assertTrue(
        "The mapping should not have the problem: " + problem, !hasProblem(problem, mapping));

    mapping.setUseValueHolderIndirection();

    assertTrue("The mapping should have the problem: " + problem, hasProblem(problem, mapping));
  }
  public void testCheckQueryKeysForValidityProblem() {
    String problem = ProblemConstants.MAPPING_QUERY_KEY_ASSOCIATIONS_INVALID;

    SimpleContactProject project = new SimpleContactProject();
    MWVariableOneToOneMapping mapping =
        (MWVariableOneToOneMapping) project.getPersonImplDescriptor().mappingNamed("contact");

    assertTrue(
        "The mapping should not have the problem: " + problem, !hasProblem(problem, mapping));

    mapping.addColumnQueryKeyPair(
        project.database().tableNamed("SEQUENCE").columnNamed("SEQ_COUNT"), "getThatQuery");

    assertTrue("The mapping should have the problem: " + problem, hasProblem(problem, mapping));
  }
  public void testNappingHasFieldAssociationsProblem() {
    String problem = ProblemConstants.MAPPING_QUERY_KEY_ASSOCIATIONS_NOT_SPECIFIED;

    SimpleContactProject project = new SimpleContactProject();
    MWVariableOneToOneMapping mapping =
        (MWVariableOneToOneMapping) project.getPersonImplDescriptor().mappingNamed("contact");

    assertTrue(
        "The mapping should not have the problem: " + problem, !hasProblem(problem, mapping));

    Iterator associations = CollectionTools.collection(mapping.columnQueryKeyPairs()).iterator();
    while (associations.hasNext()) {
      mapping.removeColumnQueryKeyPair((MWColumnQueryKeyPair) associations.next());
    }

    assertTrue("The mapping should have the problem: " + problem, hasProblem(problem, mapping));
  }
  public void testHasIndicatorValuesProblem() {
    String problem = ProblemConstants.NO_CLASS_INDICATOR_FOR_INCLUDED_CLASS;

    SimpleContactProject project = new SimpleContactProject();
    MWVariableOneToOneMapping mapping =
        (MWVariableOneToOneMapping) project.getPersonImplDescriptor().mappingNamed("contact");

    assertTrue(
        "The mapping should not have the problem: " + problem, !hasProblem(problem, mapping));

    Iterator values = mapping.getClassIndicatorPolicy().classIndicatorValues();

    while (values.hasNext()) {
      MWClassIndicatorValue value = (MWClassIndicatorValue) values.next();
      value.setIndicatorValue(null);
    }

    assertTrue("The mapping should have the problem: " + problem, hasProblem(problem, mapping));
  }