diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Daten- und Systemintegration/CamelPrototype/src/test | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Master/Daten- und Systemintegration/CamelPrototype/src/test')
3 files changed, 165 insertions, 0 deletions
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/test/java/de/h_da/fbi/dsi/ws0910/camelprototype/CreateOrderRoutesTest.java b/Master/Daten- und Systemintegration/CamelPrototype/src/test/java/de/h_da/fbi/dsi/ws0910/camelprototype/CreateOrderRoutesTest.java new file mode 100644 index 0000000..20a9bbd --- /dev/null +++ b/Master/Daten- und Systemintegration/CamelPrototype/src/test/java/de/h_da/fbi/dsi/ws0910/camelprototype/CreateOrderRoutesTest.java @@ -0,0 +1,112 @@ +package de.h_da.fbi.dsi.ws0910.camelprototype;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.jvnet.mock_javamail.Mailbox;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+@ContextConfiguration(locations="/CreateOrderRoutesTest-context.xml")
+public class CreateOrderRoutesTest extends AbstractJUnit4SpringContextTests{
+ private static final long WAIT = 2000;
+ private static Mailbox inbox;
+ private static String EMAILRECIPIENT = "neworders@mycompany.com";
+ // should be the same address as we have in our route
+ private static String ADDRESS = "http://localhost:8080/camelprototype/webservices/order";
+
+ protected static OrderEndpoint createCXFClient() {
+ // we use CXF to create a client for us as its easier than JAXWS and works
+ JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
+ factory.setServiceClass(OrderEndpoint.class);
+ factory.setAddress(ADDRESS);
+ return (OrderEndpoint) factory.create();
+ }
+ protected InputNewOrder createWSTestData() {
+ // create input parameter
+ InputNewOrder input = new InputNewOrder();
+ input.setCustomerNo("456");
+ OrderPosition orderPos1 = new OrderPosition();
+ orderPos1.setAmount(2);
+ orderPos1.setArticle("Super Gadget");
+ orderPos1.setArticleNo("7890");
+ input.getOrderpositions().add(orderPos1);
+
+ OrderPosition orderPos2 = new OrderPosition();
+ orderPos2.setAmount(8);
+ orderPos2.setArticle("Mega Gadget");
+ orderPos2.setArticleNo("6543");
+ input.getOrderpositions().add(orderPos2);
+
+ OrderPosition orderPos3 = new OrderPosition();
+ orderPos3.setAmount(3);
+ orderPos3.setArticle("Great Nonsens");
+ orderPos3.setArticleNo("N6543");
+ input.getOrderpositions().add(orderPos3);
+ return input;
+ }
+ private void createCsvTestData() throws IOException {
+ BufferedWriter bw = new BufferedWriter(new FileWriter("target/csvinput/34524.csv"));
+ bw.write("574,One Article,3\n");
+ bw.write("575,Second Article,4\n");
+ bw.write("852,Another Article,5");
+ bw.close();
+ }
+ @Test
+ public void testWebserviceNewOrder() throws Exception {
+ try {
+ // assert mailbox is empty before starting
+ assertEquals("Should not have mails", 0, inbox.size());
+ // create the webservice client
+ OrderEndpoint client = createCXFClient();
+ // create Test Order for webservice testclient
+ InputNewOrder testOrder = createWSTestData();
+ for (int count=1;count<=5;count++) {
+ // send the request
+ OutputNewOrder out = client.createOrder(testOrder);
+ // assert we got a OK back
+ assertEquals("0", out.getStatus());
+ //assert we got an order number back
+ assertFalse("Should have an order number", out.getMessage().isEmpty());
+ System.out.println("Received orderno: "+out.getMessage());
+ // let some time pass to allow Camel to pickup the file and send it as an email
+ Thread.sleep(WAIT);
+ // assert mail box
+ assertEquals("Should have got "+count+" mails", count, inbox.size());
+ }
+ } catch (Exception ex) {
+ throw new Exception("Error executing Webservice Test", ex);
+ }
+ }
+
+ @Test
+ public void testCSVNewOrder() throws Exception {
+ // assert mailbox is empty before starting
+ assertEquals("Should not have mails", 0, inbox.size());
+ // create csv test data
+ createCsvTestData();
+ // let some time pass to allow Camel to pickup the file and send it as an email
+ Thread.sleep(WAIT);
+ // assert mail box
+ assertEquals("Should have got 1 mail", 1, inbox.size());
+ }
+ @Before
+ public void cleanInbox() {
+ inbox.clear();
+ }
+ @BeforeClass
+ public static void setUp() throws Exception {
+ inbox = Mailbox.get(EMAILRECIPIENT);
+ }
+ @AfterClass
+ public static void tearDown() throws Exception {
+ OrderSystem.getInstance().dumpOrders();
+ }
+}
diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/CreateOrderRoutesTest-context.xml b/Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/CreateOrderRoutesTest-context.xml new file mode 100644 index 0000000..c485b04 --- /dev/null +++ b/Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/CreateOrderRoutesTest-context.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <import resource="classpath:META-INF/cxf/cxf.xml"/>
+ <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
+ <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
+
+ <!-- create a camel context as to start Camel -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <routeBuilder ref="orderroutes" />
+ <routeBuilder ref="ordernormalizer" />
+ </camelContext>
+ <bean id="ordernormalizer" class="de.h_da.fbi.dsi.ws0910.camelprototype.OrderNormalizer"/>
+ <bean id="ordersystem"
+ class="de.h_da.fbi.dsi.ws0910.camelprototype.OrderSystem"
+ destroy-method="shutdown"/>
+ <bean id="ordersystemadaptor"
+ class="de.h_da.fbi.dsi.ws0910.camelprototype.OrderSystemAdaptor">
+ <constructor-arg ref="ordersystem" />
+ </bean>
+ <bean id="orderroutes"
+ class="de.h_da.fbi.dsi.ws0910.camelprototype.OrderRoutes">
+ <constructor-arg index="0" type="java.lang.String" value="neworders@mycompany.com" />
+ <constructor-arg index="1" type="java.lang.String" value="someone@localhost" />
+ <constructor-arg index="2" type="java.lang.String" value="" />
+ </bean>
+</beans>
\ No newline at end of file diff --git a/Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/log4j.properties b/Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/log4j.properties new file mode 100644 index 0000000..6d3a2b3 --- /dev/null +++ b/Master/Daten- und Systemintegration/CamelPrototype/src/test/resources/log4j.properties @@ -0,0 +1,22 @@ + +# default properties to initialise log4j +log4j.rootLogger=INFO, file + +# Console appender +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + +# File appender +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +log4j.appender.file.file=target/dsi-order-test.log +log4j.appender.file.append=true + +# settings for specific packages +log4j.logger.org.springframework=WARN +log4j.logger.org.apache.cxf=WARN + +# Camel logging +log4j.logger.org.apache.camel=DEBUG
\ No newline at end of file |
