Question

I've tried various things and googled multiple hours but couldn't find a solution to my problem.

I'm using the Quality Center OTA API via Com4j to let my programm communicate with QC. It works pretty good, but now I've stumbed upon this problem:

I want to add new parameters to a test case in "Test Plan" using my programm.

If I used VB it would work somehow like this:

Dim supportParamTest As ISupportTestParameters
Set supportParamTest = TDConnection.TestFactory.Item(5)

Set testParamsFactory = supportParamTest.TestParameterFactory
Set parameter = testParamsFactory.AddItem(Null)
parameter.Name = name
parameter.Description = desc
parameter.Post

Set AddTestParameter = parameter

The important part is the call of AddItem() on the TestParameterFactory. It adds and returns a parameter that you then can give a name and description. In VB the AddItem-method is given Null as argument.

Using Java looks similar at first:

First I establish the connection and get the TestFactory (and the list of test cases).

QcConnect qc = new QcConnect(server, login, password, domain, project);
ITDConnection qcConnection = qc.getConnection();

ITestFactory qcTestFactory = qcConnection.testFactory().queryInterface(ITestFactory.class);
IList qcTestList = qcTestFactory.newList("");   

qcTestList contains all tests from Test Plan.

ITest test = qcTestList.item(1);      
ISupportTestParameters testParam = test.queryInterface(ISupportTestParameters.class);
ITestParameterFactory paramFac = testParam.testParameterFactory().queryInterface(ITestParameterFactory.class);

No problem so far. All the "casts" are successful. Now I want to call the addItem-method on the TestParameterFactory, just like in VB.

Com4jObject com = paramFac.addItem(null);

This doesn't work. The addItem()-method always returns null. I've tried various arguments like a random String, a random Integer, the test case's ID, etc. Nothing works.

How do I use this method correctly in Java?

Or in general: How do I add parameters to existing test cases in Test Plan using Java?

Quick note: Adding test cases to Test Plan works very similar to adding parameters to this test cases. You also use a factory and a addItem-method. In VB you give null as parameter, but in Java you use a String (that's interpreted as the name of the test). But as I said, that does not work in here.

Was it helpful?

Solution

I have finally found the answer to this:

Com4jObject obj = iTestParameterFactory.addItem(new Variant(Variant.Type.VT_NULL));
iTestParameter = obj.queryInterface(ITestParameter.class);
iTestParameter.name("AAB");
iTestParameter.defaultValue("BBB");
iTestParameter.description("CCC");
iTestParameter.post();

Regards.

OTHER TIPS

What you want to pass to AddItem is DBNull and not null. In VB it's the same, but in Java & .NET it's not.

Not sure how DBNull is exposed using Com4J.

Read more about this at this site.

//C# code snippet -> You have to use DBNull.Value instead of null        
//Add new parameter and assign values
    TestParameter newParam =(TestParameter)tParamFactory.AddItem(DBNull.Value);
    newParam.Name = "ParamNew";
    newParam.DefaultValue = "DefaultValue";
    newParam.Description = "AnyDesc";
    newParam.Post(); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top