Skip to content

Commit

Permalink
Java 11 migrate remaining e (#1112)
Browse files Browse the repository at this point in the history
* Moves eip-aggregator to Java 11

* Moves eip-message-channel to Java 11

* Moves eip-publish-subscribe to Java 11

* Moves eip-splitter to Java 11

* Moves eip-wire-tap to Java 11

* Moves event-aggregator to Java 11

* Moves event-asynchronous to Java 11

* Moves event-driven-architecture to Java 11

* Moves event-queue to Java 11

* Moves event-sourcing to Java 11

* Moves execute-around to Java 11

* Moves extension-objects to Java 11
  • Loading branch information
anuragagarwal561994 authored and iluwatar committed Dec 9, 2019
1 parent b09b100 commit fb2c026
Show file tree
Hide file tree
Showing 64 changed files with 306 additions and 390 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.camel.builder.RouteBuilder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
* Sometimes in enterprise systems there is a need to group incoming data in order to process it as
Expand All @@ -49,19 +48,17 @@ public class App {
*/
public static void main(String[] args) throws Exception {
// Run Spring Boot application and obtain ApplicationContext
ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
var context = SpringApplication.run(App.class, args);

// Get CamelContext from ApplicationContext
CamelContext camelContext = (CamelContext) context.getBean("camelContext");
var camelContext = (CamelContext) context.getBean("camelContext");

// Add a new routes that will handle endpoints form SplitterRoute class.
camelContext.addRoutes(new RouteBuilder() {

@Override
public void configure() throws Exception {
public void configure() {
from("{{endpoint}}").log("ENDPOINT: ${body}");
}

});

// Add producer that will send test message to an entry point in WireTapRoute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public class AggregatorRoute extends RouteBuilder {

/**
* Configures the route.
*
* @throws Exception in case of exception during configuration
*/
@Override
public void configure() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
return newExchange;
}

String in1 = (String) oldExchange.getIn().getBody();
String in2 = (String) newExchange.getIn().getBody();
var in1 = (String) oldExchange.getIn().getBody();
var in2 = (String) newExchange.getIn().getBody();

oldExchange.getIn().setBody(in1 + ";" + in2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class AppTest {

@Test
public void testMain() throws Exception {
String[] args = {};
App.main(args);
App.main(new String[]{});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

package com.iluwatar.eip.aggregator.routes;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
Expand All @@ -35,13 +37,11 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Test class for <i>AggregatorRoute</i>.
* <p>
* In order for it to work we have to mock endpoints we want to read/write to. To mock those we need to substitute
* original endpoint names to mocks.
* In order for it to work we have to mock endpoints we want to read/write to. To mock those we need
* to substitute original endpoint names to mocks.
* </p>
*/
@ExtendWith(SpringExtension.class)
Expand All @@ -59,6 +59,7 @@ public class AggregatorRouteTest {

/**
* Test if endpoint receives three separate messages.
*
* @throws Exception in case of en exception during the test
*/
@Test
Expand All @@ -76,10 +77,10 @@ public void testSplitter() throws Exception {
endpoint.expectedMessageCount(2);
endpoint.assertIsSatisfied();

String body = (String) endpoint.getReceivedExchanges().get(0).getIn().getBody();
var body = (String) endpoint.getReceivedExchanges().get(0).getIn().getBody();
assertEquals(3, body.split(";").length);

String body2 = (String) endpoint.getReceivedExchanges().get(1).getIn().getBody();
var body2 = (String) endpoint.getReceivedExchanges().get(1).getIn().getBody();
assertEquals(2, body2.split(";").length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,40 @@

package com.iluwatar.eip.aggregator.routes;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.impl.DefaultExchange;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Tests MessageAggregationStrategy
*/
public class MessageAggregationStrategyTest {

@Test
public void testAggregate() {
MessageAggregationStrategy mas = new MessageAggregationStrategy();
Exchange oldExchange = new DefaultExchange((CamelContext) null);
var mas = new MessageAggregationStrategy();
var oldExchange = new DefaultExchange((CamelContext) null);
oldExchange.getIn().setBody("TEST1");

Exchange newExchange = new DefaultExchange((CamelContext) null);
var newExchange = new DefaultExchange((CamelContext) null);
newExchange.getIn().setBody("TEST2");

Exchange output = mas.aggregate(oldExchange, newExchange);
String outputBody = (String) output.getIn().getBody();
var output = mas.aggregate(oldExchange, newExchange);
var outputBody = (String) output.getIn().getBody();
assertEquals("TEST1;TEST2", outputBody);
}

@Test
public void testAggregateOldNull() {
MessageAggregationStrategy mas = new MessageAggregationStrategy();
var mas = new MessageAggregationStrategy();

Exchange newExchange = new DefaultExchange((CamelContext) null);
var newExchange = new DefaultExchange((CamelContext) null);
newExchange.getIn().setBody("TEST2");

Exchange output = mas.aggregate(null, newExchange);
String outputBody = (String) output.getIn().getBody();
var output = mas.aggregate(null, newExchange);
var outputBody = (String) output.getIn().getBody();

assertEquals(newExchange, output);
assertEquals("TEST2", outputBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

package com.iluwatar.eip.message.channel;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.slf4j.Logger;
Expand Down Expand Up @@ -57,7 +56,7 @@ public class App {
* Program entry point.
*/
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
var context = new DefaultCamelContext();

context.addRoutes(new RouteBuilder() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@
import org.junit.jupiter.api.Test;

/**
*
* Application test
*
*/
public class AppTest {

@Test
public void test() throws Exception {
String[] args = {};
App.main(args);
App.main(new String[]{});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

package com.iluwatar.eip.publish.subscribe;

import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.slf4j.Logger;
Expand Down Expand Up @@ -55,14 +53,14 @@ public class App {
* Program entry point.
*/
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
var context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:origin").multicast().to("mock:foo", "mock:bar", "stream:out");
}
});
ProducerTemplate template = context.createProducerTemplate();
var template = context.createProducerTemplate();
context.start();
context.getRoutes().forEach(r -> LOGGER.info(r.toString()));
template.sendBody("direct:origin", "Hello from origin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@
import org.junit.jupiter.api.Test;

/**
*
* Application test
*
*/
public class AppTest {

@Test
public void test() throws Exception {
String[] args = {};
App.main(args);
App.main(new String[]{});
}
}
5 changes: 2 additions & 3 deletions eip-splitter/src/main/java/com/iluwatar/eip/splitter/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.camel.builder.RouteBuilder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
* It is very common in integration systems that incoming messages consists of many items bundled
Expand All @@ -53,10 +52,10 @@ public class App {
*/
public static void main(String[] args) throws Exception {
// Run Spring Boot application and obtain ApplicationContext
ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
var context = SpringApplication.run(App.class, args);

// Get CamelContext from ApplicationContext
CamelContext camelContext = (CamelContext) context.getBean("camelContext");
var camelContext = (CamelContext) context.getBean("camelContext");

// Add a new routes that will handle endpoints form SplitterRoute class.
camelContext.addRoutes(new RouteBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class AppTest {

@Test
public void testMain() throws Exception {
String[] args = {};
App.main(args);
App.main(new String[]{});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
/**
* Test class for <i>SplitterRoute</i>.
* <p>
* In order for it to work we have to mock endpoints we want to read/write to. To mock those we need to substitute
* original endpoint names to mocks.
* In order for it to work we have to mock endpoints we want to read/write to. To mock those we need
* to substitute original endpoint names to mocks.
* </p>
*/
@ExtendWith(SpringExtension.class)
Expand All @@ -57,14 +57,15 @@ public class SplitterRouteTest {

/**
* Test if endpoint receives three separate messages.
*
* @throws Exception in case of en exception during the test
*/
@Test
@DirtiesContext
public void testSplitter() throws Exception {

// Three items in one entry message
entry.sendBody(new String[] {"TEST1", "TEST2", "TEST3"});
entry.sendBody(new String[]{"TEST1", "TEST2", "TEST3"});

// Endpoint should have three different messages in the end order of the messages is not important
endpoint.expectedMessageCount(3);
Expand Down
5 changes: 2 additions & 3 deletions eip-wire-tap/src/main/java/com/iluwatar/eip/wiretap/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.camel.builder.RouteBuilder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
* In most integration cases there is a need to monitor the messages flowing through the system. It
Expand All @@ -52,10 +51,10 @@ public class App {
*/
public static void main(String[] args) throws Exception {
// Run Spring Boot application and obtain ApplicationContext
ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
var context = SpringApplication.run(App.class, args);

// Get CamelContext from ApplicationContext
CamelContext camelContext = (CamelContext) context.getBean("camelContext");
var camelContext = (CamelContext) context.getBean("camelContext");

// Add a new routes that will handle endpoints form WireTapRoute class.
camelContext.addRoutes(new RouteBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class AppTest {

@Test
public void testMain() throws Exception {
String[] args = {};
App.main(args);
App.main(new String[]{});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@

package com.iluwatar.eip.wiretap.routes;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.apache.camel.EndpointInject;
import org.apache.camel.Message;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.jupiter.api.Test;
Expand All @@ -36,13 +37,11 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Test class for <i>WireTapRoute</i>.
* <p>
* In order for it to work we have to mock endpoints we want to read/write to. To mock those we need to substitute
* original endpoint names to mocks.
* In order for it to work we have to mock endpoints we want to read/write to. To mock those we need
* to substitute original endpoint names to mocks.
* </p>
*/
@ExtendWith(SpringExtension.class)
Expand All @@ -63,6 +62,7 @@ public class WireTapRouteTest {

/**
* Test if both endpoints receive exactly one message containing the same, unchanged body.
*
* @throws Exception in case of en exception during the test
*/
@Test
Expand All @@ -76,8 +76,8 @@ public void testWireTap() throws Exception {
endpoint.assertIsSatisfied();
wireTapEndpoint.assertIsSatisfied();

Message endpointIn = endpoint.getExchanges().get(0).getIn();
Message wireTapEndpointIn = wireTapEndpoint.getExchanges().get(0).getIn();
var endpointIn = endpoint.getExchanges().get(0).getIn();
var wireTapEndpointIn = wireTapEndpoint.getExchanges().get(0).getIn();

assertEquals("TEST", endpointIn.getBody());
assertEquals("TEST", wireTapEndpointIn.getBody());
Expand Down

0 comments on commit fb2c026

Please sign in to comment.