/**
   * Test method for {@link
   * salomon.engine.agent.AgentProcessingComponentDAO#save(salomon.engine.agent.IAgentProcessingComponentDAO)}.
   */
  public void testSave() {
    AgentProcessingComponent comp = DAOTestHelper.createTestAgentProcessingComponent(true);
    componentDAO.save(comp);

    AgentProcessingComponent inserted =
        (AgentProcessingComponent) componentDAO.getAgentProcessingComponent(comp.getComponentId());
    assertEquals(comp.getComponentName(), inserted.getComponentName());
  }
  /**
   * Test method for {@link
   * salomon.engine.agent.AgentProcessingComponentDAO#getAgentProcessingComponents()}.
   */
  public void testGetAgentProcessingComponents() {
    // make sure at least one comp exists
    DAOTestHelper.createTestAgentProcessingComponent(false);

    IAgentProcessingComponent[] components = componentDAO.getAgentProcessingComponents();
    assertNotNull(components);
    assertTrue(components.length >= 1);
  }
  /**
   * Test method for {@link
   * salomon.engine.agent.AgentProcessingComponentDAO#getAgentProcessingComponent(java.lang.String)}.
   */
  public void testGetAgentProcessingComponentString() {
    AgentProcessingComponent comp = DAOTestHelper.createTestAgentProcessingComponent(false);

    AgentProcessingComponent inserted =
        (AgentProcessingComponent)
            componentDAO.getAgentProcessingComponent(comp.getComponentName());
    assertEquals(comp.getComponentName(), inserted.getComponentName());
    Arrays.equals(comp.getTaskManager().getTasks(), inserted.getTaskManager().getTasks());
  }
  /**
   * Test method for {@link
   * salomon.engine.agent.AgentProcessingComponentDAO#remove(salomon.engine.agent.IAgentProcessingComponentDAO)}.
   */
  public void testRemove() {
    AgentProcessingComponent comp = DAOTestHelper.createTestAgentProcessingComponent(true);
    comp.setComponentName("component-to-remove");

    componentDAO.save(comp);
    AgentProcessingComponent removed =
        (AgentProcessingComponent) componentDAO.getAgentProcessingComponent(comp.getComponentId());
    assertNotNull(removed);

    componentDAO.remove(comp);
    removed =
        (AgentProcessingComponent) componentDAO.getAgentProcessingComponent(comp.getComponentId());
    assertNull(removed);
  }
  public void testSaveWithAgents() {
    AgentProcessingComponent comp = DAOTestHelper.createTestAgentProcessingComponent(true);
    comp.setComponentName("test-comp-with-tasks");
    componentDAO.save(comp);

    // add tasks to Agent
    Task task1 = new Task();
    task1.setTaskName("task1");

    Task task2 = new Task();
    task2.setTaskName("task2");

    Task task3 = new Task();
    task3.setTaskName("task3");

    comp.getTaskManager().addTask(task1);
    comp.getTaskManager().addTask(task2);
    comp.getTaskManager().addTask(task3);

    // let's reorder the tasks
    task1.setTaskNr(2);
    task2.setTaskNr(1);
    task3.setTaskNr(0);

    componentDAO.save(comp);

    AgentProcessingComponent inserted =
        (AgentProcessingComponent) componentDAO.getAgentProcessingComponent(comp.getComponentId());
    assertEquals(comp.getComponentName(), inserted.getComponentName());
    Task[] tasks = inserted.getTaskManager().getTasks();
    assertNotNull(tasks);
    assertEquals(3, tasks.length);
    // check the order of tasks
    assertEquals("task3", tasks[0].getTaskName());
    assertEquals("task2", tasks[1].getTaskName());
    assertEquals("task1", tasks[2].getTaskName());

    // test getting tasks by id
    ITask insertedTask = inserted.getTaskManager().getTask(task1.getTaskId());
    assertNotNull(insertedTask);
    assertEquals(task1.getTaskName(), insertedTask.getTaskName());

    // test getting tasks by id
    insertedTask = inserted.getTaskManager().getTask(task1.getTaskName());
    assertNotNull(insertedTask);
    assertEquals(task1.getTaskName(), insertedTask.getTaskName());
  }