Ejemplo n.º 1
0
  @Test
  public void testFactFactories()
      throws KBTypeException, CreateException, ParseException, DeleteException {

    // Only GAFs can be Fact.class
    System.out.println("Running testFactFactories");
    System.out.println("Testing that only GAFs can be Facts");
    try {
      @SuppressWarnings("deprecation")
      Fact f = FactImpl.get(KBObjectImpl.getCore(TestConstants.flyingRule));
    } catch (KBObjectNotFoundException kboe) {
      // @todo isn't this an error/failure???
      System.out.println("Got Exception: " + kboe.toString());
    }

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy MM dd HH:mm");
    Context airlineLogMt = ContextImpl.findOrCreate("SomeAirlineLogMt");
    KBIndividual flight = KBIndividualImpl.get("FlightXYZ-APITest");

    Date d = sdf.parse("2014 03 15 10:20");
    SentenceImpl s = new SentenceImpl(TestConstants.kbapitc.endingDate, flight, d);
    Assertion a = AssertionImpl.get(s, airlineLogMt);
    @SuppressWarnings("deprecation")
    Fact flDate = FactImpl.get(KBObjectImpl.getCore(a));

    System.out.println("Testing HLID Factory");
    String hlid = a.getId();
    Fact flDate1 = FactImpl.get(hlid);
    assertTrue("Fact not equal to one from HLID", flDate1 == flDate);

    // Get based on formula and context strings
    System.out.println("Testing factory get(formulaStr, ctxStr)");
    Fact flDate2 = FactImpl.get(s.toString(), airlineLogMt.toString());
    assertTrue("Fact not equal to one from formulaStr, ctxStr", flDate2 == flDate);

    System.out.println("Testing factory get(formula, ctx)");
    Fact flDate3 = FactImpl.get(s, airlineLogMt);
    assertTrue("Fact not equal to one from formula, ctx", flDate3 == flDate);

    FirstOrderCollectionImpl flying2Col = FirstOrderCollectionImpl.get("Flying-Move");
    KBIndividual flight2 =
        KBIndividualImpl.findOrCreate("FlightABC-APITest", flying2Col, airlineLogMt);

    SentenceImpl s2 = new SentenceImpl(TestConstants.kbapitc.endingDate, flight2, d);
    FactImpl fl2Date = FactImpl.findOrCreate(s2, airlineLogMt);
    fl2Date.delete();

    Fact fl3Date = FactImpl.findOrCreate(s2.toString(), airlineLogMt.toString());
    assertFalse("Probably failed to assert, HLID is empty string", fl2Date.getId().equals(""));
  }
Ejemplo n.º 2
0
  @Test
  public void testDelete() throws KBApiException {
    System.out.println("Running testDelete");
    KBIndividual i = KBIndividualImpl.findOrCreate("PlaneTwo-APITest");
    Fact a =
        new FactImpl("#$SomeAirlineEquipmentMt", "(#$isa #$PlaneTwo-APITest #$CommercialAircraft)");
    assertEquals(
        "(ist SomeAirlineEquipmentMt (isa PlaneTwo-APITest CommercialAircraft))", a.toString());
    a.delete();

    try {
      Fact a2 =
          FactImpl.get(
              "(#$isa #$PlaneTwo-APITest #$CommercialAircraft)", "#$SomeAirlineEquipmentMt");
    } catch (CreateException ce) {

      // @todo is this supposed to be a failure????
      System.out.println("Exception: " + ce.getClass().getSimpleName() + " : " + ce.getMessage());
    }
  }