Skip to content

Commit c36c8ee

Browse files
authored
EPMRPP-94590 fix retrieving logs flow (#32)
* EPMRPP-94590 fix get logs
1 parent 689a96c commit c36c8ee

15 files changed

+262
-47
lines changed

build.gradle

+3-4
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ dependencies {
4040
implementation 'com.epam.reportportal:plugin-api'
4141
annotationProcessor 'com.epam.reportportal:plugin-api'
4242
} else {
43-
implementation 'com.github.reportportal:commons-dao:28d0461'
44-
implementation 'com.github.reportportal:plugin-api:a9a8b73'
45-
annotationProcessor 'com.github.reportportal:plugin-api:a9a8b73'
43+
implementation 'com.github.reportportal:commons-dao:4caa252'
44+
implementation 'com.github.reportportal:plugin-api:bc00459'
45+
annotationProcessor 'com.github.reportportal:plugin-api:bc00459'
4646
}
4747
implementation 'org.hibernate:hibernate-core:5.6.15.Final'
4848

@@ -59,7 +59,6 @@ dependencies {
5959

6060
test {
6161
useJUnitPlatform()
62-
onlyIf { Boolean.getBoolean(testsEnabled) } // enable for debugging purposes only
6362
}
6463

6564
generatePomFileForShadowPublication { pom.packaging = "jar" }

gradle.properties

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
version=5.11.0
22
lombokVersion=1.18.34
3-
testsEnabled=false

src/main/java/com/epam/reportportal/saucelabs/client/RestClientBuilder.java

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2024 EPAM Systems
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.epam.reportportal.saucelabs.client;
218

319
import com.epam.reportportal.saucelabs.model.IntegrationProperties;

src/main/java/com/epam/reportportal/saucelabs/command/GenerateAuthTokenCommand.java

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
package com.epam.reportportal.saucelabs.command;
22

3-
import static com.epam.reportportal.saucelabs.model.Constants.JOB_ID;
43
import static com.epam.reportportal.saucelabs.model.IntegrationParametersNames.ACCESS_TOKEN;
5-
import static com.epam.reportportal.saucelabs.model.IntegrationParametersNames.USERNAME;
64
import static com.epam.reportportal.saucelabs.utils.ValidationUtils.validateIntegrationParams;
7-
import static com.epam.reportportal.saucelabs.utils.ValidationUtils.validateJobId;
85

96
import com.epam.reportportal.extension.PluginCommand;
107
import com.epam.reportportal.rules.exception.ReportPortalException;
118
import com.epam.ta.reportportal.entity.integration.Integration;
12-
import java.nio.charset.StandardCharsets;
139
import java.util.Collections;
1410
import java.util.Map;
15-
import javax.crypto.Mac;
16-
import javax.crypto.spec.SecretKeySpec;
17-
import org.apache.commons.codec.binary.Hex;
1811
import org.jasypt.util.text.BasicTextEncryptor;
1912

2013
/**
@@ -31,20 +24,11 @@ public GenerateAuthTokenCommand(BasicTextEncryptor textEncryptor) {
3124
@Override
3225
public Object executeCommand(Integration integration, Map params) {
3326
try {
34-
validateJobId(params);
3527
validateIntegrationParams(integration.getParams());
3628

37-
String username = USERNAME.getParam(integration.getParams());
3829
String accessToken = textEncryptor.decrypt(ACCESS_TOKEN.getParam(integration.getParams()));
3930

40-
SecretKeySpec keySpec =
41-
new SecretKeySpec((username + ":" + accessToken).getBytes(StandardCharsets.UTF_8),
42-
"HmacMD5"
43-
);
44-
Mac mac = Mac.getInstance("HmacMD5");
45-
mac.init(keySpec);
46-
return Collections.singletonMap("token", Hex.encodeHexString(
47-
mac.doFinal(params.get(JOB_ID).toString().getBytes(StandardCharsets.UTF_8))));
31+
return Collections.singletonMap("token", accessToken);
4832
} catch (Exception e) {
4933
throw new ReportPortalException(e.getMessage());
5034
}

src/main/java/com/epam/reportportal/saucelabs/command/TestConnectionCommand.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.epam.reportportal.saucelabs.command;
1818

19-
import static com.epam.reportportal.saucelabs.model.Constants.GET_VDC_JOBS;
19+
import static com.epam.reportportal.saucelabs.model.Constants.TEST_CONNECTION;
2020

2121
import com.epam.reportportal.saucelabs.client.RestClientBuilder;
2222
import com.epam.reportportal.saucelabs.model.IntegrationProperties;
@@ -46,7 +46,7 @@ public Boolean executeCommand(Integration integration, Map params) {
4646
RestTemplate restTemplate = restClient.buildRestTemplate(sp);
4747

4848
try {
49-
String assetsUrl = String.format(GET_VDC_JOBS, sp.getUsername());
49+
String assetsUrl = String.format(TEST_CONNECTION, sp.getUsername());
5050
restTemplate.getForObject(assetsUrl, String.class);
5151
return true;
5252
} catch (Exception e) {

src/main/java/com/epam/reportportal/saucelabs/model/Constants.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
public class Constants {
2121

2222
public static final String JOB_ID = "jobId";
23-
public static final String LOG_URL = "log_url";
23+
public static final String LOG_URL = "sauce-log";
2424

2525
// endpoints
26-
public static final String GET_VDC_JOBS = "/rest/v1/%s/jobs";
26+
public static final String TEST_CONNECTION = "/rest/v1/%s/jobs?limit=0";
2727
public static final String GET_VDC_JOB = "/rest/v1/%s/jobs/%s";
2828
public static final String GET_VDC_JOB_LOGS = "/rest/v1/%s/jobs/%s/assets/log.json";
2929
public static final String GET_VDC_JOB_ASSETS = "/rest/v1/%s/jobs/%s/assets";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.epam.reportportal.saucelabs.command;
2+
3+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4+
5+
import com.epam.reportportal.saucelabs.client.RestClientBuilder;
6+
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.api.condition.DisabledIf;
8+
9+
class AssetsCommandTest extends BaseCommandTest {
10+
11+
@Test
12+
@DisabledIf("disabled")
13+
void getJobAssets() {
14+
AssetsCommand command = new AssetsCommand(
15+
new RestClientBuilder(basicTextEncryptor));
16+
Object response = command.executeCommand(INTEGRATION, VDC_COMMAND_PARAMS);
17+
18+
assertNotNull(response);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2024 EPAM Systems
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.epam.reportportal.saucelabs.command;
18+
19+
import static com.epam.reportportal.saucelabs.model.Constants.JOB_ID;
20+
import static com.epam.reportportal.saucelabs.utils.TestProperties.getTestProperties;
21+
22+
import com.epam.ta.reportportal.entity.integration.Integration;
23+
import com.epam.ta.reportportal.entity.integration.IntegrationParams;
24+
import java.util.HashMap;
25+
import java.util.Map;
26+
import java.util.Properties;
27+
import org.apache.commons.lang3.StringUtils;
28+
import org.jasypt.util.text.BasicTextEncryptor;
29+
import org.junit.jupiter.api.BeforeAll;
30+
31+
// set values in 'integration.properties' to enable the tests
32+
public abstract class BaseCommandTest {
33+
34+
35+
public static final Map<String, Object> VDC_COMMAND_PARAMS = new HashMap<>();
36+
public static final Map<String, Object> RDC_COMMAND_PARAMS = new HashMap<>();
37+
public static final String VDC_JOB_ID = "vdcJobId";
38+
public static final String RDC_JOB_ID = "rdcJobId";
39+
public static final Integration INTEGRATION = new Integration();
40+
41+
BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
42+
43+
@BeforeAll
44+
protected static void before() {
45+
Properties integrationProps = getTestProperties("integration.properties");
46+
Map<String, Object> params = new HashMap<>();
47+
integrationProps.keySet()
48+
.stream()
49+
.map(String::valueOf)
50+
.forEach(key -> params.put(key, integrationProps.getProperty(key)));
51+
INTEGRATION.setParams(new IntegrationParams(params));
52+
53+
Properties jobProps = getTestProperties("jobs.properties");
54+
VDC_COMMAND_PARAMS.put(JOB_ID, jobProps.get(VDC_JOB_ID));
55+
RDC_COMMAND_PARAMS.put(JOB_ID, jobProps.get(RDC_JOB_ID));
56+
57+
}
58+
59+
protected boolean disabled() {
60+
return INTEGRATION.getParams().getParams().values()
61+
.stream()
62+
.map(String::valueOf)
63+
.anyMatch(StringUtils::isEmpty);
64+
}
65+
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.epam.reportportal.saucelabs.command;
2+
3+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4+
5+
import com.epam.reportportal.saucelabs.client.RestClientBuilder;
6+
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.api.condition.DisabledIf;
8+
9+
class GetLogsCommandTest extends BaseCommandTest {
10+
11+
@Test
12+
@DisabledIf("disabled")
13+
void getVirtualDeviceLogs() {
14+
GetLogsCommand command = new GetLogsCommand(
15+
new RestClientBuilder(basicTextEncryptor));
16+
Object response = command.executeCommand(INTEGRATION, VDC_COMMAND_PARAMS);
17+
18+
assertNotNull(response);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.epam.reportportal.saucelabs.command;
2+
3+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4+
5+
import com.epam.reportportal.saucelabs.client.RestClientBuilder;
6+
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.api.condition.DisabledIf;
8+
9+
class GetRealDeviceJobCommandTest extends BaseCommandTest {
10+
11+
@Test
12+
@DisabledIf("disabled")
13+
void getRealDeviceJob() {
14+
GetRealDeviceJobCommand command = new GetRealDeviceJobCommand(
15+
new RestClientBuilder(basicTextEncryptor));
16+
Object response = command.executeCommand(INTEGRATION, RDC_COMMAND_PARAMS);
17+
18+
assertNotNull(response);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,66 @@
1+
/*
2+
* Copyright 2024 EPAM Systems
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.epam.reportportal.saucelabs.command;
218

319

420
import static com.epam.reportportal.saucelabs.model.Constants.JOB_ID;
5-
import static com.epam.reportportal.saucelabs.model.IntegrationParametersNames.ACCESS_TOKEN;
6-
import static com.epam.reportportal.saucelabs.model.IntegrationParametersNames.DATA_CENTER;
7-
import static com.epam.reportportal.saucelabs.model.IntegrationParametersNames.USERNAME;
821
import static org.junit.jupiter.api.Assertions.assertNotNull;
922

23+
import com.epam.reportportal.rules.exception.ReportPortalException;
1024
import com.epam.reportportal.saucelabs.client.RestClientBuilder;
11-
import com.epam.ta.reportportal.entity.integration.Integration;
12-
import com.epam.ta.reportportal.entity.integration.IntegrationParams;
1325
import java.util.HashMap;
1426
import java.util.Map;
1527
import org.jasypt.util.text.BasicTextEncryptor;
28+
import org.junit.jupiter.api.Assertions;
1629
import org.junit.jupiter.api.Test;
30+
import org.junit.jupiter.api.condition.DisabledIf;
1731

18-
public class GetVirtualDeviceJobCommandTest {
32+
public class GetVirtualDeviceJobCommandTest extends BaseCommandTest {
1933

20-
private static final Map<String, Object> COMMAND_PARAMS = new HashMap<>();
21-
private static final Map<String, Object> INTEGRATION_PARAMS = new HashMap<>();
34+
@Test
35+
@DisabledIf("disabled")
36+
void getVirtualDeviceJob() {
37+
GetVirtualDeviceJobCommand command = new GetVirtualDeviceJobCommand(
38+
new RestClientBuilder(basicTextEncryptor));
39+
Object response = command.executeCommand(INTEGRATION, VDC_COMMAND_PARAMS);
2240

23-
static {
24-
INTEGRATION_PARAMS.put(USERNAME.getName(), "");
25-
INTEGRATION_PARAMS.put(ACCESS_TOKEN.getName(), "");
26-
INTEGRATION_PARAMS.put(DATA_CENTER.getName(), "EU");
41+
assertNotNull(response);
42+
}
2743

28-
COMMAND_PARAMS.put(JOB_ID, "03afb43944b849e1a9cf68989222037c");
44+
@Test
45+
@DisabledIf("disabled")
46+
void getVirtualDeviceJobLogs() {
47+
GetLogsCommand command = new GetLogsCommand(new RestClientBuilder(basicTextEncryptor));
48+
Object response = command.executeCommand(INTEGRATION, VDC_COMMAND_PARAMS);
2949

50+
assertNotNull(response);
3051
}
3152

3253
@Test
33-
void executeCommand() {
34-
BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
35-
Integration integration = new Integration();
54+
@DisabledIf("disabled")
55+
void getVirtualDeviceJobNotExists() {
56+
Map<String, Object> params = new HashMap<>();
57+
params.put(JOB_ID, "not-exists-job-id");
3658

37-
integration.setParams(new IntegrationParams(INTEGRATION_PARAMS));
59+
BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
3860

39-
GetVirtualDeviceJobCommand command = new GetVirtualDeviceJobCommand(
40-
new RestClientBuilder(basicTextEncryptor));
41-
Object o = command.executeCommand(integration, COMMAND_PARAMS);
61+
GetLogsCommand command = new GetLogsCommand(new RestClientBuilder(basicTextEncryptor));
62+
Assertions.assertThrows(ReportPortalException.class,
63+
() -> command.executeCommand(INTEGRATION, params));
4264

43-
assertNotNull(o);
4465
}
4566
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.epam.reportportal.saucelabs.command;
2+
3+
import static org.junit.jupiter.api.Assertions.assertTrue;
4+
5+
import com.epam.reportportal.saucelabs.client.RestClientBuilder;
6+
import java.util.HashMap;
7+
import org.junit.jupiter.api.Test;
8+
import org.junit.jupiter.api.condition.DisabledIf;
9+
10+
class TestConnectionCommandTest extends BaseCommandTest {
11+
12+
@Test
13+
@DisabledIf("disabled")
14+
void testConnection() {
15+
TestConnectionCommand command = new TestConnectionCommand(
16+
new RestClientBuilder(basicTextEncryptor));
17+
assertTrue(command.executeCommand(INTEGRATION, new HashMap<String, Object>()));
18+
}
19+
}

0 commit comments

Comments
 (0)