mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-19 04:17:07 +00:00
Add unit tests for Configuration and ApiClient
This commit is contained in:
@@ -75,6 +75,10 @@ public class ApiClient {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDebug() {
|
||||||
|
return isDebug;
|
||||||
|
}
|
||||||
|
|
||||||
public ApiClient enableDebug() {
|
public ApiClient enableDebug() {
|
||||||
isDebug = true;
|
isDebug = true;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ public class ApiClient {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDebug() {
|
||||||
|
return isDebug;
|
||||||
|
}
|
||||||
|
|
||||||
public ApiClient enableDebug() {
|
public ApiClient enableDebug() {
|
||||||
isDebug = true;
|
isDebug = true;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package io.swagger.client;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
public class ConfigurationTest {
|
||||||
|
@Test
|
||||||
|
public void testDefaultApiClient() {
|
||||||
|
ApiClient apiClient = Configuration.getDefaultApiClient();
|
||||||
|
assertNotNull(apiClient);
|
||||||
|
assertEquals("http://petstore.swagger.io/v2", apiClient.getBasePath());
|
||||||
|
assertFalse(apiClient.isDebug());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package io.swagger.petstore.test;
|
package io.swagger.petstore.test;
|
||||||
|
|
||||||
import io.swagger.client.ApiException;
|
import io.swagger.client.ApiException;
|
||||||
|
import io.swagger.client.ApiClient;
|
||||||
|
import io.swagger.client.Configuration;
|
||||||
import io.swagger.client.api.*;
|
import io.swagger.client.api.*;
|
||||||
import io.swagger.client.model.*;
|
import io.swagger.client.model.*;
|
||||||
|
|
||||||
@@ -18,6 +20,33 @@ public class PetApiTest {
|
|||||||
api = new PetApi();
|
api = new PetApi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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().isDebug());
|
||||||
|
|
||||||
|
ApiClient oldClient = api.getApiClient();
|
||||||
|
|
||||||
|
ApiClient newClient = new ApiClient();
|
||||||
|
newClient.setBasePath("http://example.com");
|
||||||
|
newClient.enableDebug();
|
||||||
|
|
||||||
|
// set api client via constructor
|
||||||
|
api = new PetApi(newClient);
|
||||||
|
assertNotNull(api.getApiClient());
|
||||||
|
assertEquals("http://example.com", api.getApiClient().getBasePath());
|
||||||
|
assertTrue(api.getApiClient().isDebug());
|
||||||
|
|
||||||
|
// set api client via setter method
|
||||||
|
api.setApiClient(oldClient);
|
||||||
|
assertNotNull(api.getApiClient());
|
||||||
|
assertEquals("http://petstore.swagger.io/v2", api.getApiClient().getBasePath());
|
||||||
|
assertFalse(api.getApiClient().isDebug());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateAndGetPet() throws Exception {
|
public void testCreateAndGetPet() throws Exception {
|
||||||
Pet pet = createRandomPet();
|
Pet pet = createRandomPet();
|
||||||
|
|||||||
Reference in New Issue
Block a user