Created
July 18, 2012 21:14
-
-
Save kinow/3138950 to your computer and use it in GitHub Desktop.
TestLinkBUG5079_1.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* The MIT License | |
* | |
* Copyright (c) <2012> <Bruno P. Kinoshita> | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included in | |
* all copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
* THE SOFTWARE. | |
*/ | |
package br.eti.kinoshita.testlinkjavaapi; | |
import java.net.URL; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Random; | |
import br.eti.kinoshita.testlinkjavaapi.constants.ExecutionStatus; | |
import br.eti.kinoshita.testlinkjavaapi.model.Execution; | |
import br.eti.kinoshita.testlinkjavaapi.model.ReportTCResultResponse; | |
/** | |
* @author Bruno P. Kinoshita - http://www.kinoshita.eti.br | |
*/ | |
public class T { | |
public static void main(String[] args) throws Exception { | |
TestLinkAPI api = new TestLinkAPI(new URL( | |
"http://localhost/testlink-code/lib/api/xmlrpc.php"), | |
"6e255acae87a79178e5fac59bed9a000"); | |
Map<Integer, Integer> testCases = new HashMap<Integer, Integer>(); // id, | |
// externalId | |
// Ignore this block, it's only to populate the map with my existing tcs | |
{ | |
int i = 18; | |
int j = 2; | |
for (; i <= 38;) { | |
testCases.put(i, j); | |
i += 2; | |
j++; | |
} | |
} | |
for (int z = 0; z < 5; z++) { | |
System.out.println("-- Updating TC status --"); | |
for (Integer key : testCases.keySet()) { | |
System.out.println("-- TC " + key + " --"); | |
Execution exec = api.getLastExecutionResult(40, key, | |
testCases.get(key)); | |
System.out.println("latest exec: " + exec); | |
ReportTCResultResponse response = api.reportTCResult(key, | |
testCases.get(key), 40, getRandomExecutionStatus(), 2, | |
"b2", "Sample report " + System.nanoTime(), | |
Boolean.FALSE, "1", 1, "pl1", | |
getRandomCustomField("cf1"), // cf1 is the custom field | |
// name | |
Boolean.TRUE); | |
System.out.println("report TC result resp: " + response); | |
exec = api.getLastExecutionResult(40, key, testCases.get(key)); | |
System.out.println("latest exec: " + exec); | |
System.out.println("-- END --"); | |
} | |
} | |
} | |
static ExecutionStatus getRandomExecutionStatus() { | |
ExecutionStatus status = null; | |
int value = new Random().nextInt(3); | |
switch (value) { | |
case 0: | |
status = ExecutionStatus.PASSED; | |
break; | |
case 1: | |
status = ExecutionStatus.FAILED; | |
break; | |
default: | |
status = ExecutionStatus.BLOCKED; | |
break; | |
} | |
return status; | |
} | |
static Map<String, String> getRandomCustomField(String cfName) { | |
Map<String, String> cfs = new HashMap<String, String>(); | |
cfs.put(cfName, "Random CF value " + System.nanoTime()); | |
return cfs; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment