Feed aggregator

Improving the Vaadin 4 Spring Project with a Simpler MVP

Javalobby Syndicated Feed - Mon, 19-Jan-15 23:30
I’ve been using the Vaadin 4 Spring library on my current project, and this has been a very pleasant experience. Preview Text:  I’ve been using the Vaadin 4 Spring library on my current project, and this has been a very pleasant experience Legacy Sponsored:  ...
Categories: Java

Pushing the Limits - Howto use AeroGear Unified Push for Java EE and Node.js

Javalobby Syndicated Feed - Mon, 19-Jan-15 23:30
At the end of 2014 the AeroGear team announced the availability of the Red Hat JBoss Unified Push Server on 
Categories: Java

Mule ESB in Docker

Javalobby Syndicated Feed - Mon, 19-Jan-15 23:30
In this article I will attempt to run the Mule ESB community edition in Docker in order to see whether it is feasible without any greater inconvenience. My goal is to be able to use Docker both when testing as well as in a production environment in order to gain better control over the environment and to separate different types of environments. Preview Text:  ...
Categories: Java

Minecraft Is the New Doom

Javalobby Syndicated Feed - Mon, 19-Jan-15 23:30
I just read Coelacanth: Lessons from Doom and I just realized that Minecraft is the new Doom. If you don't believe me, find a teenager that has a computer (or smartphone, or tablet) that hasn't played Minecraft. Preview Text:  Minecraft and Doom, on the other hand, are built to enable hackers to expand what is possible within the game via Mods....
Categories: Java

More Effective Interviews

Javalobby Syndicated Feed - Mon, 19-Jan-15 23:30
David Smith over at baleful.net makes some interesting points about the length of most interviews: So mathematically, you will most likely get the highest confidence interval with: 1) Resume screen, 2) Phone interview, 3) In-person interviews 1-3. From the above, this should represent about 50% of the total causes, but should produce 91% of the total effect. Adding additional interview steps...
Categories: Java

Probabilistic Techniques, Data Streams and Online Learning

Javalobby Syndicated Feed - Mon, 19-Jan-15 23:30
 I look forward to 2015 as the year when randomized algorithms, probabilistic techniques and data structures become more pervasive and mainstream. The primary driving factors for this will be more and more prevalence of big data and the necessity to process them in near real time using minimal (or constant) memory bandwidth. You are given data streams where possibly you will see every data...
Categories: Java

Java 8 Streams API as Friendly ForkJoinPool Facade

Javalobby Syndicated Feed - Mon, 19-Jan-15 23:30
One of features I love the most about Java 8 is the streams API. It finally eliminates pretty much all loops from the code and lets you write code that is so much more expressive and focused. Preview Text:  One of features I love the most about Java 8 is the streams API. It finally eliminates pretty much all loops from the code and lets you write...
Categories: Java

API Best Practices: Hypermedia (Part 3)

Javalobby Syndicated Feed - Mon, 19-Jan-15 23:30
[This article was written by Mike Stowe.] Preview Text:  APIs are like roads — they are designed to help us transport data from one point to another. But unfortunately, unlike the DOT system that spans the country, the directions (hypermedia) aren’t always uniform, and depending on the API we use, we’ll probably have to utilize a different...
Categories: Java

Implementing Apache Camel Context and Camel Routes Using Spring Context

Javalobby Syndicated Feed - Mon, 19-Jan-15 23:30
Part 1 – Enabling Camel Context We can easily start a Camel context in Spring configuration file. Assuming you have a working Spring configured application. Add below code snippet in your Spring context xml. Preview Text:  When we start the Spring context, camel context will be automatically enabled. Camel context has a field ‘autoStartup’...
Categories: Java

Offloading SSL using AWS ELB

Javalobby Syndicated Feed - Mon, 19-Jan-15 23:30
If you are using AWS elastic load balancer to scale your system, you may find that it is a good solution to offload SSL termination from your servers. Why Should You Offload SSL Termination? HTTPS is an encrypted protocol, and encryption required high CPU utilization to perform the needed mathematical computations. Since most web applications are CPU bounded, you should avoid...
Categories: Java

Avoiding MySQL ALTER Table Downtime

Javalobby Syndicated Feed - Mon, 19-Jan-15 23:30
Originally Written by Andrew Moore Preview Text:  MySQL table alterations can interrupt production traffic causing bad customer experience or in worst cases, loss of revenue. Not all DBAs, developers, syadmins know MySQL well enough to avoid this pitfall. Legacy Sponsored:  ...
Categories: Java

Tutorial: Playing MP3 Files with VS1053B and FRDM Board

Javalobby Syndicated Feed - Mon, 19-Jan-15 23:30
I want to make some noise with this post!!! This tutorial is about adding music and sound capabilities to the Freescale Freedom board, and to have a lot of fun with it :-). I need this ability for a larger project working on for a while. But I thought I share that sub-part how to play sound files. So with this tutorial I can turn my Freescale Freedom board into a music or sound player :-). And...
Categories: Java

Making Custom Report Tables Using AngularJS and Django in 10 Minutes

Javalobby Syndicated Feed - Mon, 19-Jan-15 23:00
Sometimes working with django admin interface requires some tool that allows one place to collect and analyze vital statistics. For example, in our case , we would like to aggregate all available information about users and put it into a speadsheet, which could be convenient to work with. Preview Text:  Sometimes working with django admin...
Categories: Java

Automated CSS Regressive Testing in Practice

Javalobby Syndicated Feed - Mon, 19-Jan-15 22:00
We write unit-tests tests for server-side source code and for JavaScript. Even when putting aside benefits of TDD approach it gives us a priceless thing – early problem reporting during refactoring. So you make change, you run tests and you will know at once if anything broke. What about CSS? You encapsulate a declaration set into a separate rule, look through the site pages where...
Categories: Java

Windows Phone App Analytics

Javalobby Syndicated Feed - Mon, 19-Jan-15 22:00
I was recently asked what the "best" analytics solution out there is for universal apps. Unfortunately I haven't reviewed what options are available recently. In the work I do for other people they already have made the decision about what analytics solution they want to incorporate. There are lots options available and what you'll want to use will depend on the actual analytics you want to...
Categories: Java

Welcome Max Guernsey

Sustainable Test-Driven Development - Mon, 19-Jan-15 15:56
Max has joined Net Objectives, as some of you may know, as a trainer, coach, and mentor.  We've been friends with Max for a long while, and he has been a contributor to this blog and to the progress of our thinking in general. So, we're adding him to the official authorship here and when (if ever :)) we get this thing written, he will be co-author with Amir and I. I know this has been terribly Scott Bainhttp://www.blogger.com/profile/05410128716057054818noreply@blogger.com2
Categories: TDD & BDD

Mule ESB Testing (Part 1/3): Unit and functional testing

codecentric Blog - Mon, 19-Jan-15 00:00

Abstract

As generally acknowledged testing is an important part of the software development process. Tests should be applied during each phase of the software development process from developer tests to acceptance tests. In software engineering comprehensive and automated test suits will secure the quality of software and can provide a safety net for regression and incompatibility changes.

In Mule ESB integration projects these same issues arise. Components used in Mule flows, the flows themselves and the integration of flows in a system context need to be tested thoroughly.

This article is the first one in a series of articles about testing Mule ESB projects on all levels. It is focusing on the smallest components in a Mule project which are tested with unit and functional tests.

Software Testing – The Test Pyramid

Before we dive into the topic we will take a look at the testing context. Ideally testing of software projects is built bottom up. Starting with a large test case base of automated unit tests for the smallest components which make up the whole application together. Going up through architecture layers the number of test cases decreases for larger components because they are compositions of the already tested components. Reaching finally the top of the pyramid where manual supervision or manual tests make up the top of the pyramid testing the application as a whole [1].

automatedtestingpyramid

Source: http://watirmelon.com/2012/01/31/introducing-the-software-testing-ice-cream-cone/
Automated testing pyramid

Unit Tests

On the lowest level unit tests verify the correct functionality of classes. These classes can be in a Mule project simple extensions and customizations of the Mule framework. Examples include:

  • Custom transformers
  • Custom components
  • Custom expression evaluators
  • And in general all the Spring beans that a Mule application will use. Typically in a multi module project these beans are part of a dependency and are tested therefore separately in the dependency built.

Unit tests in a classical sense can test the functionality of custom classes without firing up Mule. A simple POJO class and it’s test case containing customer transformation logic could look like this:

public class CustomerTransformationComponent {
 
   public Map<String, Object> tranformCustomer(Customer customer) {
      Map<String, Object> returnMap = Maps.newHashMap();
      returnMap.put("name", customer.getName());
      // Fields mapping
      // ...
      return returnMap;
   }
}
 
public class CustomerTranformationComponentTest {
 
   @Test
   public testTransform() {
      Customer testCustomer = new Customer();
      // Create test data
      Map<String, Object> customerMap = new CustomerTransformationComponent()
            .tranformCustomer(testCustomer);
      // Assert test data
   }
}

When functionality of custom classes requires a Mule context the Mule Framework provides a Test Compability Kit (TCK) for testing extensions and customizations [3]. For each Mule component type there is an abstract parent class which is derived from org.mule.tck.junit4.AbstractMuleTestCase. They are located in mule-core-3.5.2-tests.jar for Mule version 3.5.2.

For example a Java component implementing the Mule Callable interface with a complex logic relying on the Mule Context can be tested with the aforementioned test classes:

public class CustomerComponent implements Callable {
 
   @Autowired
   public CustomerService service;
 
   @Overwrite
   public Object onCall(MuleEventContext eventContext) throws Exception {
      String customerId = (String) eventContext.getMessage().getPayload();
 
      Customer customer = service.getCustomer(customerId);
 
      Map<String, Object> customerDetails = transformCustomer(customer);
 
      return customerDetails;
   }
}
 
public class CustomerComponentTest extends SimpleJavaComponentTestCase {
 
   @Test
   public testOnCall() {
      // Create test data
      MuleEvent event = getTestEvent(payload, muleContext);
      new CustomerComponent().onCall(new DefaultMuleEventContext(event));
      // Assert test data
   }
}

These unit tests are beneficial for the following reasons:

  • Components tested with a TCK test case ensure that the common behavior of the component is compatible with the Mule framework.
  • Using a TCK test case allows the developer to concentrate on writing tests for specific behavior of their component.
  • Where testing of a method in the Component API cannot be tested by the TCK test case, the test cases provides an abstract method for the test, ensuring the developer tests all areas of the component.
  • The TCK provides a default test model that is a simple set of test classes. The developer doesn’t need to worry about writing new test classes for their test cases each time. E.g. the Mule lifecycle of a component is automatically tested.

Functional Mule Testing

When it comes to testing the interaction of components between each other in sub flows or “simple” flows functional tests are the recommended way of testing [4]. Because Mule ESB is light weight and easily embeddable in tests the use of the org.mule.tck.junit4.FunctionalTestCase class from the TCK is recommended to test parts or whole flows. This is done by creating a unit test which is derived from this class which will provide an embeddable Mule instance with a Mule context to perform functional tests of these Mule flows.

The emphasis of such tests is to the following aspects of such flows:

  • Functionality of the message flows themselves
  • Validation handling and rule based routing within these flows
  • And their error handling

For example a sub flow which is supposed to be called could look like this:

<sub-flow name="subFlow" doc:name="subFlow">	 	 
 <component class="de.codecentric.example.CustomerComponent" doc:name="Java"/>	 	 
</sub-flow>

To be able to call this sub flow we wrap the call with an VM endpoint and save it in a test resource XML file:

<flow name="TestFlow" doc:name="TestFlow">	 	 
 <vm:inbound-endpoint exchange-pattern="request-response" path="TestFlow" doc:name="VM endpoint"/>	 	 
 <flow-ref name="subFlow" doc:name="Call sub flow for testing"/>	 	 
</flow>

The corresponding unit tests could look like this:

public class SubFlowTest extends FunctionalTestCase {
 
   @Test
   public void testFlow() throws Exception{
      MuleClient client = muleContext.getClient();
      String inputPayload = "550e8400-e29b-11d4-a716-446655440000";
      // Create test data
      MuleMessage reply = client.send("vm://TestFlow", inputPayload, null, 5000);
 
      assertNotNull(reply);
      assertNotNull(reply.getPayload());
      // Assert test data
   }
 
    @Override
    protected String[] getConfigFiles() {
        return new String[]{"./src/test/app/sub-flow-test.xml", 
            "./src/main/app/sub-flow.xml"};
    }
}

Overwriting the protected String[] getConfigFiles() method provides the test case the required mule config and spring config files. We recommend to split the production xml description and provide test xml configuration in a separat XML file which is only used in specific tests.

This is a simple example how flows can be tested without mocking or changing the tests internally. Mule provides a way to add <test:component/> components in a flow for tests which provides mocking and test functionality. We do not prefer this way because the flow description will be mingled with test information. We recommend to use for such cases the MUnit library which is described in the next blog article.

Testing the (sub) flows using an embedded Mule and with a clean separation between test and production flow description provides the following benefits:

  • Configurations and flows can be tested in isolation from each other which will provide a cleaner separation of tests and reduce the size of each test case. Bugs can be identified this way more focused because they can be localized in explicit test cases.
  • It is not desired to retest Mule standard components because it can be assumed they are already tested thoroughly. Therefore only certain paths and components of flows created by the developers are required for testing.
  • Test cases need to provide an own test infrastructure which is preferably made out of in memory infrastructure components e.g. VM as a transport, ActiveMQ for JMS or H2 as a database. This is necessary because the production environment can not always be provided automated or embedded for a unit test due to license, resource or performance reasons.
  • Reuse between tests e.g. of the in memory infrastructure can be increased by providing the configuration only once for all test cases.

Conclusion

We gave in this blog article an introduction into the first steps in testing Mule applications. Starting by describing how on a lowest architectural layer components and (sub) flows of a Mule application can be tested and which benefit it yields. We described for that purpose classic unit tests with JUnit in the Mule context TCK framework and the functional tests for the TCK. These tests can be found in single module Mule applications or in libraries which contain components and sub flows which are used in multi module Mule applications.

Series

This article is part of the Mule ESB Testing series:

  • Mule ESB Testing (Part 1/3): Unit and Functional Testing (this article)
  • Mule ESB Testing (Part 2/3): Integration Testing and (Endpoint) Mocking with MUnit (not published yet)
  • Mule ESB Testing (Part 3/3): System End-to-End Testing with Docker (not published yet)

References

[1] http://martinfowler.com/bliki/TestPyramid.html
[2] http://watirmelon.com/2012/01/31/introducing-the-software-testing-ice-cream-cone/
[3] http://www.mulesoft.org/documentation/display/current/Unit+Testing
[4] http://www.mulesoft.org/documentation/display/current/Functional+Testing

The post Mule ESB Testing (Part 1/3): Unit and functional testing appeared first on codecentric Blog.

Categories: Agile, Java, TDD & BDD

A Beginner's Guide to Java Persistence Locking

Javalobby Syndicated Feed - Mon, 19-Jan-15 00:00
Implicit locking In concurrency theory, locking is used for protecting mutable shared data against hazardous data integrity anomalies. Because lock management is a very complex problem, most applications rely on their data provider implicit locking techniques. Preview Text:  In concurrency theory, locking is used for protecting...
Categories: Java

Microservices in the Enterprise: Friend or Foe?

Javalobby Syndicated Feed - Mon, 19-Jan-15 00:00
A micro approach to a macro problem? The microservice hype is everywhere, and although the industry can’t seem to agree on an exact definition, we are repeatedly told that moving away from a monolithic application to a Service-Oriented Architecture (SOA) consisting of small services is the correct way to build and evolve software systems. However, there is currently an absence of...
Categories: Java

Everything You Need to Know About Scaling MySQL – Part 2: Difficulties

Javalobby Syndicated Feed - Mon, 19-Jan-15 00:00
Originally Written by Dave AnselmiNearly 80 percent of today’s databases are SQL-based. Preview Text:  Nearly 80 percent of today’s databases are SQL-based, and while MySQL is certainly capable of handling a good deal of traffic, as your business continues to grow, your database will probably reach maximum capacity and your website will...
Categories: Java

Thread Slivers eBook at Amazon

Syndicate content