1 26 28 package de.nava.informa.utils; 29 30 import java.io.File ; 31 import java.util.Date ; 32 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 36 import de.nava.informa.core.ChannelIF; 37 import de.nava.informa.impl.basic.ChannelBuilder; 38 39 public class TestChannelRegistry extends InformaTestCase { 40 41 private static Log logger = LogFactory.getLog(InformaTestCase.class); 42 43 public TestChannelRegistry(String name) { 44 super("TestChannelRegistry", name); 45 } 46 47 public void XXXtestCreate() throws Exception { 48 ChannelRegistry reg = new ChannelRegistry(new ChannelBuilder()); 49 File inpFile = new File (getDataDir(), "xmlhack-0.91.xml"); 51 ChannelIF chA = reg.addChannel(inpFile.toURL(), 2, true); 52 Date dateA = chA.getLastUpdated(); 53 assertNull("channel shouldn't be parsed now", dateA); 54 inpFile = new File (getDataDir(), "pro-linux.rdf"); 56 ChannelIF chB = reg.addChannel(inpFile.toURL(), 2, true); 57 inpFile = new File (getDataDir(), "snipsnap-org.rss"); 59 ChannelIF chC = reg.addChannel(inpFile.toURL(), 2, true); 60 assertEquals("channel exists", 3, reg.getChannels().size()); 62 assertTrue("channel A", reg.getChannels().contains(chA)); 63 assertTrue("channel B", reg.getChannels().contains(chB)); 64 assertTrue("channel C", reg.getChannels().contains(chC)); 65 logger.info("starting to sleep ..."); 66 try { 67 Thread.sleep(5000); 68 } catch (InterruptedException e) { 69 logger.warn("Interrupted waiting thread"); 70 } 71 logger.info("... stopped sleeping"); 72 assertTrue("channel A active", reg.isActiveChannel(chA)); 74 assertTrue("channel B active", reg.isActiveChannel(chB)); 75 assertTrue("channel C active", reg.isActiveChannel(chC)); 76 assertNotNull("channel should have been updated in the meantime", 78 chA.getLastUpdated()); 79 } 80 81 public void testParseProblem() throws Exception { 82 ChannelRegistry reg = new ChannelRegistry(new ChannelBuilder()); 83 reg.setAcceptNrOfErrors(1); 84 File inpFile = new File (getDataDir(), "xmlhack-0.91.xml"); 86 File chFile = new File (getOutputDir(), "xmlhack-0.91.xml"); 87 synchronized(chFile) { 88 FileUtils.copyFile(inpFile, chFile); 89 } 90 ChannelIF chA = reg.addChannel(chFile.toURL(), 2 , true); 91 try { 93 Thread.sleep(2500); 94 } catch (InterruptedException e) { 95 logger.warn("Interrupted waiting thread"); 96 } 97 assertEquals("channel exists", 1, reg.getChannels().size()); 99 assertTrue("channel A", reg.getChannels().contains(chA)); 100 UpdateChannelInfo info = reg.getUpdateInfo(chA); 101 assertTrue("channel A active", reg.isActiveChannel(chA)); 102 assertNull("no exception", info.getLastException()); 103 assertEquals("NrProblems", 0, info.getNrProblemsOccurred()); 104 logger.info("deleting channel file"); 105 synchronized(chFile) { 107 chFile.delete(); 108 } 109 logger.info("starting to sleep ..."); 110 try { 111 Thread.sleep(2500); 113 } catch (InterruptedException e) { 114 logger.warn("Interrupted waiting thread"); 115 } 116 logger.info("... stopped sleeping"); 117 info = reg.getUpdateInfo(chA); 119 assertTrue("channel A should be deactive", !reg.isActiveChannel(chA)); 120 logger.debug("exception: " + info.getLastException()); 121 assertNotNull("Exception", info.getLastException()); 122 assertEquals("NrProblems", 1, info.getNrProblemsOccurred()); 123 } 124 125 } 126 | Popular Tags |