-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #215
- Loading branch information
Showing
11 changed files
with
251 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
...-archive-documents/src/test/java/org/imixs/archive/documents/EInvoiceAutoAdapterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package org.imixs.archive.documents; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.imixs.workflow.FileData; | ||
import org.imixs.workflow.ItemCollection; | ||
import org.imixs.workflow.engine.WorkflowMockEnvironment; | ||
import org.imixs.workflow.exceptions.AdapterException; | ||
import org.imixs.workflow.exceptions.ModelException; | ||
import org.imixs.workflow.exceptions.PluginException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.MockitoAnnotations; | ||
import org.openbpmn.bpmn.BPMNModel; | ||
|
||
/** | ||
* This test class is testing the EInvoiceAutoAdapter and tests different | ||
* kind of files | ||
* | ||
*/ | ||
class EInvoiceAutoAdapterTest { | ||
|
||
@InjectMocks | ||
protected EInvoiceAutoAdapter adapter; | ||
|
||
protected ItemCollection workitem; | ||
protected ItemCollection event; | ||
protected WorkflowMockEnvironment workflowEnvironment; | ||
BPMNModel model = null; | ||
|
||
@BeforeEach | ||
public void setUp() throws PluginException, ModelException { | ||
// Ensures that @Mock and @InjectMocks annotations are processed | ||
MockitoAnnotations.openMocks(this); | ||
workflowEnvironment = new WorkflowMockEnvironment(); | ||
|
||
// register AccessAdapter Mock | ||
workflowEnvironment.registerAdapter(adapter); | ||
|
||
// Setup Environment | ||
workflowEnvironment.setUp(); | ||
workflowEnvironment.loadBPMNModel("/bpmn/TestZUGFeRD.bpmn"); | ||
model = workflowEnvironment.getModelService().getModelManager().getModel("1.0.0"); | ||
adapter.workflowService = workflowEnvironment.getWorkflowService(); | ||
|
||
// prepare data | ||
workitem = new ItemCollection().model("1.0.0").task(100); | ||
|
||
event = new ItemCollection(); | ||
|
||
} | ||
|
||
/** | ||
* Simple test that extracts the invoice from a XML file - number and the | ||
* creditor name | ||
* | ||
* @throws AdapterException | ||
* @throws PluginException | ||
* @throws IOException | ||
*/ | ||
@Test | ||
void testXMLWithExtraction() throws AdapterException, PluginException, IOException { | ||
// Prepare test data | ||
FileData xmlFile = createFileData("e-invoice/Rechnung_R_00010.xml", "application/xml"); | ||
workitem.addFileData(xmlFile); | ||
|
||
adapter.execute(workitem, event); | ||
|
||
assertEquals("R-00010", workitem.getItemValueString("invoice.number")); | ||
assertEquals("Max Mustermann", workitem.getItemValueString("cdtr.name")); | ||
} | ||
|
||
/** | ||
* Simple test that extracts the invoice from a zugferd pdf file - number and | ||
* the creditor name | ||
* | ||
* @throws AdapterException | ||
* @throws PluginException | ||
* @throws IOException | ||
*/ | ||
@Test | ||
void testZugferdWithExtraction() throws AdapterException, PluginException, IOException { | ||
// Prepare test data | ||
FileData xmlFile = createFileData("e-invoice/Rechnung_R_00011.pdf", "application/pdf"); | ||
workitem.addFileData(xmlFile); | ||
|
||
adapter.execute(workitem, event); | ||
|
||
assertEquals("R-00011", workitem.getItemValueString("invoice.number")); | ||
assertEquals("Max Mustermann", workitem.getItemValueString("cdtr.name")); | ||
ZonedDateTime expectedZdt = ZonedDateTime.of(2021, 7, 27, 0, 0, 0, 0, ZoneId.of("Europe/Berlin")); | ||
Date expectedDate = Date.from(expectedZdt.toInstant()); | ||
|
||
assertEquals(expectedDate, workitem.getItemValueDate("invoice.date")); | ||
|
||
// Payment data | ||
assertEquals(892.50, workitem.getItemValueFloat("invoice.total")); | ||
assertEquals(750, workitem.getItemValueFloat("invoice.total.net")); | ||
assertEquals(142.5, workitem.getItemValueFloat("invoice.total.tax")); | ||
// assertEquals("xxxxxR-00011", workitem.getItemValueString("cdtr.iban")); | ||
// assertEquals("xxxxxR-00011", workitem.getItemValueString("cdtr.bic")); | ||
|
||
} | ||
|
||
/** | ||
* Creates a FileData object from a file stored under /test/resources/ | ||
* | ||
* @param fileName | ||
* @param contentType | ||
* @return | ||
* @throws IOException | ||
*/ | ||
private FileData createFileData(String fileName, String contentType) throws IOException { | ||
byte[] content = null; | ||
ClassLoader classLoader = getClass().getClassLoader(); | ||
try (InputStream is = classLoader.getResourceAsStream(fileName)) { | ||
if (is == null) { | ||
throw new IOException("Resource not found: " + fileName); | ||
} | ||
content = is.readAllBytes(); | ||
} | ||
Map<String, List<Object>> attributes = new HashMap<>(); | ||
return new FileData(fileName, content, contentType, attributes); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...flow/documents/TestEInvoiceTransform.java → ...hive/documents/TestEInvoiceTransform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...g/imixs/workflow/documents/XSLTester.java → ...rg/imixs/archive/documents/XSLTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.