Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text report testing with Java application

I am working on a project that I have to check if some(500) reports, generated from a system, are passed or failed.

I face 2 problems.

  1. Text-parsing. Each report is unique and has different formats.

report example :

Ticket sales

Movies Full_seats Sales Empty_seats

Movie 1 Monday 100 500 20

Tuesday 120 600 0

Wednesday 80 400 40

Thursday 100 500 20

Friday 100 500 20

Movie 2

Monday 100 500 20

Tuesday 120 600 0

Wednesday 80 400 40

Thursday 100 500 20

Friday 100 500 20

and so on...

end of report.

What can I do in order to map the values from the report, and save them into java collection. Is there a more clever way that to create 500 different parsing methods?

  1. compare the reports with the information from the app. I want to have a configuration file for each report and within that to write what do I need to compare from the app. for example:

report.grossSales & sales.getDay(18_9_2016).grossSales();

the above will mean for the automation to run:

if(report.grossSales != sales.getDay(18_9_2016).grossSales()){
  System.out.print("failed");
}

Feel free to suggest other ways, more clever and flexible. Thank you

like image 419
Emanonk Avatar asked Dec 02 '25 06:12

Emanonk


1 Answers

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ReadFile {
  public static void main(String[]args) throws IOException{

      FileReader in = new FileReader("C:/test.txt");
      BufferedReader br = new BufferedReader(in);
      String line = "";
      String wholeReportText="";
      while ((line = br.readLine()) != null) {
         wholeReportText += line;
      }
      in.close();

           Pattern pattern = Pattern.compile("Movies(.*?)");
           Matcher matcher = pattern.matcher(wholeReportText);
           // check all occurance
           while (matcher.find()) {
                   System.out.println(matcher.group(1));
           }

      Pattern daypat = Pattern.compile("Tuesday (.*?)");
      Matcher daymat = daypat.matcher(wholeReportText);
      // check all occurance
      while (daymat.find()) {
            System.out.println(matcher.group(1));
      }


  }
}

Your Problem needs to be broke in sub problems as in case of algorithms

Step 1) To list all the files which you need to parse (File API in java FileFilter in java NIO and Paths API in java7)

Step 2) Read and extract data from file one by one (sample code above)

Step 3) Store the extracted data in some HashMap or ArrayList

Step 4) Use collections as per your requirement

like image 168
SarthAk Avatar answered Dec 04 '25 18:12

SarthAk