diff --git a/pom.xml b/pom.xml index 89528532..a25b3c85 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,15 @@ developer + + mario-fuentes + mario@gnome.cl + Mario Fuentes + -4 + + developer + + http://sourceforge.net/projects/testlinkjavaapi diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/BaseService.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/BaseService.java index c10e4f0b..623fde7f 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/BaseService.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/BaseService.java @@ -103,7 +103,7 @@ protected void checkResponseError( Object response ) { if ( response instanceof Object[] ) // may be an array of errors (IXError) { - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); for (int i = 0; i < responseArray.length; i++) { diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/BuildService.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/BuildService.java index 7b3e059a..b694971d 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/BuildService.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/BuildService.java @@ -51,7 +51,7 @@ protected Build createBuild(Integer testPlanId, String buildName, String buildNo Map executionData = Util.getBuildMap(build); Object response = this.executeXmlRpcCall( TestLinkMethods.createBuild.toString(), executionData); - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); Map responseMap = (Map)responseArray[0]; id = Util.getInteger(responseMap, TestLinkResponseParams.id.toString()); @@ -84,7 +84,7 @@ protected Build[] getBuildsForTestPlan( Integer testPlanId ) TestLinkMethods.getBuildsForTestPlan.toString(), executionData); if ( response instanceof Object[]) { - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); builds = new Build[ responseArray.length ]; for (int i = 0; i < responseArray.length; i++) { diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/MiscService.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/MiscService.java index b5d21f96..bdecfc20 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/MiscService.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/MiscService.java @@ -333,7 +333,7 @@ protected Execution getLastExecutionResult( executionData.put( TestLinkParams.testCaseExternalId.toString(), testCaseExternalId ); Object response = this.executeXmlRpcCall( TestLinkMethods.getLastExecutionResult.toString(), executionData); - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); Map responseMap = (Map)responseArray[0]; if ( responseMap instanceof Map && responseMap.size() > 0 ) { diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestCaseService.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestCaseService.java index 392ff687..e15af36f 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestCaseService.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestCaseService.java @@ -20,6 +20,7 @@ import br.eti.kinoshita.testlinkjavaapi.model.ResponseDetails; import br.eti.kinoshita.testlinkjavaapi.model.TestCase; import br.eti.kinoshita.testlinkjavaapi.model.TestCaseStep; +import br.eti.kinoshita.testlinkjavaapi.model.TestCaseStepAction; import br.eti.kinoshita.testlinkjavaapi.model.TestImportance; import br.eti.kinoshita.testlinkjavaapi.model.TestLinkMethods; import br.eti.kinoshita.testlinkjavaapi.model.TestLinkParams; @@ -121,7 +122,7 @@ protected TestCase createTestCase( Map executionData = Util.getTestCaseMap(testCase); Object response = this.executeXmlRpcCall( TestLinkMethods.createTestCase.toString(), executionData); - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); Map responseMap = (Map)responseArray[0]; id = Util.getInteger(responseMap, TestLinkResponseParams.id.toString()); @@ -135,6 +136,74 @@ protected TestCase createTestCase( return testCase; } + + @SuppressWarnings("unchecked") + public Map createTestCaseSteps( + String testCaseExternalId, + Integer version, + TestCaseStepAction action, + List testCaseSteps + ) + throws TestLinkAPIException + { + Map responseMap = null; + + try + { + Map executionData = new HashMap(); + + executionData.put(TestLinkParams.testCaseExternalId.toString(), testCaseExternalId); + executionData.put(TestLinkParams.version.toString(), version); + executionData.put(TestLinkParams.action.toString(), action.toString()); + + List> steps = Util.getTestCaseStepsMap(testCaseSteps); + executionData.put(TestLinkParams.steps.toString(), steps); + + Object response = this.executeXmlRpcCall( + TestLinkMethods.createTestCaseSteps.toString(), executionData); + responseMap = (Map) response; + } + catch ( XmlRpcException xmlrpcex ) + { + throw new TestLinkAPIException( + "Error adding steps to test case: " + xmlrpcex.getMessage(), xmlrpcex); + } + + return responseMap; + } + + @SuppressWarnings("unchecked") + public Map deleteTestCaseSteps( + String testCaseExternalId, + Integer version, + List testCaseSteps + ) + throws TestLinkAPIException + { + Map responseMap = null; + + try + { + Map executionData = new HashMap(); + + executionData.put(TestLinkParams.testCaseExternalId.toString(), testCaseExternalId); + executionData.put(TestLinkParams.version.toString(), version); + + List steps = Util.getTestCaseStepsIdList(testCaseSteps); + executionData.put(TestLinkParams.steps.toString(), steps); + + Object response = this.executeXmlRpcCall( + TestLinkMethods.deleteTestCaseSteps.toString(), executionData); + responseMap = (Map) response; + } + catch ( XmlRpcException xmlrpcex ) + { + throw new TestLinkAPIException( + "Error deleting steps from test case: " + xmlrpcex.getMessage(), xmlrpcex); + } + + return responseMap; + } @SuppressWarnings("unchecked") protected Integer addTestCaseToTestPlan( @@ -201,7 +270,7 @@ protected TestCase[] getTestCasesForTestSuite( executionData.put(TestLinkParams.details.toString(), details); Object response = this.executeXmlRpcCall( TestLinkMethods.getTestCasesForTestSuite.toString(), executionData); - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); testCases = new TestCase[ responseArray.length ]; @@ -312,7 +381,6 @@ else if(entry.getValue() instanceof Map) return testCases; } - /** * * @param testCaseId @@ -339,7 +407,7 @@ protected TestCase getTestCase(Integer testCaseId, Object response = this.executeXmlRpcCall( TestLinkMethods.getTestCase.toString(), executionData ); - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); Map responseMap = (Map)responseArray[0]; testCase = Util.getTestCase( responseMap ); @@ -352,6 +420,42 @@ protected TestCase getTestCase(Integer testCaseId, return testCase; } + /** + * + * @param fullTestCaseExternalId Full external id: prefix-externalId + * @param version + * @return + * @throws TestLinkAPIException + */ + @SuppressWarnings("unchecked") + protected TestCase getTestCaseByExternalId( + String fullTestCaseExternalId, + Integer version) + throws TestLinkAPIException + { + TestCase testCase = null; + + try + { + Map executionData = new HashMap(); + + executionData.put(TestLinkParams.testCaseExternalId.toString(), fullTestCaseExternalId); + executionData.put(TestLinkParams.version.toString(), version); + + Object response = this.executeXmlRpcCall( TestLinkMethods.getTestCase.toString(), executionData ); + + Object[] responseArray = Util.castToArray(response); + Map responseMap = (Map)responseArray[0]; + + testCase = Util.getTestCase( responseMap ); + } + catch ( XmlRpcException xmlrpcex ) + { + throw new TestLinkAPIException( "Error getting test case info : " + xmlrpcex.getMessage(), xmlrpcex ); + } + + return testCase; + } /** * @@ -385,7 +489,7 @@ protected Integer getTestCaseIDByName( Object response = this.executeXmlRpcCall( TestLinkMethods.getTestCaseIDByName.toString(), executionData); - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); Map responseMap = (Map)responseArray[0]; testCaseID = Util.getInteger(responseMap, TestLinkResponseParams.id.toString()); @@ -636,7 +740,7 @@ protected ReportTCResultResponse reportTCResult( // the error verification routine is called inside super.executeXml... if ( response instanceof Object[] ) { - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); Map responseMap = (Map)responseArray[0]; reportTCResultResponse = Util.getReportTCResultResponse( responseMap ); diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestLinkAPI.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestLinkAPI.java index 0f21bbd5..aef95a2d 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestLinkAPI.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestLinkAPI.java @@ -51,6 +51,7 @@ import br.eti.kinoshita.testlinkjavaapi.model.ResponseDetails; import br.eti.kinoshita.testlinkjavaapi.model.TestCase; import br.eti.kinoshita.testlinkjavaapi.model.TestCaseStep; +import br.eti.kinoshita.testlinkjavaapi.model.TestCaseStepAction; import br.eti.kinoshita.testlinkjavaapi.model.TestImportance; import br.eti.kinoshita.testlinkjavaapi.model.TestPlan; import br.eti.kinoshita.testlinkjavaapi.model.TestProject; @@ -862,6 +863,133 @@ public TestCase createTestCase( ); } + /** + * Create, Update or Push a list of TestCaseSteps in a Test Case. + * + * @param testCaseExternalId + * @param version + * @param testCaseSteps + * @return a Map with results. + * @throws TestLinkAPIException + */ + public Map createTestCaseSteps( + String testCaseExternalId, + Integer version, + TestCaseStepAction action, + List testCaseSteps + ) + throws TestLinkAPIException + { + return this.testCaseService.createTestCaseSteps( + testCaseExternalId, + version, + TestCaseStepAction.Create, + testCaseSteps + ); + } + + /** + * Add a list of TestCaseSteps in a Test Case. + * A convenient method to add steps, internally call to the + * {@link #createTestCaseSteps(Integer, Integer, TestCaseStepAction, List)} method with 'Create' action. + * + * @param testCaseExternalId + * @param version + * @param testCaseSteps + * @return a Map with results. + * @throws TestLinkAPIException + */ + public Map addTestCaseSteps( + String testCaseExternalId, + Integer version, + List testCaseSteps + ) + throws TestLinkAPIException + { + return createTestCaseSteps( + testCaseExternalId, + version, + TestCaseStepAction.Create, + testCaseSteps + ); + } + + /** + * Update (override) a list of TestCaseSteps in a Test Case. + * A convenient method to update steps, internally call to the + * {@link #createTestCaseSteps(Integer, Integer, TestCaseStepAction, List)} method with 'Update' action. + * + * @param testCaseExternalId + * @param version + * @param testCaseSteps + * @return a Map with results. + * @throws TestLinkAPIException + */ + public Map updateTestCaseSteps( + String testCaseExternalId, + Integer version, + List testCaseSteps + ) + throws TestLinkAPIException + { + return createTestCaseSteps( + testCaseExternalId, + version, + TestCaseStepAction.Update, + testCaseSteps + ); + } + + /** + * Push (insert and move down previous steps) a list of + * TestCaseSteps in a TestCase. + * A convenient method to push steps, internally call to the + * {@link #createTestCaseSteps(Integer, Integer, TestCaseStepAction, List)} method with 'Push' action. + * + * @param testCaseExternalId + * @param version + * @param testCaseSteps + * @return a Map with results. + * @throws TestLinkAPIException + */ + public Map pushTestCaseSteps( + String testCaseExternalId, + Integer version, + List testCaseSteps + ) + throws TestLinkAPIException + { + return createTestCaseSteps( + testCaseExternalId, + version, + TestCaseStepAction.Push, + testCaseSteps + ); + } + + /** + * Delete a list if TestCaseSteps from a Test Case. + * + * @param testCaseExternalId + * @param version + * @param testCaseSteps + * @return a Map with results. + * @throws TestLinkAPIException + */ + public Map deleteTestCaseSteps( + String testCaseExternalId, + Integer version, + List testCaseSteps + ) + throws TestLinkAPIException + { + return this.testCaseService.deleteTestCaseSteps( + testCaseExternalId, + version, + testCaseSteps + ); + } + /** * Adds a Test Case to a Test Plan. * @param testProjectId @@ -933,6 +1061,24 @@ public TestCase getTestCase( return this.testCaseService.getTestCase(testCaseId, testCaseExternalId, version); } + /** + * Get a Test Case using the full external id, composed by the prefix and + * the external id: prefix-externalId + * + * @param fullTestCaseExternalId Full external id: prefix-externalId + * @param version + * @return Test Case. + * @throws TestLinkAPIException + */ + public TestCase getTestCaseByExternalId( + String fullTestCaseExternalId, + Integer version + ) + throws TestLinkAPIException + { + return this.testCaseService.getTestCaseByExternalId(fullTestCaseExternalId, version); + } + /** * Retrieves Test Cases for Test Plans. * diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestProjectService.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestProjectService.java index 3ed07ce8..069981b0 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestProjectService.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestProjectService.java @@ -97,7 +97,7 @@ protected TestProject createTestProject( Map executionData = Util.getTestProjectMap(testProject); Object response = this.executeXmlRpcCall( TestLinkMethods.createTestProject.toString(), executionData); - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); Map responseMap = (Map)responseArray[0]; id = Util.getInteger(responseMap, TestLinkResponseParams.id.toString()); @@ -124,7 +124,7 @@ protected TestProject getTestProjectByName(String projectName) executionData.put(TestLinkParams.testProjectName.toString(), projectName); Object response = this.executeXmlRpcCall( TestLinkMethods.getTestProjectByName.toString(), executionData); - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); Map responseMap = (Map)responseArray[0]; testProject = Util.getTestProject( responseMap ); } @@ -153,7 +153,7 @@ protected TestProject[] getProjects() Map executionData = new HashMap(); Object response = this.executeXmlRpcCall( TestLinkMethods.getProjects.toString(), executionData); - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); projects = new TestProject[responseArray.length]; for (int i = 0; i < responseArray.length; i++) { @@ -191,7 +191,7 @@ protected TestPlan[] getProjectTestPlans(Integer projectId) executionData.put(TestLinkParams.testProjectId.toString(), projectId); Object response = this.executeXmlRpcCall( TestLinkMethods.getProjectTestPlans.toString(), executionData); - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); testPlans = new TestPlan[responseArray.length]; for (int i = 0; i < responseArray.length; i++) { diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestSuiteService.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestSuiteService.java index cc20e44b..b9400c0b 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestSuiteService.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestSuiteService.java @@ -101,7 +101,7 @@ protected TestSuite createTestSuite( Map executionData = Util.getTestSuiteMap(testSuite); Object response = this.executeXmlRpcCall( TestLinkMethods.createTestSuite.toString(), executionData); - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); Map responseMap = (Map)responseArray[0]; id = Util.getInteger(responseMap, TestLinkResponseParams.id.toString()); @@ -134,7 +134,7 @@ protected TestSuite[] getTestSuiteByID(List testSuiteIds) TestLinkMethods.getTestSuiteByID.toString(), executionData); if ( response instanceof Object[] ) { - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); testSuites = new TestSuite[responseArray.length]; for (int i = 0; i < responseArray.length; i++) @@ -230,7 +230,7 @@ protected TestSuite[] getTestSuitesForTestPlan(Integer testPlanId) Object response = this.executeXmlRpcCall( TestLinkMethods.getTestSuitesForTestPlan.toString(), executionData ); - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); testSuites = new TestSuite[ responseArray.length ]; for (int i = 0; i < responseArray.length; i++) @@ -321,7 +321,7 @@ protected TestSuite[] getFirstLevelTestSuitesForTestProject(Integer testProjectI executionData.put(TestLinkParams.testProjectId.toString(), testProjectId); Object response = this.executeXmlRpcCall( TestLinkMethods.getFirstLevelTestSuitesForTestProject.toString(), executionData ); - Object[] responseArray = (Object[])response; + Object[] responseArray = Util.castToArray(response); testSuites = new TestSuite[ responseArray.length ]; for (int i = 0; i < responseArray.length; i++) diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/ExecutionType.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/ExecutionType.java index 75b30207..0ba5ac85 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/ExecutionType.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/ExecutionType.java @@ -38,6 +38,11 @@ else if ( integer == 2 ) return null; } + public Integer getValue() + { + return value; + } + /* (non-Javadoc) * @see java.lang.Enum#toString() */ diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/TestCaseStepAction.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/TestCaseStepAction.java new file mode 100644 index 00000000..5c65b858 --- /dev/null +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/TestCaseStepAction.java @@ -0,0 +1,47 @@ +/* + * The MIT License + * + * Copyright (c) <2011> + * + * 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.model; +/** + * @author Mario Fuentes - http://www.rhiscom.com + * @since 1.9.3-2 + */ +public enum TestCaseStepAction +{ + Create("create"), + Update("update"), + Push("push") + ; + + private String value; + + TestCaseStepAction(String value) + { + this.value = value; + } + + public String toString() + { + return this.value; + } +} diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/TestLinkMethods.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/TestLinkMethods.java index bfe13687..78dbf7ca 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/TestLinkMethods.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/TestLinkMethods.java @@ -39,6 +39,8 @@ public enum TestLinkMethods getProjectTestPlans("tl.getProjectTestPlans"), getTestPlanPlatforms("tl.getTestPlanPlatforms"), createTestCase("tl.createTestCase"), + createTestCaseSteps("tl.createTestCaseSteps"), + deleteTestCaseSteps("tl.deleteTestCaseSteps"), createTestSuite("tl.createTestSuite"), addTestCaseToTestPlan("tl.addTestCaseToTestPlan"), doesUserExist("tl.doesUserExist"), diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/TestLinkParams.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/TestLinkParams.java index c18d634d..6647e33f 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/TestLinkParams.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/model/TestLinkParams.java @@ -41,6 +41,7 @@ public enum TestLinkParams { actionOnDuplicatedName("actionOnDuplicatedName"), actions("actions"), + action("action"), active("active"), assignedTo("assignedto"), authorLogin("authorlogin"), @@ -64,7 +65,8 @@ public enum TestLinkParams executeStatus("executestatus"), execution("execution"), executionId("executionid"), - executionType("executiontype"), + executionType("executiontype"), + stepExecutionType("execution_type"), expectedResults("expected_results"), fileName("filename"), fileType("filetype"), diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/util/Util.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/util/Util.java index 0636e899..f051fd89 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/util/Util.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/util/Util.java @@ -69,6 +69,7 @@ */ public class Util { + public static final Object[] EMPTY_ARRAY = new Object[0]; private Util(){} @@ -293,31 +294,81 @@ public static final Map getTestCaseMap(TestCase testCase) executionData.put(TestLinkParams.authorLogin.toString(), testCase.getAuthorLogin()); executionData.put(TestLinkParams.summary.toString(), testCase.getSummary()); + List> steps = getTestCaseStepsMap(testCase.getSteps()); + executionData.put(TestLinkParams.steps.toString(), steps); + + executionData.put(TestLinkParams.preconditions.toString(), testCase.getPreconditions()); + executionData.put(TestLinkParams.importance.toString(), Util.getStringValueOrNull(testCase.getTestImportance())); + executionData.put(TestLinkParams.execution.toString(), Util.getStringValueOrNull( testCase.getExecutionType())); + executionData.put(TestLinkParams.order.toString(), testCase.getOrder()); + executionData.put(TestLinkParams.internalId.toString(), testCase.getInternalId()); + executionData.put(TestLinkParams.checkDuplicatedName.toString(), testCase.getCheckDuplicatedName()); + executionData.put(TestLinkParams.actionOnDuplicatedName.toString(), testCase.getActionOnDuplicatedName()); + + return executionData; + } + + /** + * + * @param testCaseSteps + * @return A list whit one Map for each TestCaseStep + * @since 1.9.4-1 + */ + public static final List> getTestCaseStepsMap(List testCaseSteps) + { List> steps = new ArrayList>(); - List testCaseSteps = testCase.getSteps(); + if ( testCaseSteps != null && testCaseSteps.size() > 0 ) { + /* + for(TestCaseStep step : testCaseSteps) + steps.add(getTestCaseStepMap(step)); + */ + + // Why uses an iterator over a foreach? for ( Iterator iterator = testCaseSteps.iterator(); iterator.hasNext(); ) { TestCaseStep testCaseStep = iterator.next(); - Map testCaseStepMap = getTestCaseStepMap(testCaseStep); + Map testCaseStepMap = getTestCaseStepMap(testCaseStep, true); steps.add( testCaseStepMap ); } } - executionData.put(TestLinkParams.steps.toString(), steps); - executionData.put(TestLinkParams.preconditions.toString(), testCase.getPreconditions()); - executionData.put(TestLinkParams.importance.toString(), Util.getStringValueOrNull(testCase.getTestImportance())); - executionData.put(TestLinkParams.execution.toString(), Util.getStringValueOrNull( testCase.getExecutionType())); - executionData.put(TestLinkParams.order.toString(), testCase.getOrder()); - executionData.put(TestLinkParams.internalId.toString(), testCase.getInternalId()); - executionData.put(TestLinkParams.checkDuplicatedName.toString(), testCase.getCheckDuplicatedName()); - executionData.put(TestLinkParams.actionOnDuplicatedName.toString(), testCase.getActionOnDuplicatedName()); - - return executionData; + return steps; + } + + /** + * + * @param testCaseSteps + * @return A list with the step's id + * @since 1.9.4-1 + */ + public static final List getTestCaseStepsIdList(List testCaseSteps) + { + List steps = new ArrayList(); + + if ( testCaseSteps != null && testCaseSteps.size() > 0 ) + { + /* + for (TestCaseStep step : testCaseSteps) + steps.add(step.getId()); + */ + + // Why uses an iterator over a foreach? + for ( + Iterator iterator = testCaseSteps.iterator(); + iterator.hasNext(); + ) + { + TestCaseStep testCaseStep = iterator.next(); + steps.add( testCaseStep.getNumber() ); + } + } + + return steps; } /** @@ -353,17 +404,31 @@ public static TestCaseStep getTestCaseStep( Map map ) } /** + * * @param testCaseStep * @return Map of Test Case Step. */ public static final Map getTestCaseStepMap(TestCaseStep testCaseStep) + { + return getTestCaseStepMap(testCaseStep, false); + } + + /** + * @param testCaseStep + * @param internal the API uses different names for the the same parameter in different methods. + * @return Map of Test Case Step. + */ + public static final Map getTestCaseStepMap(TestCaseStep testCaseStep, boolean internal) { Map executionData = new HashMap(); executionData.put(TestLinkParams.stepNumber.toString(), testCaseStep.getNumber()); executionData.put(TestLinkParams.actions.toString(), testCaseStep.getActions()); executionData.put(TestLinkParams.expectedResults.toString(), testCaseStep.getExpectedResults()); + if (internal) + executionData.put(TestLinkParams.stepExecutionType.toString(), testCaseStep.getExecutionType().getValue()); + else + executionData.put(TestLinkParams.executionType.toString(), testCaseStep.getExecutionType()); - executionData.put(TestLinkParams.executionType.toString(), testCaseStep.getExecutionType()); return executionData; } @@ -492,13 +557,30 @@ public static Object[] getArray( Map map, String key ) if ( map != null && map.size() > 0 ) { Object o = map.get(key); - if ( o != null ) - { - array = (Object[])o; - } + array = castToArray(o); } return array; } + + /** + * + * @param object + * @return Array of objects + */ + public static Object[] castToArray(Object object) + { + Object[] array = null; + + if ( object != null ) + { + if (object instanceof String) + array = EMPTY_ARRAY; + else + array = (Object[])object; + } + + return array; + } /** * @param build diff --git a/src/test/java/br/eti/kinoshita/testlinkjavaapi/testcase/TestGetTestCasesForTestSuiteEmptyResult.java b/src/test/java/br/eti/kinoshita/testlinkjavaapi/testcase/TestGetTestCasesForTestSuiteEmptyResult.java new file mode 100644 index 00000000..d495c1bd --- /dev/null +++ b/src/test/java/br/eti/kinoshita/testlinkjavaapi/testcase/TestGetTestCasesForTestSuiteEmptyResult.java @@ -0,0 +1,75 @@ +/* + * The MIT License + * + * Copyright (c) <2010> + * + * 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.testcase; + +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import br.eti.kinoshita.testlinkjavaapi.BaseTest; +import br.eti.kinoshita.testlinkjavaapi.TestLinkAPIException; +import br.eti.kinoshita.testlinkjavaapi.model.TestCase; + +/** + * @author Bruno P. Kinoshita - http://www.kinoshita.eti.br + * @author Mario Fiuentes - http://www.rhiscom.com + * @since + */ +public class TestGetTestCasesForTestSuiteEmptyResult +extends BaseTest +{ + + @DataProvider(name="testCaseData") + public Object[][] createData() + { + return new Object[][] + { + { + 2 + } + }; + } + + @Test(dataProvider="testCaseData") + public void testGetTestCasesForTestSuiteEmptyResult(Integer testSuiteId) + { + this.loadXMLRPCMockData("tl.getTestCasesForTestSuiteEmptyResult.xml"); + + TestCase[] testCases = null; + + try + { + testCases = this.api.getTestCasesForTestSuite(testSuiteId, true, "full"); + } + catch (TestLinkAPIException e) + { + Assert.fail(e.getMessage(), e); + } + + Assert.assertNotNull( testCases ); + + Assert.assertTrue( testCases.length == 0 ); + } + +} diff --git a/src/test/java/br/eti/kinoshita/testlinkjavaapi/testcasesteps/TestAddTestCaseSteps.java b/src/test/java/br/eti/kinoshita/testlinkjavaapi/testcasesteps/TestAddTestCaseSteps.java new file mode 100644 index 00000000..09540135 --- /dev/null +++ b/src/test/java/br/eti/kinoshita/testlinkjavaapi/testcasesteps/TestAddTestCaseSteps.java @@ -0,0 +1,100 @@ +/* + * The MIT License + * + * Copyright (c) <2011> + * + * 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.testcasesteps; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import br.eti.kinoshita.testlinkjavaapi.BaseTest; +import br.eti.kinoshita.testlinkjavaapi.TestLinkAPIException; +import br.eti.kinoshita.testlinkjavaapi.model.ExecutionType; +import br.eti.kinoshita.testlinkjavaapi.model.TestCaseStep; + +/** + * + * @author Mario Fuentes - http://www.rhiscom.com + * @since 1.9.3-2 + */ +public class TestAddTestCaseSteps extends BaseTest { + @DataProvider(name="testCaseStepData") + public Object[][] createData() + { + List steps = new ArrayList(); + steps.add(new TestCaseStep( + 1, // ID + 1, // Version + 1, // Step number + "", // Actions + "", // Expected Results + true, // Active? + ExecutionType.AUTOMATED // Execution type + )); + steps.add(new TestCaseStep( + 1, // ID + 1, // Version + 2, // Step number + "", // Actions + "", // Expected Results + true, // Active? + ExecutionType.AUTOMATED // Execution type + )); + + return new Object[][] + { + { + "1", + steps + } + }; + } + + @Test(dataProvider="testCaseStepData") + public void testCreateTestCaseSteps( + String testCaseExternalId, + List steps + ) + { + this.loadXMLRPCMockData("tl.createTestCaseSteps.xml"); + + Map result = null; + + try + { + result = api.addTestCaseSteps( + testCaseExternalId, + 1, + steps); + } catch (TestLinkAPIException e) + { + Assert.fail(e.getMessage(), e); + } + + Assert.assertNotNull( result ); + } +} diff --git a/src/test/java/br/eti/kinoshita/testlinkjavaapi/testcasesteps/TestDeleteTestCaseSteps.java b/src/test/java/br/eti/kinoshita/testlinkjavaapi/testcasesteps/TestDeleteTestCaseSteps.java new file mode 100644 index 00000000..8e272e7e --- /dev/null +++ b/src/test/java/br/eti/kinoshita/testlinkjavaapi/testcasesteps/TestDeleteTestCaseSteps.java @@ -0,0 +1,100 @@ +/* + * The MIT License + * + * Copyright (c) <2011> + * + * 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.testcasesteps; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import br.eti.kinoshita.testlinkjavaapi.BaseTest; +import br.eti.kinoshita.testlinkjavaapi.TestLinkAPIException; +import br.eti.kinoshita.testlinkjavaapi.model.ExecutionType; +import br.eti.kinoshita.testlinkjavaapi.model.TestCaseStep; + +/** + * + * @author Mario Fuentes - http://www.rhiscom.com + * @since 1.9.3-2 + */ +public class TestDeleteTestCaseSteps extends BaseTest { + @DataProvider(name="testCaseStepData") + public Object[][] createData() + { + List steps = new ArrayList(); + steps.add(new TestCaseStep( + 1, // ID + 1, // Version + 1, // Step number + "", // Actions + "", // Expected Results + true, // Active? + ExecutionType.AUTOMATED // Execution type + )); + steps.add(new TestCaseStep( + 1, // ID + 1, // Version + 2, // Step number + "", // Actions + "", // Expected Results + true, // Active? + ExecutionType.AUTOMATED // Execution type + )); + + return new Object[][] + { + { + "1", + steps + } + }; + } + + @Test(dataProvider="testCaseStepData") + public void testCreateTestCaseSteps( + String testCaseExternalId, + List steps + ) + { + this.loadXMLRPCMockData("tl.createTestCaseSteps.xml"); + + Map result = null; + + try + { + result = api.deleteTestCaseSteps( + testCaseExternalId, + 1, + steps); + } catch (TestLinkAPIException e) + { + Assert.fail(e.getMessage(), e); + } + + Assert.assertNotNull( result ); + } +} diff --git a/src/test/resources/br/eti/kinoshita/testlinkjavaapi/testdata/tl.createTestCaseSteps.xml b/src/test/resources/br/eti/kinoshita/testlinkjavaapi/testdata/tl.createTestCaseSteps.xml new file mode 100644 index 00000000..55a8c216 --- /dev/null +++ b/src/test/resources/br/eti/kinoshita/testlinkjavaapi/testdata/tl.createTestCaseSteps.xml @@ -0,0 +1,28 @@ + + + + + + + testcaseid1 + item + versionexists + stepSet + + stepNumberIDSet + + stepID + + 0 + 1 + + + 0 + 2 + + + + + + + diff --git a/src/test/resources/br/eti/kinoshita/testlinkjavaapi/testdata/tl.deleteTestCaseSteps.xml b/src/test/resources/br/eti/kinoshita/testlinkjavaapi/testdata/tl.deleteTestCaseSteps.xml new file mode 100644 index 00000000..3642aed3 --- /dev/null +++ b/src/test/resources/br/eti/kinoshita/testlinkjavaapi/testdata/tl.deleteTestCaseSteps.xml @@ -0,0 +1,32 @@ + + + + + + + testcaseid1 + item + versionexists + stepSet + 1 + id2 + step_number1 + actionsaction1 + expected_resultsresult1 + active1 + execution_type2 + + 2 + id3 + step_number2 + actionsaction2 + expected_resultsresult2 + active1 + execution_type2 + + + + + + + diff --git a/src/test/resources/br/eti/kinoshita/testlinkjavaapi/testdata/tl.getTestCasesForTestSuiteEmptyResult.xml b/src/test/resources/br/eti/kinoshita/testlinkjavaapi/testdata/tl.getTestCasesForTestSuiteEmptyResult.xml new file mode 100644 index 00000000..d39b0ec1 --- /dev/null +++ b/src/test/resources/br/eti/kinoshita/testlinkjavaapi/testdata/tl.getTestCasesForTestSuiteEmptyResult.xml @@ -0,0 +1,11 @@ + + + + + + + + + + +