public void testOneField() throws IOException { Map<String,String> params = new HashMap<>(); params.put("TestXY", "one two three"); checkOutput(params); }
private void checkOutput( final Map<String, String> params, final Collection<FileFieldInfo> fileParams) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); FormDataWriter writer = new FormDataWriter() { @Override protected void write() throws IOException { for(Map.Entry<String,String> entry : params.entrySet()) { addField(entry.getKey(), entry.getValue()); } for(FileFieldInfo info : fileParams) { addFileField(info.name, info.fileName, info.subWriter); } } }; writer.write(out); String expected = createExpectedOutput(writer.boundary, params, fileParams); assertEquals(expected, TestUtils.asString(out)); }
public void testMultipleField() throws IOException { Map<String,String> params = new HashMap<>(); params.put("TestXY", "one two three"); params.put("TestAB", "one two three four"); checkOutput(params); }
public void testFileField() throws IOException { Map<String,String> params = new HashMap<>(); params.put("TestXY", "one two three"); FileFieldInfo info = new FileFieldInfo(); info.fileName = "failname"; info.name = "naim"; info.subWriter = new PlainTextWriter("my daita"); checkOutput(params, Arrays.asList(info)); }
public void testMultipleFileField() throws IOException { Map<String,String> params = new HashMap<>(); params.put("TestXY", "one two three"); FileFieldInfo info = new FileFieldInfo(); info.fileName = "failname"; info.name = "naim"; info.subWriter = new PlainTextWriter("my daita"); FileFieldInfo info2 = new FileFieldInfo(); info2.fileName = "failname2"; info2.name = "naim2"; info2.subWriter = new PlainTextWriter("my daita2"); checkOutput(params, Arrays.asList(info, info2)); }