Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-11247

Providing utilities for integration tests

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • ALL APPLICATIONS, framework
    • None

    Description

      At https://markmail.org/message/bdf4ntvwwdl4hxtx mthl suggested:

      In order to avoid repetitive code a nice first helper method would be
      for example one for retrieving the default userLogin like what is done
      in 'QuoteTests.groovy'

          // Retrieves a particular login record.
          GenericValue getUserLogin(String userLoginId) {
              GenericValue userLogin = EntityQuery.use(delegator)
                      .from('UserLogin').where(userLoginId: userLoginId).queryOne()
              assert userLogin
              return userLogin
          }
      

      We could even add a default login user.

          // Retrieves the default login record.
          GenericValue getUserLogin() {
              return getUserLogin('system');
          }
      

      I guess we should add such method directly in the 'OFBizTestCase' class
      to be able to reuse it in all test cases and avoid having to pass the
      'delegator' and 'dispatcher' as method arguments.

      The creation of the service input map of your example would look like
      this:

           void testSendOrderChangeNotification() {
               Map serviceCtx = [
                   orderId: 'TEST_DEMO10090',
                   sendTo: 'test_email@example.com',
                   userLogin: getUserLogin()
               ]
               Map serviceResult = dispatcher.runSync('sendOrderChangeNotification', serviceCtx)
               assert ServiceUtil.isSuccess(serviceResult)
               assert serviceResult.emailType.equals("PRDS_ODR_CHANGE")
           }
      

      In any case I think that finding the generic and reusable helper methods
      can be done incrementally.

      Attachments

        1. OFBIZ-11247.patch
          2 kB
          Pawan Verma
        2. OFBIZ-11247.patch
          0.8 kB
          Pawan Verma

        Activity

          We can start with above Mathieu's proposition

          jleroux Jacques Le Roux added a comment - We can start with above Mathieu's proposition

          First step to simply using "userLogin" in tests implemeted at revision: 1868436

          jleroux Jacques Le Roux added a comment - First step to simply using "userLogin" in tests implemeted at revision: 1868436
          pawan Pawan Verma added a comment -

          OFBIZ-11247.patch

          Attaching a patch to add EntityQuery in the OFBizTestCase same as in GroovyBaseScript.groovy and use from() and select() methods directly in the Groovy test cases.

          If this looks good, we can commit it and I'll work on its application in our existing test cases.

          pawan Pawan Verma added a comment - OFBIZ-11247.patch Attaching a patch to add EntityQuery in the OFBizTestCase same as in GroovyBaseScript.groovy and use from() and select() methods directly in the Groovy test cases. If this looks good, we can commit it and I'll work on its application in our existing test cases.

          Sounds like a good idea Pawan, the patch looks good to me.

          Just a question, not sure it's needed: why not extend to all what EntityQuery class provides? I mean where, DynamicViewEntity, etc.

          jleroux Jacques Le Roux added a comment - Sounds like a good idea Pawan, the patch looks good to me. Just a question, not sure it's needed: why not extend to all what EntityQuery class provides? I mean where, DynamicViewEntity, etc.
          pawan Pawan Verma added a comment -

          Thanks, jleroux for the review.

          I took reference from GroovyBaseScript.groovy, in that we have from() and select() method. Agree to add DynamicViewEntity. Rest of the methods can be directly called using the from() method like where, cache() etc.

          Attaching a new patch here. OFBIZ-11247.patch

          pawan Pawan Verma added a comment - Thanks, jleroux  for the review. I took reference from GroovyBaseScript.groovy, in that we have from() and select() method. Agree to add DynamicViewEntity. Rest of the methods can be directly called using the from() method like where, cache() etc. Attaching a new patch here.  OFBIZ-11247.patch

          +1 for commit, thank Pawan

          jleroux Jacques Le Roux added a comment - +1 for commit, thank Pawan
          pawan Pawan Verma added a comment -

          Thanks, jleroux for the review. Committed at 1b3d3bdf4e4ebcf3597a2bb97b22c41cbe20cf6c.

          pawan Pawan Verma added a comment - Thanks, jleroux  for the review. Committed at 1b3d3bdf4e4ebcf3597a2bb97b22c41cbe20cf6c.

          People

            Unassigned Unassigned
            jleroux Jacques Le Roux
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: