Search in sources :

Example 56 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class FsMessageProducerTest method testSetFilenameCreator.

@Test
public void testSetFilenameCreator() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsProducer producer = createProducer(subdir);
    try {
        producer.setFilenameCreator(null);
        fail();
    } catch (IllegalArgumentException | NullPointerException expected) {
    }
    producer.setFilenameCreator(new EmptyFileNameCreator());
    assertEquals(EmptyFileNameCreator.class, producer.getFilenameCreator().getClass());
}
Also used : EmptyFileNameCreator(com.adaptris.core.EmptyFileNameCreator) GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 57 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class FsConsumerCase method testFsMonitor.

@Test
public void testFsMonitor() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsConsumerImpl fs = createConsumer(subdir);
    fs.setUniqueId(getName());
    Adapter adapter = new Adapter();
    adapter.setUniqueId(getName());
    Channel channel = new Channel();
    channel.setUniqueId(getName());
    StandardWorkflow wf = new StandardWorkflow();
    wf.setUniqueId(getName());
    wf.setConsumer(fs);
    channel.getWorkflowList().add(wf);
    adapter.getChannelList().add(channel);
    AdapterManager am = new AdapterManager(adapter);
    try {
        am.registerMBean();
        am.requestInit();
        String objectNameString = String.format("com.adaptris:type=ConsumerMonitor,adapter=%s,channel=%s,workflow=%s,id=%s", getName(), getName(), getName(), getName());
        MBeanServer mBeanServer = JmxHelper.findMBeanServer();
        FsConsumerMonitorMBean mbean = JMX.newMBeanProxy(mBeanServer, ObjectName.getInstance(objectNameString), FsConsumerMonitorMBean.class);
        assertEquals(0, mbean.messagesRemaining());
    } finally {
        am.requestClose();
        am.unregisterMBean();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) AdapterManager(com.adaptris.core.runtime.AdapterManager) Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) GuidGenerator(com.adaptris.util.GuidGenerator) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 58 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class FsConsumerCase method testInitWithoutMkdirs.

@Test
public void testInitWithoutMkdirs() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsConsumerImpl fs = createConsumer(subdir);
    fs.setCreateDirs(false);
    try {
        LifecycleHelper.init(fs);
        fail("Should fail since dir can't exist");
    } catch (CoreException e) {
        // Expected
        ;
    } finally {
        LifecycleHelper.close(fs);
        FileUtils.deleteQuietly(new File(PROPERTIES.getProperty(BASE_KEY), subdir));
    }
}
Also used : CoreException(com.adaptris.core.CoreException) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 59 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class FsConsumerCase method testInitWithMkdirs.

@Test
public void testInitWithMkdirs() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsConsumerImpl fs = createConsumer(subdir);
    try {
        fs.setCreateDirs(true);
        LifecycleHelper.init(fs);
    } finally {
        LifecycleHelper.close(fs);
        FileUtils.deleteQuietly(new File(PROPERTIES.getProperty(BASE_KEY), subdir));
    }
}
Also used : GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 60 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class FsConsumerCase method testBasicInit.

@Test
public void testBasicInit() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    FsConsumerImpl consumer = createConsumer(subDir);
    try {
        FsConsumerImpl consumer2 = createConsumer();
        try {
            LifecycleHelper.init(consumer2);
            fail("no destination  - should throw Exception");
        } catch (CoreException e) {
        // expected
        }
        // test creation of file filter imp...
        consumer.setFilterExpression(".*\\.xml");
        consumer.setFileFilterImp(Perl5FilenameFilter.class.getName());
        try {
            LifecycleHelper.init(consumer);
        } catch (CoreException e) {
            fail("Exception calling init with valid FileFilter " + e);
        }
        LifecycleHelper.close(consumer);
        // test creation of invalid FF Imp
        consumer.setFileFilterImp("com.class.does.not.exist.FileFilter");
        try {
            LifecycleHelper.init(consumer);
            fail("Calling init with invalid FileFilter ");
        } catch (CoreException e) {
        }
    } finally {
        FileUtils.deleteQuietly(new File(PROPERTIES.getProperty(BASE_KEY), subDir));
    }
}
Also used : Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) CoreException(com.adaptris.core.CoreException) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Aggregations

GuidGenerator (com.adaptris.util.GuidGenerator)134 Test (org.junit.Test)120 File (java.io.File)91 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)61 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)30 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)27 TimeInterval (com.adaptris.util.TimeInterval)25 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)24 RandomAccessFile (java.io.RandomAccessFile)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)23 FilenameFilter (java.io.FilenameFilter)21 ArrayList (java.util.ArrayList)20 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)18 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)15 Properties (java.util.Properties)15 Adapter (com.adaptris.core.Adapter)14 CoreException (com.adaptris.core.CoreException)11 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)9 ServiceException (com.adaptris.core.ServiceException)8 IOException (java.io.IOException)8