Project

General

Profile

Revision a400c76f

IDa400c76fcbbe92ca47c01798c378a44bf73a3e4d
Parent b1e975a8
Child a8ef58b2, 093a2fae

Added by Andreas Kohlbecker about 2 years ago

fix #7795 untilis xml DataSets can optionally be created without "[NULL]" values

View differences:

cdmlib-ext/src/test/java/eu/etaxonomy/cdm/ext/geo/EditGeoServiceTest.java
444 444
                "DESCRIPTIONBASE", "DESCRIPTIONELEMENTBASE",
445 445
                "HIBERNATE_SEQUENCES" // IMPORTANT!!!
446 446
                },
447
                "getDistributionServiceRequestParameterString" );
447
                "getDistributionServiceRequestParameterString", true );
448 448

  
449 449
    }
450 450

  
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/AbcdGgbnImportTest.java
690 690
        try {
691 691
            writeDbUnitDataSetFile(new String[] {
692 692
                    "SpecimenOrObservationBase",
693
            }, "testAttachDnaSampleToDerivedUnit");
693
            }, "testAttachDnaSampleToDerivedUnit", true);
694 694
        } catch (FileNotFoundException e) {
695 695
            e.printStackTrace();
696 696
        }
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/SpecimenImportConfiguratorTest.java
746 746
                    "TaxonNode",
747 747
                    "Classification",
748 748
                    "LanguageString"
749
            }, "testImportTwoUnitsOfSameTaxonIntoExistingClassification");
749
            }, "testImportTwoUnitsOfSameTaxonIntoExistingClassification", true);
750 750
        } catch (FileNotFoundException e) {
751 751
            e.printStackTrace();
752 752
        }
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/PreferenceDaoTest.java
162 162
            "HOMOTYPICALGROUP",
163 163
            "HIBERNATE_SEQUENCES" // IMPORTANT!!!
164 164
            },
165
            fileNameAppendix );
165
            fileNameAppendix, true );
166 166
    }
167 167
}
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/ClassificationDaoHibernateImplTest.java
435 435
	        "LANGUAGESTRING",
436 436
	        "HIBERNATE_SEQUENCES" // IMPORTANT!!!
437 437
	        },
438
	        fileNameAppendix );
438
	        fileNameAppendix, true );
439 439
  }
440 440

  
441 441
}
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/initializer/AdvancedBeanInitializerTest.java
395 395
            "",
396 396
            "HIBERNATE_SEQUENCES" // IMPORTANT!!!
397 397
            },
398
            fileNameAppendix );
398
            fileNameAppendix, true );
399 399

  
400 400
    }
401 401

  
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/ClassificationServiceImplTest.java
503 503
            "LANGUAGESTRING", "HOMOTYPICALGROUP",
504 504
            "HIBERNATE_SEQUENCES" // IMPORTANT!!!
505 505
            },
506
            fileNameAppendix );
506
            fileNameAppendix, true );
507 507

  
508 508
    }
509 509
}
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/IdentifiableServiceBaseTest.java
341 341
		        "CLASSIFICATION", "TAXONNODE",
342 342
		        "HOMOTYPICALGROUP",
343 343
		        "TERMVOCABULARY"
344
		 }, "xxxx");
344
		 }, "xxxx", true);
345 345

  
346 346
    }
347 347

  
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceDeepDeleteTest.java
503 503
                    "TaxonName",
504 504
                    "TaxonName_TypeDesignationBase",
505 505
                    "HomotypicalGroup"
506
            }, "testDeepDelete_SingleRead");
506
            }, "testDeepDelete_SingleRead", true);
507 507
        } catch (FileNotFoundException e) {
508 508
            e.printStackTrace();
509 509
        }
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceTest.java
1667 1667
                  "TeamOrPersonBase",
1668 1668
                  "LanguageString",
1669 1669
                  "DeterminationEvent"
1670
          }, "testAllKindsOfSpecimenAssociations");
1670
          }, "testAllKindsOfSpecimenAssociations", true);
1671 1671
      } catch (FileNotFoundException e) {
1672 1672
          e.printStackTrace();
1673 1673
      }
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImplTest.java
1250 1250
            "LANGUAGESTRING",
1251 1251
            "HIBERNATE_SEQUENCES" // IMPORTANT!!!
1252 1252
            },
1253
            fileNameAppendix );
1253
            fileNameAppendix, true );
1254 1254
    }
1255 1255

  
1256 1256

  
cdmlib-test/src/main/java/eu/etaxonomy/cdm/database/DataBaseTablePrinter.java
166 166
    public void printDataSetWithNull(OutputStream out, Boolean excludeTermLoadingTables,
167 167
            ITableFilterSimple excludeFilterOrig, String[] includeTableNames) {
168 168

  
169
        printDataSet(out, excludeTermLoadingTables, excludeFilterOrig, includeTableNames, true);
170

  
171
    }
172

  
173
    public void printDataSet(OutputStream out, Boolean excludeTermLoadingTables,
174
                ITableFilterSimple excludeFilterOrig, String[] includeTableNames, boolean withNull) {
175

  
169 176
        ITableFilterSimple excludeFilter = excludeFilterOrig;
170 177
        if(excludeTermLoadingTables != null && excludeTermLoadingTables.equals(true)){
171 178
            ExcludeTableFilter excludeTableFilter = new ExcludeTableFilter();
......
192 199
                }
193 200
                dataSet = new DatabaseDataSet(connection, false, excludeFilter);
194 201
            }
195
            FlatFullXmlWriter writer = new FlatFullXmlWriter(out);
202
            FlatFullXmlWriter writer = new FlatFullXmlWriter(out, withNull);
196 203
            writer.write(dataSet);
197 204
        } catch (Exception e) {
198 205
            logger.error("Error on writing dataset:", e);
......
396 403
     *
397 404
     */
398 405
    public void writeDbUnitDataSetFile(String[] includeTableNames, Class<?> testClass) throws FileNotFoundException {
399
        writeDbUnitDataSetFile(includeTableNames, testClass, null);
406
        writeDbUnitDataSetFile(includeTableNames, testClass, null, true);
400 407
    }
401 408

  
402 409
    /**
......
407 414
     * @param methodName the appendix of the generated DbUnit dataset file
408 415
     * @see {@link #writeDbUnitDataSetFile(String[], Class)}
409 416
     */
410
    public void writeDbUnitDataSetFile(String[] includeTableNames, Class<?> testClass, String methodName) throws FileNotFoundException {
417
    public void writeDbUnitDataSetFile(String[] includeTableNames, Class<?> testClass, String methodName, boolean withNullValues) throws FileNotFoundException {
411 418

  
412 419
        String pathname = "src" + File.separator + "test" + File.separator + "resources" + File.separator + testClass.getName().replace(".", File.separator);
413 420
        if(methodName!=null){
......
427 434
            file.getParentFile().mkdirs();
428 435
        }
429 436

  
430
        printDataSetWithNull(
431
            new FileOutputStream(file),
432
            false,
433
            null,
434
            includeTableNames
435
         );
437
        printDataSet(
438
                new FileOutputStream(file),
439
                false,
440
                null,
441
                includeTableNames,
442
                withNullValues
443
             );
436 444
    }
437 445

  
438 446
    /**
cdmlib-test/src/main/java/eu/etaxonomy/cdm/test/integration/CdmIntegrationTest.java
26 26
import org.dbunit.database.DatabaseConnection;
27 27
import org.dbunit.database.IDatabaseConnection;
28 28
import org.dbunit.dataset.filter.ITableFilterSimple;
29
import org.dbunit.dataset.xml.FlatXmlDataSet;
30 29
import org.dbunit.ext.h2.H2DataTypeFactory;
31 30
import org.h2.tools.Server;
32 31
import org.junit.Before;
......
34 33
import org.springframework.transaction.support.DefaultTransactionDefinition;
35 34
import org.unitils.UnitilsJUnit4;
36 35
import org.unitils.database.annotations.TestDataSource;
37
import org.unitils.dbunit.util.MultiSchemaXmlDataSetReader;
38 36
import org.unitils.orm.hibernate.annotation.HibernateSessionFactory;
39 37
import org.unitils.spring.annotation.SpringApplicationContext;
40 38
import org.unitils.spring.annotation.SpringBeanByType;
41 39

  
42 40
import eu.etaxonomy.cdm.database.DataBaseTablePrinter;
43 41
import eu.etaxonomy.cdm.model.common.CdmBase;
44
import eu.etaxonomy.cdm.test.unitils.FlatFullXmlWriter;
45 42

  
46 43
/**
47 44
 * Abstract base class for integration testing a spring / hibernate application using
......
376 373
     * @throws FileNotFoundException
377 374
     * @see #writeDbUnitDataSetFile(String[])
378 375
     */
379
    public void writeDbUnitDataSetFile(String[] includeTableNames, String fileAppendix) throws FileNotFoundException {
380
        dbTablePrinter.writeDbUnitDataSetFile(includeTableNames, this.getClass(), fileAppendix);
376
    public void writeDbUnitDataSetFile(String[] includeTableNames, String fileAppendix, boolean withNullValues) throws FileNotFoundException {
377
        dbTablePrinter.writeDbUnitDataSetFile(includeTableNames, this.getClass(), fileAppendix, withNullValues);
381 378
    }
382 379

  
383 380
    /**
cdmlib-test/src/main/java/eu/etaxonomy/cdm/test/integration/CdmTransactionalIntegrationTestExample.java
77 77
            "CLASSIFICATION", "TAXONNODE",
78 78
            "HIBERNATE_SEQUENCES" // IMPORTANT!!!
79 79
            },
80
            fileNameAppendix );
80
            fileNameAppendix, true );
81 81
  }
82 82

  
83 83
}
cdmlib-test/src/main/java/eu/etaxonomy/cdm/test/unitils/FlatFullXmlWriter.java
19 19
import org.dbunit.util.xml.XmlWriter;
20 20
import org.slf4j.Logger;
21 21
import org.slf4j.LoggerFactory;
22
import org.unitils.dbunit.util.MultiSchemaXmlDataSetReader;
23 22

  
24 23
/**
25 24
 * This is a variant of the {@link org.dbunit.dataset.xml.FlatXmlWriter}, which in
......
48 47
    private int _activeRowCount;
49 48
    private boolean _includeEmptyTable = false;
50 49
    private String _systemId = null;
50
    private boolean writeNullValues = true;
51 51

  
52 52
    public FlatFullXmlWriter(OutputStream out) throws IOException
53 53
    {
54
        this(out, null);
54
        this(out, null, true);
55
    }
56

  
57
    public FlatFullXmlWriter(OutputStream out, boolean writeNullValues) throws IOException
58
    {
59
        this(out, null, writeNullValues);
55 60
    }
56 61

  
57 62
    /**
......
60 65
     * Can be null. See {@link XmlWriter#XmlWriter(OutputStream, String)}.
61 66
     * @throws UnsupportedEncodingException
62 67
     */
63
    public FlatFullXmlWriter(OutputStream outputStream, String encoding)
68
    public FlatFullXmlWriter(OutputStream outputStream, String encoding, boolean writeNullValues)
64 69
    throws UnsupportedEncodingException
65 70
    {
66 71
        _xmlWriter = new XmlWriter(outputStream, encoding);
67 72
        _xmlWriter.enablePrettyPrint(true);
73
        this.writeNullValues = writeNullValues;
68 74
    }
69 75

  
70 76
    public FlatFullXmlWriter(Writer writer)
......
199 205

  
200 206
                try
201 207
                {
202
                	String stringValue;
208
                	String stringValue = null;
203 209
                	if (value == null)
204 210
                	{
205
                		stringValue = "[null]";
211
                	    if(writeNullValues){
212
                	        stringValue = "[null]";
213
                	    }
206 214
                	} else {
207 215
                		stringValue = DataType.asString(value);
208 216
                	}
209
                    _xmlWriter.writeAttribute(columnName, stringValue, true);
217
                	if(stringValue != null){
218
                	    _xmlWriter.writeAttribute(columnName, stringValue, true);
219
                	}
210 220
                }
211 221
                catch (TypeCastException e)
212 222
                {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)