tbrugz avatar tbrugz committed beeac53

test: changes in CSV test (using apache-commons-csv)

Comments (0)

Files changed (1)

src_test/tbrugz/queryon/http/WinstoneAndH2HttpRequestTest.java

 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.sql.SQLException;
+import java.util.Iterator;
 
 import javax.naming.NamingException;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVParser;
 import org.apache.commons.csv.CSVRecord;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 		HttpEntity entity1 = response1.getEntity();
 		Reader in = new InputStreamReader(entity1.getContent());
 		
-		int count = 0;
+		//int count = 0;
 		CSVFormat format = CSVFormat.newBuilder(CSVFormat.DEFAULT).withHeader().build();
-		for (CSVRecord record: format.parse(in)) {
+		CSVParser parser = new CSVParser(in, format);
+		System.out.println("headers: "+parser.getHeaderMap());
+		Iterator<CSVRecord> it = parser.iterator();
+		
+		Assert.assertTrue("Must have 1st element", it.hasNext());
+		CSVRecord record = it.next();
+		System.out.println("1st record (name = '"+record.get("name")+"'): "+record);
+		Assert.assertEquals("1st record name must be DEPT", "DEPT", record.get("name"));
+		
+		Assert.assertTrue("Must have 2nd element", it.hasNext());
+		record = it.next();
+		System.out.println("2nd record (name = '"+record.get("name")+"'): "+record);
+		Assert.assertEquals("1st record name must be DEPT", "EMP", record.get("name"));
+		
+		Assert.assertFalse("Must not have have 3rd element", it.hasNext());
+		/*for (CSVRecord record: format.parse(in)) {
 			/*for (String field : record) {
 				System.out.print("\"" + field + "\", ");
 			}
-			System.out.println();*/
+			System.out.println();* /
 			System.out.println("record: "+record);
 			count++;
 		}
 		
-		Assert.assertEquals("Should have 2 (data) rows", 2, count);
+		Assert.assertEquals("Should have 2 (data) rows", 2, count);*/
 		
 		EntityUtils.consume(entity1);
 		httpGet.releaseConnection();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.