1
0
-1

I need to add a SvcConn to an existing SvcDef parameter in my unit test. How do I create and add a configured SvcConn object to an existing SvcDef object using the Fluent API?

Thanks,

Blake

    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      More context on what you are trying to achieve would be helpful. Do you just need to use different connection parameters in your unit test?

      In this case I would look at adding test parameters to the service containing the test endpoint information.

      You should then be able to update the Service Connection i your test script as follows:

      1. Blake Hunter

        I think the real problem here is that I cannot create a new SvcDef or SvcConn object with the Fluent API. My unit test #invoke method provides me with a SvcDef that is created without a SvcConn and I cannot create a new SvcConn to provide to the SvcConnUpdater that you described above. I think for developers to be able to setup the proper object configuration to create different test case scenarios then we need support from the fluent API to be able to create both SvcDef and SvcConn objects. I simply cannot write my unit test at the moment to test different scenarios.

      2. Ben Warner

        Can you clearly explain your use case as I'm having a lot of trouble trying to understand why you would want to create a new SvcDef in a unit test. The idea of a unit test script is to test an existing SvcDef.

        I also don't understand why you would want to create a new SvcConn and apply it to a SvcDef that does not already have an SvcConn defined. If your SvcDef is created without a SvcConn then simply add the serviceConnection attribute to your service-def.json file as described here and my suggestion above should work for you.

      3. Blake Hunter

        My service under test will take a SvcDef as an input parameter. It will then call a method that takes the SvcDef and gets the SvcConn from that and then gets the Banamex service endpoint from that SvcConn. It does this to generate the full URL that I will need to call an external Banamex Service. 

        This is what the code looks like: 

        If I don't provide my service under test with a service definition (SvcDef) that contains the SvcConn with my endpoint then it will throw an NPE. I need this to make sure that my service is actually working and calling my endpoint. 

        I'm also sure that at some point I will want to create alternate SvcDef and SvcConn objects for other test cases with different configurations to simulate different real world scenarios. 

      4. Ben Warner

        If you need to create additional service definitions then use the Fluent SDK for this, don't try to do it in unit test code. The function above could take a SvcConn object instead of a SvcDef object and still function the same way.

        I can see an edge case for creating new SvcConn objects in test scripts so you may want to request this feature.

      5. Blake Hunter

        The invoke method in my fluent service does not take a SvcConn object so I have no way of passing that object into my service under test. Additionally I should not be making changes to my production code for the sole purpose of supporting a unit test.

        I can only interact with my service under test through objects passed into the #invoke parameters or querying the DB to retrieve persistent entities. We need to have the flexibility to build any an all configurations of any parameter we pass to the fluent service invoke methods so we can drive the different execution paths needed for test cases.

      CommentAdd your comment...
    2.  
      1
      0
      -1

      Hi Blake,

      The short answer is that you cannot do that to an existing SvcDef object.

      SvcDef declares its svcConn member as final, so it cannot be set outside the constructor.

      You can create a new SvcDef object using the constructor which takes a ServiceDefinition as parameter.  That would populate the svcConn member with a new SvcConn object.

      Can you provide a little more information about what you are trying to achieve?

      1. Blake Hunter

        Hi Bill,

        I did attempt to create a new SvcDef object using its constructor with a ServiceDefinition as an argument but I cannot create or even import the ServiceDefinition class into a fluent class as it is part of the restricted core API. So I'm a bit stuck at the moment.

        I am trying to configure the SvcDef to be used by my service to include the SvcConn that I will define with a custom defined endpoint.

        Thanks,

        Blake

      CommentAdd your comment...