Skip to content

Commit

Permalink
Merge pull request #148 from smartcar/update-lib-version
Browse files Browse the repository at this point in the history
feat: upgrade java-sdk version from 4.3.0 to 4.4.0
  • Loading branch information
aytekin-smartcar authored May 8, 2024
2 parents 04a4869 + 1219f04 commit ef42277
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 41 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ The recommended method for obtaining the SDK is via Gradle or Maven through the

### Gradle
```groovy
compile "com.smartcar.sdk:java-sdk:4.3.0"
compile "com.smartcar.sdk:java-sdk:4.4.0"
```

### Maven
```xml
<dependency>
<groupId>com.smartcar.sdk</groupId>
<artifactId>java-sdk</artifactId>
<version>4.3.0</version>
<version>4.4.0</version>
</dependency>
```

### Jar Direct Download
* [java-sdk-4.3.0.jar](https://repo1.maven.org/maven2/com/smartcar/sdk/java-sdk/4.3.0/java-sdk-4.3.0.jar)
* [java-sdk-4.3.0-sources.jar](https://repo1.maven.org/maven2/com/smartcar/sdk/java-sdk/4.3.0/java-sdk-4.3.0-sources.jar)
* [java-sdk-4.3.0-javadoc.jar](https://repo1.maven.org/maven2/com/smartcar/sdk/java-sdk/4.3.0/java-sdk-4.3.0-javadoc.jar)
* [java-sdk-4.4.0.jar](https://repo1.maven.org/maven2/com/smartcar/sdk/java-sdk/4.4.0/java-sdk-4.4.0.jar)
* [java-sdk-4.4.0-sources.jar](https://repo1.maven.org/maven2/com/smartcar/sdk/java-sdk/4.4.0/java-sdk-4.4.0-sources.jar)
* [java-sdk-4.4.0-javadoc.jar](https://repo1.maven.org/maven2/com/smartcar/sdk/java-sdk/4.4.0/java-sdk-4.4.0-javadoc.jar)

Signatures and other downloads available at [Maven Central](https://central.sonatype.com/artifact/com.smartcar.sdk/java-sdk/4.3.0).
Signatures and other downloads available at [Maven Central](https://central.sonatype.com/artifact/com.smartcar.sdk/java-sdk/4.4.0).

## Usage

Expand Down Expand Up @@ -136,7 +136,7 @@ In accordance with the Semantic Versioning specification, the addition of suppor
[ci-url]: https://travis-ci.com/smartcar/java-sdk
[coverage-image]: https://codecov.io/gh/smartcar/java-sdk/branch/master/graph/badge.svg?token=nZAITx7w3X
[coverage-url]: https://codecov.io/gh/smartcar/java-sdk
[javadoc-image]: https://img.shields.io/badge/javadoc-4.3.0-brightgreen.svg
[javadoc-image]: https://img.shields.io/badge/javadoc-4.4.0-brightgreen.svg
[javadoc-url]: https://smartcar.github.io/java-sdk
[maven-image]: https://img.shields.io/maven-central/v/com.smartcar.sdk/java-sdk.svg?label=Maven%20Central
[maven-url]: https://central.sonatype.com/artifact/com.smartcar.sdk/java-sdk
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
libGroup=com.smartcar.sdk
libName=java-sdk
libVersion=4.3.0
libVersion=4.4.0
libDescription=Smartcar Java SDK
97 changes: 64 additions & 33 deletions src/integration/java/com/smartcar/sdk/helpers/AuthHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
Expand All @@ -17,21 +19,20 @@
/** Provides all shared functionality among integration tests. */
public class AuthHelpers {
public static final String[] DEFAULT_SCOPE = {
"required:control_navigation",
"required:control_security",
"required:read_vehicle_info",
"required:read_location",
"required:read_odometer",
"required:read_vin",
"required:read_fuel",
"required:read_battery",
"required:read_charge",
"required:read_engine_oil",
"required:read_tires",
"required:control_navigation",
"required:control_security",
"required:read_vehicle_info",
"required:read_location",
"required:read_odometer",
"required:read_vin",
"required:read_fuel",
"required:read_battery",
"required:read_charge",
"required:read_engine_oil",
"required:read_tires",
};

private static final boolean HEADLESS =
System.getenv("CI") != null || System.getenv("HEADLESS") != null;
private static final boolean HEADLESS = System.getenv("CI") != null || System.getenv("HEADLESS") != null;
private static final HashMap<String, String> ENV_VAR_CACHE = new HashMap<>();

public static String getClientId() {
Expand All @@ -50,8 +51,31 @@ public static String getWebhookId() {
return safeGetEnv("E2E_SMARTCAR_WEBHOOK_ID");
}

public static String getBrowser() {
return safeGetEnv("BROWSER", "firefox");
}

public static WebDriver setupDriver() {
String browser = getBrowser();
WebDriver driver;

if ("chrome".equalsIgnoreCase(browser)) {
ChromeOptions options = new ChromeOptions();
options.setHeadless(HEADLESS);
driver = new ChromeDriver(options);
} else {
// Default to Firefox
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(HEADLESS);
driver = new FirefoxDriver(options);
}

return driver;
}

/**
* Creates an AuthClient builder and sets Client ID, Client Secret, and Redirect URI and also
* Creates an AuthClient builder and sets Client ID, Client Secret, and Redirect
* URI and also
* enables test mode.
*/
public static AuthClient.Builder getConfiguredAuthClientBuilder() throws Exception {
Expand All @@ -72,41 +96,37 @@ public static String runAuthFlow(String authorizeURL) {
* @throws IllegalStateException if URL is invalid
* @throws IllegalStateException if error is returned from connect
* @param authorizeURL - fully built authorize url
* @param make - which make to select
* @param make - which make to select
* @return auth code
*/
public static String runAuthFlow(String authorizeURL, String make) {
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
FirefoxOptions options = new FirefoxOptions().setHeadless(HEADLESS);

WebDriver driver = new FirefoxDriver(options);
WebDriver driver = setupDriver();

WebDriverWait wait = new WebDriverWait(driver, 10);

driver.get(authorizeURL);

// Preamble
WebElement preambleButton =
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("continue-button")));
WebElement preambleButton = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("continue-button")));
preambleButton.click();

// Brand Selector
WebElement brandButton =
wait.until(
ExpectedConditions.presenceOfElementLocated(
By.cssSelector("button#" + make.toUpperCase() + ".brand-list-item")));
WebElement brandButton = wait.until(
ExpectedConditions.presenceOfElementLocated(
By.cssSelector("button#" + make.toUpperCase() + ".brand-list-item")));
brandButton.click();

// Login
String email = UUID.randomUUID() + "@email.com";
WebElement signInButton =
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("sign-in-button")));
WebElement signInButton = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("sign-in-button")));
driver.findElement(By.id("username")).sendKeys(email);
driver.findElement(By.id("password")).sendKeys("password");
signInButton.click();

// Grant
WebElement permissionsApprovalButton =
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("approval-button")));
WebElement permissionsApprovalButton = wait
.until(ExpectedConditions.presenceOfElementLocated(By.id("approval-button")));
permissionsApprovalButton.click();

// Redirect
Expand Down Expand Up @@ -139,21 +159,32 @@ private static String getCodeFromUrl(URL url) {
}

/**
* Wrapper around System.getenv that throws an error if the variable is not set (also caches the
* value)
* Wrapper around System.getenv that returns a default value if the variable is
* not set
* (also caches the value).
*
* @return the environment variable that the name maps to
* @param name The name of the environment variable.
* @param defaultValue The default value to return if the environment variable
* is not set.
* @return The environment variable value or the default value if the variable
* is not set.
*/
private static String safeGetEnv(String name) {
private static String safeGetEnv(String name, String defaultValue) {
if (ENV_VAR_CACHE.containsKey(name)) {
return ENV_VAR_CACHE.get(name);
}

String value = System.getenv(name);
if (value == null) {
throw new RuntimeException("\"" + name + "\" environment variable must be set");
value = defaultValue; // Use default value if environment variable is not set
}
ENV_VAR_CACHE.put(name, value);
return value;
}

// Optionally, you can also maintain the original method signature as an
// overload
private static String safeGetEnv(String name) {
return safeGetEnv(name, null);
}
}

0 comments on commit ef42277

Please sign in to comment.