diff --git a/framework/example/script/org/ofbiz/example/example/ExampleServices.xml b/framework/example/script/org/ofbiz/example/example/ExampleServices.xml index 28b13089bc..b26fa6bf3b 100644 --- a/framework/example/script/org/ofbiz/example/example/ExampleServices.xml +++ b/framework/example/script/org/ofbiz/example/example/ExampleServices.xml @@ -89,4 +89,38 @@ under the License. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/framework/example/servicedef/services.xml b/framework/example/servicedef/services.xml index d4a4564970..7bbcdeb635 100644 --- a/framework/example/servicedef/services.xml +++ b/framework/example/servicedef/services.xml @@ -131,4 +131,11 @@ under the License. location="org/ofbiz/example/ExamplePermissionServices.xml" invoke="exampleGenericPermission"> + + + + + + diff --git a/framework/example/testdef/tests.xml b/framework/example/testdef/tests.xml index 595bc8af0a..7c280c5a40 100644 --- a/framework/example/testdef/tests.xml +++ b/framework/example/testdef/tests.xml @@ -25,4 +25,9 @@ under the License. + + + + + diff --git a/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java b/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java index 655c458a29..638d5b801d 100644 --- a/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java +++ b/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -19,13 +19,24 @@ package org.ofbiz.testtools; import junit.framework.TestResult; +import junit.framework.AssertionFailedError; import org.w3c.dom.Element; +import org.ofbiz.service.LocalDispatcher; +import org.ofbiz.service.GenericServiceException; +import org.ofbiz.service.ServiceUtil; +import org.ofbiz.service.ModelService; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilValidate; + +import java.util.Map; +import java.util.List; +import java.util.Iterator; public class ServiceTest extends TestCaseBase { public static final String module = ServiceTest.class.getName(); - + protected String serviceName; /** @@ -41,7 +52,44 @@ public class ServiceTest extends TestCaseBase { } public void run(TestResult result) { - // TODO Auto-generated method stub - + + result.startTest(this); + + LocalDispatcher dispatcher = modelTestSuite.getDispatcher(); + + try { + + Map serviceResult = dispatcher.runSync(serviceName, UtilMisc.toMap("testCase", this)); + + // do something with the errorMessage + String errorMessage = (String) serviceResult.get(ModelService.ERROR_MESSAGE); + if (UtilValidate.isNotEmpty(errorMessage)) { + result.addFailure(this, new AssertionFailedError(errorMessage)); + } + + // do something with the errorMessageList + List errorMessageList = (List) serviceResult.get(ModelService.ERROR_MESSAGE_LIST); + if (UtilValidate.isNotEmpty(errorMessageList)) { + Iterator i = errorMessageList.iterator(); + while (i.hasNext()) { + result.addFailure(this, new AssertionFailedError((String) i.next())); + } + } + + // do something with the errorMessageMap + Map errorMessageMap = (Map) serviceResult.get(ModelService.ERROR_MESSAGE_MAP); + if (!UtilValidate.isEmpty(errorMessageMap)) { + Iterator i = errorMessageMap.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry entry = (Map.Entry) i.next(); + result.addFailure(this, new AssertionFailedError(entry.getKey() + ": " + entry.getValue())); + } + } + + } catch (GenericServiceException e) { + result.addError(this, e); + } + + result.endTest(this); } }