How to download a file from TestResource using JAVA OTA (COM4J)

1.6k views Asked by At

Actually I need to download the XLS file from Test Resource using Resource ID in java

Can any one help me out Please

I tried with below pece of code but m missing something on it

    IQCResourceFolderFactory rft = tdc.queryInterface(IQCResourceFolderFactory.class)​;
    Com4jObject dfe = rft.item(3252);
    IQCResourceFactory fds = dfe.queryInterface(IQCResourceFactory.class);
    IList C = fds.newList("");
    System.out.println(C.count());

above code throw me "Null pointer exception in Com4jObject dfe = rft.item(3252);

Please Help

Thanks in advance

1

There are 1 answers

0
Ganeshja On

Successfully downloaded the desired files from Test Resources by providing Resource Folder ID

Here is the working source code :

ITDConnection6 QCConnection = ClassFactory.createTDConnection();

QCConnection object should be declared with ITDConnection6 to access all QC attributes

IQCResourceFolderFactory resourceFolderFactory = QCConnection.qcResourceFolderFactory().queryInterface(IQCResourceFolderFactory.class);
IList folders = resourceFolderFactory.newList("");
for(Com4jObject rec : folders)
{
    IQCResourceFolder resourceFolder = rec.queryInterface(IQCResourceFolder.class);
    if(resourceFolder.id().toString().equals(properties.getProperty("ResourceFolderID")))
    {   
        Com4jObject objResourceFactory = resourceFolder.qcResourceFactory();
        IQCResourceFactory resourceFactory = objResourceFactory.queryInterface(IQCResourceFactory.class);
        IList resources = resourceFactory.newList("");
         for(Com4jObject objResource : resources)
         {
                IQCResource resource  = objResource.queryInterface(IQCResource.class);  ;
                IResourceStorage resourceStorage = resource.queryInterface(IResourceStorage.class);                     
                resourceStorage.downloadResource("D:\\", true);
         }
    }
}