package dk.statsbiblioteket.newspaper.metadatachecker;

import dk.statsbiblioteket.medieplatform.autonomous.Batch;
import dk.statsbiblioteket.medieplatform.autonomous.ResultCollector;
import dk.statsbiblioteket.medieplatform.autonomous.iterator.common.AttributeParsingEvent;
import dk.statsbiblioteket.medieplatform.autonomous.iterator.common.NodeBeginsParsingEvent;
import dk.statsbiblioteket.medieplatform.autonomous.iterator.common.NodeEndParsingEvent;
import dk.statsbiblioteket.newspaper.metadatachecker.mockers.AltoMocker;
import dk.statsbiblioteket.newspaper.metadatachecker.mockers.MixerMockup;
import org.testng.annotations.Test;

import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;

public class AltoMixCrossCheckEventHandlerTest {

    @Test
    public void goodTest() {
        ResultCollector resultCollector = new ResultCollector("foo", "bar");

        final String batchId = "400022028241";
        final String film = "1";
        final String avisID = "adresseavisen1759";
        final String publishDate = "1795-06";
        final String pictureNumber = "0006";
        final Batch batch = new Batch();
        batch.setBatchID(batchId);
        batch.setRoundTripNumber(1);
        AttributeParsingEvent eventMix = MixerMockup.getMixPageAttributeParsingEvent(
                film, avisID, publishDate, pictureNumber, batch, 2286, 2864, 400, "",15, "microfilm");
        AttributeParsingEvent eventAlto = AltoMocker.getAltoPageAttributeParsingEvent(
                film, avisID, publishDate, pictureNumber, batch, 2286, 2864);
        AltoMixCrossCheckEventHandler handler = new AltoMixCrossCheckEventHandler(resultCollector);
        handler.handleNodeBegin(new NodeBeginsParsingEvent("good"));
        handler.handleAttribute(eventMix);
        handler.handleAttribute(eventAlto);
        handler.handleNodeEnd(new NodeEndParsingEvent("good"));


        assertTrue(resultCollector.isSuccess());


    }

    @Test
    public void badTest() {
        final String batchId = "400022028241";
        final String film = "1";
        final String avisID = "adresseavisen1759";
        final String publishDate = "1795-06";
        final String pictureNumber = "0006";
        final Batch batch = new Batch();
        batch.setBatchID(batchId);
        batch.setRoundTripNumber(1);
        AttributeParsingEvent eventMix = MixerMockup.getMixPageAttributeParsingEvent(
                film, avisID, publishDate, pictureNumber, batch, 2286, 2864, 400,"",15, "microfilm");
        AttributeParsingEvent eventAlto = AltoMocker.getAltoPageAttributeParsingEvent(
                film, avisID, publishDate, pictureNumber, batch, 2285, 2863);
        ResultCollector resultCollector = new ResultCollector("foo", "bar");
        AltoMixCrossCheckEventHandler handler = new AltoMixCrossCheckEventHandler(resultCollector);
        handler.handleNodeBegin(new NodeBeginsParsingEvent("bad"));
        handler.handleAttribute(eventMix);
        handler.handleAttribute(eventAlto);
        handler.handleNodeEnd(new NodeEndParsingEvent("bad"));


        assertFalse(resultCollector.isSuccess());


    }


}

@@ -441,32 +441,107 @@
 ndParsingEvent;%0A
+import dk.statsbiblioteket.newspaper.metadatachecker.caches.DocumentCache;%0A
 import dk.statsb
@@ -597,16 +597,16 @@
 Mocker;%0A
-
 import d
@@ -973,16 +973,75 @@
  %22bar%22);
+%0A        DocumentCache documentCache = new DocumentCache();
 %0A%0A      
@@ -1812,32 +1812,47 @@
 (resultCollector
+, documentCache
 );%0A        handl
@@ -2148,32 +2148,91 @@
 oid badTest() %7B%0A
+        DocumentCache documentCache = new DocumentCache();%0A
         final St
@@ -2972,32 +2972,32 @@
 (%22foo%22, %22bar%22);%0A
-
         AltoMixC
@@ -3077,16 +3077,31 @@
 ollector
+, documentCache
 );%0A     

Test updated for caching