Skip to content

Commit 1622ab4

Browse files
authored
Merge pull request #19 from greydaemon/DOT-4804
Downgraded java version to support GS integration
2 parents a26786f + 46218c4 commit 1622ab4

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

pom.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project
3-
xmlns="http://maven.apache.org/POM/4.0.0"
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>io.github.lambdatest</groupId>
88
<artifactId>lambdatest-java-sdk</artifactId>
@@ -46,7 +46,7 @@
4646
<dependency>
4747
<groupId>org.apache.httpcomponents</groupId>
4848
<artifactId>httpmime</artifactId>
49-
<version>4.5.13</version> <!-- Use the latest stable version -->
49+
<version>4.5.13</version>
5050
</dependency>
5151
<dependency>
5252
<groupId>org.json</groupId>
@@ -76,7 +76,7 @@
7676
<dependency>
7777
<groupId>com.fasterxml.jackson.core</groupId>
7878
<artifactId>jackson-databind</artifactId>
79-
<version>2.16.1</version> <!-- Use the latest version -->
79+
<version>2.16.1</version>
8080
</dependency>
8181
</dependencies>
8282
<build>

src/main/java/io/github/lambdatest/SmartUIAppSnapshot.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.openqa.selenium.TakesScreenshot;
1313

1414
import java.io.File;
15+
import java.util.HashMap;
1516
import java.util.Map;
1617
import java.util.Objects;
1718
import java.util.logging.Logger;
@@ -30,16 +31,15 @@ public SmartUIAppSnapshot() {
3031
this.gson = new Gson();
3132
}
3233

33-
3434
public void start(Map<String, String> options) throws Exception{
3535
try{
3636
this.projectToken = getProjectToken(options);
3737
log.info("Project token set as: " + this.projectToken);
3838
} catch (Exception e){
3939
log.severe(Constants.Errors.PROJECT_TOKEN_UNSET);
40-
throw new Exception("Project token is a mandatory field");
40+
throw new Exception("Project token is a mandatory field", e);
4141
}
42-
Map<String, String> envVars = System.getenv();
42+
Map<String, String> envVars = new HashMap<>(System.getenv());
4343
GitInfo git = GitUtils.getGitInfo(envVars);
4444
// Authenticate user and create a build
4545
try {
@@ -49,7 +49,7 @@ public void start(Map<String, String> options) throws Exception{
4949
options.put("buildName", this.buildData.getName());
5050
} catch(Exception e) {
5151
log.severe("Couldn't create build: " + e.getMessage());
52-
throw new IllegalStateException("Couldn't create build: " + e.getMessage());
52+
throw new Exception("Couldn't create build: " + e.getMessage());
5353
}
5454
}
5555
public void start() throws Exception{
@@ -69,7 +69,7 @@ public void start() throws Exception{
6969
log.info("Build ID set : " + this.buildData.getBuildId() + "for Build name : "+ this.buildData.getName());
7070
} catch(Exception e) {
7171
log.severe("Couldn't create build: " + e.getMessage());
72-
throw new IllegalStateException("Couldn't create build: " + e.getMessage());
72+
throw new Exception("Couldn't create build due to: ", e);
7373
}
7474
}
7575

@@ -90,7 +90,7 @@ private String getProjectToken(Map<String, String> options) {
9090

9191
public void smartuiAppSnapshot(AppiumDriver appiumDriver, String screenshotName, Map<String, String> options) throws Exception {
9292
try {
93-
if (Objects.isNull(appiumDriver)) {
93+
if (appiumDriver == null) {
9494
log.severe(Constants.Errors.SELENIUM_DRIVER_NULL +" during take snapshot");
9595
throw new IllegalArgumentException(Constants.Errors.SELENIUM_DRIVER_NULL);
9696
}
@@ -107,7 +107,7 @@ public void smartuiAppSnapshot(AppiumDriver appiumDriver, String screenshotName,
107107
uploadSnapshotRequest.setScreenshotName(screenshotName);
108108
uploadSnapshotRequest.setProjectToken(projectToken);
109109
Dimension d = appiumDriver.manage().window().getSize();
110-
int w = d.getWidth(), h = d.getWidth();
110+
int w = d.getWidth(), h = d.getHeight();
111111
uploadSnapshotRequest.setViewport(w+"x"+h);
112112
log.info("Device viewport set to: "+ uploadSnapshotRequest.getViewport());
113113
String platform = "", deviceName="", browserName ="";
@@ -117,10 +117,10 @@ public void smartuiAppSnapshot(AppiumDriver appiumDriver, String screenshotName,
117117
if(options != null && options.containsKey("deviceName")){
118118
deviceName = options.get("deviceName").trim();
119119
}
120-
if(Objects.isNull(deviceName) || deviceName.isEmpty()){
120+
if(deviceName == null || deviceName.isEmpty()){
121121
throw new IllegalArgumentException(Constants.Errors.DEVICE_NAME_NULL);
122122
}
123-
if(Objects.isNull(platform) || platform.isEmpty()){
123+
if(platform == null || platform.isEmpty()){
124124
if(deviceName.toLowerCase().startsWith("i")){
125125
browserName = "iOS";
126126
}

src/main/java/io/github/lambdatest/utils/GitUtils.java

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.util.List;
1313
import java.util.Map;
1414

15-
import java.util.logging.Logger;
1615
import java.util.stream.Collectors;
1716

1817
public class GitUtils {

src/main/java/io/github/lambdatest/utils/HttpClientUtil.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.nio.charset.StandardCharsets;
2626
import java.util.Map;
2727
import java.util.Objects;
28+
import java.util.logging.Level;
2829
import java.util.logging.Logger;
2930

3031

@@ -72,8 +73,9 @@ private String delete(String url,Map<String, String> headers) throws IOException
7273
return entity != null ? EntityUtils.toString(entity) : null;
7374
}
7475
catch (Exception e){
75-
log.warning("Exception occured in delete "+ e.getMessage());}
76-
return "Success";
76+
log.warning("Exception occurred in Delete" + e);
77+
throw e;
78+
}
7779
}
7880

7981
private String post(String url, String data) throws IOException {
@@ -173,7 +175,6 @@ public boolean isUserAuthenticated(String projectToken) throws IOException {
173175
return true;
174176
}
175177
else{
176-
log.warning("Error in authenticating user ...");
177178
throw new IllegalArgumentException(Constants.Errors.USER_AUTH_ERROR);
178179
}
179180
}
@@ -209,19 +210,18 @@ public void stopBuild(String buildId, Map<String, String> headers) throws IOExce
209210
}
210211
}
211212
String response = delete(Constants.SmartUIRoutes.HOST_URL + Constants.SmartUIRoutes.SMARTUI_FINALISE_BUILD_ROUTE +buildId, headers);
212-
log.info("Response of stop Build: "+ response + "for buildId" + buildId);
213213
}
214214

215215
public String uploadScreenshot(String url, File screenshot , UploadSnapshotRequest uploadScreenshotRequest, BuildData data) throws IOException {
216216

217-
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
217+
try {
218218
HttpPost uploadRequest = new HttpPost(url);
219219
uploadRequest.setHeader("projectToken", uploadScreenshotRequest.getProjectToken());
220220

221221
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
222222
builder.setMode(HttpMultipartMode.STRICT);
223223

224-
builder.addBinaryBody("screenshot", screenshot, ContentType.IMAGE_PNG, screenshot.getName());
224+
builder.addBinaryBody("screenshot", screenshot, ContentType.create("image/png"), screenshot.getName());
225225
builder.addTextBody("buildId", uploadScreenshotRequest.getBuildId());
226226
builder.addTextBody("buildName", uploadScreenshotRequest.getBuildName());
227227
builder.addTextBody("screenshotName", uploadScreenshotRequest.getScreenshotName());

src/main/java/io/github/lambdatest/utils/SmartUIUtil.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import java.io.File;
55
import java.util.*;
6+
import java.util.logging.Level;
67
import java.util.logging.Logger;
78

89
import io.github.lambdatest.models.*;
@@ -24,7 +25,7 @@ public boolean isSmartUIRunning() {
2425
httpClient.isSmartUIRunning();
2526
return true;
2627
} catch (Exception e) {
27-
log.severe(e.getMessage());
28+
log.severe("Exception occurred " + e);
2829
return false;
2930
}
3031
}
@@ -112,7 +113,7 @@ public BuildResponse build(GitInfo git ,String projectToken, Map<String, String>
112113
if(Objects.nonNull(git)){
113114
createBuildRequest.setGit(git);}
114115
String createBuildJson = gson.toJson(createBuildRequest);
115-
Map<String,String> header = new HashMap<>() ;
116+
Map<String,String> header = new HashMap<String, String>() ;
116117
header.put(Constants.PROJECT_TOKEN, projectToken);
117118
String createBuildResponse = httpClient.createSmartUIBuild(createBuildJson, header);
118119
BuildResponse buildData = gson.fromJson(createBuildResponse, BuildResponse.class);
@@ -124,7 +125,7 @@ public BuildResponse build(GitInfo git ,String projectToken, Map<String, String>
124125

125126
public void stopBuild(String buildId, String projectToken) throws Exception{
126127
try{
127-
Map<String,String> headers = new HashMap<>();
128+
Map<String,String> headers = new HashMap<String, String>();
128129
headers.put(Constants.PROJECT_TOKEN, projectToken);
129130
httpClient.stopBuild(buildId, headers);
130131
}

0 commit comments

Comments
 (0)