unit testing - Test flat file content and format in Java -
i have send flat file external system. sample file content given below:
start 20150602 header 100.00usd product test1 50.00usd product test2 50.00usd footer 002
this file should follow below guidelines:
first line - starts start, space, today's date in yyyymmdd header line - starts header, space, total amount of first, second, third etc products 2 decimal points, currency first product - starts product, space, product name left aligned total 25 characters, amount 2 decimal points, currency more products similar first product, number of products dynamic footer - starts footer, space, total number of products 3 digits
this format has been given external system vendor in excel.
can of suggest better testing strategy in these case? there tools test file content , format?
in situations this, prefer explore options starting simple approach, based on elementary java features. here, each line may described regular expression:
start (\d{8}) header (\d+\.\d{2})(\w{3}) product (.{25}) (\d+\.\d{2})(\w{3}) footer (\d{3})
you may not need parentheses if don't need extract , check values. otoh, add list of strings, providing names these fields can entered map.
you can add minimum , maximum repeat count each line, let write simple logic iterate through lines of file.
these might factory method calls of above defined couple of lines:
linedef.create( "header (\\d+\\.\\d{2})(\\w{3})", 1, 1, "totalamount", "totalcurrency" ); linedef.create( "product (.{25}) (\\d+\\.\\d{2})(\\w{3})", 1, 999, "name", "amount", "currency" );
Comments
Post a Comment