87 lines
2.5 KiB
Java
87 lines
2.5 KiB
Java
package com.alexanderlogistics.rest;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.fail;
|
|
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
import java.util.logging.Logger;
|
|
|
|
import org.imixs.melman.FormAuthenticator;
|
|
import org.imixs.melman.RestAPIException;
|
|
import org.imixs.melman.WorkflowClient;
|
|
import org.imixs.workflow.ItemCollection;
|
|
import org.imixs.workflow.exceptions.PluginException;
|
|
import org.imixs.workflow.xml.XMLDataCollectionAdapter;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import jakarta.xml.bind.JAXBException;
|
|
|
|
/**
|
|
* A simple example how to send an invoice document remote.
|
|
*
|
|
*/
|
|
// @Disabled
|
|
public class TestSendInvoice {
|
|
|
|
private static Logger logger = Logger.getLogger(TestSendInvoice.class.getName());
|
|
|
|
WorkflowClient client = null;
|
|
|
|
// String restAPI = "https://test.alexander-logistics.office-workflow.de/api";
|
|
String restAPI = "http://localhost:8080/api";
|
|
String userID = "kutzner-service";
|
|
String password = "imixs";
|
|
|
|
/**
|
|
* Setup a new Rest Client
|
|
*
|
|
* @throws PluginException
|
|
*/
|
|
@BeforeEach
|
|
public void setup() throws PluginException {
|
|
|
|
client = new WorkflowClient(restAPI);
|
|
FormAuthenticator aut;
|
|
try {
|
|
aut = new FormAuthenticator(restAPI, userID, password);
|
|
client.registerClientRequestFilter(aut);
|
|
} catch (RestAPIException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create an event log entry....
|
|
*
|
|
*/
|
|
@Test
|
|
public void sendXMLData() {
|
|
|
|
logger.info("send invoice...");
|
|
ItemCollection payLoad = new ItemCollection();
|
|
ItemCollection result = null;
|
|
try {
|
|
// read test data
|
|
List<ItemCollection> col = null;
|
|
// read default content
|
|
|
|
col = XMLDataCollectionAdapter
|
|
.readCollectionFromInputStream(getClass().getResourceAsStream("/invoice-01.xml"));
|
|
assertEquals(1, col.size());
|
|
// set invoice data....
|
|
// XMLDataCollection result = client.postXMLDocument("workflow/workitem",
|
|
// XMLDocumentAdapter.getDocument(col.get(0)));
|
|
result = client.processWorkitem(col.get(0));
|
|
|
|
logger.info("completed");
|
|
} catch (RestAPIException | JAXBException | IOException e) {
|
|
logger.severe("Failed to send event log entry: " + e.getMessage());
|
|
|
|
fail(e);
|
|
}
|
|
}
|
|
|
|
}
|