package fixtures.bodyformdata;

import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.InputStream;

import fixtures.bodyformdata.implementation.AutoRestSwaggerBATFormDataServiceImpl;

public class FormdataTests {
    private static AutoRestSwaggerBATFormDataService client;

    @BeforeClass
    public static void setup() {
        client = new AutoRestSwaggerBATFormDataServiceImpl("http://localhost:3000");
    }

    @Test
    public void uploadFile() throws Exception {
        ClassLoader classLoader = getClass().getClassLoader();
        InputStream stream = classLoader.getResourceAsStream("upload.txt");
        byte[] bytes = IOUtils.toByteArray(stream);
        stream.close();
        InputStream result = client.formdatas().uploadFile(bytes, "sample.png").getBody();
        try {
            Assert.assertEquals(new String(bytes), IOUtils.toString(result));
        } finally {
            result.close();
        }
    }

    @Test
    public void uploadFileViaBody() throws Exception {
        ClassLoader classLoader = getClass().getClassLoader();
        InputStream stream = classLoader.getResourceAsStream("upload.txt");
        byte[] bytes = IOUtils.toByteArray(stream);
        stream.close();
        InputStream result = client.formdatas().uploadFileViaBody(bytes).getBody();
        try {
            Assert.assertEquals(new String(bytes), IOUtils.toString(result));
        } finally {
            result.close();
        }
    }
}

@@ -25,16 +25,60 @@
 mdata;%0A%0A
+import com.microsoft.rest.ServiceResponse;%0A%0A
 import o
@@ -107,16 +107,16 @@
 OUtils;%0A
-
 import o
@@ -186,16 +186,44 @@
 .Test;%0A%0A
+import java.io.IOException;%0A
 import j
@@ -325,16 +325,76 @@
 iceImpl;
+%0Aimport rx.exceptions.Exceptions;%0Aimport rx.functions.Func1;
 %0A%0Apublic
@@ -1269,32 +1269,37 @@
 ader();%0A        
+try (
 InputStream stre
@@ -1344,34 +1344,37 @@
 upload.txt%22)
-;%0A
+) %7B%0A 
         
 byte%5B%5D bytes
@@ -1353,32 +1353,35 @@
 t%22)) %7B%0A         
+   
 byte%5B%5D bytes = I
@@ -1408,32 +1408,36 @@
 tream);%0A        
+    
 stream.close();%0A
@@ -1444,34 +1444,33 @@
         
-InputStream result
+    byte%5B%5D actual
  = clien
@@ -1504,26 +1504,97 @@
 Body
+Async
 (bytes)
-.getBody();
+%0A                    .map(new Func1%3CServiceResponse%3CInputStream%3E, byte%5B%5D%3E() %7B
 %0A   
@@ -1590,38 +1590,33 @@
 %5B%5D%3E() %7B%0A        
-try %7B%0A
+ 
             Asse
@@ -1615,119 +1615,549 @@
     
-Assert.assertEquals(new String(bytes), IOUtils.toString(result));%0A        %7D finally %7B%0A            result.close(
+   @Override%0A                        public byte%5B%5D call(ServiceResponse%3CInputStream%3E inputStreamServiceResponse) %7B%0A                            try %7B%0A                                return IOUtils.toByteArray(inputStreamServiceResponse.getBody());%0A                            %7D catch (IOException e) %7B%0A                                throw Exceptions.propagate(e);%0A                            %7D%0A                        %7D%0A                    %7D).toBlocking().single();%0A            Assert.assertEquals(new String(bytes), IOUtils.toString(actual)
 );%0A 
@@ -2161,20 +2161,21 @@
 ;%0A        %7D%0A
+%0A
     %7D%0A%7D%0A

Fix formdata test