Author: nmalin
Date: Wed Oct 8 12:17:55 2014
New Revision: 1630079
URL: http://svn.apache.org/r1630079
Log:
Add junit test to control entity-auto on create, update and delete to ensure no
regression when the entity-auto engine will be improve (like OFBIZ-5800)
Added:
ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEntityAutoTests.java
(with props)
Modified:
ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml
ofbiz/trunk/framework/service/servicedef/services_test_se.xml
ofbiz/trunk/framework/service/testdef/servicetests.xml
Modified: ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml?rev=1630079&r1=1630078&r2=1630079&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml (original)
+++ ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml Wed Oct 8
12:17:55 2014
@@ -123,6 +123,21 @@ under the License.
<prim-key field="testFieldTypeId"/>
</entity>
<!-- =========================================================
+ Testing Item entity : testing line on a Testing entity
+ ========================================================= -->
+ <entity entity-name="TestingItem"
+ package-name="org.ofbiz.entity.test"
+ title="Testing Item">
+ <field name="testingId" type="id-ne"/>
+ <field name="testingSeqId" type="id-ne"/>
+ <field name="testingHistory" type="very-long"/>
+ <prim-key field="testingId"/>
+ <prim-key field="testingSeqId"/>
+ <relation type="one" fk-name="TESTING_IT_TEST"
rel-entity-name="Testing">
+ <key-map field-name="testingId"/>
+ </relation>
+ </entity>
+ <!-- =========================================================
Testing Node entity : hierarchy of nodes having
'testing node member' as potential members
========================================================= -->
Modified: ofbiz/trunk/framework/service/servicedef/services_test_se.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/servicedef/services_test_se.xml?rev=1630079&r1=1630078&r2=1630079&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/servicedef/services_test_se.xml (original)
+++ ofbiz/trunk/framework/service/servicedef/services_test_se.xml Wed Oct 8
12:17:55 2014
@@ -48,6 +48,50 @@ under the License.
location="org.ofbiz.service.test.ServiceEngineTestServices"
invoke="testServiceLockWaitTimeoutRetryWaiter">
</service>
+ <!-- testing different entity-auto call-->
+ <service name="testEntityAutoCreateTestingPkPresent" auth="false"
+ engine="entity-auto" default-entity-name="Testing" invoke="create">
+ <auto-attributes include="pk" mode="IN" optional="false"/>
+ <auto-attributes include="nonpk" mode="IN" optional="true"/>
+ </service>
+ <service name="testEntityAutoCreateTestingPkMissing" auth="false"
+ engine="entity-auto" default-entity-name="Testing" invoke="create">
+ <auto-attributes include="nonpk" mode="IN" optional="true"/>
+ <attribute name="testingId" mode="OUT" type="String"/>
+ </service>
+ <service name="testEntityAutoCreateTestingItemPkPresent" auth="false"
+ engine="entity-auto" default-entity-name="TestingItem" invoke="create">
+ <auto-attributes include="pk" mode="IN" optional="false"/>
+ <auto-attributes include="nonpk" mode="IN" optional="true"/>
+ </service>
+ <service name="testEntityAutoCreateTestingItemPkMissing" auth="false"
+ engine="entity-auto" default-entity-name="TestingItem" invoke="create">
+ <auto-attributes include="nonpk" mode="IN" optional="true"/>
+ <attribute name="testingId" mode="IN" type="String"/>
+ <attribute name="testingSeqId" mode="OUT" type="String"/>
+ </service>
+ <service name="testEntityAutoCreateTestingNodeMemberPkPresent" auth="false"
+ engine="entity-auto" default-entity-name="TestingNodeMember"
invoke="create">
+ <auto-attributes include="pk" mode="IN" optional="false"/>
+ <auto-attributes include="nonpk" mode="IN" optional="true"/>
+ </service>
+ <service name="testEntityAutoCreateTestingNodeMemberPkMissing" auth="false"
+ engine="entity-auto" default-entity-name="TestingNodeMember"
invoke="create">
+ <auto-attributes include="nonpk" mode="IN" optional="true"/>
+ <attribute name="testingId" mode="IN" type="String"/>
+ <attribute name="testingNodeId" mode="IN" type="String"/>
+ <attribute name="fromDate" mode="OUT" type="String"/>
+ </service>
+ <service name="testEntityAutoUpdateTesting" auth="false"
+ engine="entity-auto" default-entity-name="Testing" invoke="update">
+ <auto-attributes include="pk" mode="IN" optional="false"/>
+ <auto-attributes include="nonpk" mode="IN" optional="true"/>
+ </service>
+ <service name="testEntityAutoRemoveTesting" auth="false"
+ engine="entity-auto" default-entity-name="Testing" invoke="delete">
+ <auto-attributes include="pk" mode="IN" optional="false"/>
+ </service>
+
<!-- lock wait timeout retry testing services - a scenario that we can't
do automatically with the single service because the parent owns the tx we have
to have end before it will succeed -->
<service name="testServiceLockWaitTimeoutRetryCantRecover" engine="java"
auth="false" transaction-timeout="2"
location="org.ofbiz.service.test.ServiceEngineTestServices"
invoke="testServiceLockWaitTimeoutRetryCantRecover">
Added:
ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEntityAutoTests.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEntityAutoTests.java?rev=1630079&view=auto
==============================================================================
---
ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEntityAutoTests.java
(added)
+++
ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEntityAutoTests.java
Wed Oct 8 12:17:55 2014
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
*******************************************************************************/
+package org.ofbiz.service.test;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.service.ServiceUtil;
+import org.ofbiz.service.testtools.OFBizTestCase;
+
+public class ServiceEntityAutoTests extends OFBizTestCase {
+
+ public ServiceEntityAutoTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ }
+
+ public void testEntityAutoCreateSinglPkEntity() throws Exception {
+ //test create with given pk
+ Map<String, Object> testingPkPresentMap = new HashMap<String,
Object>();
+ testingPkPresentMap.put("testingId", "TESTING_1");
+ testingPkPresentMap.put("testingName", "entity auto testing");
+ Map<String, Object> results =
dispatcher.runSync("testEntityAutoCreateTestingPkPresent", testingPkPresentMap);
+ assertTrue(ServiceUtil.isSuccess(results));
+ GenericValue testing = delegator.findOne("Testing", false,
"testingId", "TESTING_1");
+ assertNotNull(testing);
+
+ //test create with auto sequence
+ Map<String, Object> testingPkMissingMap = new HashMap<String,
Object>();
+ testingPkPresentMap.put("testingName", "entity auto testing without pk
part in");
+ results = dispatcher.runSync("testEntityAutoCreateTestingPkMissing",
testingPkMissingMap);
+ assertTrue(ServiceUtil.isSuccess(results));
+ testing = delegator.findOne("Testing", false, "testingId",
results.get("testingId"));
+ assertNotNull(testing);
+
+ //test collision
+ results = dispatcher.runSync("testEntityAutoCreateTestingPkPresent",
testingPkPresentMap, 10, true);
+ assertTrue(ServiceUtil.isError(results));
+ }
+
+ public void testEntityAutoCreateDoublePkEntity() throws Exception {
+ delegator.create("Testing", "testingId", "TESTING_2");
+
+ //test create with given pk
+ Map<String, Object> testingItemPkPresentMap =
UtilMisc.toMap("testingId", "TESTING_2", "testingSeqId", "00001");
+ Map<String, Object> results =
dispatcher.runSync("testEntityAutoCreateTestingItemPkPresent",
testingItemPkPresentMap);
+ assertTrue(ServiceUtil.isSuccess(results));
+ GenericValue testingItem = delegator.findOne("TestingItem", false,
"testingId", "TESTING_2", "testingSeqId", "00001");
+ assertNotNull(testingItem);
+
+ //test create with auto sub-sequence
+ Map<String, Object> testingItemPkMissingMap =
UtilMisc.toMap("testingId", "TESTING_2");
+ results =
dispatcher.runSync("testEntityAutoCreateTestingItemPkMissing",
testingItemPkMissingMap);
+ assertTrue(ServiceUtil.isSuccess(results));
+ testingItem = delegator.findOne("TestingItem", false, "testingId",
"TESTING_2", "testingSeqId", results.get("testingSeqId"));
+ assertNotNull(testingItem);
+ assertEquals("00002", testingItem.get("testingSeqId"));
+
+ //test collision
+ results =
dispatcher.runSync("testEntityAutoCreateTestingItemPkPresent",
testingItemPkPresentMap, 10, true);
+ assertTrue(ServiceUtil.isError(results));
+ //assertEquals("", ServiceUtil.getErrorMessage(results));
+ }
+
+ public void testEntityAutoCreateMultiPkEntity() throws Exception {
+ delegator.create("TestingNode", "testingNodeId", "NODE_1");
+ delegator.create("Testing", "testingId", "TESTING_3");
+
+ //test create given pk
+ Map<String, Object> testingNodeMemberPkPresentMap =
UtilMisc.toMap("testingId", "TESTING_3",
+ "testingNodeId", "NODE_1", "fromDate",
UtilDateTime.toTimestamp("01/01/2010 00:00:00"));
+ Map<String, Object> results =
dispatcher.runSync("testEntityAutoCreateTestingNodeMemberPkPresent",
testingNodeMemberPkPresentMap);
+ assertTrue(ServiceUtil.isSuccess(results));
+ GenericValue testingNodeMember =
delegator.findOne("TestingNodeMember", false, testingNodeMemberPkPresentMap);
+ assertNotNull(testingNodeMember);
+ testingNodeMember.remove();
+
+ //test create auto sub-sequence
+ //test missing pk
+ Map<String, Object> testingNodeMemberPkMissingMap =
UtilMisc.toMap("testingId", "TESTING_3", "testingNodeId", "NODE_1");
+ results =
dispatcher.runSync("testEntityAutoCreateTestingNodeMemberPkMissing",
testingNodeMemberPkMissingMap, 10, true);
+ assertTrue(ServiceUtil.isError(results));
+ assertTrue(ServiceUtil.getErrorMessage(results).contains("1. a single
OUT pk for primary auto-sequencing"));
+ }
+
+ public void testEntityAutoUpdateEntity() throws Exception {
+ delegator.create("Testing", "testingId", "TESTING_4", "testingName",
"entity auto testing");
+
+ //test update with exist pk
+ Map<String, Object> testingUpdateMap = UtilMisc.toMap("testingId",
"TESTING_4", "testingName", "entity auto testing updated");
+ Map<String, Object> results =
dispatcher.runSync("testEntityAutoUpdateTesting", testingUpdateMap);
+ assertTrue(ServiceUtil.isSuccess(results));
+ GenericValue testing = delegator.findOne("Testing", false,
"testingId", "TESTING_4");
+ assertEquals("entity auto testing updated",
testing.getString("testingName"));
+
+ //test update with bad pk
+ Map<String, Object> testingUpdateFailedMap =
UtilMisc.toMap("testingId", "TESTING_4_FAILED", "testingName", "entity auto
testing updated");
+ results = dispatcher.runSync("testEntityAutoUpdateTesting",
testingUpdateFailedMap, 10, true);
+ assertTrue(ServiceUtil.isError(results));
+ assertEquals(UtilProperties.getMessage("ServiceErrorUiLabels",
"ServiceValueNotFound", Locale.ENGLISH), ServiceUtil.getErrorMessage(results));
+ }
+
+ public void testEntityAutoDeleteEntity() throws Exception {
+ delegator.create("Testing", "testingId", "TESTING_5");
+
+ //test delete with exist pk
+ Map<String, Object> testingDeleteMap = UtilMisc.toMap("testingId",
"TESTING_5");
+ Map<String, Object> results =
dispatcher.runSync("testEntityAutoRemoveTesting", testingDeleteMap);
+ assertTrue(ServiceUtil.isSuccess(results));
+ GenericValue testing = delegator.findOne("Testing", false,
"testingId", "TESTING_5");
+ assertNull(testing);
+
+ //test create with bad pk
+ Map<String, Object> testingDeleteFailedMap =
UtilMisc.toMap("testingId", "TESTING_5_FAILED");
+ results = dispatcher.runSync("testEntityAutoRemoveTesting",
testingDeleteFailedMap);
+ assertTrue(ServiceUtil.isSuccess(results));
+ //assertEquals(UtilProperties.getMessage("ServiceErrorUiLabels",
"ServiceValueNotFound", Locale.ENGLISH), ServiceUtil.getErrorMessage(results));
+ }
+}
Propchange:
ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEntityAutoTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEntityAutoTests.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange:
ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEntityAutoTests.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: ofbiz/trunk/framework/service/testdef/servicetests.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/testdef/servicetests.xml?rev=1630079&r1=1630078&r2=1630079&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/testdef/servicetests.xml (original)
+++ ofbiz/trunk/framework/service/testdef/servicetests.xml Wed Oct 8 12:17:55
2014
@@ -23,6 +23,7 @@ under the License.
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd">
<test-case case-name="service-tests"><junit-test-suite
class-name="org.ofbiz.service.test.ServiceEngineTests"/></test-case>
<test-case case-name="service-soap-tests"><junit-test-suite
class-name="org.ofbiz.service.test.ServiceSOAPTests"/></test-case>
+ <test-case case-name="service-entity-auto-tests"><junit-test-suite
class-name="org.ofbiz.service.test.ServiceEntityAutoTests"/></test-case>
<test-case case-name="load-service-test-data">
<entity-xml action="load"
entity-xml-url="component://service/testdef/data/ServiceTestData.xml"/>