forked from loafle/openapi-generator-original
Java clients: fix test cases on HTTP basic auth
This commit is contained in:
@@ -141,7 +141,7 @@ public class ApiClient {
|
||||
this.lenientDatetimeFormat = true;
|
||||
|
||||
// Set default User-Agent.
|
||||
setUserAgent("Java-Swagger");
|
||||
setUserAgent("Swagger-Codegen/1.0.0/java");
|
||||
|
||||
// Setup authentications (key: authentication name, value: 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_secret", new ApiKeyAuth("header", "x-test_api_client_secret"));
|
||||
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_header", new ApiKeyAuth("header", "test_api_key_header"));
|
||||
// Prevent the authentications from being modified.
|
||||
|
||||
@@ -151,21 +151,25 @@ public class ApiClientTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetUsername() {
|
||||
try {
|
||||
apiClient.setUsername("my-username");
|
||||
fail("there should be no HTTP basic authentications");
|
||||
} catch (RuntimeException e) {
|
||||
public void testSetUsernameAndPassword() {
|
||||
HttpBasicAuth auth = null;
|
||||
for (Authentication _auth : apiClient.getAuthentications().values()) {
|
||||
if (_auth instanceof HttpBasicAuth) {
|
||||
auth = (HttpBasicAuth) _auth;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
auth.setUsername(null);
|
||||
auth.setPassword(null);
|
||||
|
||||
@Test
|
||||
public void testSetPassword() {
|
||||
try {
|
||||
apiClient.setPassword("my-password");
|
||||
fail("there should be no HTTP basic authentications");
|
||||
} catch (RuntimeException e) {
|
||||
}
|
||||
apiClient.setUsername("my-username");
|
||||
apiClient.setPassword("my-password");
|
||||
assertEquals("my-username", auth.getUsername());
|
||||
assertEquals("my-password", auth.getPassword());
|
||||
|
||||
// reset values
|
||||
auth.setUsername(null);
|
||||
auth.setPassword(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user