diff --git a/framework/entity/entitydef/entitymodel_test.xml b/framework/entity/entitydef/entitymodel_test.xml
index f9fb9ab28d..c7fe4a6d6c 100644
--- a/framework/entity/entitydef/entitymodel_test.xml
+++ b/framework/entity/entitydef/entitymodel_test.xml
@@ -122,6 +122,21 @@ under the License.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/framework/service/src/org/ofbiz/service/test/ServiceEntityAutoTests.java b/framework/service/src/org/ofbiz/service/test/ServiceEntityAutoTests.java
new file mode 100644
index 0000000000..a640e4e10c
--- /dev/null
+++ b/framework/service/src/org/ofbiz/service/test/ServiceEntityAutoTests.java
@@ -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 testingPkPresentMap = new HashMap();
+ testingPkPresentMap.put("testingId", "TESTING_1");
+ testingPkPresentMap.put("testingName", "entity auto testing");
+ Map 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 testingPkMissingMap = new HashMap();
+ 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 testingItemPkPresentMap = UtilMisc.toMap("testingId", "TESTING_2", "testingSeqId", "00001");
+ Map 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 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 testingNodeMemberPkPresentMap = UtilMisc.toMap("testingId", "TESTING_3",
+ "testingNodeId", "NODE_1", "fromDate", UtilDateTime.toTimestamp("01/01/2010 00:00:00"));
+ Map 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 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 testingUpdateMap = UtilMisc.toMap("testingId", "TESTING_4", "testingName", "entity auto testing updated");
+ Map 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 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 testingDeleteMap = UtilMisc.toMap("testingId", "TESTING_5");
+ Map 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 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));
+ }
+}
diff --git a/framework/service/testdef/servicetests.xml b/framework/service/testdef/servicetests.xml
index 6f20b9cc2b..d6b46934ff 100644
--- a/framework/service/testdef/servicetests.xml
+++ b/framework/service/testdef/servicetests.xml
@@ -23,6 +23,7 @@ under the License.
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd">
+