Uploaded image for project: 'Fuse Tools'
  1. Fuse Tools
  2. FUSETOOLS-47

Creating new Camel Test Case - Should add camel-test dependency

    Details

    • Type: Enhancement
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 2.1.0
    • Component/s: Camel Editor
    • Labels:
      None

      Description

      When you use the create Camel Test Case, to create a junit test for your Camel app. Then at some point in the wizard it suggest to add JUnit 4 to the "classpath".

      1)
      I think the first problem is that junit could already be added as a "Maven dependency".

      		<!-- for testing -->
      		<dependency>
      			<groupId>junit</groupId>
      			<artifactId>junit</artifactId>
      			<scope>test</scope>
      		</dependency>

      Which I already have.

      2)
      I have problem selecting the Camel XML file I want to use for creating an unit test.
      If I select it using the wizard, the selection is not "returned" back to the main wizard. And thus its empty.
      If I manually type the XML file name, it doesn't matter.

      3)
      The generated source may look like (code to load XML file is not present, could be because of #2)

       
      package org.apache.camel.example.spring;
       
      import static org.junit.Assert.*;
       
      import org.apache.camel.test.junit4.CamelSpringTestSupport;
       
      public class MyCoolTest extends CamelSpringTestSupport {
       
      }

      The import org.apache.camel.test.junit4.CamelSpringTestSupport; is from camel-test component.

      So if the wizard could suggest or auto-add that dependency. But it should be added to the maven dependency in the pom.xml file.
      I dont know if that is ever possible, as maven isn't native supported in eclipse.

        Gliffy Diagrams

          Activity

          Hide
          davsclaus Claus Ibsen added a comment -

          btw I copied the camel-example-spring from the camel trunk to my eclipse workspace, and loaded it as a Maven project.

          Show
          davsclaus Claus Ibsen added a comment - btw I copied the camel-example-spring from the camel trunk to my eclipse workspace, and loaded it as a Maven project.
          Hide
          davsclaus Claus Ibsen added a comment -

          Ah if I typed the full path for the XML file src/main/resources/META-INF/spring/camel-context.xml then the Create Camel Test wizard, generated source code which loads the xml file

          /**
           * 
           */
          package org.apache.camel.example.spring;
           
          import static org.junit.Assert.*;
           
          import org.apache.camel.EndpointInject;
          import org.apache.camel.Produce;
          import org.apache.camel.ProducerTemplate;
          import org.apache.camel.builder.RouteBuilder;
          import org.apache.camel.component.mock.MockEndpoint;
          import org.apache.camel.test.junit4.CamelSpringTestSupport;
          import org.junit.Before;
          import org.junit.Test;
          import org.springframework.context.support.ClassPathXmlApplicationContext;
           
          /**
           * @author davsclaus
           *
           */
          public class MyOtherCoolTest extends CamelSpringTestSupport {
           
          	/* (non-Javadoc)
          	 * @see org.apache.camel.test.junit4.CamelSpringTestSupport#setUp()
          	 */
          	@Before
          	public void setUp() throws Exception {
          		super.setUp();
          	}
           
          	@Test
          	public void testCamelRoute() throws Exception {
           
          		// define some expectations
          		// TODO add some expectations here!!
           
          		assertMockEndpointsSatisfied();
          	}
           
          	@Override
          	protected ClassPathXmlApplicationContext createApplicationContext() {
          		return new ClassPathXmlApplicationContext(
          				"src/main/resources/META-INF/spring/camel-context.xml");
          	}
           
          }

          Show
          davsclaus Claus Ibsen added a comment - Ah if I typed the full path for the XML file src/main/resources/META-INF/spring/camel-context.xml then the Create Camel Test wizard, generated source code which loads the xml file /** * */ package org.apache.camel.example.spring;   import static org.junit.Assert.*;   import org.apache.camel.EndpointInject; import org.apache.camel.Produce; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.junit4.CamelSpringTestSupport; import org.junit.Before; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext;   /** * @author davsclaus * */ public class MyOtherCoolTest extends CamelSpringTestSupport {   /* (non-Javadoc) * @see org.apache.camel.test.junit4.CamelSpringTestSupport#setUp() */ @Before public void setUp() throws Exception { super.setUp(); }   @Test public void testCamelRoute() throws Exception {   // define some expectations // TODO add some expectations here!!   assertMockEndpointsSatisfied(); }   @Override protected ClassPathXmlApplicationContext createApplicationContext() { return new ClassPathXmlApplicationContext( "src/main/resources/META-INF/spring/camel-context.xml"); }   }
          Hide
          davsclaus Claus Ibsen added a comment -

          This is still a problem in 1.1.71.

          The wizard asks about adding JUnit4, but it should also ask about camel-test artifact as well.

          Show
          davsclaus Claus Ibsen added a comment - This is still a problem in 1.1.71. The wizard asks about adding JUnit4, but it should also ask about camel-test artifact as well.
          Hide
          davsclaus Claus Ibsen added a comment -

          Well in fact the wizard should only ask about adding camel-test as it got dependency on junit.

          Show
          davsclaus Claus Ibsen added a comment - Well in fact the wizard should only ask about adding camel-test as it got dependency on junit.
          Hide
          lhein Lars Heinemann added a comment -

          camel-test is now added as scope "test" dependency if not already there.

          Show
          lhein Lars Heinemann added a comment - camel-test is now added as scope "test" dependency if not already there.
          Hide
          jastrachan James Strachan added a comment -

          its looking great now thanks!

          One minor nit - after hitting Finish on the wizard the test case is created; its got red squiggles due to missing imports - and the pom.xml is updated to reflect the new camel-test dependency.

          As soon as I double click on the pom.xml it recognises its changed & fires a build & the red squiggles go away.

          I wonder could we fire a build/refresh of pom.xml in the IDE when we've updated it? Then the red squiggles should automatically disappear without the user doing anything. i.e. after pressing "Finish" on the wizard the IDE should show the newly created test case and the red squiggles should disappear as the IDE does a refresh/build on pom.xml

          Show
          jastrachan James Strachan added a comment - its looking great now thanks! One minor nit - after hitting Finish on the wizard the test case is created; its got red squiggles due to missing imports - and the pom.xml is updated to reflect the new camel-test dependency. As soon as I double click on the pom.xml it recognises its changed & fires a build & the red squiggles go away. I wonder could we fire a build/refresh of pom.xml in the IDE when we've updated it? Then the red squiggles should automatically disappear without the user doing anything. i.e. after pressing "Finish" on the wizard the IDE should show the newly created test case and the red squiggles should disappear as the IDE does a refresh/build on pom.xml
          Hide
          jastrachan James Strachan added a comment -

          I just created a new camel-activemq project, created a test case from the camel-context.xml, then hit Finish - got the red squiggles, then I right clicked on the pom.xml and hit "refresh" and it noticed it'd changed and the red squiggles went. So I think just a refresh on pom.xml would do the trick.

          Show
          jastrachan James Strachan added a comment - I just created a new camel-activemq project, created a test case from the camel-context.xml, then hit Finish - got the red squiggles, then I right clicked on the pom.xml and hit "refresh" and it noticed it'd changed and the red squiggles went. So I think just a refresh on pom.xml would do the trick.
          Hide
          jastrachan James Strachan added a comment -

          Its a one liner, so I just added a refresh in there and it works perfectly now - thanks Lars!

          Show
          jastrachan James Strachan added a comment - Its a one liner, so I just added a refresh in there and it works perfectly now - thanks Lars!
          Hide
          tsedmik Tomáš Sedmík added a comment -

          verified - JBDSIS 8.0.2.GA

          Show
          tsedmik Tomáš Sedmík added a comment - verified - JBDSIS 8.0.2.GA

            People

            • Assignee:
              lhein Lars Heinemann
              Reporter:
              davsclaus Claus Ibsen
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development