createTestCase() issues using JAVAAPI

Discussion and information for XML-RPC interface.

Moderators: Amaradana, TurboPT, TL Developers

Post Reply
dkwang
TestLink user
Posts: 2
Joined: Fri Dec 13, 2013 8:02 pm

createTestCase() issues using JAVAAPI

Post by dkwang »

Hello TestLink gurus,

I'm currently trying out the testlink java api and have looked at some sample code of how to create a simple test case. I've found this example from http://testlinkjavaapi.sourceforge.net:

Code: Select all

    List<TestCaseStep> steps = new ArrayList<TestCaseStep>();
    TestCaseStep step = new TestCaseStep();
    step.setNumber(1);
    step.setExpectedResults("User name appeared in top menu.");
    step.setExecutionType(ExecutionType.MANUAL);
    step.setActions("Go to login screen and enter user credentials.");
    steps.add(step);
        
        TestCase tc = api.createTestCase(
            "TcName", // testCaseName
            new Integer(2), // testSuiteId
            new Integer(1), // testProjectId
            "admin", // authorLogin
            "No summary", // summary
            steps, // steps
            null, // preconditions
            TestImportance.HIGH, // importance
            ExecutionType.MANUAL, // execution
            new Integer(10), // order
            null, // internalId
            null, // checkDuplicatedName 
            null); // actionOnDuplicatedName
    
    System.out.println("Test case with steps created");
I've created some simple calls to the api method's. Here's a snippet:

Code: Select all

    TestSuite ts = null;
    TestCase  tc = null;
    TestProject project = null;
    TestPlan tp = null;
 
 // Create a Test Project      
        try {
                project = api.createTestProject(
                                "TestLink Java API Test", //testProjectName
                                "TJAT", //testProjectPrefix
                                "Testing Java API Intergration", //notes
                                true, //enableRequirements
                                true, //enableTestPriority
                                true, //enableAutomation
                                false, //enableInventory
                                true, //isActive
                                false); //isPublic
        } catch (TestLinkAPIException e) {
                e.printStackTrace( System.err );
                System.exit(-1);
        }        
        		
        // Create a Test Plan
        try {
          	tp = api.createTestPlan("TestLink API Test Plan", "TestLink Java API Project", "Testing TestLink JAVA API", true, false);        
        } catch (TestLinkAPIException e) {
                e.printStackTrace( System.err );
                System.exit(-1); 
        }        
        
        // Create Test Suite
        try {
        	TestProject testLinkProject = api.getTestProjectByName("TestLink Java API Project");
        	
        	ts = api.createTestSuite(testLinkProject.getId(), "TestLink TestSuite", "Testing TestLink JAVA API library integration", null, 1, true, ActionOnDuplicate.CREATE_NEW_VERSION);
        	System.out.println( "Created Test Suite: " + ts.getName() );
        } catch (TestLinkAPIException e) {
        	e.printStackTrace( System.err );
        	System.exit(1);
        }        
       
		// Create Test Case
        List<TestCaseStep> steps = new ArrayList<TestCaseStep>();
        TestCaseStep step = new TestCaseStep();
        step.setNumber(1);
        step.setExpectedResults("User name appeared in top menu.");
        step.setExecutionType(null);
        step.setActions("Go to login screen and enter user credentials.");
        steps.add(step);

        try {
        tc = api.createTestCase("TestLink TestCase", ts.getId(), project.getId(), "ValidUserLogin", "TestLink TestCase Summary", steps, null, null, null, new Integer(10), null, true, ActionOnDuplicate.GENERATE_NEW);
	    } catch (TestLinkAPIException e) {
	    	e.printStackTrace( System.err );
	    	System.exit(1);
	    }
	}
The problem I am encountering is that this appears to create the test case successfully, but the code throws an exception which prevents me from continuing to create additional test cases if needed. I've searched the forum for similar topics and the only one similar is from 2011 with no real concrete information on why this is or how to resolved (http://forum.testlink.org/viewtopic.php?f=10&t=4993).

Exception I am seeing is:
Exception in thread "main" br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException: Error creating test plan: Failed to parse server's response: Expected methodResponse element, got pre
at br.eti.kinoshita.testlinkjavaapi.TestCaseService.createTestCase(TestCaseService.java:128)
at br.eti.kinoshita.testlinkjavaapi.TestLinkAPI.createTestCase(TestLinkAPI.java:742)
at com.directv.TestLinkCheck.main(TestLinkCheck.java:140)
Caused by: org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse server's response: Expected methodResponse element, got pre
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:188)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
at org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
at org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:158)
at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:147)
at br.eti.kinoshita.testlinkjavaapi.BaseService.executeXmlRpcCall(BaseService.java:90)
at br.eti.kinoshita.testlinkjavaapi.TestCaseService.createTestCase(TestCaseService.java:119)
... 2 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 6; Expected methodResponse element, got pre
at org.apache.xmlrpc.parser.XmlRpcResponseParser.startElement(XmlRpcResponseParser.java:101)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:186)
... 11 more


If someone could provide me with some insight of what I may be doing wrong in the call, that would really help me understand.

Thank You in advance for your precious time.
fman
Member of TestLink Community
Posts: 3123
Joined: Tue Nov 15, 2005 7:19 am

Re: createTestCase() issues using JAVAAPI

Post by fman »

1. testlink version is always needed
2. in order to understand if issue is on java client (then fixing it is not in change of TestLink dev team) or in the php server side, it will be better if you
check with the PHP samples provided with TestLink if you can create test cases.
Try to contact author of javaapi
Have you follow advice present on testlinkjavaapi site?
=> This project is developed separately from TestLink. Issues should be reported here here.
dkwang
TestLink user
Posts: 2
Joined: Fri Dec 13, 2013 8:02 pm

Re: createTestCase() issues using JAVAAPI

Post by dkwang »

Thank fman for your time in responding and correcting my subject line.

1. I'm working with version 1.9.
2. I'll not quite familiar with PHP, but will look at the samples provided to get a better understanding.
3. I'll try to contact the author of the api and hopefully get a response.
4. I'll post whatever I find, as it may help others.
Post Reply