QC10 to ALM12 : Bug creation script using java and OTA

324 views Asked by At

Here is my problem :

With QC10 my groovy script was OK and able to create bug :

import org.codehaus.groovy.scriptom.*
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.*;
import org.apache.log4j.Logger;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

def QC_Summary = context.getProperty("QC_Summary");
def QC_Description = context.getProperty("QC_Description");
def QC_Severity = context.getProperty("QC_Severity");
def QC_RefAnomalie = context.getProperty("QC_RefAnomalie");
def QC_DetectionDate = context.getProperty("QC_DetectionDate");

def tdc = new ActiveXObject ('TDApiOle80.TDConnection')
tdc.InitConnectionEx('http://xxxx:8080/qcbin')
tdc.Login(context.getProperty("QCUserName"), context.getProperty("QCPassword"));
tdc.Connect(context.getProperty("QCDomain"),context.getProperty("QCProject"));

def newDefect= tdc.BugFactory.AddItem("");

newDefect.AutoPost = false;
//newDefect.AssignedTo = "tga"; /*inutile*/
newDefect.DetectedBy = "wdi_testeurs"; /*fixe=test_wdi*/
newDefect.Status = "Transféré";
log.info "QC_Summary : " + QC_Summary;
//newDefect.Summary = QC_Summary;
newDefect._setField("BG_SUMMARY",QC_Summary.toString());

newDefect._setField("BG_DESCRIPTION",QC_Description);
newDefect._setField("BG_SEVERITY",QC_Severity);
newDefect._setField("BG_USER_01",QC_RefAnomalie);
newDefect._setField("BG_USER_02","jira"); /*fixe=jira*/
newDefect._setField("BG_USER_04","jira"); /*fixe=jira*/
newDefect._setField("BG_USER_05","Recette");
newDefect._setField("BG_DETECTION_DATE",QC_DetectionDate);

newDefect.Post();

def AddBug = newDefect.ID;

log.info "AddBug : " + AddBug;

tdc.Disconnect();
tdc = null;

But now on ALM12, method BugFactory.AddItem("") does not work anymore sending error like bad type of argument.I tried "", 0, -10, System.DBNull.Value as argument but it is not working.

Do you have any issue ? Perhaps using Dispatch class ?


I've got it :

import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.*;
import org.apache.log4j.Logger;

public static void setIndexedProperty(Dispatch activex, String name, Variant[] indexes, Variant value)
{
    Variant[] variants = new Variant[indexes.length + 1];            
    for(int i=0; i<indexes.length; i++) {
        variants[i] = indexes[i];
    }
    variants[variants.length-1] = value;
    Dispatch.invoke(activex, name, Dispatch.Put, variants, new int[variants.length]);
}

Calendar currentDate = Calendar.getInstance();
SimpleDateFormat formatter =  new SimpleDateFormat("MM/dd/yyyy");
String dateNow = formatter.format(currentDate.getTime());


ActiveXComponent QCObj = null;
QCObj = new ActiveXComponent("TDApiOle80.TDConnection");
Dispatch.call(QCObj,"initConnectionEx","http://xxxxx:8080/qcbin");
Dispatch.call(QCObj,"login","login","password");
Dispatch.call(QCObj,"connect","domain" , "projet");

Dispatch bugF = null;
bugF = Dispatch.call(QCObj ,"bugFactory").toDispatch();
Variant paramVal = new Variant();
paramVal.putNull();

Dispatch theBug = null;
theBug = Dispatch.call(bugF , "AddItem",paramVal).toDispatch();
Dispatch.put(theBug,"Summary","summary");
Dispatch.put(theBug,"status", "Nouveau");
Dispatch.put(theBug,"DetectedBy", "xxxxxx");

List<Variant> parm1 = new ArrayList<Variant>();
parm1.add(new Variant("BG_SEVERITY"));
Variant value1 = new Variant("2-Major");
setIndexedProperty(theBug, "Field", parm1.toArray(new Variant[1]), value1);

List<Variant> parm2 = new ArrayList<Variant>();
parm2.add(new Variant("BG_DETECTION_DATE"));
Variant value2 = new Variant(dateNow);
setIndexedProperty(theBug, "Field", parm2.toArray(new Variant[1]), value2);

List<Variant> parm3 = new ArrayList<Variant>();
parm3.add(new Variant("BG_DESCRIPTION"));
Variant value3 = new Variant("description");
setIndexedProperty(theBug, "Field", parm3.toArray(new Variant[1]), value3);

Dispatch.call(theBug,"Post");

This is THE SOLUTION in groovy !

0

There are 0 answers