Menu

Testing for *any* result

2005-01-04
2013-04-25
  • David Fishburn

    David Fishburn - 2005-01-04

    Current CVS.

    I want to write a test where I call a stored procedure  and get a resultset back.

    I do not want to match on the *data* coming back, but I do want to ensure there is 1 row of data, and the data is an INTEGER.

    Think of this situation.
    You insert a new row.
    The data returned is the PK from a SEQUENCE, IDENTITY, AUTOINCREMENT field.

    So, depending on how many times the test was run, I just want to make sure 1 row was returned, and it was an INTEGER.

    I have been reading through the docs, and am thinking this is related to SQLUnit Assertions, but am not getting too far.

    Thanks,
    Dave

     
    • Sujit Pal

      Sujit Pal - 2005-01-06

      Yes, this situation should be handled with Assertions, but there is currently no assertion defined for the case you are looking for. Perhaps something like "resultset-types-equal" should be what you are looking for. I will write this and let you know in one or two days.

      -sujit

       
    • Sujit Pal

      Sujit Pal - 2005-01-19

      Hi Dave,

      I have added the code necessary to do this. Let me know if there are problems.

      -sujit

       
    • David Fishburn

      David Fishburn - 2005-01-27

      Could you show a simple test script for this, and I will try it out.

      Thanks,
      Dave

       
    • Sujit Pal

      Sujit Pal - 2005-01-27

      I have an example in test/mock/assertiontests.xml, called "Testing type-only matching". Its the last one. You could replace 1001 by 0 for example.

      -sujit

       
    • sica79

      sica79 - 2006-01-06

      Hy! My Name is Marius Soimusan and I have the same problem with you. I tried your solution but it doesn't work. In fact I want to call a store procedure (SqlServer) and only verify that it returns 1 row.
      Here is my example:
      <test name="2-Get Next Message For Session">
      <call>
      <stmt>{call DL_GetNextMessageForSession(?,?)}</stmt>
      <param id="1" type="INTEGER" inout="in">${SessionID}</param>
      <param id="2" type="INTEGER" inout="in">${SessionStartTimestamp}</param>
      </call>
      <result>
      <resultset id="1" rowcount="1" />
      </result>
      </test>

      thanks

       
    • Sujit Pal

      Sujit Pal - 2006-01-07

      Hi Marius,

      I was able to run a similar test as yours. Here is my test:
        <test name="Testing rowcount functionality">
          <call>
            <stmt>aSimpleResult</stmt>
          </call>
          <result>
            <resultset id="1" rowcount="1" />
          </result>
        </test>

      and here is my result:
        [sqlunit] Running test[37]: Testing rowcount functionality (9ms)

      when I change the rowcount to "2", I get:
        [sqlunit] Assertion "resultsets-equal" failed (2 != 1 at result[1].rowcount)
        [sqlunit] *** expected:
        [sqlunit] <result>
        [sqlunit]   <resultset id="1" rowcount="2" />
        [sqlunit] </result>
        [sqlunit] *** but got:
        [sqlunit] <result>
        [sqlunit]   <resultset id="1">
        [sqlunit]     <row id="1">
        [sqlunit]       <col id="1" name="col1" type="INTEGER">1</col>
        [sqlunit]     </row>
        [sqlunit]   </resultset>
        [sqlunit] </result>

      which is also what I expect. Can you check and see if you got everything the same way or if there are differences?

      And when you say it does not work, I take it you mean that the test fails when you expect it to succeed, is that right? Or are you getting some sort of exception?

      Thanks
      Sujit

       
    • sica79

      sica79 - 2006-01-09

      Hy Sujit!

      First of all thank you for your help! :)
      The result for my test in the log file is this:
      [sqlunit] Running test[3]: 1-Get Next Message For Session (711ms)
      [sqlunit] At ${result[3,1,2]}, could not convert java.lang.Integer returned from database to TINYINT(-6)

      Because the SP it returns 8 cols with diferent data types. For those columns with types like TINYINT ar SMALLINT I have this message. If I convert those columns to INT type It works but I dont want to change the types of the result columns of my StoredProcedure. I think there is a way to check only the rowcount without verifying the types for each columns in the result set of my SP.

      thanks

       
    • sica79

      sica79 - 2006-01-09

      Hy Sujit!

      I did it! :) I created the file usertypes.properties in the etc dir of my SQLUnit installation dir and I remaped the types TINYINT and SMALLINT to IntegerType (Java) for microsoft_sql_server. If you are interested:

      microsoft_sql_server.SMALLINT.class = net.sourceforge.sqlunit.types.IntegerType
      microsoft_sql_server.SMALLINT.type = 5

      microsoft_sql_server.TINYINT.class = net.sourceforge.sqlunit.types.IntegerType
      microsoft_sql_server.TINYINT.type = -6

      Thanks a lot and have a good day :)

       
    • Sujit Pal

      Sujit Pal - 2006-01-10

      Hi Marius,

      Thank you very much. The fix was submitted by Andrew Arch recently though, and I uploaded it to CVS. This is post version 4.9 though. I will include both of you in the credits for the next release.

      Thanks again,
      -sujit

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.