Project

General

Profile

« Previous | Next » 

Revision 96dc2943

Added by Andreas Müller over 4 years ago

ref #8508 add first ERMS pipeline tests

View differences:

cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/erms/validation/PesiErmsValidator.java
8 8
*/
9 9
package eu.etaxonomy.cdm.io.pesi.erms.validation;
10 10

  
11
import java.sql.ResultSet;
12
import java.sql.SQLException;
13

  
11 14
import org.apache.log4j.Logger;
12 15

  
13 16
import eu.etaxonomy.cdm.app.pesi.PesiDestinations;
......
15 18
import eu.etaxonomy.cdm.io.common.Source;
16 19

  
17 20
/**
21
 * Tests the ERMS -> PESI pipeline by comparing the source DB with destination PESI DB.
22
 *
18 23
 * @author a.mueller
19 24
 * @since 01.09.2019
20 25
 */
......
29 34
    private Source destination = defaultDestination;
30 35

  
31 36
    public void invoke(Source source, Source destination){
37
        boolean success = true;
32 38
        this.source = source;
33 39
        this.destination = destination;
34
        testReferences();
35
        testTaxa();
36
        testTaxonRelations();
40
        success &= testReferences();
41
        success &= testTaxa();
42
        success &= testTaxonRelations();
37 43
        //TBC
38
        System.out.println("end validation");
44
        System.out.println("end validation " + (success? "":"NOT ") + "successful.");
39 45
    }
40 46

  
41
    /**
42
     *
43
     */
44
    private void testTaxonRelations() {
45
        // TODO Auto-generated method stub
47
    private boolean testTaxonRelations() {
48
        boolean success = true;
49
        return success;
46 50
    }
47 51

  
48
    private void testTaxa() {
49
        testTaxaCount();
52
    private boolean testTaxa() {
53
        boolean success = testTaxaCount();
54
        return success;
50 55
    }
51 56

  
52
    /**
53
     *
54
     */
55
    private void testTaxaCount() {
57
    private boolean testTaxaCount() {
56 58
        int countSrc = source.getUniqueInteger("SELECT count(*) FROM tu ");
57 59
        int countDest = destination.getUniqueInteger("SELECT count(*) FROM Taxon ");
58
        equals("Taxon count ", countSrc, countDest);
60
        return equals("Taxon count ", countSrc, countDest);
59 61
    }
60 62

  
61
    private void testReferences() {
62
        testReferenceCount();
63
        testSingleReferences();
64
        //TOD TBC
63
    private boolean testReferences() {
64
        boolean success = testReferenceCount();
65
        if (success){
66
            try {
67
                success &= testSingleReferences();
68
            } catch (SQLException e) {
69
                e.printStackTrace();
70
            }
71
        }
72
        return success;
65 73
    }
66 74

  
67
    /**
68
     *
69
     */
70
    private void testSingleReferences() {
71
        srcRS = source.getResultSet("SELECT count(*) FROM sources ");
72
        int countDest = destination.getUniqueInteger("SELECT count(*) FROM Source s WHERE s.OriginalDB = 'erms'");  // +1 for the source reference "erms" but this has no OriginalDB
75
    private boolean testSingleReferences() throws SQLException {
76
        boolean success = true;
77
        ResultSet srcRS = source.getResultSet("SELECT s.* FROM sources s ORDER BY s.id ");
78
        ResultSet destRS = destination.getResultSet("SELECT s.* FROM Source s "
79
                + " WHERE s.OriginalDB = 'erms' ORDER BY s.RefIdInSource");  // +1 for the source reference "erms" but this has no OriginalDB
80
        if (srcRS.next() && destRS.next()){
81
            success &= testSingleReference(srcRS, destRS);
82
        }
83
        return success;
84
    }
73 85

  
86
    private boolean testSingleReference(ResultSet srcRS, ResultSet destRS) throws SQLException {
87
        //id, RefIdInSource
88
        boolean success = equals("Reference ID ", srcRS.getInt("id"), destRS.getInt("RefIdInSource"));
74 89

  
90
        //TODO TBC
91
        return success;
75 92
    }
76 93

  
77
    private void testReferenceCount() {
94
    private boolean testReferenceCount() {
78 95
        int countSrc = source.getUniqueInteger("SELECT count(*) FROM sources ");
79 96
        int countDest = destination.getUniqueInteger("SELECT count(*) FROM Source s WHERE s.OriginalDB = 'erms'");  // +1 for the source reference "erms" but this has no OriginalDB
80
        equals("Reference count ", countSrc, countDest);
97
        boolean success = equals("Reference count ", countSrc, countDest);
98
        return success;
81 99
    }
82 100

  
83
    private void equals(String messageStart, int nSrc, int nDest) {
101
    private boolean equals(String messageStart, int nSrc, int nDest) {
84 102
        if (nSrc != nDest){
85 103
            String message = messageStart + " must be equal, but was not. Source: "+  nSrc + "; Destination: " + nDest;
86 104
            logger.warn(message);
105
            return false;
87 106
        }else{
88 107
            logger.info(messageStart + " were equal: " + nSrc);
108
            return true;
89 109
        }
90 110
    }
91 111

  

Also available in: Unified diff