Skip to content

Commit

Permalink
report-kit: adding excel writing test
Browse files Browse the repository at this point in the history
  • Loading branch information
itsoulltd committed Aug 9, 2022
1 parent b520155 commit 31f61d3
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package com.infoworks.lab.services.excel;

import com.fasterxml.jackson.core.type.TypeReference;
import com.infoworks.lab.definition.ContentWriter;
import com.infoworks.lab.util.services.iResourceService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;
import java.io.File;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

public class ExcelWritingServiceTest {

Expand All @@ -14,4 +26,38 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
}

@Test
public void readJsonAndWriteToExcel() throws Exception {
//Reading From Resources:
iResourceService manager = iResourceService.create();
File imfFile = new File("rider-mock-data.json");
InputStream ios = manager.createStream(imfFile);
String json = manager.readAsString(ios);
ios.close();
Map<String, Object> data = manager.readAsJsonObject(json, new TypeReference<Map<String, Object>>() {});

//Prepare Report-Data:
List<Map<String, Object>> riders = (List<Map<String, Object>>) data.get("findRiders");
Map<Integer, List<String>> inferable = new HashMap();
AtomicInteger count = new AtomicInteger(0);
//Adding Header
inferable.put(count.getAndIncrement(), Arrays.asList("Name", "Geo-Hash", "Email", "Age", "Gender"));
riders.forEach(entry -> {
List<String> loj = entry
.values().stream()
.filter(val -> val != null)
.map(val -> val.toString())
.collect(Collectors.toList());
inferable.put(count.getAndIncrement(), loj);
});

//Excel Writer:
ExcelWritingService writingService = new ExcelWritingService();
//ContentWriter writer = writingService.createWriter(true, "target/rider-report-1.xlsx", true);
ContentWriter writer = writingService.createAsyncWriter(100, "target/rider-report-2.xlsx", true);
writer.write("output", inferable, true);
writer.close();
Assert.assertTrue(true);
}
}
42 changes: 42 additions & 0 deletions ReportContentIOKit/src/test/resources/rider-mock-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"verify": {
"isVerified": true
},
"findRiders": [
{
"name": "Rahim",
"geoHash": "GeoHash-1",
"email": "[email protected]",
"age": 19,
"gender": "Male"
},
{
"name": "Karim",
"geoHash": "GeoHash-2",
"email": "[email protected]",
"age": 30,
"gender": "Male"
},
{
"name": "Jamal",
"geoHash": "GeoHash-3",
"email": "[email protected]",
"age": 20,
"gender": "Male"
},
{
"name": "Naiem",
"geoHash": "GeoHash-4",
"email": "[email protected]",
"age": 29,
"gender": "Male"
},
{
"name": "Naiem Uddin Ahmed",
"geoHash": "GeoHash-4",
"email": "[email protected]",
"age": 29,
"gender": "Male"
}
]
}

0 comments on commit 31f61d3

Please sign in to comment.