CSC/ECE 517 Spring 2015/ch1a 17 WL: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(116 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<h1>Apache Camel</h1>
<font size="5"><b>Apache Camel</b></font>


=='''Background'''==
Apache Camel is an open-source framework to exchange, route and transform data using various protocols. It is prepackaged with components for dealing with various backend systems and powerful routing and filter capabilities.<ref>Apache Camel - Open Source Routing Framework,Axel Irriger, from http://www.methodsandtools.com/tools/tools.php?camel</ref> The domain-specific language means that Apache Camel can support [http://en.wikipedia.org/wiki/Type_safety type-safe] smart completion of routing rules in an integrated development environment using regular Java code without large amounts of XML configuration files, though XML configuration inside [http://projects.spring.io/spring-framework/ Spring] is also supported.<ref>Apache Camel, in Wikipedia, the free encyclopedia, from http://en.wikipedia.org/wiki/Apache_Camel</ref>Camel is an integration framework that aims to make your integration projects productive and fun.
Test automation is the use of software to control the execution of tests cases, the comparison of actual to predicted results, the setting up of test preconditions, and other test control and test reporting functions.<ref>''The Testing Network, An Integral Approach to Test Activities in Large Software Projects'' by Jean-Jacques Pierre Henry (Aug 17, 2008), p413, ISBN 978-3-540-78504-0</ref> Test Automation is a development discipline as it uses scripting languages to instruct the tool how to interact with your application. As such careful consideration needs to be paid to


* Exception handling for bugs that occur during testing cycles(i.e, unexpected error messages during a test run).
__TOC__
* How the tool synchronizes with your application(e.g. if there are slow response times from your environment)
* The level of maintenance required to keep the tests up to date with changes in the application [http://en.wikipedia.org/wiki/Graphical_user_interface GUI](i.e, new buttons, data fields, custom controls etc)


Any test automation framework is a set of assumptions, concepts and tools that provide support for automating the major activities in the testing process. The main advantage of a framework is
=='''Introduction'''==
The Camel project was started in early 2007, but although it’s relatively young, Camel is already a mature open source project, available under the liberal Apache 2 license, and it has a strong community.
Camel’s focus is on simplifying integration. We’re confident that by the time you finish reading these pages, you’ll appreciate Camel and add it to your “must have” list of tools.
The Apache Camel project was named Camel simply because the name is short and easy to remember. Rumor has it the name may be inspired by the fact that one of the founders once smoked Camel cigarettes. At the Camel website a [http://camel.apache.org/why-the-name-camel.html FAQ entry] lists other lighthearted reasons for the name.<ref>Camel in Action, Claus Ibsen, Jonathan Anstey, from http://manning.com/ibsen/chapter1sample.pdf</ref>


* Increased Productivity
=='''Content'''==
* Easy and Reduced maintenance effort
In order to understand what Apache Camel is, we need to understand what Enterprise Integration Patterns are.
* Consistent automation development across projects
* Process driven than person driven approach
* Controlled maintenance of automation artifacts


There is a range of automation testing tools available. Some of them are licensed and few others are open sourced. QTP, Cucumber, Capybara and other tools<ref>http://en.wikipedia.org/wiki/List_of_web_testing_tools</ref>
Let's start with what we presumably already know: [http://en.wikipedia.org/wiki/Singleton_pattern, The Singleton pattern], [http://en.wikipedia.org/wiki/Factory_method_pattern, the Factory pattern], etc; They are merely ways of organizing your solution to the problem, but they are not solutions themselves. These patterns were analyzed and extracted for the rest of us by the Gang of Four, when they published their book: Design Patterns. They saved some of us tremendous effort in thinking of how to best structure our code.


=='''Description'''==
Much like the Gang of Four, Gregor Hohpe and Bobby Woolf authored the book Enterprise Integration Patterns ([http://www.enterpriseintegrationpatterns.com, EIP]) in which they propose and document a set of new patterns and blueprints for how we could best design large component-based systems, where components can be running on the same process or in a different machine.
HP UFT is generally used for GUI based Test Case Automation, it can also automate some non-GUI based test cases like database testing, webservice testing and file based operations. It offers a graphical user interface, keyboard support, multiple testing views, and scripting language.
<ref>http://www.softwaretestinghelp.com/qtp-quicktest-professional-tutorial-1/</ref>
===Data Driven Testing===
HP Unified Functional Testing allows us to perform data-driven testing. For example, data can be output to a data table for reuse. [http://en.wikipedia.org/wiki/Data-driven_testing Data-driven testing] is implemented as a Microsoft Excel workbook, which is accessible from HP Unified Functional Testing. HP Unified Functional Testing has two data tables: the Global data sheet and Action (local) data sheets. The test steps can read data from these data tables in order to drive variable data into the application under test, and verify the expected result.<ref>http://www.qtp10.com/2009/07/using-global-and-action-data-sheets-in.html</ref>


===Views===
They basically propose that we structure our system to be message oriented -- where components communicate with each others using messages as inputs and outputs and absolutely nothing else. They show us a complete set of patterns that we may choose from and implement in our different components that will together form the whole system.<ref>StackOverflow, Claus Ibsen, from http://stackoverflow.com/questions/8845186/what-exactly-is-apache-camel</ref>
HP Unified Functional Testing provides two views—and ways to modify—a test script: Keyword View and Expert View. These views enable HP Unified Functional Testing to act as an Integrated Development Environment (IDE) for the test, and HP Unified Functional Testing includes many standard IDE features, such as breakpoints to pause a test at predetermined places.<ref>http://en.wikipedia.org/wiki/HP_QuickTest_Professional</ref>


====Keyword view====
<div class="center" style="width: auto; margin-left: auto; margin-right: auto;"> [[File:Camel_concepts.png]]</div>
Keyword View lets users create and view the steps of a test in a modular, table format. In Keyword View, users can also view properties for items such as checkpoints, output values, and actions, use conditional and loop statements, and insert breakpoints to assist in debugging a test.<ref>http://www.qtp10.com/2009/07/working-with-keyword-view-in-hp-qtp.html</ref>


====Expert View====
<div class="center" style="width: auto; margin-left: auto; margin-right: auto;">Figure 1 shows how these three items actually map to Camel concepts.<ref>Open Source Integration with Apache Camel and How Fuse IDE Can Help, Jonathan Anstey, http://java.dzone.com/articles/open-source-integration-apache</ref></div>
Expert view displays test code using [http://en.wikipedia.org/wiki/VBScript VBScript]. Designed for more advanced users, users can edit all test actions except for the root Global action, and changes are synchronized with the Keyword View.<ref>http:/
 
=='''Examples'''==
===Example 1===
 
This mini-guide takes you through the source code of a [https://svn.apache.org/repos/asf/camel/trunk/examples/camel-example-jms-file/src/main/java/org/apache/camel/example/jmstofile/CamelJmsToFileExample.java simple example].<ref>Walk through an Example Code, http://camel.apache.org/walk-through-an-example.html</ref>
We start with creating a [http://camel.apache.org/camelcontext.html CamelContext] - which is a container for [http://camel.apache.org/components.html Components], [http://camel.apache.org/routes.html Routes] etc:
<pre>
CamelContext context = new DefaultCamelContext();
</pre>
There is more than one way of adding a Component to the CamelContext. You can add components implicitly - when we set up the routing - as we do here for the [http://camel.apache.org/file2.html FileComponent]:
<pre>
context.addRoutes(new RouteBuilder() {
    public void configure() {
        from("test-jms:queue:test.queue").to("file://test");
    }
});
</pre>
or explicitly - as we do here when we add the JMS Component:
<pre>
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
// Note we can explicit name the component
context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
</pre>
The above works with any JMS provider. If we know we are using [http://camel.apache.org/activemq.html ActiveMQ] we can use an even simpler form using the activeMQComponent() method while specifying the [http://activemq.apache.org/configuring-transports.html brokerURL] used to connect to ActiveMQ
<pre>
camelContext.addComponent("activemq", activeMQComponent("vm://localhost?broker.persistent=false"));
</pre>
In normal use, an external system would be firing messages or events directly into Camel through one if its [http://camel.apache.org/components.html Components] but we are going to use the [http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/ProducerTemplate.html ProducerTemplate] which is a really easy way for testing your configuration:
<pre>
ProducerTemplate template = context.createProducerTemplate();
</pre>
Next you <b> must </b> start the camel context. If you are using [http://camel.apache.org/spring.html Spring] to configure the camel context this is automatically done for you; though if you are using a pure Java approach then you just need to call the start() method
<pre>
camelContext.start();
</pre>
This will start all of the configured routing rules.
So after starting the [http://camel.apache.org/camelcontext.html CamelContext], we can fire some objects into camel:
<pre>
for (int i = 0; i < 10; i++) {
    template.sendBody("test-jms:queue:test.queue", "Test Message: " + i);
}
</pre>
===Example 2===
 
The second sample <ref> Apache Camel - Open Source Routing Framework, Axel Irriger, from http://www.methodsandtools.com/tools/tools.php?camel </ref> moves a file from directory A to directory B. Because this is rather easy, we'll add a XSLT transformation to it.
Using the Java [http://en.wikipedia.org/wiki/Domain-specific_language, DSL], the definition is:
<pre>
from("file: //inbox")       (1)
.to("xslt:someXSLT.xsl")  (2)
.to("file://outbox");       (3)
</pre>
What does this do?
In line (1), a route definition starts with the from keyword. As a parameter, the URL-style string defines that the file component shall be used for this. Everything after the slashes is passed as a parameter to the file component. In this case, the component scans the "inbox" folder for files and passes them on the next processing step.
 
In line (2), another component is instantiated. This time, the XSLT component is used with an XSL template, loaded from the Java classpath. Everything sent to this component gets transformed using that XSLT. The output of the transformation is passed on to the next step.
 
In line (3), another file component is used. This actually is another instance of the same component which was already configured on line (1). Everything sent to it will be written to the "outbox" folder.
As you see, this is a very straightforward and convenient way of configuring data flow. The next sample is a little bit more complex.
 
===Example 3===
 
This sample <ref>Apache Camel - Open Source Routing Framework, Axel Irriger, from http://www.methodsandtools.com/tools/tools.php?camel </ref>  may be used to upload data into a database.
 
For this to work, you must know that the JDBC component of Apache Camel sends SQL queries to a datasource. To use that component, you need to read the file content, create an SQL query from it and send this, to the database.
 
Using the Spring [http://en.wikipedia.org/wiki/Domain-specific_language, DSL], the result is (slightly modified from the Apache Camel homepage):
 
<pre>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
  <route>
      <from uri="file://inbox"/>
      <to uri="xslt:someXSL.xsl"/>
      <to uri="jdbc:testdb"/>
  </route>
</camelContext>
<!-- Just add a demo to show how to bind a date source for camel in Spring-->
<bean id="testdb"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName"value="org.hsqldb.jdbcDriver"/>
      <property name="url"value="jdbc:hsqldb:mem:camel_jdbc"/>
      <property name="username"value="sa"/>
  <property name="password"value="" />
</bean>
</pre>
Instead of using a stylesheet to perform the transformation, it would also be valid to use a Java bean, which serves the same purpose but may perform some more powerful operations.
 
===Example 4===
 
In the fourth sample<ref> Apache Camel - Open Source Routing Framework, Axel Irriger, from http://www.methodsandtools.com/tools/tools.php?camel </ref> , we'll take a look at how we can read data from the database and dump it to a file. Since that would be very much like what we did before, we'll add a persistence layer to it, with a JMS queue in-between.
 
Using the Java [http://en.wikipedia.org/wiki/Domain-specific_language, DSL], we get this source code:
<pre>
from("timer://foo?period=60000").
  setBody(constant("select content from downloadTable")).
  to("jdbc:testDB").
  to("jms:queue:order ");
from("jms:queue:order").to("file://outbox");
</pre>
The above sample does use the timer component. Every minute, the given SQL statement is executed and its result is sent to the JMS queue. From there, it is read and sent to the file system.
 
==<b>Conclusion</b>==
Apache Camel offers you the interfaces for the EIPs, the base objects, commonly needed implementations, debugging tools, a configuration system, and many other helpers which will save you a ton of time when you want to implement your solution to follow the EIPs.
 
Take MVC. MVC is pretty simple in theory and we could implement it without any framework help. But good MVC frameworks provide us with the structure ready-to-use and have gone the extra mile and thought out all the other "side" things you need when you create a large MVC project and that's why we use them most of the time.
 
That's exactly what Apache Camel is for EIPs. It's a complete production-ready framework for people who want to implement their solution to follow the EIPs.
 
=='''References'''==
<references/>

Latest revision as of 16:58, 2 March 2015

Apache Camel

Apache Camel is an open-source framework to exchange, route and transform data using various protocols. It is prepackaged with components for dealing with various backend systems and powerful routing and filter capabilities.<ref>Apache Camel - Open Source Routing Framework,Axel Irriger, from http://www.methodsandtools.com/tools/tools.php?camel</ref> The domain-specific language means that Apache Camel can support type-safe smart completion of routing rules in an integrated development environment using regular Java code without large amounts of XML configuration files, though XML configuration inside Spring is also supported.<ref>Apache Camel, in Wikipedia, the free encyclopedia, from http://en.wikipedia.org/wiki/Apache_Camel</ref>Camel is an integration framework that aims to make your integration projects productive and fun.

Introduction

The Camel project was started in early 2007, but although it’s relatively young, Camel is already a mature open source project, available under the liberal Apache 2 license, and it has a strong community. Camel’s focus is on simplifying integration. We’re confident that by the time you finish reading these pages, you’ll appreciate Camel and add it to your “must have” list of tools. The Apache Camel project was named Camel simply because the name is short and easy to remember. Rumor has it the name may be inspired by the fact that one of the founders once smoked Camel cigarettes. At the Camel website a FAQ entry lists other lighthearted reasons for the name.<ref>Camel in Action, Claus Ibsen, Jonathan Anstey, from http://manning.com/ibsen/chapter1sample.pdf</ref>

Content

In order to understand what Apache Camel is, we need to understand what Enterprise Integration Patterns are.

Let's start with what we presumably already know: The Singleton pattern, the Factory pattern, etc; They are merely ways of organizing your solution to the problem, but they are not solutions themselves. These patterns were analyzed and extracted for the rest of us by the Gang of Four, when they published their book: Design Patterns. They saved some of us tremendous effort in thinking of how to best structure our code.

Much like the Gang of Four, Gregor Hohpe and Bobby Woolf authored the book Enterprise Integration Patterns (EIP) in which they propose and document a set of new patterns and blueprints for how we could best design large component-based systems, where components can be running on the same process or in a different machine.

They basically propose that we structure our system to be message oriented -- where components communicate with each others using messages as inputs and outputs and absolutely nothing else. They show us a complete set of patterns that we may choose from and implement in our different components that will together form the whole system.<ref>StackOverflow, Claus Ibsen, from http://stackoverflow.com/questions/8845186/what-exactly-is-apache-camel</ref>

Figure 1 shows how these three items actually map to Camel concepts.<ref>Open Source Integration with Apache Camel and How Fuse IDE Can Help, Jonathan Anstey, http://java.dzone.com/articles/open-source-integration-apache</ref>

Examples

Example 1

This mini-guide takes you through the source code of a simple example.<ref>Walk through an Example Code, http://camel.apache.org/walk-through-an-example.html</ref> We start with creating a CamelContext - which is a container for Components, Routes etc:

CamelContext context = new DefaultCamelContext();

There is more than one way of adding a Component to the CamelContext. You can add components implicitly - when we set up the routing - as we do here for the FileComponent:

context.addRoutes(new RouteBuilder() {
    public void configure() {
        from("test-jms:queue:test.queue").to("file://test");
    }
});

or explicitly - as we do here when we add the JMS Component:

ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
// Note we can explicit name the component
context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));

The above works with any JMS provider. If we know we are using ActiveMQ we can use an even simpler form using the activeMQComponent() method while specifying the brokerURL used to connect to ActiveMQ

camelContext.addComponent("activemq", activeMQComponent("vm://localhost?broker.persistent=false"));

In normal use, an external system would be firing messages or events directly into Camel through one if its Components but we are going to use the ProducerTemplate which is a really easy way for testing your configuration:

ProducerTemplate template = context.createProducerTemplate();

Next you must start the camel context. If you are using Spring to configure the camel context this is automatically done for you; though if you are using a pure Java approach then you just need to call the start() method

camelContext.start();

This will start all of the configured routing rules. So after starting the CamelContext, we can fire some objects into camel:

for (int i = 0; i < 10; i++) {
    template.sendBody("test-jms:queue:test.queue", "Test Message: " + i);
}

Example 2

The second sample <ref> Apache Camel - Open Source Routing Framework, Axel Irriger, from http://www.methodsandtools.com/tools/tools.php?camel </ref> moves a file from directory A to directory B. Because this is rather easy, we'll add a XSLT transformation to it. Using the Java DSL, the definition is:

from("file: //inbox")	      (1)
.to("xslt:someXSLT.xsl")  (2)
.to("file://outbox");	      (3)

What does this do? In line (1), a route definition starts with the from keyword. As a parameter, the URL-style string defines that the file component shall be used for this. Everything after the slashes is passed as a parameter to the file component. In this case, the component scans the "inbox" folder for files and passes them on the next processing step.

In line (2), another component is instantiated. This time, the XSLT component is used with an XSL template, loaded from the Java classpath. Everything sent to this component gets transformed using that XSLT. The output of the transformation is passed on to the next step.

In line (3), another file component is used. This actually is another instance of the same component which was already configured on line (1). Everything sent to it will be written to the "outbox" folder. As you see, this is a very straightforward and convenient way of configuring data flow. The next sample is a little bit more complex.

Example 3

This sample <ref>Apache Camel - Open Source Routing Framework, Axel Irriger, from http://www.methodsandtools.com/tools/tools.php?camel </ref> may be used to upload data into a database.

For this to work, you must know that the JDBC component of Apache Camel sends SQL queries to a datasource. To use that component, you need to read the file content, create an SQL query from it and send this, to the database.

Using the Spring DSL, the result is (slightly modified from the Apache Camel homepage):

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
   <route>
      <from uri="file://inbox"/>
      <to uri="xslt:someXSL.xsl"/>
      <to uri="jdbc:testdb"/>
   </route>
</camelContext>
<!-- Just add a demo to show how to bind a date source for camel in Spring-->
<bean id="testdb"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName"value="org.hsqldb.jdbcDriver"/>
      <property name="url"value="jdbc:hsqldb:mem:camel_jdbc"/>
      <property name="username"value="sa"/>
   <property name="password"value="" />
</bean>

Instead of using a stylesheet to perform the transformation, it would also be valid to use a Java bean, which serves the same purpose but may perform some more powerful operations.

Example 4

In the fourth sample<ref> Apache Camel - Open Source Routing Framework, Axel Irriger, from http://www.methodsandtools.com/tools/tools.php?camel </ref> , we'll take a look at how we can read data from the database and dump it to a file. Since that would be very much like what we did before, we'll add a persistence layer to it, with a JMS queue in-between.

Using the Java DSL, we get this source code:

from("timer://foo?period=60000").
   setBody(constant("select content from downloadTable")).
   to("jdbc:testDB").
   to("jms:queue:order ");
from("jms:queue:order").to("file://outbox");

The above sample does use the timer component. Every minute, the given SQL statement is executed and its result is sent to the JMS queue. From there, it is read and sent to the file system.

Conclusion

Apache Camel offers you the interfaces for the EIPs, the base objects, commonly needed implementations, debugging tools, a configuration system, and many other helpers which will save you a ton of time when you want to implement your solution to follow the EIPs.

Take MVC. MVC is pretty simple in theory and we could implement it without any framework help. But good MVC frameworks provide us with the structure ready-to-use and have gone the extra mile and thought out all the other "side" things you need when you create a large MVC project and that's why we use them most of the time.

That's exactly what Apache Camel is for EIPs. It's a complete production-ready framework for people who want to implement their solution to follow the EIPs.

References

<references/>