summaryrefslogtreecommitdiffstats
path: root/Master/Daten- und Systemintegration/CamelPrototype/src/test/java
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Daten- und Systemintegration/CamelPrototype/src/test/java
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Daten- und Systemintegration/CamelPrototype/src/test/java')
-rw-r--r--Master/Daten- und Systemintegration/CamelPrototype/src/test/java/de/h_da/fbi/dsi/ws0910/camelprototype/CreateOrderRoutesTest.java112
1 files changed, 112 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();
+ }
+}