public void test_can_rename_state()
      throws NameAlreadyBoundException, InvalidActionLanguageSyntaxException {
    String stateName = "State1";
    String newStateName = "State2";
    EntityDomain domain = new EntityDomain("TestDomain");
    EntityClass klass = new EntityClass("Class");
    domain.addClass(klass);
    EntityState newState = new EntityState(stateName);
    klass.addState(newState);

    EditorCommand_RenameState command = new EditorCommand_RenameState();
    command.setDomain(domain);
    command.setStateId(stateName);
    command.setNewStateName(newStateName);
    command.setClassId("Class");

    Assert.assertEquals(false, klass.hasStateWithName(newStateName));
    Assert.assertEquals(true, klass.hasStateWithName(stateName));

    Assert.assertEquals(true, command.canDoCommand().returnStatus());
    Assert.assertEquals(true, command.doCommand().returnStatus());

    Assert.assertEquals(true, klass.hasStateWithName(newStateName));
    Assert.assertEquals(false, klass.hasStateWithName(stateName));
  }
  public void test_i_f_empty_instance_set_fails_if_instance_set_is_from_an_any_select()
      throws InvalidActionLanguageSyntaxException, NameAlreadyBoundException {
    String proc = "";
    proc += "SELECT ANY notASet RELATED BY self->R1;\n";
    proc += "IF EMPTY notASet THEN\n";
    proc += "END IF;\n";

    EntityDomain ttdDomain = DomainTTD.getTTDDomain();
    EntityClass user = ttdDomain.getEntityClassWithName("User");
    EntityState state = new EntityState("Initial");
    user.addState(state);
    EntityProcedure procedure = new EntityProcedure(state);
    procedure.setProcedure(proc);

    Assert.assertTrue(procedure.validate());
  }
  public void test_i_f_not_empty_instance_set_fails_if_instance_set_is_not_a_set()
      throws InvalidActionLanguageSyntaxException, NameAlreadyBoundException {
    String proc = "";
    proc += "CREATE notASet FROM User;\n";
    proc += "IF NOT EMPTY notASet THEN\n";
    proc += "END IF;\n";

    EntityDomain ttdDomain = DomainTTD.getTTDDomain();
    EntityClass user = ttdDomain.getEntityClassWithName("User");
    EntityState state = new EntityState("Initial");
    user.addState(state);
    EntityProcedure procedure = new EntityProcedure(state);
    procedure.setProcedure(proc);

    Assert.assertTrue(procedure.validate());
  }
  public void test_valid_if_empty()
      throws InvalidActionLanguageSyntaxException, NameAlreadyBoundException {
    String proc = "";
    proc += "SELECT MANY tasks RELATED BY self->R1;\n";
    proc += "IF EMPTY tasks THEN\n";
    proc += "END IF;\n";

    EntityDomain ttdDomain = DomainTTD.getTTDDomain();
    EntityClass user = ttdDomain.getEntityClassWithName("User");
    EntityState state = new EntityState("Initial");
    user.addState(state);
    EntityProcedure procedure = new EntityProcedure(state);
    procedure.setProcedure(proc);

    Assert.assertTrue(procedure.validate());
    Assert.assertEquals(0, TestHelper.countValidationErrors(procedure));
  }
  public void test_i_f_not_empty_instance_set_fails_if_instance_set_cannot_be_identified()
      throws InvalidActionLanguageSyntaxException, NameAlreadyBoundException {
    String proc = "";
    proc += "IF NOT EMPTY cantFind THEN\n";
    proc += "END IF;\n";

    EntityDomain ttdDomain = DomainTTD.getTTDDomain();
    EntityClass user = ttdDomain.getEntityClassWithName("User");
    EntityState state = new EntityState("Initial");
    user.addState(state);
    EntityProcedure procedure = new EntityProcedure(state);
    procedure.setProcedure(proc);

    Assert.assertTrue(!procedure.validate());
    Assert.assertEquals(1, TestHelper.countValidationErrors(procedure));
    Assert.assertTrue(
        TestHelper.checkValidationResultsForAnErrorOfType(
            procedure, CouldNotIdentifyInstanceSetValidationError.class));
  }