diff --git a/src/main/java/io/carbone/CarboneServices.java b/src/main/java/io/carbone/CarboneServices.java
index 30828b6..cb47ee3 100644
--- a/src/main/java/io/carbone/CarboneServices.java
+++ b/src/main/java/io/carbone/CarboneServices.java
@@ -20,7 +20,7 @@ class CarboneServices implements ICarboneServices {
int err;
private final ICarboneTemplateClient carboneTemplateClient;
private final ICarboneRenderClient carboneRenderClient;
- private final ICarboneStatusClient carboneStatusClient ;
+ private final ICarboneStatusClient carboneStatusClient;
String reportName;
public CarboneServices(ICarboneTemplateClient carboneTemplateClient, ICarboneRenderClient carboneRenderClient, ICarboneStatusClient carboneStatusClient) {
@@ -43,7 +43,7 @@ public String addTemplate(byte[] templateFile) throws CarboneException {
}
@Override
- public boolean deleteTemplate(String templateId) throws CarboneException {
+ public boolean deleteTemplate(String templateId) throws CarboneException {
CarboneResponse carboneResponse = carboneTemplateClient.deleteTemplate(templateId);
return carboneResponse.isSuccess();
}
@@ -63,7 +63,7 @@ public String generateTemplateId(String path) {
e.printStackTrace();
return null;
}
-
+
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-256");
@@ -71,7 +71,7 @@ public String generateTemplateId(String path) {
e.printStackTrace();
return null;
}
-
+
digest.update(fileBytes);
byte[] hashByte = digest.digest();
StringBuilder hexString = new StringBuilder();
@@ -86,8 +86,8 @@ public String generateTemplateId(String path) {
return null;
}
}
- public CarboneDocument render(String Json, String fileOrTemplateID) throws CarboneException
- {
+
+ public CarboneDocument render(String Json, String fileOrTemplateID) throws CarboneException {
if (fileOrTemplateID.isEmpty()) {
throw new CarboneException("Carbone SDK render error: argument is missing: file_or_template_id");
}
@@ -98,14 +98,12 @@ public CarboneDocument render(String Json, String fileOrTemplateID) throws Carbo
File file = new File(fileOrTemplateID);
if (!file.exists()) {
resp = carboneRenderClient.renderReport(Json, fileOrTemplateID);
- }
- else {
+ } else {
try {
String templateId = generateTemplateId(fileOrTemplateID);
resp = carboneRenderClient.renderReport(Json, templateId);
} catch (CarboneException e) {
- if(e.getHttpStatus() == 404)
- {
+ if (e.getHttpStatus() == 404) {
try {
Path filePath = Paths.get(fileOrTemplateID);
CarboneResponse respAddTemplate = carboneTemplateClient.addTemplate(Files.readAllBytes(filePath));
@@ -117,8 +115,7 @@ public CarboneDocument render(String Json, String fileOrTemplateID) throws Carbo
} catch (IOException err) {
throw new CarboneException("Carbone SDK render error: failed to read template file");
}
- }
- else{
+ } else {
throw new CarboneException("Carbone SDK render error: failed to generate the template id");
}
}
@@ -127,7 +124,7 @@ public CarboneDocument render(String Json, String fileOrTemplateID) throws Carbo
throw new CarboneException("Carbone SDK render error: something went wrong");
}
if (!resp.isSuccess()) {
- throw new CarboneException("Carbone SDK render error: render_id empty");
+ throw new CarboneException(String.format("Carbone SDK render error: %s", resp.getError()));
}
return getReport(resp.getData().getRenderId());
}
@@ -135,8 +132,7 @@ public CarboneDocument render(String Json, String fileOrTemplateID) throws Carbo
@Override
public String renderReport(String renderData, String templateId) throws CarboneException {
- if(checkPathIsAbsolute(templateId))
- {
+ if (checkPathIsAbsolute(templateId)) {
String newTemplateId = generateTemplateId(templateId);
CarboneResponse carboneResponse = carboneRenderClient.renderReport(renderData, newTemplateId);
return carboneResponse.getData().getRenderId();
@@ -150,18 +146,16 @@ public String renderReport(String renderData, String templateId) throws CarboneE
public CarboneDocument getReport(String renderId) throws CarboneException {
CarboneDocument response = carboneRenderClient.getReport(renderId);
return response;
- }
+ }
@Override
- public byte[] getTemplate(String templateId) throws CarboneException
- {
+ public byte[] getTemplate(String templateId) throws CarboneException {
CarboneFileResponse response = carboneTemplateClient.getTemplate(templateId);
return response.getFileContent();
}
@Override
- public String getStatus() throws CarboneException
- {
+ public String getStatus() throws CarboneException {
Response response = null;
try {
response = carboneStatusClient.getStatus();
diff --git a/src/test/java/io/carbone/CarboneTest.java b/src/test/java/io/carbone/CarboneTest.java
index 3bb4fbc..95a1da8 100644
--- a/src/test/java/io/carbone/CarboneTest.java
+++ b/src/test/java/io/carbone/CarboneTest.java
@@ -32,28 +32,28 @@ public class CarboneTest {
ICarboneStatusClient carboneStatus = mock(CarboneStatusClient.class);
ICarboneServices carboneServices = CarboneServicesFactory.CARBONE_SERVICES_FACTORY_INSTANCE.create(carboneTemplate, carboneRender, carboneStatus);
CarboneException carboneException;
-
-
+
+
String directory = System.getProperty("user.dir");
@Test
public void Test_Add_Template_With_Path() throws CarboneException, IOException, InterruptedException {
CarboneResponse.CarboneResponseData responseData = CarboneResponse.CarboneResponseData.builder()
- .templateId("fb9241ea2218ffd8f974110e539386384620244618c2efbf182b7bd47242987B")
- .build();
+ .templateId("fb9241ea2218ffd8f974110e539386384620244618c2efbf182b7bd47242987B")
+ .build();
CarboneResponse mockedResponse = CarboneResponse.builder()
- .success(true)
- .data(responseData)
- .build();
+ .success(true)
+ .data(responseData)
+ .build();
String filename = "/src/test/java/io/carbone/template3.odt";
String file = directory + filename;
Path filePath = Paths.get(directory, filename);
byte[] fileBytes = Files.readAllBytes(filePath);
when(carboneTemplate.addTemplate(fileBytes)).thenReturn(mockedResponse);
-
- String resp = carboneServices.addTemplate(file);
+
+ String resp = carboneServices.addTemplate(file);
assertEquals(resp, mockedResponse.getData().templateId);
}
@@ -62,68 +62,62 @@ public void Test_Add_Template_With_Path() throws CarboneException, IOException,
public void Test_Add_Template_With_Array_Byte() throws CarboneException, IOException, InterruptedException {
CarboneResponse.CarboneResponseData responseData = CarboneResponse.CarboneResponseData.builder()
- .templateId("fb9241ea2218ffd8f974110e539386384620244618c2efbf182b7bd47242987B")
- .build();
+ .templateId("fb9241ea2218ffd8f974110e539386384620244618c2efbf182b7bd47242987B")
+ .build();
CarboneResponse mockedResponse = CarboneResponse.builder()
- .success(true)
- .data(responseData)
- .build();
+ .success(true)
+ .data(responseData)
+ .build();
String filename = "/src/test/java/io/carbone/template3.odt";
Path filePath = Paths.get(directory, filename);
byte[] fileBytes = Files.readAllBytes(filePath);
when(carboneTemplate.addTemplate(fileBytes)).thenReturn(mockedResponse);
-
- String resp = carboneServices.addTemplate(Files.readAllBytes(filePath));
+
+ String resp = carboneServices.addTemplate(Files.readAllBytes(filePath));
assertEquals(resp, mockedResponse.getData().templateId);
}
@Test
- public void Test_Add_Template_Error_Path() throws CarboneException, IOException
- {
+ public void Test_Add_Template_Error_Path() throws CarboneException, IOException {
String filename = "/src/test/java/io/carbone/template.odt";
Path filePath = Paths.get(filename);
- try{
+ try {
carboneTemplate.addTemplate(Files.readAllBytes(filePath));
- }
- catch(NoSuchFileException e)
- {
+ } catch (NoSuchFileException e) {
assertEquals(filename, e.getMessage());
}
}
@Test
- public void Test_Delete_Template() throws CarboneException
- {
+ public void Test_Delete_Template() throws CarboneException {
CarboneResponse mockedResponse = CarboneResponse.builder()
- .success(true)
- .error(null)
- .build();
+ .success(true)
+ .error(null)
+ .build();
when(carboneTemplate.deleteTemplate("fb9241ea2218ffd8f974110e539386384620244618c2efbf182b7bd47242987a")).thenReturn(mockedResponse);
boolean resp = carboneServices.deleteTemplate("fb9241ea2218ffd8f974110e539386384620244618c2efbf182b7bd47242987a");
-
+
assertEquals(resp, mockedResponse.isSuccess());
}
- @Test
- public void Test_Delete_Template_Error_Already_Deleted() throws CarboneException
- {
+ @Test
+ public void Test_Delete_Template_Error_Already_Deleted() throws CarboneException {
CarboneResponse mockedResponse = CarboneResponse.builder()
- .success(false)
- .error("Error: Cannot remove template, does it exist ?")
- .build();
+ .success(false)
+ .error("Error: Cannot remove template, does it exist ?")
+ .build();
when(carboneTemplate.deleteTemplate("fb9241ea2218ffd8f974110e539386384620244618c2efbf182b7bd47242987a")).thenReturn(mockedResponse);
boolean resp = carboneServices.deleteTemplate("fb9241ea2218ffd8f974110e539386384620244618c2efbf182b7bd47242987a");
-
+
assertEquals(resp, mockedResponse.isSuccess());
}
@Test
- public void Test_Generate_TemplateId()
- {
+ public void Test_Generate_TemplateId() {
String filename = "/src/test/java/io/carbone/template3.odt";
Path filePath = Paths.get(directory, filename);
@@ -133,13 +127,12 @@ public void Test_Generate_TemplateId()
}
@Test
- public void Test_Generate_TemplateId_With_A_Wrong_Path() throws NoSuchFileException
- {
+ public void Test_Generate_TemplateId_With_A_Wrong_Path() throws NoSuchFileException {
String filename = "";
String templateId = carboneServices.generateTemplateId(filename);
-
+
assertNull(templateId);
-
+
}
@Test
@@ -157,16 +150,15 @@ public void Test_Get_Template() throws IOException, CarboneException {
}
@Test
- public void Test_Render_Repport_With_Template_Id() throws CarboneException
- {
+ public void Test_Render_Repport_With_Template_Id() throws CarboneException {
String templateId = "fb9241ea2218ffd8f974110e539386384620244618c2efbf182b7bd47242987B";
CarboneResponse.CarboneResponseData responseData = CarboneResponse.CarboneResponseData.builder()
- .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
- .build();
+ .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
+ .build();
CarboneResponse mockedResponse = CarboneResponse.builder()
- .success(true)
- .data(responseData)
- .build();
+ .success(true)
+ .data(responseData)
+ .build();
String json = "{ \"data\": { \"invoiceId\": \"FR-2023-781\", \"invoiceDate\": \"2023-01-17\", \"name\": \"Quentin Le Forestier\", \"phone\": \"+33 (0)2 23 12 33 24\", \"email\": \"tim+serverpro@carbone.io\", \"partner\": { \"name\": \"Corp\", \"phone\": \"+33 (0)6 27 89 01 23\", \"email\": \"quentinleforestierleforestier0@gmail.com\", \"vat\": \"FR45899106785\", \"siren\": \"899106785\", \"address\": { \"street\": \"12 Doctor Street\", \"postalcode\": 34920, \"city\": \"Anger\", \"country\": \"France\" } }, \"note\": \"Our team is confident that this cutting-edge technology will enhance your operations and take your business to the next level. Should you have any questions or concerns, please don't hesitate to reach out to us.\", \"subscriptionFromDate\": \"2023-02-02T07:28:05+00:00\", \"subscriptionToDate\": \"2024-04-18T07:28:05+00:00\", \"products\": [ { \"name\": \"Rackmount case (With bays for multiple 3.5-inch drives and room for the motherboard and other components.)\", \"exTaxTotal\": 1000, \"unit\": 1000, \"vat\": 20, \"qty\": 1 }, { \"name\": \"Motherboard (has the necessary number of SATA ports for your storage needs)\", \"exTaxTotal\": 150, \"unit\": 150, \"vat\": 20, \"qty\": 1 }, { \"name\": \"3.5-inch SATA hard drives (20TO)\", \"exTaxTotal\": 1000, \"unit\": 100, \"vat\": 20, \"qty\": 10 }, { \"name\": \"Processor ( A low-power consumption processor)\", \"exTaxTotal\": 100, \"unit\": 100, \"vat\": 20, \"qty\": 1 }, { \"name\": \"4GB DDR5 RAM\", \"exTaxTotal\": 120, \"unit\": 30, \"vat\": 20, \"qty\": 4 } ], \"exTaxTotal\": 1870, \"taxTotal\": 374, \"inTaxTotal\": 2244, \"amountRemaining\": 1044, \"invoicePaymentList\": [ { \"paymentDate\": \"2023-02-03T07:28:05+00:00\", \"typeSelect\": \"Paiement\", \"amount\": 1200 } ], \"payment\": { \"name\": \"SEPA Transfer\", \"typeSelect\": \"SEPAtransfer\", \"condition\": \"Upon receipt of invoice\", \"bankLabel\": \"Revolut\", \"bankBIC\": \"REVOGB2L\", \"bankIBAN\": \"FR2112739000409352423869N75\" } }, \"convertTo\" : { \"formatName\" : \"pdf\" } }";
when(carboneRender.renderReport(json, templateId)).thenReturn(mockedResponse);
@@ -177,15 +169,14 @@ public void Test_Render_Repport_With_Template_Id() throws CarboneException
}
@Test
- public void Test_Render_Repport_With_Path() throws CarboneException
- {
+ public void Test_Render_Repport_With_Path() throws CarboneException {
CarboneResponse.CarboneResponseData responseData = CarboneResponse.CarboneResponseData.builder()
- .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
- .build();
+ .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
+ .build();
CarboneResponse mockedResponse = CarboneResponse.builder()
- .success(true)
- .data(responseData)
- .build();
+ .success(true)
+ .data(responseData)
+ .build();
String filename = directory + "/src/test/java/io/carbone/template3.odt";
String json = "{ \"data\": { \"invoiceId\": \"FR-2023-781\", \"invoiceDate\": \"2023-01-17\", \"name\": \"Quentin Le Forestier\", \"phone\": \"+33 (0)2 23 12 33 24\", \"email\": \"tim+serverpro@carbone.io\", \"partner\": { \"name\": \"Corp\", \"phone\": \"+33 (0)6 27 89 01 23\", \"email\": \"quentinleforestierleforestier0@gmail.com\", \"vat\": \"FR45899106785\", \"siren\": \"899106785\", \"address\": { \"street\": \"12 Doctor Street\", \"postalcode\": 34920, \"city\": \"Anger\", \"country\": \"France\" } }, \"note\": \"Our team is confident that this cutting-edge technology will enhance your operations and take your business to the next level. Should you have any questions or concerns, please don't hesitate to reach out to us.\", \"subscriptionFromDate\": \"2023-02-02T07:28:05+00:00\", \"subscriptionToDate\": \"2024-04-18T07:28:05+00:00\", \"products\": [ { \"name\": \"Rackmount case (With bays for multiple 3.5-inch drives and room for the motherboard and other components.)\", \"exTaxTotal\": 1000, \"unit\": 1000, \"vat\": 20, \"qty\": 1 }, { \"name\": \"Motherboard (has the necessary number of SATA ports for your storage needs)\", \"exTaxTotal\": 150, \"unit\": 150, \"vat\": 20, \"qty\": 1 }, { \"name\": \"3.5-inch SATA hard drives (20TO)\", \"exTaxTotal\": 1000, \"unit\": 100, \"vat\": 20, \"qty\": 10 }, { \"name\": \"Processor ( A low-power consumption processor)\", \"exTaxTotal\": 100, \"unit\": 100, \"vat\": 20, \"qty\": 1 }, { \"name\": \"4GB DDR5 RAM\", \"exTaxTotal\": 120, \"unit\": 30, \"vat\": 20, \"qty\": 4 } ], \"exTaxTotal\": 1870, \"taxTotal\": 374, \"inTaxTotal\": 2244, \"amountRemaining\": 1044, \"invoicePaymentList\": [ { \"paymentDate\": \"2023-02-03T07:28:05+00:00\", \"typeSelect\": \"Paiement\", \"amount\": 1200 } ], \"payment\": { \"name\": \"SEPA Transfer\", \"typeSelect\": \"SEPAtransfer\", \"condition\": \"Upon receipt of invoice\", \"bankLabel\": \"Revolut\", \"bankBIC\": \"REVOGB2L\", \"bankIBAN\": \"FR2112739000409352423869N75\" } }, \"convertTo\" : { \"formatName\" : \"pdf\" } }";
String templateID = carboneServices.generateTemplateId(filename);
@@ -197,8 +188,7 @@ public void Test_Render_Repport_With_Path() throws CarboneException
}
@Test
- public void Test_Get_Report() throws IOException, CarboneException
- {
+ public void Test_Get_Report() throws IOException, CarboneException {
String renderId = "MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf";
String filename = "/src/test/java/io/carbone/template3.odt";
String name = "test.pdf";
@@ -215,13 +205,12 @@ public void Test_Get_Report() throws IOException, CarboneException
}
@Test
- public void Test_Render_Template_Id() throws CarboneException
- {
+ public void Test_Render_Template_Id() throws CarboneException {
String fakeTemplateId = "FakeTemplateId";
String json = "{ \"data\": { \"invoiceId\": \"FR-2023-781\", \"invoiceDate\": \"2023-01-17\", \"name\": \"Quentin Le Forestier\", \"phone\": \"+33 (0)2 23 12 33 24\", \"email\": \"tim+serverpro@carbone.io\", \"partner\": { \"name\": \"Corp\", \"phone\": \"+33 (0)6 27 89 01 23\", \"email\": \"quentinleforestierleforestier0@gmail.com\", \"vat\": \"FR45899106785\", \"siren\": \"899106785\", \"address\": { \"street\": \"12 Doctor Street\", \"postalcode\": 34920, \"city\": \"Anger\", \"country\": \"France\" } }, \"note\": \"Our team is confident that this cutting-edge technology will enhance your operations and take your business to the next level. Should you have any questions or concerns, please don't hesitate to reach out to us.\", \"subscriptionFromDate\": \"2023-02-02T07:28:05+00:00\", \"subscriptionToDate\": \"2024-04-18T07:28:05+00:00\", \"products\": [ { \"name\": \"Rackmount case (With bays for multiple 3.5-inch drives and room for the motherboard and other components.)\", \"exTaxTotal\": 1000, \"unit\": 1000, \"vat\": 20, \"qty\": 1 }, { \"name\": \"Motherboard (has the necessary number of SATA ports for your storage needs)\", \"exTaxTotal\": 150, \"unit\": 150, \"vat\": 20, \"qty\": 1 }, { \"name\": \"3.5-inch SATA hard drives (20TO)\", \"exTaxTotal\": 1000, \"unit\": 100, \"vat\": 20, \"qty\": 10 }, { \"name\": \"Processor ( A low-power consumption processor)\", \"exTaxTotal\": 100, \"unit\": 100, \"vat\": 20, \"qty\": 1 }, { \"name\": \"4GB DDR5 RAM\", \"exTaxTotal\": 120, \"unit\": 30, \"vat\": 20, \"qty\": 4 } ], \"exTaxTotal\": 1870, \"taxTotal\": 374, \"inTaxTotal\": 2244, \"amountRemaining\": 1044, \"invoicePaymentList\": [ { \"paymentDate\": \"2023-02-03T07:28:05+00:00\", \"typeSelect\": \"Paiement\", \"amount\": 1200 } ], \"payment\": { \"name\": \"SEPA Transfer\", \"typeSelect\": \"SEPAtransfer\", \"condition\": \"Upon receipt of invoice\", \"bankLabel\": \"Revolut\", \"bankBIC\": \"REVOGB2L\", \"bankIBAN\": \"FR2112739000409352423869N75\" } }, \"convertTo\" : { \"formatName\" : \"pdf\" } }";
- when(carboneRender.renderReport(json, fakeTemplateId)).thenThrow(new CarboneException("Carbone SDK render error: Error while rendering template Error: 404 Not Found"));
+ when(carboneRender.renderReport(json, fakeTemplateId)).thenThrow(new CarboneException("Carbone SDK render error: Error while rendering template Error: 404 Not Found"));
try {
carboneServices.render(json, fakeTemplateId);
} catch (CarboneException e) {
@@ -230,18 +219,17 @@ public void Test_Render_Template_Id() throws CarboneException
}
@Test
- public void Test_Render_Error_From_Directory() throws CarboneException, NoSuchFileException
- {
+ public void Test_Render_Error_From_Directory() throws CarboneException, NoSuchFileException {
String filename = "/src/test/java/io/carbone/template.odt";
String json = "{ \"data\": { \"invoiceId\": \"FR-2023-781\", \"invoiceDate\": \"2023-01-17\", \"name\": \"Quentin Le Forestier\", \"phone\": \"+33 (0)2 23 12 33 24\", \"email\": \"tim+serverpro@carbone.io\", \"partner\": { \"name\": \"Corp\", \"phone\": \"+33 (0)6 27 89 01 23\", \"email\": \"quentinleforestierleforestier0@gmail.com\", \"vat\": \"FR45899106785\", \"siren\": \"899106785\", \"address\": { \"street\": \"12 Doctor Street\", \"postalcode\": 34920, \"city\": \"Anger\", \"country\": \"France\" } }, \"note\": \"Our team is confident that this cutting-edge technology will enhance your operations and take your business to the next level. Should you have any questions or concerns, please don't hesitate to reach out to us.\", \"subscriptionFromDate\": \"2023-02-02T07:28:05+00:00\", \"subscriptionToDate\": \"2024-04-18T07:28:05+00:00\", \"products\": [ { \"name\": \"Rackmount case (With bays for multiple 3.5-inch drives and room for the motherboard and other components.)\", \"exTaxTotal\": 1000, \"unit\": 1000, \"vat\": 20, \"qty\": 1 }, { \"name\": \"Motherboard (has the necessary number of SATA ports for your storage needs)\", \"exTaxTotal\": 150, \"unit\": 150, \"vat\": 20, \"qty\": 1 }, { \"name\": \"3.5-inch SATA hard drives (20TO)\", \"exTaxTotal\": 1000, \"unit\": 100, \"vat\": 20, \"qty\": 10 }, { \"name\": \"Processor ( A low-power consumption processor)\", \"exTaxTotal\": 100, \"unit\": 100, \"vat\": 20, \"qty\": 1 }, { \"name\": \"4GB DDR5 RAM\", \"exTaxTotal\": 120, \"unit\": 30, \"vat\": 20, \"qty\": 4 } ], \"exTaxTotal\": 1870, \"taxTotal\": 374, \"inTaxTotal\": 2244, \"amountRemaining\": 1044, \"invoicePaymentList\": [ { \"paymentDate\": \"2023-02-03T07:28:05+00:00\", \"typeSelect\": \"Paiement\", \"amount\": 1200 } ], \"payment\": { \"name\": \"SEPA Transfer\", \"typeSelect\": \"SEPAtransfer\", \"condition\": \"Upon receipt of invoice\", \"bankLabel\": \"Revolut\", \"bankBIC\": \"REVOGB2L\", \"bankIBAN\": \"FR2112739000409352423869N75\" } }, \"convertTo\" : { \"formatName\" : \"pdf\" } }";
- when(carboneRender.renderReport(json, filename)).thenThrow(new CarboneException("Carbone SDK render error: failled to generate the template id"));
+ when(carboneRender.renderReport(json, filename)).thenThrow(new CarboneException("Carbone SDK render error: failled to generate the template id"));
try {
carboneServices.render(json, filename);
} catch (CarboneException e) {
assertEquals("Carbone SDK render error: failled to generate the template id", e.getMessage());
}
-
+
}
@Test
@@ -250,30 +238,28 @@ public void Test_Render_A_Report_From_An_Null_Template_Id() throws CarboneExcept
final String templateId = "";
final String json = "{ \"data\": { \"invoiceId\": \"FR-2023-781\", \"invoiceDate\": \"2023-01-17\", \"name\": \"Quentin Le Forestier\", \"phone\": \"+33 (0)2 23 12 33 24\", \"email\": \"tim+serverpro@carbone.io\", \"partner\": { \"name\": \"Corp\", \"phone\": \"+33 (0)6 27 89 01 23\", \"email\": \"quentinleforestierleforestier0@gmail.com\", \"vat\": \"FR45899106785\", \"siren\": \"899106785\", \"address\": { \"street\": \"12 Doctor Street\", \"postalcode\": 34920, \"city\": \"Anger\", \"country\": \"France\" } }, \"note\": \"Our team is confident that this cutting-edge technology will enhance your operations and take your business to the next level. Should you have any questions or concerns, please don't hesitate to reach out to us.\", \"subscriptionFromDate\": \"2023-02-02T07:28:05+00:00\", \"subscriptionToDate\": \"2024-04-18T07:28:05+00:00\", \"products\": [ { \"name\": \"Rackmount case (With bays for multiple 3.5-inch drives and room for the motherboard and other components.)\", \"exTaxTotal\": 1000, \"unit\": 1000, \"vat\": 20, \"qty\": 1 }, { \"name\": \"Motherboard (has the necessary number of SATA ports for your storage needs)\", \"exTaxTotal\": 150, \"unit\": 150, \"vat\": 20, \"qty\": 1 }, { \"name\": \"3.5-inch SATA hard drives (20TO)\", \"exTaxTotal\": 1000, \"unit\": 100, \"vat\": 20, \"qty\": 10 }, { \"name\": \"Processor ( A low-power consumption processor)\", \"exTaxTotal\": 100, \"unit\": 100, \"vat\": 20, \"qty\": 1 }, { \"name\": \"4GB DDR5 RAM\", \"exTaxTotal\": 120, \"unit\": 30, \"vat\": 20, \"qty\": 4 } ], \"exTaxTotal\": 1870, \"taxTotal\": 374, \"inTaxTotal\": 2244, \"amountRemaining\": 1044, \"invoicePaymentList\": [ { \"paymentDate\": \"2023-02-03T07:28:05+00:00\", \"typeSelect\": \"Paiement\", \"amount\": 1200 } ], \"payment\": { \"name\": \"SEPA Transfer\", \"typeSelect\": \"SEPAtransfer\", \"condition\": \"Upon receipt of invoice\", \"bankLabel\": \"Revolut\", \"bankBIC\": \"REVOGB2L\", \"bankIBAN\": \"FR2112739000409352423869N75\" } }, \"convertTo\" : { \"formatName\" : \"pdf\" } }";
final String name = "test.pdf";
-
+
CarboneResponse.CarboneResponseData responseData = CarboneResponse.CarboneResponseData.builder()
- .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
- .build();
+ .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
+ .build();
CarboneResponse mockedResponse = CarboneResponse.builder()
- .success(true)
- .data(responseData)
- .build();
+ .success(true)
+ .data(responseData)
+ .build();
String filename = "/src/test/java/io/carbone/template3.odt";
Path filePath = Paths.get(directory, filename);
byte[] fileBytes = Files.readAllBytes(filePath);
when(carboneRender.renderReport(json, templateId)).thenReturn(mockedResponse);
when(carboneRender.getReport(mockedResponse.getData().renderId)).thenReturn(new CarboneDocument(fileBytes, name));
-
- try{
+
+ try {
carboneServices.render(json, templateId);
- }
- catch(CarboneException e){
+ } catch (CarboneException e) {
assertEquals(e.getMessage(), "Carbone SDK render error: argument is missing: file_or_template_id");
}
-
-
-
+
+
}
@@ -283,30 +269,28 @@ public void Test_Render_A_Report_From_An_Null_Json() throws CarboneException, IO
final String templateId = "fb9241ea2218ffd8f974110e539386384620244618c2efbf182b7bd47242987B";
final String json = "";
final String name = "test.pdf";
-
+
CarboneResponse.CarboneResponseData responseData = CarboneResponse.CarboneResponseData.builder()
- .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
- .build();
+ .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
+ .build();
CarboneResponse mockedResponse = CarboneResponse.builder()
- .success(true)
- .data(responseData)
- .build();
+ .success(true)
+ .data(responseData)
+ .build();
String filename = "/src/test/java/io/carbone/template3.odt";
Path filePath = Paths.get(directory, filename);
byte[] fileBytes = Files.readAllBytes(filePath);
when(carboneRender.renderReport(json, templateId)).thenReturn(mockedResponse);
when(carboneRender.getReport(mockedResponse.getData().renderId)).thenReturn(new CarboneDocument(fileBytes, name));
-
- try{
+
+ try {
carboneServices.render(json, templateId);
- }
- catch(CarboneException e){
+ } catch (CarboneException e) {
assertEquals(e.getMessage(), "Carbone SDK render error: argument is missing: json_data");
}
-
-
-
+
+
}
@Test
@@ -315,30 +299,30 @@ public void Test_Render_A_Report_From_An_Existing_Template_Id() throws CarboneEx
final String templateId = "fb9241ea2218ffd8f974110e539386384620244618c2efbf182b7bd47242987B";
final String json = "{ \"data\": { \"invoiceId\": \"FR-2023-781\", \"invoiceDate\": \"2023-01-17\", \"name\": \"Quentin Le Forestier\", \"phone\": \"+33 (0)2 23 12 33 24\", \"email\": \"tim+serverpro@carbone.io\", \"partner\": { \"name\": \"Corp\", \"phone\": \"+33 (0)6 27 89 01 23\", \"email\": \"quentinleforestierleforestier0@gmail.com\", \"vat\": \"FR45899106785\", \"siren\": \"899106785\", \"address\": { \"street\": \"12 Doctor Street\", \"postalcode\": 34920, \"city\": \"Anger\", \"country\": \"France\" } }, \"note\": \"Our team is confident that this cutting-edge technology will enhance your operations and take your business to the next level. Should you have any questions or concerns, please don't hesitate to reach out to us.\", \"subscriptionFromDate\": \"2023-02-02T07:28:05+00:00\", \"subscriptionToDate\": \"2024-04-18T07:28:05+00:00\", \"products\": [ { \"name\": \"Rackmount case (With bays for multiple 3.5-inch drives and room for the motherboard and other components.)\", \"exTaxTotal\": 1000, \"unit\": 1000, \"vat\": 20, \"qty\": 1 }, { \"name\": \"Motherboard (has the necessary number of SATA ports for your storage needs)\", \"exTaxTotal\": 150, \"unit\": 150, \"vat\": 20, \"qty\": 1 }, { \"name\": \"3.5-inch SATA hard drives (20TO)\", \"exTaxTotal\": 1000, \"unit\": 100, \"vat\": 20, \"qty\": 10 }, { \"name\": \"Processor ( A low-power consumption processor)\", \"exTaxTotal\": 100, \"unit\": 100, \"vat\": 20, \"qty\": 1 }, { \"name\": \"4GB DDR5 RAM\", \"exTaxTotal\": 120, \"unit\": 30, \"vat\": 20, \"qty\": 4 } ], \"exTaxTotal\": 1870, \"taxTotal\": 374, \"inTaxTotal\": 2244, \"amountRemaining\": 1044, \"invoicePaymentList\": [ { \"paymentDate\": \"2023-02-03T07:28:05+00:00\", \"typeSelect\": \"Paiement\", \"amount\": 1200 } ], \"payment\": { \"name\": \"SEPA Transfer\", \"typeSelect\": \"SEPAtransfer\", \"condition\": \"Upon receipt of invoice\", \"bankLabel\": \"Revolut\", \"bankBIC\": \"REVOGB2L\", \"bankIBAN\": \"FR2112739000409352423869N75\" } }, \"convertTo\" : { \"formatName\" : \"pdf\" } }";
final String name = "test.pdf";
-
+
CarboneResponse.CarboneResponseData responseData = CarboneResponse.CarboneResponseData.builder()
- .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
- .build();
+ .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
+ .build();
CarboneResponse mockedResponse = CarboneResponse.builder()
- .success(true)
- .data(responseData)
- .build();
+ .success(true)
+ .data(responseData)
+ .build();
String filename = "/src/test/java/io/carbone/template3.odt";
Path filePath = Paths.get(directory, filename);
byte[] fileBytes = Files.readAllBytes(filePath);
when(carboneRender.renderReport(json, templateId)).thenReturn(mockedResponse);
when(carboneRender.getReport(mockedResponse.getData().renderId)).thenReturn(new CarboneDocument(fileBytes, name));
-
+
CarboneDocument resp = carboneServices.render(json, templateId);
-
-
+
+
assertArrayEquals(fileBytes, resp.getFileContent());
assertEquals(resp.getName(), name);
}
@Test
- public void Test_Render_From_A_Template_Already_Upload() throws IOException, CarboneException{
+ public void Test_Render_From_A_Template_Already_Upload() throws IOException, CarboneException {
final String json = "{ \"data\": { \"invoiceId\": \"FR-2023-781\", \"invoiceDate\": \"2023-01-17\", \"name\": \"Quentin Le Forestier\", \"phone\": \"+33 (0)2 23 12 33 24\", \"email\": \"tim+serverpro@carbone.io\", \"partner\": { \"name\": \"Corp\", \"phone\": \"+33 (0)6 27 89 01 23\", \"email\": \"quentinleforestierleforestier0@gmail.com\", \"vat\": \"FR45899106785\", \"siren\": \"899106785\", \"address\": { \"street\": \"12 Doctor Street\", \"postalcode\": 34920, \"city\": \"Anger\", \"country\": \"France\" } }, \"note\": \"Our team is confident that this cutting-edge technology will enhance your operations and take your business to the next level. Should you have any questions or concerns, please don't hesitate to reach out to us.\", \"subscriptionFromDate\": \"2023-02-02T07:28:05+00:00\", \"subscriptionToDate\": \"2024-04-18T07:28:05+00:00\", \"products\": [ { \"name\": \"Rackmount case (With bays for multiple 3.5-inch drives and room for the motherboard and other components.)\", \"exTaxTotal\": 1000, \"unit\": 1000, \"vat\": 20, \"qty\": 1 }, { \"name\": \"Motherboard (has the necessary number of SATA ports for your storage needs)\", \"exTaxTotal\": 150, \"unit\": 150, \"vat\": 20, \"qty\": 1 }, { \"name\": \"3.5-inch SATA hard drives (20TO)\", \"exTaxTotal\": 1000, \"unit\": 100, \"vat\": 20, \"qty\": 10 }, { \"name\": \"Processor ( A low-power consumption processor)\", \"exTaxTotal\": 100, \"unit\": 100, \"vat\": 20, \"qty\": 1 }, { \"name\": \"4GB DDR5 RAM\", \"exTaxTotal\": 120, \"unit\": 30, \"vat\": 20, \"qty\": 4 } ], \"exTaxTotal\": 1870, \"taxTotal\": 374, \"inTaxTotal\": 2244, \"amountRemaining\": 1044, \"invoicePaymentList\": [ { \"paymentDate\": \"2023-02-03T07:28:05+00:00\", \"typeSelect\": \"Paiement\", \"amount\": 1200 } ], \"payment\": { \"name\": \"SEPA Transfer\", \"typeSelect\": \"SEPAtransfer\", \"condition\": \"Upon receipt of invoice\", \"bankLabel\": \"Revolut\", \"bankBIC\": \"REVOGB2L\", \"bankIBAN\": \"FR2112739000409352423869N75\" } }, \"convertTo\" : { \"formatName\" : \"pdf\" } }";
final String name = "test.pdf";
final String templateId = "d13876946291b722c3071c8ed2787037bbb3902e2503f955783c6f5912c5b1d4";
@@ -348,26 +332,26 @@ public void Test_Render_From_A_Template_Already_Upload() throws IOException, Car
byte[] fileBytes = Files.readAllBytes(filePath);
CarboneResponse.CarboneResponseData responseData = CarboneResponse.CarboneResponseData.builder()
- .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
- .build();
+ .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
+ .build();
CarboneResponse mockedResponse = CarboneResponse.builder()
- .success(true)
- .data(responseData)
- .build();
-
+ .success(true)
+ .data(responseData)
+ .build();
+
when(carboneRender.renderReport(json, templateId)).thenReturn(mockedResponse);
when(carboneRender.getReport(mockedResponse.getData().renderId)).thenReturn(new CarboneDocument(fileBytes, name));
CarboneDocument resp = carboneServices.render(json, templateId);
-
-
+
+
assertArrayEquals(fileBytes, resp.getFileContent());
assertEquals(resp.getName(), name);
}
@Test
- public void Test_Render_Something_Wrong() throws IOException, CarboneException{
+ public void Test_Render_Something_Wrong() throws IOException, CarboneException {
final String json = "{ \"data\": { \"invoiceId\": \"FR-2023-781\", \"invoiceDate\": \"2023-01-17\", \"name\": \"Quentin Le Forestier\", \"phone\": \"+33 (0)2 23 12 33 24\", \"email\": \"tim+serverpro@carbone.io\", \"partner\": { \"name\": \"Corp\", \"phone\": \"+33 (0)6 27 89 01 23\", \"email\": \"quentinleforestierleforestier0@gmail.com\", \"vat\": \"FR45899106785\", \"siren\": \"899106785\", \"address\": { \"street\": \"12 Doctor Street\", \"postalcode\": 34920, \"city\": \"Anger\", \"country\": \"France\" } }, \"note\": \"Our team is confident that this cutting-edge technology will enhance your operations and take your business to the next level. Should you have any questions or concerns, please don't hesitate to reach out to us.\", \"subscriptionFromDate\": \"2023-02-02T07:28:05+00:00\", \"subscriptionToDate\": \"2024-04-18T07:28:05+00:00\", \"products\": [ { \"name\": \"Rackmount case (With bays for multiple 3.5-inch drives and room for the motherboard and other components.)\", \"exTaxTotal\": 1000, \"unit\": 1000, \"vat\": 20, \"qty\": 1 }, { \"name\": \"Motherboard (has the necessary number of SATA ports for your storage needs)\", \"exTaxTotal\": 150, \"unit\": 150, \"vat\": 20, \"qty\": 1 }, { \"name\": \"3.5-inch SATA hard drives (20TO)\", \"exTaxTotal\": 1000, \"unit\": 100, \"vat\": 20, \"qty\": 10 }, { \"name\": \"Processor ( A low-power consumption processor)\", \"exTaxTotal\": 100, \"unit\": 100, \"vat\": 20, \"qty\": 1 }, { \"name\": \"4GB DDR5 RAM\", \"exTaxTotal\": 120, \"unit\": 30, \"vat\": 20, \"qty\": 4 } ], \"exTaxTotal\": 1870, \"taxTotal\": 374, \"inTaxTotal\": 2244, \"amountRemaining\": 1044, \"invoicePaymentList\": [ { \"paymentDate\": \"2023-02-03T07:28:05+00:00\", \"typeSelect\": \"Paiement\", \"amount\": 1200 } ], \"payment\": { \"name\": \"SEPA Transfer\", \"typeSelect\": \"SEPAtransfer\", \"condition\": \"Upon receipt of invoice\", \"bankLabel\": \"Revolut\", \"bankBIC\": \"REVOGB2L\", \"bankIBAN\": \"FR2112739000409352423869N75\" } }, \"convertTo\" : { \"formatName\" : \"pdf\" } }";
final String name = "test.pdf";
@@ -376,28 +360,54 @@ public void Test_Render_Something_Wrong() throws IOException, CarboneException{
Path filePath = Paths.get(directory, filename);
byte[] fileBytes = Files.readAllBytes(filePath);
-
+
CarboneResponse.CarboneResponseData responseData = CarboneResponse.CarboneResponseData.builder()
- .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
- .build();
+ .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
+ .build();
CarboneResponse mockedResponse = CarboneResponse.builder()
- .success(true)
- .data(responseData)
- .build();
-
+ .success(true)
+ .data(responseData)
+ .build();
+
when(carboneRender.renderReport(json, directory + filename)).thenReturn(mockedResponse);
when(carboneRender.getReport(mockedResponse.getData().renderId)).thenReturn(new CarboneDocument(fileBytes, name));
- try{
+ try {
carboneServices.render(json, directory + filename);
- }
- catch(CarboneException e){
+ } catch (CarboneException e) {
assertEquals(e.getMessage(), "Carbone SDK render error: something went wrong");
}
}
+ @Test
+ public void Test_Render_A_Specific_Error_Occurs() throws IOException, CarboneException {
+ final String json = "{ \"data\": { \"invoiceId\": \"FR-2023-781\", \"invoiceDate\": \"2023-01-17\", \"name\": \"Quentin Le Forestier\", \"phone\": \"+33 (0)2 23 12 33 24\", \"email\": \"tim+serverpro@carbone.io\", \"partner\": { \"name\": \"Corp\", \"phone\": \"+33 (0)6 27 89 01 23\", \"email\": \"quentinleforestierleforestier0@gmail.com\", \"vat\": \"FR45899106785\", \"siren\": \"899106785\", \"address\": { \"street\": \"12 Doctor Street\", \"postalcode\": 34920, \"city\": \"Anger\", \"country\": \"France\" } }, \"note\": \"Our team is confident that this cutting-edge technology will enhance your operations and take your business to the next level. Should you have any questions or concerns, please don't hesitate to reach out to us.\", \"subscriptionFromDate\": \"2023-02-02T07:28:05+00:00\", \"subscriptionToDate\": \"2024-04-18T07:28:05+00:00\", \"products\": [ { \"name\": \"Rackmount case (With bays for multiple 3.5-inch drives and room for the motherboard and other components.)\", \"exTaxTotal\": 1000, \"unit\": 1000, \"vat\": 20, \"qty\": 1 }, { \"name\": \"Motherboard (has the necessary number of SATA ports for your storage needs)\", \"exTaxTotal\": 150, \"unit\": 150, \"vat\": 20, \"qty\": 1 }, { \"name\": \"3.5-inch SATA hard drives (20TO)\", \"exTaxTotal\": 1000, \"unit\": 100, \"vat\": 20, \"qty\": 10 }, { \"name\": \"Processor ( A low-power consumption processor)\", \"exTaxTotal\": 100, \"unit\": 100, \"vat\": 20, \"qty\": 1 }, { \"name\": \"4GB DDR5 RAM\", \"exTaxTotal\": 120, \"unit\": 30, \"vat\": 20, \"qty\": 4 } ], \"exTaxTotal\": 1870, \"taxTotal\": 374, \"inTaxTotal\": 2244, \"amountRemaining\": 1044, \"invoicePaymentList\": [ { \"paymentDate\": \"2023-02-03T07:28:05+00:00\", \"typeSelect\": \"Paiement\", \"amount\": 1200 } ], \"payment\": { \"name\": \"SEPA Transfer\", \"typeSelect\": \"SEPAtransfer\", \"condition\": \"Upon receipt of invoice\", \"bankLabel\": \"Revolut\", \"bankBIC\": \"REVOGB2L\", \"bankIBAN\": \"FR2112739000409352423869N75\" } }, \"convertTo\" : { \"formatName\" : \"pdf\" } }";
+ final String name = "test.pdf";
+ final String templateId = "d13876946291b722c3071c8ed2787037bbb3902e2503f955783c6f5912c5b1d4";
+
+ String filename = "/src/test/java/io/carbone/template3.odt";
+ Path filePath = Paths.get(directory, filename);
+ byte[] fileBytes = Files.readAllBytes(filePath);
+
+ CarboneResponse.CarboneResponseData responseData = CarboneResponse.CarboneResponseData.builder()
+ .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
+ .build();
+ CarboneResponse mockedResponse = CarboneResponse.builder()
+ .success(false)
+ .error("This is a specific error")
+ .build();
+
+ when(carboneRender.renderReport(json, templateId)).thenReturn(mockedResponse);
+
+ try {
+ carboneServices.render(json, templateId);
+ } catch (CarboneException e) {
+ assertEquals(e.getMessage(), "Carbone SDK render error: This is a specific error");
+ }
+
+ }
@Test
- public void Test_Render_From_A_Generate_Template_Id() throws IOException, CarboneException{
+ public void Test_Render_From_A_Generate_Template_Id() throws IOException, CarboneException {
final String json = "{ \"data\": { \"invoiceId\": \"FR-2023-781\", \"invoiceDate\": \"2023-01-17\", \"name\": \"Quentin Le Forestier\", \"phone\": \"+33 (0)2 23 12 33 24\", \"email\": \"tim+serverpro@carbone.io\", \"partner\": { \"name\": \"Corp\", \"phone\": \"+33 (0)6 27 89 01 23\", \"email\": \"quentinleforestierleforestier0@gmail.com\", \"vat\": \"FR45899106785\", \"siren\": \"899106785\", \"address\": { \"street\": \"12 Doctor Street\", \"postalcode\": 34920, \"city\": \"Anger\", \"country\": \"France\" } }, \"note\": \"Our team is confident that this cutting-edge technology will enhance your operations and take your business to the next level. Should you have any questions or concerns, please don't hesitate to reach out to us.\", \"subscriptionFromDate\": \"2023-02-02T07:28:05+00:00\", \"subscriptionToDate\": \"2024-04-18T07:28:05+00:00\", \"products\": [ { \"name\": \"Rackmount case (With bays for multiple 3.5-inch drives and room for the motherboard and other components.)\", \"exTaxTotal\": 1000, \"unit\": 1000, \"vat\": 20, \"qty\": 1 }, { \"name\": \"Motherboard (has the necessary number of SATA ports for your storage needs)\", \"exTaxTotal\": 150, \"unit\": 150, \"vat\": 20, \"qty\": 1 }, { \"name\": \"3.5-inch SATA hard drives (20TO)\", \"exTaxTotal\": 1000, \"unit\": 100, \"vat\": 20, \"qty\": 10 }, { \"name\": \"Processor ( A low-power consumption processor)\", \"exTaxTotal\": 100, \"unit\": 100, \"vat\": 20, \"qty\": 1 }, { \"name\": \"4GB DDR5 RAM\", \"exTaxTotal\": 120, \"unit\": 30, \"vat\": 20, \"qty\": 4 } ], \"exTaxTotal\": 1870, \"taxTotal\": 374, \"inTaxTotal\": 2244, \"amountRemaining\": 1044, \"invoicePaymentList\": [ { \"paymentDate\": \"2023-02-03T07:28:05+00:00\", \"typeSelect\": \"Paiement\", \"amount\": 1200 } ], \"payment\": { \"name\": \"SEPA Transfer\", \"typeSelect\": \"SEPAtransfer\", \"condition\": \"Upon receipt of invoice\", \"bankLabel\": \"Revolut\", \"bankBIC\": \"REVOGB2L\", \"bankIBAN\": \"FR2112739000409352423869N75\" } }, \"convertTo\" : { \"formatName\" : \"pdf\" } }";
final String name = "test.pdf";
@@ -407,39 +417,39 @@ public void Test_Render_From_A_Generate_Template_Id() throws IOException, Carbon
byte[] fileBytes = Files.readAllBytes(filePath);
String templateId = carboneServices.generateTemplateId(filename);
CarboneResponse.CarboneResponseData responseDataRender = CarboneResponse.CarboneResponseData.builder()
- .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
- .build();
+ .renderId("MTAuMjAuMTEuNDAgICAgCRLu7jNNEe84ubAa82ofaAcmVwb3J0.pdf")
+ .build();
CarboneResponse mockedResponseRender = CarboneResponse.builder()
- .success(true)
- .data(responseDataRender)
- .build();
-
+ .success(true)
+ .data(responseDataRender)
+ .build();
+
CarboneResponse.CarboneResponseData responseData = CarboneResponse.CarboneResponseData.builder()
- .templateId(templateId)
- .build();
+ .templateId(templateId)
+ .build();
CarboneResponse mockedResponse = CarboneResponse.builder()
- .success(true)
- .data(responseData)
- .build();
+ .success(true)
+ .data(responseData)
+ .build();
CarboneResponse mocked = CarboneResponse.builder()
- .success(false)
- .build();
+ .success(false)
+ .build();
CarboneException mockException = CarboneException.builder()
- .carboneResponse(mocked)
- .httpStatus(404)
- .build();
-
+ .carboneResponse(mocked)
+ .httpStatus(404)
+ .build();
+
when(carboneRender.renderReport(json, templateId)).thenThrow(mockException).thenReturn(mockedResponseRender);
-
+
when(carboneTemplate.addTemplate(fileBytes)).thenReturn(mockedResponse);
when(carboneRender.getReport(mockedResponseRender.getData().renderId)).thenReturn(new CarboneDocument(fileBytes, name));
-
+
CarboneDocument resp = carboneServices.render(json, filename);
-
-
+
+
assertArrayEquals(fileBytes, resp.getFileContent());
assertEquals(resp.getName(), name);
-
+
}
@Test
@@ -451,19 +461,19 @@ public void Test_Get_Status() throws CarboneException {
Request originalRequest = Request.create(Request.HttpMethod.GET, CARBONE_URI + "/status", headers, null, StandardCharsets.UTF_8, null);
Response response = Response.builder()
- .status(200)
- .request(originalRequest)
- .headers(Collections.emptyMap())
- .body("{\"success\":true,\"code\":200,\"message\":\"OK\",\"version\":\"4.22.8\"}", StandardCharsets.UTF_8)
- .build();
+ .status(200)
+ .request(originalRequest)
+ .headers(Collections.emptyMap())
+ .body("{\"success\":true,\"code\":200,\"message\":\"OK\",\"version\":\"4.22.8\"}", StandardCharsets.UTF_8)
+ .build();
when(carboneStatus.getStatus()).thenReturn(response);
String result = carboneServices.getStatus();
assertEquals("{\"success\":true,\"code\":200,\"message\":\"OK\",\"version\":\"4.22.8\"}", result);
}
- @Test
- public void Test_Set_Carbon_Uri() throws CarboneException{
+ @Test
+ public void Test_Set_Carbon_Uri() throws CarboneException {
CarboneServicesFactory.CARBONE_SERVICES_FACTORY_INSTANCE.SetCarboneUrl(directory);
@@ -471,14 +481,14 @@ public void Test_Set_Carbon_Uri() throws CarboneException{
}
@Test
- public void Test_Carbon_Service_Fectory() throws CarboneException{
+ public void Test_Carbon_Service_Fectory() throws CarboneException {
ICarboneServices carboneService = CarboneServicesFactory.CARBONE_SERVICES_FACTORY_INSTANCE.create("token", "4");
String status = carboneService.getStatus();
assertEquals(status.contains("\"success\":true,\"code\":200"), true);
}
@Test
- public void Test_Carbon_Service_Fectory_With_No_Argument() throws CarboneException{
+ public void Test_Carbon_Service_Fectory_With_No_Argument() throws CarboneException {
ICarboneServices carboneService = CarboneServicesFactory.CARBONE_SERVICES_FACTORY_INSTANCE.create("");
String status = carboneService.getStatus();
assertEquals(status.contains("\"success\":true,\"code\":200"), true);