Search in sources :

Example 16 with TestConfiguration

use of nl.nn.adapterframework.testutil.TestConfiguration in project iaf by ibissource.

the class PipeLineTest method giveWarningWhenForwardIsAlreadyDefined.

@Test
public void giveWarningWhenForwardIsAlreadyDefined() throws ConfigurationException {
    TestConfiguration configuration = new TestConfiguration();
    PipeLine pipeline = configuration.createBean(PipeLine.class);
    String pipeForwardName = "EchoPipe next pipe";
    EchoPipe pipe = configuration.createBean(EchoPipe.class);
    pipe.setName(pipe.getClass().getSimpleName() + " under test");
    pipe.registerForward(new PipeForward("success", pipeForwardName));
    pipe.registerForward(new PipeForward("success", pipeForwardName));
    pipe.setPipeLine(pipeline);
    pipeline.addPipe(pipe);
    EchoPipe pipe2 = configuration.createBean(EchoPipe.class);
    pipe2.setName(pipeForwardName);
    pipe.registerForward(new PipeForward("success", "exit"));
    pipe.registerForward(new PipeForward("success", "exit"));
    pipe.registerForward(new PipeForward("success", "exit"));
    // Surprisingly this doesn't cause any warnings
    pipe.registerForward(new PipeForward("success", "exit"));
    pipe2.setPipeLine(pipeline);
    pipeline.addPipe(pipe2);
    PipeLineExit exit = new PipeLineExit();
    exit.setPath("exit");
    exit.setState(ExitState.SUCCESS);
    pipeline.registerPipeLineExit(exit);
    pipeline.configure();
    assertEquals("pipes should cause a configuration warning", 1, configuration.getConfigurationWarnings().getWarnings().size());
    assertThat(configuration.getConfigWarning(0), StringEndsWith.endsWith("] has forward [success] which is already registered"));
    assertEquals("pipe1 should only have 1 pipe-forward", 1, pipe.getForwards().size());
    assertEquals("pipe1 forward should default to next pipe", pipeForwardName, pipe.getForwards().get(PipeForward.SUCCESS_FORWARD_NAME).getPath());
    assertEquals("pipe2 should only have 1 pipe-forward", 1, pipe2.getForwards().size());
    assertEquals("pipe2 forward should default to pipeline-exit", "exit", pipe2.getForwards().get(PipeForward.SUCCESS_FORWARD_NAME).getPath());
    configuration.close();
    configuration = null;
}
Also used : EchoPipe(nl.nn.adapterframework.pipes.EchoPipe) TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) Test(org.junit.Test)

Example 17 with TestConfiguration

use of nl.nn.adapterframework.testutil.TestConfiguration in project iaf by ibissource.

the class ClassLoaderManagerTest method createAdapter4ServiceClassLoader.

private static void createAdapter4ServiceClassLoader(String config4Adaptername) throws ConfigurationException {
    // Mock a configuration with an adapter in it
    IbisManager ibisManager = spy(new DefaultIbisManager());
    ibisManager.setIbisContext(ibisContext);
    Configuration configuration = new TestConfiguration();
    configuration.setName("dummyConfiguration");
    configuration.setVersion("1");
    configuration.setIbisManager(ibisManager);
    Adapter adapter = spy(new Adapter());
    adapter.setName(config4Adaptername);
    PipeLine pl = new PipeLine();
    pl.setFirstPipe("dummy");
    EchoPipe pipe = new EchoPipe();
    pipe.setName("dummy");
    pl.addPipe(pipe);
    PipeLineExit ple = new PipeLineExit();
    ple.setPath("success");
    ple.setState(ExitState.SUCCESS);
    pl.registerPipeLineExit(ple);
    adapter.setPipeLine(pl);
    doAnswer(new Answer<PipeLineResult>() {

        @Override
        public PipeLineResult answer(InvocationOnMock invocation) throws Throwable {
            PipeLineSession session = (PipeLineSession) invocation.getArguments()[2];
            URL file = this.getClass().getResource(JAR_FILE);
            session.put("configurationJar", Misc.streamToBytes(file.openStream()));
            return new PipeLineResult();
        }
    }).when(adapter).processMessage(anyString(), any(Message.class), any(PipeLineSession.class));
    adapter.setConfiguration(configuration);
    configuration.registerAdapter(adapter);
    ibisManager.addConfiguration(configuration);
    when(ibisContext.getIbisManager()).thenReturn(ibisManager);
}
Also used : DefaultIbisManager(nl.nn.adapterframework.unmanaged.DefaultIbisManager) TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) Message(nl.nn.adapterframework.stream.Message) EchoPipe(nl.nn.adapterframework.pipes.EchoPipe) TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Adapter(nl.nn.adapterframework.core.Adapter) URL(java.net.URL) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) PipeLine(nl.nn.adapterframework.core.PipeLine) DefaultIbisManager(nl.nn.adapterframework.unmanaged.DefaultIbisManager) PipeLineExit(nl.nn.adapterframework.core.PipeLineExit)

Example 18 with TestConfiguration

use of nl.nn.adapterframework.testutil.TestConfiguration in project iaf by ibissource.

the class ConfigurationDigesterTest method testNewConfigurationPreParser.

// Both OLD and NEW configuration parsers should set the same values for 'loadedConfiguration': properties resolved, secrets hidden
// The new configuration parser returns the configuration with all property not yet resolved
@Test
public void testNewConfigurationPreParser() throws Exception {
    ConfigurationDigester digester = new ConfigurationDigester();
    Resource resource = Resource.getResource("/Digester/SimpleConfiguration/Configuration.xml");
    Properties properties = new Properties();
    properties.setProperty("HelloWorld.active", "false");
    properties.setProperty("HelloBeautifulWorld.active", "!false");
    // new style non-escaped property values
    properties.setProperty("digester.property", "[ >\"< ]");
    properties.setProperty("secret", "GEHEIM");
    properties.setProperty("properties.hide", "secret");
    Configuration configuration = new TestConfiguration();
    XmlWriter loadedConfigWriter = new XmlWriter();
    digester.parseAndResolveEntitiesAndProperties(loadedConfigWriter, configuration, resource, properties);
    String result = loadedConfigWriter.toString();
    String expected = TestFileUtils.getTestFile("/Digester/Loaded/SimpleConfigurationUnresolved.xml");
    MatchUtils.assertXmlEquals(expected, result);
    String storedResult = configuration.getLoadedConfiguration();
    String storedExpected = TestFileUtils.getTestFile("/Digester/Loaded/SimpleConfigurationResolvedAndHidden.xml");
    MatchUtils.assertXmlEquals(storedExpected, storedResult);
    loadedConfigWriter = new XmlWriter();
    properties.setProperty(STUB4TESTTOOL_CONFIGURATION_KEY, "true");
    digester.parseAndResolveEntitiesAndProperties(loadedConfigWriter, configuration, resource, properties);
    String stubbedExpected = TestFileUtils.getTestFile("/Digester/Loaded/SimpleConfigurationStubbed.xml");
    MatchUtils.assertXmlEquals(stubbedExpected, loadedConfigWriter.toString());
}
Also used : TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) Configuration(nl.nn.adapterframework.configuration.Configuration) Resource(nl.nn.adapterframework.core.Resource) TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) Properties(java.util.Properties) ConfigurationDigester(nl.nn.adapterframework.configuration.ConfigurationDigester) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) Test(org.junit.Test)

Example 19 with TestConfiguration

use of nl.nn.adapterframework.testutil.TestConfiguration in project iaf by ibissource.

the class OpenApiTestBase method setUp.

@Before
public void setUp() throws ServletException {
    configuration = new TestConfiguration();
    AppConstants.getInstance().setProperty("hostname", "hostname");
}
Also used : TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) Before(org.junit.Before)

Example 20 with TestConfiguration

use of nl.nn.adapterframework.testutil.TestConfiguration in project iaf by ibissource.

the class CleanupDatabaseJobTest method setup.

@Override
@Before
public void setup() throws Exception {
    super.setup();
    System.setProperty("tableName", tableName);
    runMigrator(TEST_CHANGESET_PATH);
    configuration = new TestConfiguration();
    Adapter adapter = setupAdapter();
    configuration.registerAdapter(adapter);
    jobDef = new CleanupDatabaseJob() {

        @Override
        protected Set<String> getAllLockerDatasourceNames(IbisManager ibisManager) {
            return Collections.singleton(getDataSourceName());
        }
    };
    configuration.autowireByName(jobDef);
}
Also used : Set(java.util.Set) IbisManager(nl.nn.adapterframework.configuration.IbisManager) TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) Adapter(nl.nn.adapterframework.core.Adapter) CleanupDatabaseJob(nl.nn.adapterframework.scheduler.job.CleanupDatabaseJob) Before(org.junit.Before)

Aggregations

TestConfiguration (nl.nn.adapterframework.testutil.TestConfiguration)21 Test (org.junit.Test)12 Before (org.junit.Before)7 EchoPipe (nl.nn.adapterframework.pipes.EchoPipe)5 Message (nl.nn.adapterframework.stream.Message)3 MessageKeeper (nl.nn.adapterframework.util.MessageKeeper)3 Configuration (nl.nn.adapterframework.configuration.Configuration)2 IbisManager (nl.nn.adapterframework.configuration.IbisManager)2 Adapter (nl.nn.adapterframework.core.Adapter)2 PipeLine (nl.nn.adapterframework.core.PipeLine)2 PipeLineExit (nl.nn.adapterframework.core.PipeLineExit)2 PipeLineResult (nl.nn.adapterframework.core.PipeLineResult)2 PipeLineSession (nl.nn.adapterframework.core.PipeLineSession)2 CorePipeProcessor (nl.nn.adapterframework.processors.CorePipeProcessor)2 URL (java.net.URL)1 Properties (java.util.Properties)1 Set (java.util.Set)1 SecurityContext (javax.ws.rs.core.SecurityContext)1 ConfigurationDigester (nl.nn.adapterframework.configuration.ConfigurationDigester)1 IbisContext (nl.nn.adapterframework.configuration.IbisContext)1