#BAEL-6916: update test cases
This commit is contained in:
parent
036531949f
commit
d48a45c15a
|
@ -1,5 +1,21 @@
|
||||||
package com.apache.baeldung.camel.jackson;
|
package com.apache.baeldung.camel.jackson;
|
||||||
|
|
||||||
|
import com.baeldung.camel.apache.Application;
|
||||||
|
import com.baeldung.camel.apache.jackson.Fruit;
|
||||||
|
import org.apache.camel.Configuration;
|
||||||
|
import org.apache.camel.EndpointInject;
|
||||||
|
import org.apache.camel.ProducerTemplate;
|
||||||
|
import org.apache.camel.RoutesBuilder;
|
||||||
|
import org.apache.camel.builder.RouteBuilder;
|
||||||
|
import org.apache.camel.component.jackson.ListJacksonDataFormat;
|
||||||
|
import org.apache.camel.component.mock.MockEndpoint;
|
||||||
|
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -7,25 +23,42 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.camel.builder.RouteBuilder;
|
import static org.springframework.test.util.AssertionErrors.assertEquals;
|
||||||
import org.apache.camel.component.jackson.ListJacksonDataFormat;
|
import static org.springframework.test.util.AssertionErrors.assertNotNull;
|
||||||
import org.apache.camel.component.mock.MockEndpoint;
|
|
||||||
import org.apache.camel.test.junit4.CamelTestSupport;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.baeldung.camel.apache.jackson.Fruit;
|
@CamelSpringBootTest
|
||||||
|
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||||
|
@SpringBootTest(classes = {Application.class, FruitArrayJacksonUnmarshalUnitTest.TestConfig.class})
|
||||||
|
public class FruitArrayJacksonUnmarshalUnitTest {
|
||||||
|
|
||||||
public class FruitArrayJacksonUnmarshalUnitTest extends CamelTestSupport {
|
@Autowired
|
||||||
|
private ProducerTemplate template;
|
||||||
|
|
||||||
|
@EndpointInject("mock:marshalledObject")
|
||||||
|
private MockEndpoint mock;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class TestConfig {
|
||||||
|
@Bean
|
||||||
|
RoutesBuilder route() {
|
||||||
|
return new RouteBuilder() {
|
||||||
|
@Override
|
||||||
|
public void configure() throws Exception {
|
||||||
|
from("direct:jsonInput").unmarshal(new ListJacksonDataFormat(Fruit.class))
|
||||||
|
.to("mock:marshalledObject");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenJsonFruitArray_whenUnmarshalled_thenSuccess() throws Exception {
|
public void givenJsonFruitArray_whenUnmarshalled_thenSuccess() throws Exception {
|
||||||
MockEndpoint mock = getMockEndpoint("mock:marshalledObject");
|
mock.setExpectedMessageCount(1);
|
||||||
mock.expectedMessageCount(1);
|
|
||||||
mock.message(0).body().isInstanceOf(List.class);
|
mock.message(0).body().isInstanceOf(List.class);
|
||||||
|
|
||||||
String json = readJsonFromFile("/json/fruit-array.json");
|
String json = readJsonFromFile("/json/fruit-array.json");
|
||||||
template.sendBody("direct:jsonInput", json);
|
template.sendBody("direct:jsonInput", json);
|
||||||
assertMockEndpointsSatisfied();
|
mock.assertIsSatisfied();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Fruit> fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
|
List<Fruit> fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
|
||||||
|
@ -41,18 +74,6 @@ public class FruitArrayJacksonUnmarshalUnitTest extends CamelTestSupport {
|
||||||
assertEquals("Fruit name", "Apple", fruit.getName());
|
assertEquals("Fruit name", "Apple", fruit.getName());
|
||||||
assertEquals("Fruit id", 101, fruit.getId());
|
assertEquals("Fruit id", 101, fruit.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected RouteBuilder createRouteBuilder() throws Exception {
|
|
||||||
return new RouteBuilder() {
|
|
||||||
@Override
|
|
||||||
public void configure() throws Exception {
|
|
||||||
|
|
||||||
from("direct:jsonInput").unmarshal(new ListJacksonDataFormat(Fruit.class))
|
|
||||||
.to("mock:marshalledObject");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private String readJsonFromFile(String path) throws URISyntaxException, IOException {
|
private String readJsonFromFile(String path) throws URISyntaxException, IOException {
|
||||||
URL resource = FruitArrayJacksonUnmarshalUnitTest.class.getResource(path);
|
URL resource = FruitArrayJacksonUnmarshalUnitTest.class.getResource(path);
|
||||||
|
|
|
@ -1,5 +1,21 @@
|
||||||
package com.apache.baeldung.camel.jackson;
|
package com.apache.baeldung.camel.jackson;
|
||||||
|
|
||||||
|
import com.baeldung.camel.apache.Application;
|
||||||
|
import com.baeldung.camel.apache.jackson.Fruit;
|
||||||
|
import com.baeldung.camel.apache.jackson.FruitList;
|
||||||
|
import org.apache.camel.Configuration;
|
||||||
|
import org.apache.camel.EndpointInject;
|
||||||
|
import org.apache.camel.ProducerTemplate;
|
||||||
|
import org.apache.camel.RoutesBuilder;
|
||||||
|
import org.apache.camel.builder.RouteBuilder;
|
||||||
|
import org.apache.camel.component.jackson.JacksonDataFormat;
|
||||||
|
import org.apache.camel.component.mock.MockEndpoint;
|
||||||
|
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -7,26 +23,41 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.camel.builder.RouteBuilder;
|
import static org.springframework.test.util.AssertionErrors.assertEquals;
|
||||||
import org.apache.camel.component.jackson.JacksonDataFormat;
|
import static org.springframework.test.util.AssertionErrors.assertNotNull;
|
||||||
import org.apache.camel.component.mock.MockEndpoint;
|
|
||||||
import org.apache.camel.test.junit4.CamelTestSupport;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.baeldung.camel.apache.jackson.Fruit;
|
@CamelSpringBootTest
|
||||||
import com.baeldung.camel.apache.jackson.FruitList;
|
@SpringBootTest(classes = {Application.class, FruitListJacksonUnmarshalUnitTest.TestConfig.class})
|
||||||
|
public class FruitListJacksonUnmarshalUnitTest {
|
||||||
|
|
||||||
public class FruitListJacksonUnmarshalUnitTest extends CamelTestSupport {
|
@Autowired
|
||||||
|
ProducerTemplate template;
|
||||||
|
|
||||||
|
@EndpointInject("mock:marshalledObject")
|
||||||
|
private MockEndpoint mock;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class TestConfig {
|
||||||
|
@Bean
|
||||||
|
RoutesBuilder route() {
|
||||||
|
return new RouteBuilder() {
|
||||||
|
@Override
|
||||||
|
public void configure() throws Exception {
|
||||||
|
from("direct:jsonInput").unmarshal(new JacksonDataFormat(FruitList.class))
|
||||||
|
.to("mock:marshalledObject");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenJsonFruitList_whenUnmarshalled_thenSuccess() throws Exception {
|
public void givenJsonFruitList_whenUnmarshalled_thenSuccess() throws Exception {
|
||||||
MockEndpoint mock = getMockEndpoint("mock:marshalledObject");
|
mock.setExpectedMessageCount(1);
|
||||||
mock.expectedMessageCount(1);
|
|
||||||
mock.message(0).body().isInstanceOf(FruitList.class);
|
mock.message(0).body().isInstanceOf(FruitList.class);
|
||||||
|
|
||||||
String json = readJsonFromFile("/json/fruit-list.json");
|
String json = readJsonFromFile("/json/fruit-list.json");
|
||||||
template.sendBody("direct:jsonInput", json);
|
template.sendBody("direct:jsonInput", json);
|
||||||
assertMockEndpointsSatisfied();
|
mock.assertIsSatisfied();
|
||||||
|
|
||||||
FruitList fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(FruitList.class);
|
FruitList fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(FruitList.class);
|
||||||
assertNotNull("Fruit lists should not be null", fruitList);
|
assertNotNull("Fruit lists should not be null", fruitList);
|
||||||
|
@ -43,17 +74,6 @@ public class FruitListJacksonUnmarshalUnitTest extends CamelTestSupport {
|
||||||
assertEquals("Fruit id", 101, fruit.getId());
|
assertEquals("Fruit id", 101, fruit.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected RouteBuilder createRouteBuilder() throws Exception {
|
|
||||||
return new RouteBuilder() {
|
|
||||||
@Override
|
|
||||||
public void configure() throws Exception {
|
|
||||||
from("direct:jsonInput").unmarshal(new JacksonDataFormat(FruitList.class))
|
|
||||||
.to("mock:marshalledObject");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private String readJsonFromFile(String path) throws URISyntaxException, IOException {
|
private String readJsonFromFile(String path) throws URISyntaxException, IOException {
|
||||||
URL resource = FruitListJacksonUnmarshalUnitTest.class.getResource(path);
|
URL resource = FruitListJacksonUnmarshalUnitTest.class.getResource(path);
|
||||||
return new String(Files.readAllBytes(Paths.get(resource.toURI())));
|
return new String(Files.readAllBytes(Paths.get(resource.toURI())));
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
package com.apache.camel.file.processor;
|
package com.apache.camel.file.processor;
|
||||||
|
|
||||||
import java.io.File;
|
import com.baeldung.camel.apache.file.FileProcessor;
|
||||||
|
|
||||||
import org.apache.camel.CamelContext;
|
import org.apache.camel.CamelContext;
|
||||||
import org.apache.camel.builder.RouteBuilder;
|
import org.apache.camel.builder.RouteBuilder;
|
||||||
import org.apache.camel.impl.DefaultCamelContext;
|
import org.apache.camel.impl.DefaultCamelContext;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|
||||||
|
|
||||||
import com.baeldung.camel.apache.file.FileProcessor;
|
import java.io.File;
|
||||||
|
|
||||||
|
|
||||||
public class FileProcessorIntegrationTest {
|
public class FileProcessorIntegrationTest {
|
||||||
|
@ -67,9 +65,10 @@ public class FileProcessorIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void moveFolderContentSpringDSLTest() throws InterruptedException {
|
public void moveFolderContentSpringDSLTest() throws InterruptedException {
|
||||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml");
|
// ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml");
|
||||||
|
// ApplicationContext applicationContext = ContextLoader.getCurrentWebApplicationContext();
|
||||||
Thread.sleep(DURATION_MILIS);
|
Thread.sleep(DURATION_MILIS);
|
||||||
applicationContext.close();
|
//applicationContext.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue