Пример #1
0
  @Test
  public void testApiClient() {
    // the default api client is used
    assertEquals(Configuration.getDefaultApiClient(), api.getApiClient());
    assertNotNull(api.getApiClient());
    assertEquals("http://petstore.swagger.io/v2", api.getApiClient().getBasePath());
    assertFalse(api.getApiClient().isDebugging());

    ApiClient oldClient = api.getApiClient();

    ApiClient newClient = new ApiClient();
    newClient.setBasePath("http://example.com");
    newClient.setDebugging(true);

    // set api client via constructor
    api = new PetApi(newClient);
    assertNotNull(api.getApiClient());
    assertEquals("http://example.com", api.getApiClient().getBasePath());
    assertTrue(api.getApiClient().isDebugging());

    // set api client via setter method
    api.setApiClient(oldClient);
    assertNotNull(api.getApiClient());
    assertEquals("http://petstore.swagger.io/v2", api.getApiClient().getBasePath());
    assertFalse(api.getApiClient().isDebugging());
  }
Пример #2
0
 private <T> T deserializeJson(String json, Class<T> klass, ApiClient apiClient) {
   ObjectMapper mapper = apiClient.getJSON().getContext(null);
   try {
     return mapper.readValue(json, klass);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Пример #3
0
 private String serializeJson(Object o, ApiClient apiClient) {
   ObjectMapper mapper = apiClient.getJSON().getContext(null);
   try {
     return mapper.writeValueAsString(o);
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }