forked from loafle/openapi-generator-original
Java clients: fix test cases on HTTP basic auth
This commit is contained in:
parent
4100a8537b
commit
33483055a5
@ -112,21 +112,25 @@ public class ApiClientTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetUsername() {
|
public void testSetUsernameAndPassword() {
|
||||||
try {
|
HttpBasicAuth auth = null;
|
||||||
apiClient.setUsername("my-username");
|
for (Authentication _auth : apiClient.getAuthentications().values()) {
|
||||||
fail("there should be no HTTP basic authentications");
|
if (_auth instanceof HttpBasicAuth) {
|
||||||
} catch (RuntimeException e) {
|
auth = (HttpBasicAuth) _auth;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
auth.setUsername(null);
|
||||||
|
auth.setPassword(null);
|
||||||
|
|
||||||
@Test
|
apiClient.setUsername("my-username");
|
||||||
public void testSetPassword() {
|
|
||||||
try {
|
|
||||||
apiClient.setPassword("my-password");
|
apiClient.setPassword("my-password");
|
||||||
fail("there should be no HTTP basic authentications");
|
assertEquals("my-username", auth.getUsername());
|
||||||
} catch (RuntimeException e) {
|
assertEquals("my-password", auth.getPassword());
|
||||||
}
|
|
||||||
|
// reset values
|
||||||
|
auth.setUsername(null);
|
||||||
|
auth.setPassword(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -48,7 +48,7 @@ import io.swagger.client.auth.HttpBasicAuth;
|
|||||||
import io.swagger.client.auth.ApiKeyAuth;
|
import io.swagger.client.auth.ApiKeyAuth;
|
||||||
import io.swagger.client.auth.OAuth;
|
import io.swagger.client.auth.OAuth;
|
||||||
|
|
||||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:21.885+08:00")
|
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-03-17T17:22:31.147+08:00")
|
||||||
public class ApiClient {
|
public class ApiClient {
|
||||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||||
private String basePath = "http://petstore.swagger.io/v2";
|
private String basePath = "http://petstore.swagger.io/v2";
|
||||||
@ -80,7 +80,7 @@ public class ApiClient {
|
|||||||
this.json.setDateFormat((DateFormat) dateFormat.clone());
|
this.json.setDateFormat((DateFormat) dateFormat.clone());
|
||||||
|
|
||||||
// Set default User-Agent.
|
// Set default User-Agent.
|
||||||
setUserAgent("Java-Swagger");
|
setUserAgent("Swagger-Codegen/1.0.0/java");
|
||||||
|
|
||||||
// Setup authentications (key: authentication name, value: authentication).
|
// Setup authentications (key: authentication name, value: authentication).
|
||||||
authentications = new HashMap<String, Authentication>();
|
authentications = new HashMap<String, Authentication>();
|
||||||
@ -88,6 +88,7 @@ public class ApiClient {
|
|||||||
authentications.put("test_api_client_id", new ApiKeyAuth("header", "x-test_api_client_id"));
|
authentications.put("test_api_client_id", new ApiKeyAuth("header", "x-test_api_client_id"));
|
||||||
authentications.put("test_api_client_secret", new ApiKeyAuth("header", "x-test_api_client_secret"));
|
authentications.put("test_api_client_secret", new ApiKeyAuth("header", "x-test_api_client_secret"));
|
||||||
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
|
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
|
||||||
|
authentications.put("test_http_basic", new HttpBasicAuth());
|
||||||
authentications.put("test_api_key_query", new ApiKeyAuth("query", "test_api_key_query"));
|
authentications.put("test_api_key_query", new ApiKeyAuth("query", "test_api_key_query"));
|
||||||
authentications.put("test_api_key_header", new ApiKeyAuth("header", "test_api_key_header"));
|
authentications.put("test_api_key_header", new ApiKeyAuth("header", "test_api_key_header"));
|
||||||
// Prevent the authentications from being modified.
|
// Prevent the authentications from being modified.
|
||||||
|
@ -112,21 +112,25 @@ public class ApiClientTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetUsername() {
|
public void testSetUsernameAndPassword() {
|
||||||
try {
|
HttpBasicAuth auth = null;
|
||||||
apiClient.setUsername("my-username");
|
for (Authentication _auth : apiClient.getAuthentications().values()) {
|
||||||
fail("there should be no HTTP basic authentications");
|
if (_auth instanceof HttpBasicAuth) {
|
||||||
} catch (RuntimeException e) {
|
auth = (HttpBasicAuth) _auth;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
auth.setUsername(null);
|
||||||
|
auth.setPassword(null);
|
||||||
|
|
||||||
@Test
|
apiClient.setUsername("my-username");
|
||||||
public void testSetPassword() {
|
|
||||||
try {
|
|
||||||
apiClient.setPassword("my-password");
|
apiClient.setPassword("my-password");
|
||||||
fail("there should be no HTTP basic authentications");
|
assertEquals("my-username", auth.getUsername());
|
||||||
} catch (RuntimeException e) {
|
assertEquals("my-password", auth.getPassword());
|
||||||
}
|
|
||||||
|
// reset values
|
||||||
|
auth.setUsername(null);
|
||||||
|
auth.setPassword(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -141,7 +141,7 @@ public class ApiClient {
|
|||||||
this.lenientDatetimeFormat = true;
|
this.lenientDatetimeFormat = true;
|
||||||
|
|
||||||
// Set default User-Agent.
|
// Set default User-Agent.
|
||||||
setUserAgent("Java-Swagger");
|
setUserAgent("Swagger-Codegen/1.0.0/java");
|
||||||
|
|
||||||
// Setup authentications (key: authentication name, value: authentication).
|
// Setup authentications (key: authentication name, value: authentication).
|
||||||
authentications = new HashMap<String, Authentication>();
|
authentications = new HashMap<String, Authentication>();
|
||||||
@ -149,6 +149,7 @@ public class ApiClient {
|
|||||||
authentications.put("test_api_client_id", new ApiKeyAuth("header", "x-test_api_client_id"));
|
authentications.put("test_api_client_id", new ApiKeyAuth("header", "x-test_api_client_id"));
|
||||||
authentications.put("test_api_client_secret", new ApiKeyAuth("header", "x-test_api_client_secret"));
|
authentications.put("test_api_client_secret", new ApiKeyAuth("header", "x-test_api_client_secret"));
|
||||||
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
|
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
|
||||||
|
authentications.put("test_http_basic", new HttpBasicAuth());
|
||||||
authentications.put("test_api_key_query", new ApiKeyAuth("query", "test_api_key_query"));
|
authentications.put("test_api_key_query", new ApiKeyAuth("query", "test_api_key_query"));
|
||||||
authentications.put("test_api_key_header", new ApiKeyAuth("header", "test_api_key_header"));
|
authentications.put("test_api_key_header", new ApiKeyAuth("header", "test_api_key_header"));
|
||||||
// Prevent the authentications from being modified.
|
// Prevent the authentications from being modified.
|
||||||
|
@ -151,21 +151,25 @@ public class ApiClientTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetUsername() {
|
public void testSetUsernameAndPassword() {
|
||||||
try {
|
HttpBasicAuth auth = null;
|
||||||
apiClient.setUsername("my-username");
|
for (Authentication _auth : apiClient.getAuthentications().values()) {
|
||||||
fail("there should be no HTTP basic authentications");
|
if (_auth instanceof HttpBasicAuth) {
|
||||||
} catch (RuntimeException e) {
|
auth = (HttpBasicAuth) _auth;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
auth.setUsername(null);
|
||||||
|
auth.setPassword(null);
|
||||||
|
|
||||||
@Test
|
apiClient.setUsername("my-username");
|
||||||
public void testSetPassword() {
|
|
||||||
try {
|
|
||||||
apiClient.setPassword("my-password");
|
apiClient.setPassword("my-password");
|
||||||
fail("there should be no HTTP basic authentications");
|
assertEquals("my-username", auth.getUsername());
|
||||||
} catch (RuntimeException e) {
|
assertEquals("my-password", auth.getPassword());
|
||||||
}
|
|
||||||
|
// reset values
|
||||||
|
auth.setUsername(null);
|
||||||
|
auth.setPassword(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user