DDMFormInstanceRecordCSVWriter implements DDMFormInstanceRecordWriter { @Override public DDMFormInstanceRecordWriterResponse write( DDMFormInstanceRecordWriterRequest ddmFormInstanceRecordWriterRequest) throws Exception { StringBundler sb = new StringBundler(3); Map<String, String> ddmFormFieldsLabel = ddmFormInstanceRecordWriterRequest.getDDMFormFieldsLabel(); sb.append(writeValues(ddmFormFieldsLabel.values())); sb.append(StringPool.NEW_LINE); sb.append( writeRecords( ddmFormInstanceRecordWriterRequest.getDDMFormFieldValues())); String csv = sb.toString(); DDMFormInstanceRecordWriterResponse.Builder builder = DDMFormInstanceRecordWriterResponse.Builder.newBuilder( csv.getBytes()); return builder.build(); }  @Override DDMFormInstanceRecordWriterResponse write(
			DDMFormInstanceRecordWriterRequest
				ddmFormInstanceRecordWriterRequest);  }
@Test public void testWrite() throws Exception { Map<String, String> ddmFormFieldsLabel = LinkedHashMapBuilder.put( "field1", "Field 1" ).put( "field2", "Field 2" ).put( "field3", "Field 3" ).put( "field4", "Field 4" ).build(); List<Map<String, String>> ddmFormFieldValues = new ArrayList<Map<String, String>>() { { add( LinkedHashMapBuilder.put( "field1", "2" ).put( "field2", "esta é uma 'string'" ).put( "field3", "false" ).put( "field4", "11.7" ).build()); add( LinkedHashMapBuilder.put( "field1", "1" ).put( "field2", "esta é uma 'string'" ).put( "field3", "" ).put( "field4", "10" ).build()); } }; DDMFormInstanceRecordWriterRequest.Builder builder = DDMFormInstanceRecordWriterRequest.Builder.newBuilder( ddmFormFieldsLabel, ddmFormFieldValues); DDMFormInstanceRecordCSVWriter ddmFormInstanceRecordCSVWriter = new DDMFormInstanceRecordCSVWriter(); DDMFormInstanceRecordWriterResponse ddmFormInstanceRecordWriterResponse = ddmFormInstanceRecordCSVWriter.write(builder.build()); StringBundler sb = new StringBundler(3); sb.append("Field 1,Field 2,Field 3,Field 4\n"); sb.append("2,esta é uma 'string',false,11.7\n"); sb.append("1,esta é uma 'string',,10"); String expected = sb.toString(); Assert.assertArrayEquals( expected.getBytes(), ddmFormInstanceRecordWriterResponse.getContent()); }
@Test public void testWriteAfterChangeFieldName() throws Exception { Map<String, String> ddmFormFieldsLabel = LinkedHashMapBuilder.put( "field1", "Field 1" ).put( "field1AfterChangeName", "Field 1" ).put( "field2", "Field 2" ).build(); List<Map<String, String>> ddmFormFieldValues = new ArrayList<Map<String, String>>() { { add( HashMapBuilder.put( "field1", "1" ).put( "field1AfterChangeName", "" ).put( "field2", "esta é uma 'string'" ).build()); add( HashMapBuilder.put( "field1", "" ).put( "field1AfterChangeName", "2" ).put( "field2", "esta é uma 'string'" ).build()); } }; DDMFormInstanceRecordWriterRequest.Builder builder = DDMFormInstanceRecordWriterRequest.Builder.newBuilder( ddmFormFieldsLabel, ddmFormFieldValues); DDMFormInstanceRecordCSVWriter ddmFormInstanceRecordCSVWriter = new DDMFormInstanceRecordCSVWriter(); DDMFormInstanceRecordWriterResponse ddmFormInstanceRecordWriterResponse = ddmFormInstanceRecordCSVWriter.write(builder.build()); StringBundler sb = new StringBundler(3); sb.append("Field 1 (field1),Field 1 (field1AfterChangeName),Field 2\n"); sb.append("1,,esta é uma 'string'\n"); sb.append(",2,esta é uma 'string'"); String expected = sb.toString(); Assert.assertArrayEquals( expected.getBytes(), ddmFormInstanceRecordWriterResponse.getContent()); }