[ofbiz-framework] branch trunk updated: Improved: Convert testCreateAndUpdateContactList test from XML to Groovy(OFBIZ-11877)

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 testCreateAndUpdateContactList test from XML to Groovy(OFBIZ-11877)

Pawan Verma-2
This is an automated email from the ASF dual-hosted git repository.

pawan 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 d962777  Improved: Convert testCreateAndUpdateContactList test from XML to Groovy(OFBIZ-11877)
d962777 is described below

commit d962777c771285683737795a0c6db9c55e9d7823
Author: Pawan Verma <[hidden email]>
AuthorDate: Fri Jul 31 12:07:52 2020 +0530

    Improved: Convert testCreateAndUpdateContactList test from XML to Groovy(OFBIZ-11877)
   
    Thanks, Jacques for the review.
---
 .../minilang/marketing/test/MarketingTests.xml     | 93 ----------------------
 .../apache/ofbiz/marketing/MarketingTests.groovy   | 82 +++++++++++++++++++
 applications/marketing/testdef/MarketingTests.xml  |  2 +-
 3 files changed, 83 insertions(+), 94 deletions(-)

diff --git a/applications/marketing/minilang/marketing/test/MarketingTests.xml b/applications/marketing/minilang/marketing/test/MarketingTests.xml
deleted file mode 100644
index 2750135..0000000
--- a/applications/marketing/minilang/marketing/test/MarketingTests.xml
+++ /dev/null
@@ -1,93 +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">
-
-    <!-- Test case for create and update contact list -->
-    <simple-method  method-name="testCreateAndUpdateContactList" short-description="Test case to check create and update contact list services" login-required="false">
-        <!-- Precondition:
-            Create contact list
-            1. Go to the Marketing Manager
-            2. Select the Contact List menu item
-            3. Click Create New Contact List
-            4. Enter fields in contact list form
-
-            Edit contact list
-            1. Go to edit contact list screen
-            2. Add / modify fields
-            3. Click on save
-        -->
-        <!-- process tested by test case:
-             1. This test the process for create and update contact list
-        -->
-        <!-- Post condition:
-             Contact list should be created and updated successfully
-        -->
-
-        <!-- create contact list -->
-        <set field="contactListTypeId" value="ANNOUNCEMENT"/>
-        <set field="contactListName" value="Announcement List" type="String"/>
-        <set field="contactMechTypeId" value="EMAIL_ADDRESS"/>
-
-        <entity-one entity-name="UserLogin" value-field="userLogin" auto-field-map="false">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="createServiceCtx.userLogin" from-field="userLogin"/>
-        <set field="createServiceCtx.contactListTypeId" from-field="contactListTypeId"/>
-        <set field="createServiceCtx.contactListName" from-field="contactListName"/>
-        <set field="createServiceCtx.contactMechTypeId" from-field="contactMechTypeId"/>
-
-        <call-service service-name="createContactList" in-map-name="createServiceCtx">
-            <result-to-field result-name="contactListId"/>
-        </call-service>
-        <log level="info" message="========  Created contactListId [${contactListId}] ======="/>
-        <entity-one entity-name="ContactList" value-field="contactList"/>
-        <assert>
-            <not><if-empty field="contactList"/></not>
-            <if-compare-field field="contactList.contactListTypeId" to-field="contactListTypeId" operator="equals"/>
-            <if-compare-field field="contactList.contactListName" to-field="contactListName" operator="equals"/>
-            <if-compare-field field="contactList.contactMechTypeId" to-field="contactMechTypeId" operator="equals"/>
-        </assert>
-        <check-errors/>
-
-        <!-- update contact list -->
-        <set field="contactListTypeId" value="ANNOUNCEMENT"/>
-        <set field="contactListName" value="Announcement Records" type="String"/>
-        <set field="contactMechTypeId" value="POSTAL_ADDRESS"/>
-
-        <!-- preparing new map for updateContactList service -->
-        <set field="updateServiceCtx.userLogin" from-field="userLogin"/>
-        <set field="updateServiceCtx.contactListTypeId" from-field="contactListTypeId"/>
-        <set field="updateServiceCtx.contactListName" from-field="contactListName"/>
-        <set field="updateServiceCtx.contactMechTypeId" from-field="contactMechTypeId"/>
-        <set field="updateServiceCtx.contactListId" from-field="contactListId"/>
-        <call-service service-name="updateContactList" in-map-name="updateServiceCtx"/>
-
-        <entity-one entity-name="ContactList" value-field="contactList"/>
-        <assert>
-            <not><if-empty field="contactList"/></not>
-            <if-compare-field field="contactList.contactListTypeId" to-field="contactListTypeId" operator="equals"/>
-            <if-compare-field field="contactList.contactListName" to-field="contactListName" operator="equals"/>
-            <if-compare-field field="contactList.contactMechTypeId" to-field="contactMechTypeId" operator="equals"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-</simple-methods>
diff --git a/applications/marketing/src/main/groovy/org/apache/ofbiz/marketing/MarketingTests.groovy b/applications/marketing/src/main/groovy/org/apache/ofbiz/marketing/MarketingTests.groovy
new file mode 100644
index 0000000..412c23c
--- /dev/null
+++ b/applications/marketing/src/main/groovy/org/apache/ofbiz/marketing/MarketingTests.groovy
@@ -0,0 +1,82 @@
+/*
+ * 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 applications.marketing.src.main.groovy.org.apache.ofbiz.marketing
+
+import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.service.ServiceUtil
+import org.apache.ofbiz.service.testtools.OFBizTestCase
+
+class MarketingTests extends OFBizTestCase {
+    public MarketingTests(String name) {
+        super(name)
+    }
+
+    void testCreateAndUpdateContactList() {
+        /* Precondition:
+        Create contact list
+        1. Go to the Marketing Manager
+        2. Select the Contact List menu item
+        3. Click Create New Contact List
+        4. Enter fields in contact list form
+
+        Edit contact list
+        1. Go to edit contact list screen
+        2. Add / modify fields
+        3. Click on save
+
+        process tested by test case:
+
+        1. This test the process for create and update contact list
+
+        Post condition: Contact list should be created and updated successfully
+        */
+
+        //create contact list
+        Map serviceCtx = [
+                contactListTypeId: "ANNOUNCEMENT",
+                contactListName: "Announcement List",
+                contactMechTypeId: "EMAIL_ADDRESS",
+                userLogin: userLogin
+        ]
+        Map serviceResult = dispatcher.runSync("createContactList", serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        String contactListId = serviceResult.contactListId
+
+        GenericValue contactList = from("ContactList").where("contactListId", contactListId).queryOne()
+        assert contactList != null
+        assert contactList.contactMechTypeId == "EMAIL_ADDRESS"
+
+        //update contact list
+        serviceCtx = [
+                contactListTypeId: "ANNOUNCEMENT",
+                contactListName: "Announcement Records",
+                contactMechTypeId: "POSTAL_ADDRESS",
+                contactListId: contactListId,
+                userLogin: userLogin
+        ]
+        serviceResult = dispatcher.runSync("updateContactList", serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        contactList.refresh()
+
+        assert contactList != null
+        assert contactList.contactMechTypeId == "POSTAL_ADDRESS"
+    }
+
+}
\ No newline at end of file
diff --git a/applications/marketing/testdef/MarketingTests.xml b/applications/marketing/testdef/MarketingTests.xml
index 384a1fc..18ed5d1 100644
--- a/applications/marketing/testdef/MarketingTests.xml
+++ b/applications/marketing/testdef/MarketingTests.xml
@@ -22,6 +22,6 @@
         xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd">
 
     <test-case case-name="marketing-tests">
-        <simple-method-test location="component://marketing/minilang/marketing/test/MarketingTests.xml"/>
+        <junit-test-suite class-name="applications.marketing.src.main.groovy.org.apache.ofbiz.marketing.MarketingTests"/>
     </test-case>
 </test-suite>