/** * Asserts that the nth StoreMessage is regarding the given arc file and that the arc file is * delete if and only if store succeeded. * * @param n The relevant index to marc.getStoreMsgs() * @param arcFile The arc file that was stored * @param shouldSucceed Whether store was supposed to succeed */ private void assertStoreStatus(int n, File arcFile, boolean shouldSucceed) { StoreMessage sm = marc.getStoreMsgs().get(n); assertEquals( "Upload should attempt to upload the specified files", arcFile.getName(), sm.getArcfileName()); if (shouldSucceed) { assertFalse("Upload should delete a properly uploaded file", arcFile.exists()); } else { assertTrue( "Upload should not delete a file that wasn't " + " properly uploaded", arcFile.exists()); } }
/** Disabled, fails on Jenkins */ public void failingTestArcRepositoryCalls() { DatabaseAdmin da = DatabaseAdmin.getInstance(); assertFalse("Should not contain NON-EXISTING-FILE", da.hasEntry("NON-EXISTING-FILE")); assertFalse( "Should not contain StoreMessage for NON-EXISTING-FILE", da.hasReplyInfo("NON-EXISTING-FILE")); StoreMessage storeMsg1 = new StoreMessage(Channels.getError(), TestInfo.TEST_FILE_1); JMSConnectionMockupMQ.updateMsgID(storeMsg1, "store1"); da.addEntry(TestInfo.TEST_FILE_1.getName(), storeMsg1, "1234567890"); // make sure that the test instance can now be found. assertTrue( "Should contain " + TestInfo.TEST_FILE_1.getName(), da.hasEntry(TestInfo.TEST_FILE_1.getName())); assertTrue( "Should have replyInfo for " + TestInfo.TEST_FILE_1.getName(), da.hasReplyInfo(TestInfo.TEST_FILE_1.getName())); assertEquals( "Should have the given checksum", "1234567890", da.getCheckSum(TestInfo.TEST_FILE_1.getName())); // Test the hasState. assertFalse( "Should not yet have a acceptable state", da.hasState(TestInfo.TEST_FILE_1.getName(), ONE.getIdentificationChannel().getName())); da.setState( TestInfo.TEST_FILE_1.getName(), ONE.getIdentificationChannel().getName(), ReplicaStoreState.UPLOAD_STARTED); assertTrue( "Should now have a acceptable state", da.hasState(TestInfo.TEST_FILE_1.getName(), ONE.getIdentificationChannel().getName())); assertEquals( "Should have the same state", da.getState(TestInfo.TEST_FILE_1.getName(), ONE.getIdentificationChannel().getName()), ReplicaStoreState.UPLOAD_STARTED); StoreMessage storeMsg2 = new StoreMessage(Channels.getError(), TestInfo.TEST_FILE_1); JMSConnectionMockupMQ.updateMsgID(storeMsg2, "store2"); da.setReplyInfo(storeMsg2.getArcfileName(), storeMsg2); da.setState( TestInfo.TEST_FILE_1.getName(), ONE.getIdentificationChannel().getName(), ReplicaStoreState.UPLOAD_COMPLETED); da.setState( TestInfo.TEST_FILE_1.getName(), TWO.getIdentificationChannel().getName(), ReplicaStoreState.UPLOAD_COMPLETED); da.setState( TestInfo.TEST_FILE_1.getName(), THREE.getIdentificationChannel().getName(), ReplicaStoreState.UPLOAD_COMPLETED); StoreMessage retrievedMsg = da.removeReplyInfo(TestInfo.TEST_FILE_1.getName()); assertEquals("The message should have the new ID.", "store2", retrievedMsg.getID()); try { da.setCheckSum(TestInfo.TEST_FILE_1.getName(), "0987654321"); fail("An illegal state exception should be thrown here."); } catch (IllegalState e) { // expected } Set<String> filenames = da.getAllFileNames(); assertTrue( "Should contain the file '" + TestInfo.TEST_FILE_1.getName() + "' but was '" + filenames, filenames.contains(TestInfo.TEST_FILE_1.getName())); filenames = da.getAllFileNames(THREE, ReplicaStoreState.UPLOAD_FAILED); assertTrue( "The list of files with state UPLOAD_FAILED for replica " + "THREE should be empty, but it was: " + filenames, filenames.isEmpty()); filenames = da.getAllFileNames(THREE, ReplicaStoreState.UPLOAD_COMPLETED); assertTrue( "The list of files with state UPLOAD_COMPLETED for replica " + "THREE should contain the file: '" + TestInfo.TEST_FILE_1.getName() + "', but it contained: " + filenames, filenames.contains(TestInfo.TEST_FILE_1.getName())); }