31
31
import org .exist .test .ExistEmbeddedServer ;
32
32
import org .exist .test .TestConstants ;
33
33
import org .exist .util .DatabaseConfigurationException ;
34
+ import org .exist .util .FileInputSource ;
34
35
import org .exist .util .FileUtils ;
35
36
import org .exist .util .LockException ;
36
37
import org .exist .xmldb .XmldbURI ;
37
38
import org .junit .Ignore ;
38
39
import org .junit .Rule ;
39
40
import org .junit .Test ;
41
+ import org .xml .sax .InputSource ;
40
42
41
43
import java .io .IOException ;
42
44
import java .nio .file .Files ;
51
53
*/
52
54
public abstract class AbstractRecoverTest {
53
55
54
- private static final boolean COMMIT = true ;
55
- private static final boolean NO_COMMIT = false ;
56
+ protected static final boolean COMMIT = true ;
57
+ protected static final boolean NO_COMMIT = false ;
56
58
57
- private static final boolean MUST_EXIST = true ;
58
- private static final boolean MUST_NOT_EXIST = false ;
59
+ protected static final boolean MUST_EXIST = true ;
60
+ protected static final boolean MUST_NOT_EXIST = false ;
59
61
60
62
/**
61
63
* We set useTemporaryStorage=true for ExistEmbeddedServer
@@ -599,7 +601,7 @@ public void replaceWithoutCommitThenDeleteWithoutCommitAndLoad_isRepeatable() th
599
601
* unfinished (i.e. neither committed, aborted, or closed)
600
602
* @param file The file that to store
601
603
*/
602
- private void store (final boolean commitAndClose , final Path file ) throws EXistException , PermissionDeniedException ,
604
+ protected void store (final boolean commitAndClose , final Path file ) throws EXistException , PermissionDeniedException ,
603
605
IOException , TriggerException , LockException {
604
606
store (commitAndClose , file , FileUtils .fileName (file ));
605
607
}
@@ -614,6 +616,20 @@ private void store(final boolean commitAndClose, final Path file) throws EXistEx
614
616
*/
615
617
private void store (final boolean commitAndClose , final Path file , final String dbFilename ) throws EXistException ,
616
618
PermissionDeniedException , IOException , TriggerException , LockException {
619
+ store (commitAndClose , new FileInputSource (file ), dbFilename );
620
+ }
621
+
622
+ /**
623
+ * Store a document into the database.
624
+ *
625
+ * @param commitAndClose true if the transaction should be committed. false will leave the transaction
626
+ * unfinished (i.e. neither committed, aborted, or closed)
627
+ * @param data The data to store in the document
628
+ * @param dbFilename the name to use when storing the file in the database
629
+ */
630
+ protected void store (final boolean commitAndClose , final InputSource data , final String dbFilename ) throws EXistException ,
631
+ PermissionDeniedException , IOException , TriggerException , LockException {
632
+
617
633
final BrokerPool pool = existEmbeddedServer .getBrokerPool ();
618
634
final TransactionManager transact = pool .getTransactionManager ();
619
635
@@ -625,7 +641,7 @@ private void store(final boolean commitAndClose, final Path file, final String d
625
641
assertNotNull (root );
626
642
broker .saveCollection (transaction , root );
627
643
628
- storeAndVerify (broker , transaction , root , file , dbFilename );
644
+ storeAndVerify (broker , transaction , root , data , dbFilename );
629
645
630
646
if (commitAndClose ) {
631
647
transaction .commit ();
@@ -640,11 +656,11 @@ private void store(final boolean commitAndClose, final Path file, final String d
640
656
* @param broker The database broker
641
657
* @param transaction The database transaction
642
658
* @param collection The Collection into which the document should be stored
643
- * @param file The file which holds the content for the document to store in the database
659
+ * @param data The content for the document to store in the database
644
660
* @param dbFilename The name to store the document as in the database
645
661
*/
646
662
protected abstract void storeAndVerify (final DBBroker broker , final Txn transaction , final Collection collection ,
647
- final Path file , final String dbFilename ) throws EXistException , PermissionDeniedException ,
663
+ final InputSource data , final String dbFilename ) throws EXistException , PermissionDeniedException ,
648
664
IOException , TriggerException , LockException ;
649
665
650
666
/**
@@ -667,6 +683,18 @@ private void read(final boolean shouldExist, final Path file)
667
683
*/
668
684
private void read (final boolean shouldExist , final Path file , final String dbFilename )
669
685
throws EXistException , PermissionDeniedException , IOException {
686
+ read (shouldExist , new FileInputSource (file ), dbFilename );
687
+ }
688
+
689
+ /**
690
+ * Read a document from the database.
691
+ *
692
+ * @param shouldExist true if the document should exist in the database, false if the document should not exist
693
+ * @param data The data that was previously stored
694
+ * @param dbFilename The name of the file to read from the database
695
+ */
696
+ protected void read (final boolean shouldExist , final InputSource data , final String dbFilename )
697
+ throws EXistException , PermissionDeniedException , IOException {
670
698
final BrokerPool pool = existEmbeddedServer .getBrokerPool ();
671
699
try (final DBBroker broker = pool .get (Optional .of (pool .getSecurityManager ().getSystemSubject ()))) {
672
700
final XmldbURI uri = TestConstants .TEST_COLLECTION_URI .append (dbFilename );
@@ -677,7 +705,7 @@ private void read(final boolean shouldExist, final Path file, final String dbFil
677
705
} else {
678
706
assertNotNull ("Document does not exist in the database: " + uri , doc );
679
707
680
- readAndVerify (broker , doc , file , dbFilename );
708
+ readAndVerify (broker , doc , data , dbFilename );
681
709
}
682
710
}
683
711
}
@@ -687,11 +715,11 @@ private void read(final boolean shouldExist, final Path file, final String dbFil
687
715
*
688
716
* @param broker The database broker.
689
717
* @param doc The document from the database.
690
- * @param file The file that was previously stored
718
+ * @param data The data that was previously stored
691
719
* @param dbFilename The name of the file read from the database
692
720
*/
693
721
protected abstract void readAndVerify (final DBBroker broker , final DocumentImpl doc ,
694
- final Path file , final String dbFilename ) throws EXistException , PermissionDeniedException , IOException ;
722
+ final InputSource data , final String dbFilename ) throws EXistException , PermissionDeniedException , IOException ;
695
723
696
724
/**
697
725
* Delete a document from the database.
@@ -737,7 +765,7 @@ private void delete(final boolean commitAndClose, final String dbFilename)
737
765
}
738
766
}
739
767
740
- private void flushJournal () {
768
+ protected void flushJournal () {
741
769
final BrokerPool pool = existEmbeddedServer .getBrokerPool ();
742
770
pool .getJournalManager ().get ().flush (true , false );
743
771
}
0 commit comments