import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.IOException;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
assertTrue(map.size() == size);
}
- private void checkfindReportsByDateBetweenSize(String DateFrom, String DateTo, int size) {
- try {
- String datePattern = "MM-dd-yyyy";
- SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
- Date df = sdf.parse(DateFrom);
- Date dt = sdf.parse(DateTo);
- Response resp = Reports.findReportsByDateBetween(df,dt);
- checkReportSize(resp, size);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ private void checkfindReportsByDateBetweenSize(String dateFrom, String dateTo, int size) throws ParseException {
+ String datePattern = "MM-dd-yyyy";
+ SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
+ Date df = sdf.parse(dateFrom);
+ Date dt = sdf.parse(dateTo);
+ Response resp = Reports.findReportsByDateBetween(df,dt);
+ checkReportSize(resp, size);
}
- private void checkfindReportsByDateBetween() {
+ private void checkfindReportsByDateBetween() throws ParseException {
log("checkfindReportsByDateBetween");
final int size1 = 3;
checkfindReportsByDateBetweenSize("05-08-2017","05-09-2017",size1);
checkReportSize(resp, size);
}
- private boolean checkEqualsJSON(String json1, String json2) {
- boolean res = false;
- try {
- ObjectMapper om = new ObjectMapper();
- @SuppressWarnings("unchecked")
- Map<String, Object> map1 = (Map<String, Object>)(om.readValue(json1, Map.class));
- @SuppressWarnings("unchecked")
- Map<String, Object> map2 = (Map<String, Object>)(om.readValue(json2, Map.class));
- res = map1.equals(map2);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return res;
+ private boolean checkEqualsJSON(String json1, String json2) throws IOException {
+ ObjectMapper om = new ObjectMapper();
+ @SuppressWarnings("unchecked")
+ Map<String, Object> map1 = (Map<String, Object>)(om.readValue(json1, Map.class));
+ @SuppressWarnings("unchecked")
+ Map<String, Object> map2 = (Map<String, Object>)(om.readValue(json2, Map.class));
+ return map1.equals(map2);
}
- private void assertReportEquals(String current, String expected) {
- try {
- Response resp = Reports.findReportsByType(current);
- String json1 = resp.getBody().asString();
- String json2 = readReport(expected);
- assertTrue(checkEqualsJSON(json1, json2));
- } catch (Exception e) {
- e.printStackTrace();
- }
+ private void assertReportEquals(String current, String expected) throws IOException {
+ Response resp = Reports.findReportsByType(current);
+ String json1 = resp.getBody().asString();
+ String json2 = readReport(expected);
+ assertTrue(checkEqualsJSON(json1, json2));
}
- private void checkfindReportsByType() {
+ private void checkfindReportsByType() throws IOException {
log("checkfindReportsByType");
assertReportEquals(SMACK, SMACK_REPORT_EXPECTED);
assertReportEquals(DAC, DAC_REPORT_EXPECTED);
}
@Test
- public void testTIAReports() throws InterruptedException, IOException {
+ public void testTIAReports() throws InterruptedException, IOException, ParseException {
log("Create new user for TIA get report scenario");
createNewUser();
String uuid = "TIA-test-uuid";
SortedMap<Integer, Map<String, String>> mapReports = new TreeMap<>();
List<Report> reports = reportService.findReportsByResult(result);
int rec = 0;
- for (Report report : reports) putReport2Map(++rec,report,mapReports);
+ for (Report report : reports) {
+ putReport2Map(++rec,report,mapReports);
+ }
LOG.debug(format("findReportsByResult by result:%s - %s ", result, mapReports));
return new ResponseEntity<>(new Gson().toJson(mapReports), httpHeaders, HttpStatus.OK);
}
ReportType reportType = reportTypeService.findByName(type);
List<Report> reports = reportService.findReportsByType(reportType);
int rec = 0;
- for (Report report : reports) putReport2Map(++rec,report,mapReports);
+ for (Report report : reports) {
+ putReport2Map(++rec,report,mapReports);
+ }
LOG.debug(format("findReportsByType by type:%s - %s ", type, mapReports));
return new ResponseEntity<>(new Gson().toJson(mapReports), httpHeaders, HttpStatus.OK);
}
SortedMap<Integer, Map<String, String>> mapReports = new TreeMap<>();
List<Report> reports = reportService.findReportsByDateBetween(dateFrom, dateTo);
int rec = 0;
- String datePattern = "hh:mm a; MMM dd, yyyy"; //12:25 PM; May 08, 2017
+ String datePattern = "hh:mm a; MMM dd, yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
for (Report report : reports) {
try {
Date date = sdf.parse(report.getDate());
- if (date.before(dateTo) && date.after(dateFrom)) putReport2Map(++rec,report,mapReports);
+ if (date.before(dateTo) && date.after(dateFrom)) {
+ putReport2Map(++rec,report,mapReports);
+ }
} catch (Exception e) {
LOG.error("Wrong date format: " + report.getReport());
}