springtestdbunit / spring-test-dbunit

Integration between the Spring testing framework and DBUnit
http://springtestdbunit.github.com/spring-test-dbunit/
Apache License 2.0
476 stars 238 forks source link

Allow specifying dataSetLoader in @DtabaseSetup/@ExpectedDatabase/@DatabaseTearDown #162

Open pavel-kalmykov opened 5 years ago

pavel-kalmykov commented 5 years ago

All of my datasets use the FlatXmlDataSet format, but now I need to compare some HTML strings. To achieve that, I need to use the XmlDataSet format so I can wrap my expected HTML into a CDATA tag (because writing it in an attribute using the FlatXmlDataSet format is impossible due to XML limitations).

Currently, I can set up @DbUnitConfiguration(dataSetLoader = XmlDataSetLoader.class), but that would mean I would need to rewrite all of my already created datasets (or at least the ones I created for the class).

Is there any possibility to set a dataSetLoader atomically to a specific dataset to load (@DatabaseSetup, @ExpectedDatabase, @DatabaseTearDown)? It would be very useful.

Thanks in advance.

ppodgorsek commented 5 years ago

Is there a reason you cannot split that test class into 2 separate ones? You would then be able to define the @DbUnitConfiguration per test class.

pavel-kalmykov commented 5 years ago

Because I use a FlatXmlDataSet for the setup and a XmlDataSet for the expected data (which contains the HTML). I could modify the first one to be a XmlDataSet as well, but anyway what I proposed would be a nice feature to have.

ppodgorsek commented 5 years ago

Could you provide examples of such files please? Although I can understand the purpose of different loaders for different test classes/methods, I'm struggling to understand why the same test would use different loaders for the sample and expected data. It'll probably be easier to see the added value with an example.

pavel-kalmykov commented 5 years ago

So I have this schema: image and I want to test a save method for the versiones_plantilla table. But, for that, I need to populate the plantilla table previously:

<!DOCTYPE dataset SYSTEM "../schema.dtd">
<dataset>
  <PLANTILLAS COD_PLANTILLA="1" DES_PLANTILLA="Plantilla de prueba"/>
</dataset>

(that's the one I told you I could migrate to a XmlDataSet)

And this is what I expect versiones_plantilla to have once I inserted a new row on it:

<!DOCTYPE dataset SYSTEM "../xmlschema.dtd">
<dataset>
    <table name="VERSIONES_PLANTILLA">
        <column>COD_PLANTILLA</column>
        <column>COD_CANAL</column>
        <column>COD_IDIOMA</column>
        <column>DES_CUERPO_PLANTILLA</column>
        <column>IND_FORMATEO_PERSONALIZADO</column>
        <row>
            <value>1</value>
            <value>MAIL</value>
            <value>ES</value>
            <value><![CDATA[<html>

<head>
    <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
    <meta name=Generator content="Microsoft Word 15 (filtered)">
    <script type="text/javascript"
            src="https://gc.kis.v2.scr.kaspersky-labs.com/A7EF89DD-49B2-F746-9205-E0F5C53F8442/main.js"
            charset="UTF-8"></script>
    <style>
        /* Font Definitions */
        @font-face {
            font-family: "Cambria Math";
            panose-1: 2 4 5 3 5 4 6 3 2 4;
        }

        @font-face {
            font-family: Calibri;
            panose-1: 2 15 5 2 2 2 4 3 2 4;
        }

        /* Style Definitions */
        p.MsoNormal,
        li.MsoNormal,
        div.MsoNormal {
            margin-top: 0cm;
            margin-right: 0cm;
            margin-bottom: 8.0pt;
            margin-left: 0cm;
            line-height: 106%;
            font-size: 11.0pt;
            font-family: "Calibri", sans-serif;
        }

        a:link,
        span.MsoHyperlink {
            color: blue;
            text-decoration: underline;
        }

        a:visited,
        span.MsoHyperlinkFollowed {
            color: #954F72;
            text-decoration: underline;
        }

        p {
            margin-right: 0cm;
            margin-left: 0cm;
            font-size: 12.0pt;
            font-family: "Times New Roman", serif;
        }

        .MsoChpDefault {
            font-family: "Calibri", sans-serif;
        }

        .MsoPapDefault {
            margin-bottom: 8.0pt;
            line-height: 107%;
        }

        @page WordSection1 {
            size: 841.9pt 595.3pt;
            margin: 3.0cm 70.85pt 3.0cm 70.85pt;
        }

        div.WordSection1 {
            page: WordSection1;
        }
    </style>

</head>

<body lang=ES link=blue vlink="#954F72">

<div class=WordSection1>

    <p style='margin:0cm;margin-bottom:.0001pt'><span style='font-family:"Calibri",sans-serif;
color:black'>Comunicamos la incidencia producida y la siguiente propuesta de
                inhabilitación:</span></p>

    <p style='margin:0cm;margin-bottom:.0001pt'><b><span style='font-family:"Calibri",sans-serif;
color:black'>Resolución:</span></b><span style='font-family:"Calibri",sans-serif;
color:black'> Positiva </span></p>

    <p style='margin:0cm;margin-bottom:.0001pt'><span style='font-family:"Calibri",sans-serif;
color:black'>Conductor: Juan</span></p>

    <p style='margin:0cm;margin-bottom:.0001pt'><span style='font-family:"Calibri",sans-serif;
color:black'>Rogamos traslade esta información al transportista.</span></p>

    <p style='margin:0cm;margin-bottom:.0001pt'><span style='font-family:"Calibri",sans-serif;
color:black'>&nbsp;</span></p>
</div>

<p>This is a sample footer</p>
</body>

</html>]]></value>
            <value>Y</value>
        </row>
    </table>
</dataset>