Develop a Trigger

Implementation

Developing a trigger essentially consists in implementing the main java class (extending CTrigger) so it's pretty simple.

Implementing the main java class

The main java class will have to extend the class com.xqual.xtrigger.CTrigger
There will be XXX methods to implement. These methods will be automatically called by XStudio or XAgent's whenever it's needed:

Trigger Process

Methods to implement (or not)

Most of the time you will want to implement only a very few of those methods. there are currently 21 implementable methods:
  • CTriggerStatus initialize()
    This is called at startup time of the trigger (so when XStudio or XAgent are started)
  • CTriggerStatus terminate()
    This is called when XStudio or XAgent are stopped.
  • CTriggerStatus onRequirementsTreeRefreshed()
  • CTriggerStatus onRequirementCreated(int id, String name, String description,
         short status, short priority, int risk)

  • CTriggerStatus onRequirementUpdated(int id, Vector changeList)
  • CTriggerStatus onRequirementsDeleted(Vector<Integer> ids)
  • CTriggerStatus onRequirementsMoved(Vector<Integer> ids, int folderId)
  • CTriggerStatus onTestsTreeRefreshed()
  • CTriggerStatus onTestCreated(int id, String name, short type, short status, short priority)
  • CTriggerStatus onTestUpdated(int id, Vector changeList)
  • CTriggerStatus onTestsDeleted(Vector<Integer> ids)
  • CTriggerStatus onTestsMoved(Vector<Integer> ids, int folderId)
  • CTriggerStatus onTestcaseCreated(int id, String name, String description,
         boolean readyForManualRun, boolean readyForAutomatedRun,
         String procedure)

  • CTriggerStatus onTestcaseUpdated(int id, Vector changeList)
  • CTriggerStatus onTestcasesDeleted(Vector<Integer> ids)
  • CTriggerStatus onTestcaseExecuted(int id, short status)
  • CTriggerStatus onBugsTreeRefreshed()
  • CTriggerStatus onBugCreated(int id, String name, String description, String stepToReproduce,
         short reproducibility, int platform, int os,
         short status, short severity, short priority,
         int reporter, Vector assigneeIds, Vector sutIds,
         Hashtable customFieldIntegerHashtable,
         Hashtable customFieldStringHashtable,
         Hashtable customFieldBooleanHashtable,
         Hashtable customFieldHtmlHashtable,
         Hashtable customFieldStringChoiceHashtable)

  • CTriggerStatus onBugUpdated(int id, Vector changeList)
  • CTriggerStatus onBugsDeleted(Vector<Integer> ids)
  • CTriggerStatus onBugsMoved(Vector<Integer> ids, int folderId)

The mandatory APIs

Build structured status to be returned

The status returned are included in the CTriggerStatus object returned by any of the methods to implement described above.
Most of the time you will build a CTriggerStatus object using this kind of code:
// in this case, RESULT_FAILURE is the status returned and the message must describe the issue
return new CTriggerStatus(RESULT_FAILURE, message);

// in this case, RESULT_SUCCESS is the status returned and the message provide additional info.
return new CTriggerStatus(RESULT_FAILURE, message);

// in this case, RESULT_SUCCESS is the status returned and no message are provided
return new CTriggerStatus();

for more details about the result codes, check out the SDK API reference.