Author: jonesde
Date: Wed Mar 7 17:21:49 2007 New Revision: 515876 URL: http://svn.apache.org/viewvc?view=rev&rev=515876 Log: Appled patches from Joe Eckard for the ServiceTest implementation, and example to use it; Jira #OFBIZ-791; I made a small change to the patch to show the key and value for the error message Map Modified: ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml ofbiz/trunk/framework/example/servicedef/services.xml ofbiz/trunk/framework/example/testdef/tests.xml ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java Modified: ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml?view=diff&rev=515876&r1=515875&r2=515876 ============================================================================== --- ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml (original) +++ ofbiz/trunk/framework/example/script/org/ofbiz/example/example/ExampleServices.xml Wed Mar 7 17:21:49 2007 @@ -89,4 +89,38 @@ <entity-one entity-name="ExampleItem" value-name="lookedUpValue"/> <remove-value value-name="lookedUpValue"/> </simple-method> + + <!-- Example ServiceTest Service --> + <simple-method method-name="testCreateExampleService" short-description="test the create example service" login-required="false"> + + <set field="createExampleMap.exampleTypeId" value="CONTRIVED"/> + <set field="createExampleMap.exampleName" value="Test Example"/> + <set field="createExampleMap.statusId" value="EXST_IN_DESIGN"/> + + <entity-one entity-name="UserLogin" value-name="createExampleMap.userLogin" auto-field-map="false"> + <field-map field-name="userLoginId" value="system"/> + </entity-one> + + <call-service service-name="createExample" in-map-name="createExampleMap"> + <result-to-field result-name="exampleId" field-name="lookupMap.exampleId"/> + </call-service> + <check-errors/> + + <entity-one entity-name="Example" value-name="example" auto-field-map="false"> + <field-map field-name="exampleId" value="lookupMap.exampleId"/> + </entity-one> + + <assert> + <not><if-empty field-name="example"/></not> + </assert> + <check-errors/> + + <assert> + <if-compare field-name="example.exampleTypeId" value="createExampleMap.exampleTypeId" operator="equals"/> + <if-compare field-name="example.exampleName" value="createExampleMap.exampleName" operator="equals"/> + <if-compare field-name="example.statusId" value="createExampleMap.statusId" operator="equals"/> + </assert> + <check-errors/> + </simple-method> + </simple-methods> Modified: ofbiz/trunk/framework/example/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/servicedef/services.xml?view=diff&rev=515876&r1=515875&r2=515876 ============================================================================== --- ofbiz/trunk/framework/example/servicedef/services.xml (original) +++ ofbiz/trunk/framework/example/servicedef/services.xml Wed Mar 7 17:21:49 2007 @@ -131,4 +131,11 @@ location="org/ofbiz/example/ExamplePermissionServices.xml" invoke="exampleGenericPermission"> <implements service="permissionInterface"/> </service> + + <!-- Example ServiceTest Service --> + <service name="testCreateExampleService" engine="simple" + location="org/ofbiz/example/example/ExampleServices.xml" invoke="testCreateExampleService"> + <implements service="testServiceInterface"/> + </service> + </services> Modified: ofbiz/trunk/framework/example/testdef/tests.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/testdef/tests.xml?view=diff&rev=515876&r1=515875&r2=515876 ============================================================================== --- ofbiz/trunk/framework/example/testdef/tests.xml (original) +++ ofbiz/trunk/framework/example/testdef/tests.xml Wed Mar 7 17:21:49 2007 @@ -25,4 +25,9 @@ <test-case case-name="userLoginEntityXmlAssert"> <entity-xml-assert entity-xml-url="component://example/testdef/assertdata/TestUserLoginData.xml"/> </test-case> + + <test-case case-name="testCreateExampleService"> + <service-test service-name="testCreateExampleService"/> + </test-case> + </test-suite> Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java?view=diff&rev=515876&r1=515875&r2=515876 ============================================================================== --- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java (original) +++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java Wed Mar 7 17:21:49 2007 @@ -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 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); } } |
Free forum by Nabble | Edit this page |