public void testCycConstant() {
    System.out.println("\n*** testCycConstant ***");
    try {
      CycObjectFactory.resetCycConstantCaches();
      assertEquals(0, CycObjectFactory.getCycConstantCacheByNameSize());
      String guidString = TAME_ANIMAL.getGuid().getGuidString();
      String constantName = TAME_ANIMAL.getName();
      CycObjectFactory.addCycConstantCache(TAME_ANIMAL);
      assertNotNull(TAME_ANIMAL);
      assertEquals(1, CycObjectFactory.getCycConstantCacheByNameSize());

      // Attempt to create a duplicate returns the cached existing object.
      CycConstant cycConstant2 = new CycConstant(constantName, CycObjectFactory.makeGuid(guidString));
      CycObjectFactory.addCycConstantCache(cycConstant2);
      assertEquals(1, CycObjectFactory.getCycConstantCacheByNameSize());
      assertEquals(TAME_ANIMAL, cycConstant2);

      CycConstant cycConstant3 = new CycConstant(constantName, CycObjectFactory.makeGuid(guidString));
      CycObjectFactory.addCycConstantCache(cycConstant3);
      assertEquals(TAME_ANIMAL.toString(), cycConstant3.toString());
      assertEquals(TAME_ANIMAL.cyclify(), cycConstant3.cyclify());
      assertEquals(TAME_ANIMAL, cycConstant3);
      testCycObjectRetrievable(TAME_ANIMAL);


      // compareTo
      ArrayList constants = new ArrayList();

      constants.add(DOG);
      constants.add(CAT);
      constants.add(BRAZIL);
      constants.add(COLLECTION);
      Collections.sort(constants);
      assertEquals("[Brazil, Cat, Collection, Dog]", constants.toString());

      CycConstant cycConstant4 =
              TRANSPORTATION_DEVICE_VEHICLE;

      XMLStringWriter xmlStringWriter = new XMLStringWriter();
      cycConstant4.toXML(xmlStringWriter, 0, false);
      String expectedXML =
              "<constant>\n"
              + "  <guid>c0bce169-9c29-11b1-9dad-c379636f7270</guid>\n"
              + "  <name>TransportationDevice-Vehicle</name>\n"
              + "</constant>\n";
      assertEquals(expectedXML, xmlStringWriter.toString());
      assertEquals(expectedXML, cycConstant4.toXMLString());
      String cycConstantXMLString = cycConstant4.toXMLString();
      CycObjectFactory.resetCycConstantCaches();
      Object object = CycObjectFactory.unmarshall(cycConstantXMLString);
      assertTrue(object instanceof CycConstant);
      assertEquals(cycConstant4, (CycConstant) object);
    } catch (Exception e) {
      failWithException(e);
    }

    System.out.println("*** testCycConstant OK ***");
  }