|
28 | 28 | import com.proofpoint.bootstrap.LifeCycleManager; |
29 | 29 | import com.proofpoint.discovery.client.testing.TestingDiscoveryModule; |
30 | 30 | import com.proofpoint.event.client.JsonEventModule; |
31 | | -import com.proofpoint.http.client.BodyGenerator; |
32 | 31 | import com.proofpoint.http.client.HttpClient; |
33 | 32 | import com.proofpoint.http.client.StatusResponseHandler.StatusResponse; |
34 | 33 | import com.proofpoint.http.client.StringResponseHandler.StringResponse; |
|
48 | 47 |
|
49 | 48 | import java.io.File; |
50 | 49 | import java.io.IOException; |
51 | | -import java.io.OutputStream; |
52 | 50 | import java.net.URI; |
53 | 51 | import java.util.concurrent.ExecutionException; |
54 | 52 |
|
55 | 53 | import static com.proofpoint.http.client.JsonBodyGenerator.jsonBodyGenerator; |
56 | 54 | import static com.proofpoint.http.client.Request.Builder.prepareDelete; |
57 | 55 | import static com.proofpoint.http.client.Request.Builder.prepareGet; |
58 | 56 | import static com.proofpoint.http.client.Request.Builder.preparePost; |
| 57 | +import static com.proofpoint.http.client.SmileBodyGenerator.smileBodyGenerator; |
59 | 58 | import static com.proofpoint.http.client.StaticBodyGenerator.createStaticBodyGenerator; |
60 | 59 | import static com.proofpoint.http.client.StatusResponseHandler.createStatusResponseHandler; |
61 | 60 | import static com.proofpoint.http.client.StringResponseHandler.createStringResponseHandler; |
|
68 | 67 | public class TestServer |
69 | 68 | { |
70 | 69 | private static final JsonCodec<Object> OBJECT_CODEC = JsonCodec.jsonCodec(Object.class); |
71 | | - private static final ObjectMapper MAPPER = new ObjectMapper(new SmileFactory()).disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); |
72 | 70 | private static final Object TESTING_SINGLE_EVENT_STRUCTURE = ImmutableList.of( |
73 | 71 | ImmutableMap.of( |
74 | 72 | "type", "Test", |
@@ -169,18 +167,10 @@ public void testPostSmile() |
169 | 167 | throws IOException, ExecutionException, InterruptedException |
170 | 168 | { |
171 | 169 | StatusResponse response = client.execute(preparePost() |
172 | | - .setUri(urlFor("/v2/event")) |
173 | | - .setHeader("Content-Type", "application/x-jackson-smile") |
174 | | - .setBodyGenerator(new BodyGenerator() |
175 | | - { |
176 | | - @Override |
177 | | - public void write(OutputStream outputStream) |
178 | | - throws Exception |
179 | | - { |
180 | | - MAPPER.writeValue(outputStream, TESTING_SINGLE_EVENT_STRUCTURE); |
181 | | - } |
182 | | - }) |
183 | | - .build(), |
| 170 | + .setUri(urlFor("/v2/event")) |
| 171 | + .setHeader("Content-Type", "application/x-jackson-smile") |
| 172 | + .setBodyGenerator(smileBodyGenerator(OBJECT_CODEC, TESTING_SINGLE_EVENT_STRUCTURE)) |
| 173 | + .build(), |
184 | 174 | createStatusResponseHandler()); |
185 | 175 |
|
186 | 176 | assertEquals(response.getStatusCode(), Status.ACCEPTED.getStatusCode()); |
@@ -248,15 +238,7 @@ public void testDistributeSmile() |
248 | 238 | StatusResponse response = client.execute(preparePost() |
249 | 239 | .setUri(urlFor("/v2/event/distribute")) |
250 | 240 | .setHeader("Content-Type", "application/x-jackson-smile") |
251 | | - .setBodyGenerator(new BodyGenerator() |
252 | | - { |
253 | | - @Override |
254 | | - public void write(OutputStream outputStream) |
255 | | - throws Exception |
256 | | - { |
257 | | - MAPPER.writeValue(outputStream, TESTING_SINGLE_EVENT_STRUCTURE); |
258 | | - } |
259 | | - }) |
| 241 | + .setBodyGenerator(smileBodyGenerator(OBJECT_CODEC, TESTING_SINGLE_EVENT_STRUCTURE)) |
260 | 242 | .build(), |
261 | 243 | createStatusResponseHandler()); |
262 | 244 |
|
|
0 commit comments