/** * Validates that the stage properly identifies when a message should be restored * * @throws Exception on error */ @Test public void testRestoreMissingMessage() throws Exception { List<IMessageContext> msgs = new ArrayList<IMessageContext>(); IMessageContext msg = EasyMock.createStrictMock(IMessageContext.class); msgs.add(msg); // isUpdate & does not need restorage == don't store! EasyMock.expect(msg.shouldReplaceStorage()).andReturn(false); EasyMock.expect(msg.isUpdate()).andReturn(true); EasyMock.replay(msg); List<IMessageContext> needsStorage = Itertools.filter(PartitionStoreStage.NEEDS_STORAGE, msgs); assertTrue(needsStorage.isEmpty()); EasyMock.verify(msg); EasyMock.reset(msg); // should replace storage will bypass the other tests EasyMock.expect(msg.shouldReplaceStorage()).andReturn(true); EasyMock.replay(msg); needsStorage = Itertools.filter(PartitionStoreStage.NEEDS_STORAGE, msgs); assertEquals(1, needsStorage.size()); EasyMock.verify(msg); EasyMock.reset(msg); // !isUpdate & no filepath & does not need restorage == store! EasyMock.expect(msg.shouldReplaceStorage()).andReturn(false); EasyMock.expect(msg.isUpdate()).andReturn(false); EasyMock.expect(msg.getStoreFileSubPath()).andReturn(null); EasyMock.replay(msg); needsStorage = Itertools.filter(PartitionStoreStage.NEEDS_STORAGE, msgs); assertEquals(1, needsStorage.size()); EasyMock.verify(msg); EasyMock.reset(msg); }