MCPcopy Index your code
hub / github.com/OpenFeign/feign / CustomClientTest

Class CustomClientTest

form/src/test/java/feign/form/CustomClientTest.java:38–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36import org.springframework.boot.test.context.SpringBootTest;
37
38@SpringBootTest(webEnvironment = DEFINED_PORT, classes = Server.class)
39class CustomClientTest {
40
41 private static CustomClient API;
42
43 @TempDir static Path logDir;
44
45 @BeforeAll
46 static void configureClient() {
47 var encoder = new FormEncoder(new JacksonEncoder());
48 var processor = (MultipartFormContentProcessor) encoder.getContentProcessor(MULTIPART);
49 processor.addFirstWriter(new CustomByteArrayWriter());
50
51 var logFile = logDir.resolve("log.txt").toString();
52
53 API =
54 Feign.builder()
55 .encoder(encoder)
56 .logger(new JavaLogger(CustomClientTest.class).appendToFile(logFile))
57 .logLevel(FULL)
58 .target(CustomClient.class, "http://localhost:8080");
59 }
60
61 @Test
62 void test() {
63 assertThat(API.uploadByteArray(new byte[0])).isNotNull().isEqualTo("popa.txt");
64 }
65
66 private static final class CustomByteArrayWriter extends ByteArrayWriter {
67
68 @Override
69 protected void write(Output output, String key, Object value) throws EncodeException {
70 writeFileMetadata(output, key, "popa.txt", null);
71
72 var bytes = (byte[]) value;
73 output.write(bytes);
74 }
75 }
76
77 interface CustomClient {
78
79 @RequestLine("POST /upload/byte_array")
80 @Headers("Content-Type: multipart/form-data")
81 String uploadByteArray(@Param("file") byte[] bytes);
82 }
83}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected