[ofbiz-framework] branch trunk updated: Improved: Convert PartyContactMechTests.xml to Groovy (OFBIZ-11854)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Improved: Convert PartyContactMechTests.xml to Groovy (OFBIZ-11854)

akashjain
This is an automated email from the ASF dual-hosted git repository.

akashjain pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new b4fbbc4  Improved: Convert PartyContactMechTests.xml to Groovy (OFBIZ-11854)
b4fbbc4 is described below

commit b4fbbc49341a8be2f94ca9f71f56ae9b4f4ea7c9
Author: Akash Jain <[hidden email]>
AuthorDate: Tue Aug 4 22:35:58 2020 +0530

    Improved: Convert PartyContactMechTests.xml to Groovy (OFBIZ-11854)
---
 .../party/minilang/test/PartyContactMechTests.xml  | 408 -------------------
 .../ofbiz/party/PartyContactMechTests.groovy       | 433 +++++++++++++++++++++
 .../party/testdef/PartyContactMechTests.xml        |   2 +-
 3 files changed, 434 insertions(+), 409 deletions(-)

diff --git a/applications/party/minilang/test/PartyContactMechTests.xml b/applications/party/minilang/test/PartyContactMechTests.xml
deleted file mode 100644
index 58e4360..0000000
--- a/applications/party/minilang/test/PartyContactMechTests.xml
+++ /dev/null
@@ -1,408 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-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.
--->
-
-<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-        xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd">
-
-    <simple-method method-name="testUpdatePartyEmailAddress" short-description="Test updatePartyEmailAddress service" login-required="false">
-        <set field="partyId" value="DemoCustomer"/>
-        <set field="contactMechTypeId" value="EMAIL_ADDRESS"/>
-        <!-- first try with just updating without changing the email address -->
-        <set field="serviceCtx.partyId" from-field="partyId"/>
-        <set field="serviceCtx.emailAddress" value="[hidden email]"/>
-        <set field="serviceCtx.contactMechId" value="9026"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-
-        <call-service service-name="updatePartyEmailAddress" in-map-name="serviceCtx">
-            <result-to-field result-name="contactMechId"/>
-        </call-service>
-        <entity-one entity-name="ContactMech" value-field="contactMech"/>
-        <assert>
-            <not><if-empty field="contactMech"/></not>
-            <if-compare-field field="contactMechId" to-field="serviceCtx.contactMechId" operator="equals"/>
-            <if-compare-field field="contactMech.infoString" to-field="serviceCtx.emailAddress" operator="equals"/>
-        </assert>
-        <check-errors/>
-
-        <clear-field field="contactMech"/>
-        <!-- now update with changing the email address, a new record will be created in ContactMech entity this time -->
-        <set field="serviceCtx.emailAddress" value="[hidden email]"/>
-        <call-service service-name="updatePartyEmailAddress" in-map-name="serviceCtx">
-            <result-to-field result-name="contactMechId" field="newContactMechId"/>
-        </call-service>
-        <entity-one entity-name="ContactMech" value-field="contactMech">
-            <field-map field-name="contactMechId" from-field="newContactMechId"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="contactMech"/></not>
-            <if-compare-field field="newContactMechId" to-field="serviceCtx.contactMechId" operator="not-equals"/>
-            <if-compare-field field="contactMech.infoString" to-field="serviceCtx.emailAddress" operator="equals"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testUpdatePartyTelecomNumber" short-description="Test updatePartyTelecomNumber service" login-required="false">
-        <set field="partyId" value="DemoCustomer"/>
-        <set field="serviceCtx.partyId" from-field="partyId"/>
-        <set field="serviceCtx.contactMechId" value="9025"/>
-        <set field="serviceCtx.countryCode" value="1"/>
-        <set field="serviceCtx.areaCode" value="801"/>
-        <set field="serviceCtx.contactNumber" value="555-5555"/>
-
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-
-        <call-service service-name="updatePartyTelecomNumber" in-map-name="serviceCtx">
-           <result-to-field result-name="contactMechId"/>
-        </call-service>
-        <entity-one entity-name="ContactMech" value-field="contactMech"/>
-        <assert>
-            <not><if-empty field="contactMech"/></not>
-            <if-compare-field field="contactMechId" to-field="serviceCtx.contactMechId" operator="equals"/>
-        </assert>
-        <clear-field field="telecomNumber"/>
-        <get-related-one  value-field="contactMech" relation-name="TelecomNumber" to-value-field="telecomNumber"/>
-        <assert>
-            <not><if-empty field="telecomNumber"/></not>
-            <if-compare-field field="telecomNumber.areaCode" to-field="serviceCtx.areaCode" operator="equals"/>
-            <if-compare-field field="telecomNumber.contactNumber" to-field="serviceCtx.contactNumber" operator="equals"/>
-        </assert>
-        <check-errors/>
-
-        <clear-field field="contactMech"/>
-        <clear-field field="telecomNumber"/>
-
-        <!-- try now with changing the telecom number, a new record will be created in ContactMech, TelecomNumber entity this time -->
-        <set field="serviceCtx.contactNumber" value="555-6666"/>
-        <call-service service-name="updatePartyTelecomNumber" in-map-name="serviceCtx">
-           <result-to-field result-name="contactMechId" field="newContactMechId"/>
-        </call-service>
-        <entity-one entity-name="ContactMech" value-field="contactMech">
-            <field-map field-name="contactMechId" from-field="newContactMechId"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="contactMech"/></not>
-            <if-compare-field field="newContactMechId" to-field="serviceCtx.contactMechId" operator="not-equals"/>
-        </assert>
-        <get-related-one  value-field="contactMech" relation-name="TelecomNumber" to-value-field="telecomNumber"/>
-        <assert>
-            <not><if-empty field="telecomNumber"/></not>
-            <if-compare-field field="telecomNumber.contactNumber" to-field="serviceCtx.contactNumber" operator="equals"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testUpdatePartyPostalAddress" short-description="Test updatePartyPostalAddress service" login-required="false">
-        <set field="partyId" value="DemoCustomer"/>
-        <call-class-method method-name="findPartyLatestPostalAddress" class-name="org.apache.ofbiz.party.party.PartyWorker" ret-field="postalAddress">
-            <field field="partyId" type="java.lang.String"/>
-            <field field="delegator" type="org.apache.ofbiz.entity.Delegator"/>
-        </call-class-method>
-        <!-- first try with just updating without changing the postal address -->
-        <set-service-fields service-name="updatePartyPostalAddress" map="postalAddress" to-map="serviceCtx"/>
-        <set field="serviceCtx.partyId" from-field="partyId"/>
-
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-
-        <call-service service-name="updatePartyPostalAddress" in-map-name="serviceCtx">
-            <result-to-field result-name="contactMechId"/>
-        </call-service>
-        <entity-one entity-name="ContactMech" value-field="contactMech"/>
-        <assert>
-            <not><if-empty field="contactMech"/></not>
-            <if-compare-field field="contactMechId" to-field="serviceCtx.contactMechId" operator="equals"/>
-        </assert>
-        <clear-field field="postalAddress"/>
-        <get-related-one  value-field="contactMech" relation-name="PostalAddress" to-value-field="postalAddress"/>
-        <assert>
-            <not><if-empty field="postalAddress"/></not>
-            <if-compare-field field="postalAddress.address1" to-field="serviceCtx.address1" operator="equals"/>
-            <if-compare-field field="postalAddress.stateProvinceGeoId" to-field="serviceCtx.stateProvinceGeoId" operator="equals"/>
-            <if-compare-field field="postalAddress.postalCode" to-field="serviceCtx.postalCode" operator="equals"/>
-        </assert>
-        <check-errors/>
-
-        <clear-field field="contactMech"/>
-        <clear-field field="postalAddress"/>
-
-        <!-- try now with changing the postal address fields, a new record will be created in ContactMech, PostalAddress entity this time -->
-        <set field="serviceCtx.stateProvinceGeoId" value="VA"/>
-        <set field="serviceCtx.postalCode" value="20147"/>
-        <call-service service-name="updatePartyPostalAddress" in-map-name="serviceCtx">
-           <result-to-field result-name="contactMechId" field="newContactMechId"/>
-        </call-service>
-        <entity-one entity-name="ContactMech" value-field="contactMech">
-            <field-map field-name="contactMechId" from-field="newContactMechId"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="contactMech"/></not>
-            <if-compare-field field="newContactMechId" to-field="serviceCtx.contactMechId" operator="not-equals"/>
-        </assert>
-        <get-related-one  value-field="contactMech" relation-name="PostalAddress" to-value-field="postalAddress"/>
-        <assert>
-            <not><if-empty field="postalAddress"/></not>
-            <if-compare-field field="postalAddress.stateProvinceGeoId" to-field="serviceCtx.stateProvinceGeoId" operator="equals"/>
-            <if-compare-field field="postalAddress.postalCode" to-field="serviceCtx.postalCode" operator="equals"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-
-    <simple-method method-name="testCreatePartyEmailAddress" short-description="Test case for service createPartyEmailAddress" login-required="false">
-        <set field="partyId" value="DemoEmployee"/>
-        <set field="emailAddress" value="[hidden email]"/>
-        <set field="contactMechPurposeTypeId" value="PRIMARY_EMAIL"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <set field="serviceCtx.partyId" from-field="partyId"/>
-        <set field="serviceCtx.emailAddress" from-field="emailAddress"/>
-        <set field="serviceCtx.contactMechPurposeTypeId" from-field="contactMechPurposeTypeId"/>
-        <call-service service-name="createPartyEmailAddress" in-map-name="serviceCtx">
-            <result-to-field result-name="contactMechId"/>
-        </call-service>
-        <entity-one entity-name="ContactMech" value-field="contactMech"/>
-        <entity-condition entity-name="PartyContactMech" list="pcmList" filter-by-date="true">
-            <condition-expr field-name="contactMechId" from-field="contactMechId"/>
-            <order-by field-name="fromDate"/>
-        </entity-condition>
-        <first-from-list list="pcmList" entry="pcm"/>
-        <entity-condition entity-name="PartyContactMechPurpose" list="pcmpList" filter-by-date="true">
-            <condition-expr field-name="contactMechId" from-field="contactMechId"/>
-            <order-by field-name="fromDate"/>
-        </entity-condition>
-        <first-from-list list="pcmpList" entry="pcmp"/>
-        <assert>
-            <not><if-empty field="contactMech"/></not>
-            <if-compare-field field="contactMech.infoString" operator="equals" to-field="emailAddress"/>
-            <not><if-empty field="pcmList"/></not>
-            <if-compare-field field="pcm.partyId" operator="equals" to-field="partyId"/>
-            <not><if-empty field="pcmpList"/></not>
-            <if-compare-field field="pcmp.partyId" operator="equals" to-field="partyId"/>
-            <if-compare-field field="pcmp.contactMechPurposeTypeId" operator="equals" to-field="contactMechPurposeTypeId"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testCreatePartyTelecomNumber" short-description="Test case for service createPartyTelecomNumber" login-required="false">
-        <set field="serviceCtx.partyId" value="DemoEmployee"/>
-        <set field="serviceCtx.areaCode" value="801"/>
-        <set field="serviceCtx.contactNumber" value="888-8899"/>
-        <set field="serviceCtx.contactMechPurposeTypeId" value="PRIMARY_PHONE"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="createPartyTelecomNumber" in-map-name="serviceCtx">
-            <result-to-field result-name="contactMechId"/>
-        </call-service>
-        <entity-one entity-name="ContactMech" value-field="contactMech"/>
-        <entity-one entity-name="TelecomNumber" value-field="telecomNumber"/>
-        <entity-and entity-name="PartyContactMech" list="pcmList" filter-by-date="true">
-            <field-map field-name="contactMechId"/>
-        </entity-and>
-        <first-from-list  list="pcmList" entry="pcm"/>
-        <first-from-list list="partyContactMechList" entry="partyContactMech"/>
-        <entity-and entity-name="PartyContactMechPurpose" list="pcmpList" filter-by-date="true">
-            <field-map field-name="contactMechId"/>
-        </entity-and>
-        <first-from-list list="pcmpList" entry="pcmp"/>
-        <assert>
-            <not><if-empty field="contactMech"/></not>
-            <not><if-empty field="telecomNumber"/></not>
-            <if-compare field="telecomNumber.areaCode" operator="equals" value="801"/>
-            <if-compare field="telecomNumber.contactNumber" operator="equals" value="888-8899"/>
-            <not><if-empty field="pcmList"/></not>
-            <if-compare field="pcm.partyId" operator="equals" value="DemoEmployee"/>
-            <not><if-empty field="pcmpList"/></not>
-             <if-compare field="pcmp.partyId" operator="equals" value="DemoEmployee"/>
-             <if-compare field="pcmp.contactMechPurposeTypeId" operator="equals" value="PRIMARY_PHONE"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testCreateUpdatePartyTelecomNumberWithCreate" short-description="Test the service for create telecom number" login-required="false">
-        <set field="serviceCtx.partyId" value="DemoCustomer"/>
-        <set field="serviceCtx.contactMechPurposeTypeId" value="PHONE_WORK"/>
-        <set field="serviceCtx.areaCode" value="801"/>
-        <set field="serviceCtx.contactNumber" value="888-8888"/>
-        <set field="serviceCtx.extension" value="444"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="DemoCustomer"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="createUpdatePartyTelecomNumber" in-map-name="serviceCtx">
-            <result-to-field result-name="contactMechId"/>
-        </call-service>
-        <entity-one entity-name="ContactMech" value-field="contactMech"/>
-        <entity-one entity-name="TelecomNumber" value-field="telecomNumber"/>
-        <entity-and entity-name="PartyContactMech" list="pcmList" filter-by-date="true">
-            <field-map field-name="contactMechId"/>
-        </entity-and>
-        <first-from-list list="pcmList" entry="pcm"/>
-        <entity-and entity-name="PartyContactMechPurpose" list="pcmpList" filter-by-date="true">
-            <field-map field-name="contactMechId"/>
-        </entity-and>
-        <first-from-list list="pcmpList" entry="pcmp"/>
-        <assert>
-            <not><if-empty field="contactMech"/></not>
-            <not><if-empty field="telecomNumber"/></not>
-            <if-compare field="telecomNumber.areaCode" operator="equals" value="801"/>
-            <if-compare field="telecomNumber.contactNumber" operator="equals" value="888-8888"/>
-            <if-compare field="pcm.extension" operator="equals" value="444"/>
-            <not><if-empty field="pcm"/></not>
-            <not><if-empty field="pcmp"/></not>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testCreateUpdatePartyTelecomNumberWithUpdate"  short-description="Test the service for update telecom number" login-required="false">
-        <set field="serviceCtx.partyId" value="DemoCustomer"/>
-        <set field="serviceCtx.contactMechId" value="9125"/>
-        <set field="serviceCtx.contactMechPurposeTypeId" value="PHONE_HOME"/>
-        <set field="serviceCtx.areaCode" value="802"/>
-        <set field="serviceCtx.contactNumber" value="555-5555"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="DemoCustomer"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="createUpdatePartyTelecomNumber" in-map-name="serviceCtx">
-            <result-to-field result-name="contactMechId"/>
-        </call-service>
-        <assert>
-            <if-compare field="contactMechId" operator="not-equals" value="9125"/>
-        </assert>
-        <check-errors/>
-        <entity-and entity-name="PartyContactMechPurpose" list="pcmpListOld">
-            <field-map field-name="contactMechId" value="9125"/>
-        </entity-and>
-        <first-from-list list="pcmpListOld" entry="pcmpOld"/>
-        <assert>
-            <not><if-empty field="pcmpOld.thruDate"/></not>
-        </assert>
-        <check-errors/>
-        <entity-one entity-name="ContactMech" value-field="contactMech"/>
-        <entity-one entity-name="TelecomNumber" value-field="telecomNumber"/>
-        <entity-and entity-name="PartyContactMech" list="pcmList" filter-by-date="true">
-            <field-map field-name="contactMechId"/>
-        </entity-and>
-        <first-from-list list="pcmList" entry="pcm"/>
-        <entity-and entity-name="PartyContactMechPurpose" list="pcmpList" filter-by-date="true">
-            <field-map field-name="contactMechId"/>
-        </entity-and>
-        <first-from-list list="pcmpList" entry="pcmp"/>
-        <assert>
-            <not><if-empty field="contactMech"/></not>
-            <not><if-empty field="telecomNumber"/></not>
-            <if-compare field="telecomNumber.areaCode" operator="equals" value="802"/>
-            <if-compare field="telecomNumber.contactNumber" operator="equals" value="555-5555"/>
-            <not><if-empty field="pcm"/></not>
-            <not><if-empty field="pcmp"/></not>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testCreateUpdatePartyEmailAddressWithCreate" short-description="Test the service for create email address" login-required="false">
-        <set field="serviceCtx.partyId" value="DemoCustomer"/>
-        <set field="serviceCtx.contactMechPurposeTypeId" value="PRIMARY_EMAIL"/>
-        <set field="serviceCtx.emailAddress" value="[hidden email]"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="DemoCustomer"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="createUpdatePartyEmailAddress" in-map-name="serviceCtx">
-            <result-to-field result-name="contactMechId"/>
-            <result-to-field result-name="emailAddress"/>
-        </call-service>
-        <assert>
-            <if-compare field="emailAddress" operator="equals" value="[hidden email]"/>
-        </assert>
-        <check-errors/>
-        <entity-one entity-name="ContactMech" value-field="contactMech"/>
-        <entity-and entity-name="PartyContactMech" list="pcmList" filter-by-date="true">
-            <field-map field-name="contactMechId"/>
-        </entity-and>
-        <first-from-list list="pcmList" entry="pcm"/>
-        <entity-and entity-name="PartyContactMechPurpose" list="pcmpList" filter-by-date="true">
-            <field-map field-name="contactMechId"/>
-        </entity-and>
-        <first-from-list list="pcmpList" entry="pcmp"/>
-        <assert>
-            <not><if-empty field="contactMech"/></not>
-            <if-compare field="contactMech.infoString" operator="equals" value="[hidden email]"/>
-            <not><if-empty field="pcm"/></not>
-            <not><if-empty field="pcmp"/></not>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testCreateUpdatePartyEmailAddressWithUpdate" short-description="Test the service for update email address" login-required="false">
-        <set field="serviceCtx.partyId" value="DemoCustomer"/>
-        <set field="serviceCtx.contactMechId" value="9126"/>
-        <set field="serviceCtx.contactMechPurposeTypeId" value="PRIMARY_EMAIL"/>
-        <set field="serviceCtx.emailAddress" value="[hidden email]"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="DemoCustomer"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="createUpdatePartyEmailAddress" in-map-name="serviceCtx">
-            <result-to-field result-name="contactMechId"/>
-            <result-to-field result-name="emailAddress"/>
-        </call-service>
-        <assert>
-            <if-compare field="contactMechId" operator="not-equals" value="9126"/>
-            <if-compare field="emailAddress" operator="equals" value="[hidden email]"/>
-        </assert>
-        <check-errors/>
-        <entity-and entity-name="PartyContactMechPurpose" list="pcmpListOld">
-            <field-map field-name="contactMechId" value="9126"/>
-        </entity-and>
-        <first-from-list list="pcmpListOld" entry="pcmpOld"/>
-        <assert>
-            <not><if-empty field="pcmpOld.thruDate"/></not>
-        </assert>
-        <check-errors/>
-        <entity-one entity-name="ContactMech" value-field="contactMech"/>
-        <entity-and entity-name="PartyContactMech" list="pcmList" filter-by-date="true">
-            <field-map field-name="contactMechId"/>
-        </entity-and>
-        <first-from-list list="pcmList" entry="pcm"/>
-        <entity-and entity-name="PartyContactMechPurpose" list="pcmpList" filter-by-date="true">
-            <field-map field-name="contactMechId"/>
-        </entity-and>
-        <first-from-list list="pcmpList" entry="pcmp"/>
-        <assert>
-            <not><if-empty field="contactMech"/></not>
-            <if-compare field="contactMech.infoString" operator="equals" value="[hidden email]"/>
-            <not><if-empty field="pcm"/></not>
-            <not><if-empty field="pcmp"/></not>
-        </assert>
-        <check-errors/>
-    </simple-method>
-</simple-methods>
diff --git a/applications/party/src/main/groovy/org/apache/ofbiz/party/PartyContactMechTests.groovy b/applications/party/src/main/groovy/org/apache/ofbiz/party/PartyContactMechTests.groovy
new file mode 100644
index 0000000..4371153
--- /dev/null
+++ b/applications/party/src/main/groovy/org/apache/ofbiz/party/PartyContactMechTests.groovy
@@ -0,0 +1,433 @@
+/*
+ * 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.apache.ofbiz.party
+
+import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.party.party.PartyWorker
+import org.apache.ofbiz.service.ModelService
+import org.apache.ofbiz.service.ServiceUtil
+import org.apache.ofbiz.service.testtools.OFBizTestCase
+
+class PartyContactMechTests extends OFBizTestCase {
+    public PartyContactMechTests(String name) {
+        super(name)
+    }
+
+    void testUpdatePartyEmailAddress() {
+        String partyId = 'DemoCustomer'
+        String contactMechTypeId = 'EMAIL_ADDRESS'
+        String emailAddress = '[hidden email]'
+
+        // first try with just updating without changing the email address
+        Map serviceCtx = [
+                partyId   : partyId,
+                contactMechTypeId  : contactMechTypeId,
+                emailAddress: emailAddress,
+                contactMechId: '9026',
+                userLogin : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('updatePartyEmailAddress', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String contactMechId = serviceResult.contactMechId
+        assert contactMechId
+
+        GenericValue contactMech = from("ContactMech")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert contactMech
+        assert contactMechId.equals(serviceCtx.contactMechId)
+        assert contactMech.infoString.equals(serviceCtx.emailAddress)
+
+        // now update with changing the email address, a new record will be created in ContactMech entity this time
+        serviceResult.clear()
+        serviceCtx.emailAddress = '[hidden email]'
+        serviceResult = dispatcher.runSync('updatePartyEmailAddress', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String newContactMechId = serviceResult.contactMechId
+        assert newContactMechId
+
+        contactMech.clear()
+        contactMech = from("ContactMech")
+                .where('contactMechId', newContactMechId)
+                .queryOne()
+        assert contactMech
+        assert !contactMechId.equals(newContactMechId)
+        assert contactMech.infoString.equals(serviceCtx.emailAddress)
+    }
+
+    void testUpdatePartyTelecomNumber() {
+        String partyId = 'DemoCustomer'
+
+        // first try with just updating without changing the email address
+        Map serviceCtx = [
+                partyId   : partyId,
+                contactMechId: '9025',
+                countryCode: '1',
+                areaCode: '801',
+                contactNumber: '555-5555',
+                userLogin : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('updatePartyTelecomNumber', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String contactMechId = serviceResult.contactMechId
+        assert contactMechId
+
+        GenericValue contactMech = from("ContactMech")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert contactMech
+        assert contactMechId.equals(serviceCtx.contactMechId)
+
+        GenericValue telecomNumber = from("TelecomNumber")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert telecomNumber
+        assert telecomNumber.areaCode.equals(serviceCtx.areaCode)
+        assert telecomNumber.contactNumber.equals(serviceCtx.contactNumber)
+
+        // try now with changing the telecom number, a new record will be created in ContactMech, TelecomNumber entity this time
+        serviceResult.clear()
+        serviceCtx.contactNumber = '555-6666'
+        serviceResult = dispatcher.runSync('updatePartyTelecomNumber', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String newContactMechId = serviceResult.contactMechId
+        assert newContactMechId
+
+        contactMech.clear()
+        contactMech = from("ContactMech")
+                .where('contactMechId', newContactMechId)
+                .queryOne()
+        assert contactMech
+        assert !contactMechId.equals(newContactMechId)
+
+        telecomNumber.clear()
+        telecomNumber = from("TelecomNumber")
+                .where('contactMechId', newContactMechId)
+                .queryOne()
+        assert telecomNumber
+        assert telecomNumber.areaCode.equals(serviceCtx.areaCode)
+        assert telecomNumber.contactNumber.equals(serviceCtx.contactNumber)
+    }
+
+    void testUpdatePartyPostalAddress() {
+        String partyId = 'DemoCustomer'
+
+        // first try with just updating without changing the postal address
+        GenericValue postalAddress = PartyWorker.findPartyLatestPostalAddress(partyId, delegator)
+        Map serviceCtx = dispatcher.getDispatchContext().makeValidContext("updatePartyPostalAddress", ModelService.IN_PARAM, postalAddress)
+        serviceCtx.partyId = partyId
+        serviceCtx.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('updatePartyPostalAddress', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String contactMechId = serviceResult.contactMechId
+        assert contactMechId
+        assert contactMechId.equals(serviceCtx.contactMechId)
+
+        GenericValue contactMech = from("ContactMech")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert contactMech
+
+        postalAddress.clear()
+        postalAddress = from("PostalAddress")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert postalAddress
+        assert postalAddress.address1.equals(serviceCtx.address1)
+        assert postalAddress.stateProvinceGeoId.equals(serviceCtx.stateProvinceGeoId)
+        assert postalAddress.postalCode.equals(serviceCtx.postalCode)
+
+        // try now with changing the postal address fields, a new record will be created in ContactMech, PostalAddress entity this time
+        serviceResult.clear()
+        serviceCtx.stateProvinceGeoId = 'VA'
+        serviceCtx.postalCode = '20147'
+        serviceResult = dispatcher.runSync('updatePartyPostalAddress', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String newContactMechId = serviceResult.contactMechId
+        assert newContactMechId
+
+        contactMech.clear()
+        contactMech = from("ContactMech")
+                .where('contactMechId', newContactMechId)
+                .queryOne()
+        assert contactMech
+        assert !contactMechId.equals(newContactMechId)
+
+        postalAddress.clear()
+        postalAddress = from("PostalAddress")
+                .where('contactMechId', newContactMechId)
+                .queryOne()
+        assert postalAddress
+        assert postalAddress.stateProvinceGeoId.equals(serviceCtx.stateProvinceGeoId)
+        assert postalAddress.postalCode.equals(serviceCtx.postalCode)
+    }
+
+    void testCreatePartyEmailAddress() {
+        String partyId = 'DemoEmployee'
+        String emailAddress = '[hidden email]'
+        String contactMechPurposeTypeId = 'PRIMARY_EMAIL'
+
+        Map serviceCtx = [
+                partyId: partyId,
+                contactMechPurposeTypeId: contactMechPurposeTypeId,
+                emailAddress: emailAddress,
+                userLogin : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('createPartyEmailAddress', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String contactMechId = serviceResult.contactMechId
+        assert contactMechId
+
+        GenericValue contactMech = from("ContactMech")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert contactMech
+        assert emailAddress.equals(contactMech.infoString)
+
+        GenericValue partyContactMech = from("PartyContactMech")
+                .where('contactMechId', contactMechId)
+                .filterByDate().orderBy('fromDate')
+                .queryFirst()
+        assert partyContactMech
+        assert partyId.equals(partyContactMech.partyId)
+
+        GenericValue partyContactMechPurpose = from("PartyContactMechPurpose")
+                .where('contactMechId', contactMechId)
+                .filterByDate().orderBy('fromDate')
+                .queryFirst()
+        assert partyContactMechPurpose
+        assert partyId.equals(partyContactMechPurpose.partyId)
+        assert contactMechPurposeTypeId.equals(partyContactMechPurpose.contactMechPurposeTypeId)
+    }
+
+    void testCreatePartyTelecomNumber() {
+        String partyId = 'DemoEmployee'
+        String areaCode = '801'
+        String contactNumber = '888-8899'
+        String contactMechPurposeTypeId = 'PRIMARY_PHONE'
+
+        Map serviceCtx = [
+                partyId: partyId,
+                contactMechPurposeTypeId: contactMechPurposeTypeId,
+                areaCode: areaCode,
+                contactNumber: contactNumber,
+                userLogin : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('createPartyTelecomNumber', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String contactMechId = serviceResult.contactMechId
+        assert contactMechId
+
+        GenericValue contactMech = from("ContactMech")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert contactMech
+        GenericValue telecomNumber = from("TelecomNumber")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert telecomNumber
+        assert areaCode.equals(telecomNumber.areaCode)
+        assert contactNumber.equals(telecomNumber.contactNumber)
+
+        GenericValue partyContactMech = from("PartyContactMech")
+                .where('contactMechId', contactMechId)
+                .filterByDate().queryFirst()
+        assert partyContactMech
+        assert partyId.equals(partyContactMech.partyId)
+
+        GenericValue partyContactMechPurpose = from("PartyContactMechPurpose")
+                .where('contactMechId', contactMechId)
+                .filterByDate().queryFirst()
+        assert partyContactMechPurpose
+        assert partyId.equals(partyContactMechPurpose.partyId)
+        assert contactMechPurposeTypeId.equals(partyContactMechPurpose.contactMechPurposeTypeId)
+    }
+
+    void testCreateUpdatePartyTelecomNumberWithCreate() {
+        String partyId = 'DemoCustomer'
+        String contactMechPurposeTypeId = 'PHONE_WORK'
+        String areaCode = '801'
+        String contactNumber = '888-8888'
+        String extension = '444'
+
+        Map serviceCtx = [
+                partyId: partyId,
+                contactMechPurposeTypeId: contactMechPurposeTypeId,
+                areaCode: areaCode,
+                contactNumber: contactNumber,
+                extension: extension,
+                userLogin : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('createUpdatePartyTelecomNumber', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String contactMechId = serviceResult.contactMechId
+        assert contactMechId
+
+        GenericValue contactMech = from("ContactMech")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert contactMech
+        GenericValue telecomNumber = from("TelecomNumber")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert telecomNumber
+        assert areaCode.equals(telecomNumber.areaCode)
+        assert contactNumber.equals(telecomNumber.contactNumber)
+
+        GenericValue partyContactMech = from("PartyContactMech")
+                .where('contactMechId', contactMechId)
+                .filterByDate().queryFirst()
+        assert partyContactMech
+        assert partyId.equals(partyContactMech.partyId)
+        assert extension.equals(partyContactMech.extension)
+
+        GenericValue partyContactMechPurpose = from("PartyContactMechPurpose")
+                .where('contactMechId', contactMechId)
+                .filterByDate().queryFirst()
+        assert partyContactMechPurpose
+        assert partyId.equals(partyContactMechPurpose.partyId)
+        assert contactMechPurposeTypeId.equals(partyContactMechPurpose.contactMechPurposeTypeId)
+    }
+
+    void testCreateUpdatePartyTelecomNumberWithUpdate() {
+        String partyId = 'DemoCustomer'
+        String contactMechPurposeTypeId = 'PHONE_HOME'
+        String areaCode = '802'
+        String contactNumber = '555-5555'
+
+        Map serviceCtx = [
+                partyId: partyId,
+                contactMechId: '9125',
+                contactMechPurposeTypeId: contactMechPurposeTypeId,
+                areaCode: areaCode,
+                contactNumber: contactNumber,
+                userLogin : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('createUpdatePartyTelecomNumber', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String contactMechId = serviceResult.contactMechId
+        assert contactMechId != '9125'
+
+        GenericValue partyContactMechPurpose = from("PartyContactMechPurpose")
+                .where('contactMechId', '9125')
+                .queryFirst()
+        assert partyContactMechPurpose
+        assert partyContactMechPurpose.thruDate
+
+        GenericValue contactMech = from("ContactMech")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert contactMech
+
+        GenericValue telecomNumber = from("TelecomNumber")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert telecomNumber
+        assert areaCode.equals(telecomNumber.areaCode)
+        assert contactNumber.equals(telecomNumber.contactNumber)
+
+        GenericValue partyContactMech = from("PartyContactMech")
+                .where('contactMechId', contactMechId)
+                .filterByDate().queryFirst()
+        assert partyContactMech
+
+        partyContactMechPurpose.clear()
+        partyContactMechPurpose = from("PartyContactMechPurpose")
+                .where('contactMechId', contactMechId)
+                .filterByDate().queryFirst()
+        assert partyContactMechPurpose
+    }
+
+    void testCreateUpdatePartyEmailAddressWithCreate() {
+        String partyId = 'DemoCustomer'
+        String contactMechPurposeTypeId = 'PRIMARY_EMAIL'
+        String emailAddress = '[hidden email]'
+
+        Map serviceCtx = [
+                partyId: partyId,
+                contactMechPurposeTypeId: contactMechPurposeTypeId,
+                emailAddress: emailAddress,
+                userLogin : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('createUpdatePartyEmailAddress', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String contactMechId = serviceResult.contactMechId
+        assert contactMechId
+        assert emailAddress.equals(serviceResult.emailAddress)
+
+        GenericValue contactMech = from("ContactMech")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert contactMech
+        assert emailAddress.equals(contactMech.infoString)
+
+        GenericValue partyContactMech = from("PartyContactMech")
+                .where('contactMechId', contactMechId)
+                .filterByDate().queryFirst()
+        assert partyContactMech
+
+        GenericValue partyContactMechPurpose = from("PartyContactMechPurpose")
+                .where('contactMechId', contactMechId)
+                .filterByDate().queryFirst()
+        assert partyContactMechPurpose
+    }
+
+    void testCreateUpdatePartyEmailAddressWithUpdate() {
+        String partyId = 'DemoCustomer'
+        String contactMechPurposeTypeId = 'PRIMARY_EMAIL'
+        String emailAddress = '[hidden email]'
+
+        Map serviceCtx = [
+                partyId: partyId,
+                contactMechId: '9126',
+                contactMechPurposeTypeId: contactMechPurposeTypeId,
+                emailAddress: emailAddress,
+                userLogin : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('createUpdatePartyEmailAddress', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String contactMechId = serviceResult.contactMechId
+        assert contactMechId
+        assert contactMechId != '9126'
+        assert emailAddress.equals(serviceResult.emailAddress)
+
+        GenericValue partyContactMechPurpose = from("PartyContactMechPurpose")
+                .where('contactMechId', '9126')
+                .queryFirst()
+        assert partyContactMechPurpose
+        assert partyContactMechPurpose.thruDate != null
+
+        GenericValue contactMech = from("ContactMech")
+                .where('contactMechId', contactMechId)
+                .queryOne()
+        assert contactMech
+        assert emailAddress.equals(contactMech.infoString)
+
+        GenericValue partyContactMech = from("PartyContactMech")
+                .where('contactMechId', contactMechId)
+                .filterByDate().queryFirst()
+        assert partyContactMech
+
+        partyContactMechPurpose.clear()
+        partyContactMechPurpose = from("PartyContactMechPurpose")
+                .where('contactMechId', contactMechId)
+                .filterByDate().queryFirst()
+        assert partyContactMechPurpose
+    }
+}
\ No newline at end of file
diff --git a/applications/party/testdef/PartyContactMechTests.xml b/applications/party/testdef/PartyContactMechTests.xml
index de4f662..a21c952 100644
--- a/applications/party/testdef/PartyContactMechTests.xml
+++ b/applications/party/testdef/PartyContactMechTests.xml
@@ -28,7 +28,7 @@
         <junit-test-suite class-name="org.apache.ofbiz.party.ContactMechWorkerTests"/>
     </test-case>
     <test-case case-name="partyContactMech-tests">
-        <simple-method-test location="component://party/minilang/test/PartyContactMechTests.xml"/>
+        <junit-test-suite class-name="org.apache.ofbiz.party.PartyContactMechTests"/>
     </test-case>