Skip to content

Commit

Permalink
EPMRPP-94590 fix get logs
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Nov 8, 2024
1 parent 689a96c commit 3dfab40
Show file tree
Hide file tree
Showing 15 changed files with 259 additions and 44 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ dependencies {

test {
useJUnitPlatform()
onlyIf { Boolean.getBoolean(testsEnabled) } // enable for debugging purposes only
}

generatePomFileForShadowPublication { pom.packaging = "jar" }
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
version=5.11.0
lombokVersion=1.18.34
testsEnabled=false
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.saucelabs.client;

import com.epam.reportportal.saucelabs.model.IntegrationProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package com.epam.reportportal.saucelabs.command;

import static com.epam.reportportal.saucelabs.model.Constants.JOB_ID;
import static com.epam.reportportal.saucelabs.model.IntegrationParametersNames.ACCESS_TOKEN;
import static com.epam.reportportal.saucelabs.model.IntegrationParametersNames.USERNAME;
import static com.epam.reportportal.saucelabs.utils.ValidationUtils.validateIntegrationParams;
import static com.epam.reportportal.saucelabs.utils.ValidationUtils.validateJobId;

import com.epam.reportportal.extension.PluginCommand;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.entity.integration.Integration;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Map;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Hex;
import org.jasypt.util.text.BasicTextEncryptor;

/**
Expand All @@ -31,20 +24,11 @@ public GenerateAuthTokenCommand(BasicTextEncryptor textEncryptor) {
@Override
public Object executeCommand(Integration integration, Map params) {
try {
validateJobId(params);
validateIntegrationParams(integration.getParams());

String username = USERNAME.getParam(integration.getParams());
String accessToken = textEncryptor.decrypt(ACCESS_TOKEN.getParam(integration.getParams()));

SecretKeySpec keySpec =
new SecretKeySpec((username + ":" + accessToken).getBytes(StandardCharsets.UTF_8),
"HmacMD5"
);
Mac mac = Mac.getInstance("HmacMD5");
mac.init(keySpec);
return Collections.singletonMap("token", Hex.encodeHexString(
mac.doFinal(params.get(JOB_ID).toString().getBytes(StandardCharsets.UTF_8))));
return Collections.singletonMap("token", accessToken);
} catch (Exception e) {
throw new ReportPortalException(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.epam.reportportal.saucelabs.command;

import static com.epam.reportportal.saucelabs.model.Constants.GET_VDC_JOBS;
import static com.epam.reportportal.saucelabs.model.Constants.TEST_CONNECTION;

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

try {
String assetsUrl = String.format(GET_VDC_JOBS, sp.getUsername());
String assetsUrl = String.format(TEST_CONNECTION, sp.getUsername());
restTemplate.getForObject(assetsUrl, String.class);
return true;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
public class Constants {

public static final String JOB_ID = "jobId";
public static final String LOG_URL = "log_url";
public static final String LOG_URL = "sauce-log";

// endpoints
public static final String GET_VDC_JOBS = "/rest/v1/%s/jobs";
public static final String TEST_CONNECTION = "/rest/v1/%s/jobs?limit=0";
public static final String GET_VDC_JOB = "/rest/v1/%s/jobs/%s";
public static final String GET_VDC_JOB_LOGS = "/rest/v1/%s/jobs/%s/assets/log.json";
public static final String GET_VDC_JOB_ASSETS = "/rest/v1/%s/jobs/%s/assets";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.epam.reportportal.saucelabs.command;

import static org.junit.jupiter.api.Assertions.assertNotNull;

import com.epam.reportportal.saucelabs.client.RestClientBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;

class AssetsCommandTest extends BaseCommandTest {

@Test
@DisabledIf("disabled")
void getJobAssets() {
AssetsCommand command = new AssetsCommand(
new RestClientBuilder(basicTextEncryptor));
Object response = command.executeCommand(INTEGRATION, VDC_COMMAND_PARAMS);

assertNotNull(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.saucelabs.command;

import static com.epam.reportportal.saucelabs.model.Constants.JOB_ID;
import static com.epam.reportportal.saucelabs.utils.TestProperties.getTestProperties;

import com.epam.ta.reportportal.entity.integration.Integration;
import com.epam.ta.reportportal.entity.integration.IntegrationParams;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.jasypt.util.text.BasicTextEncryptor;
import org.junit.jupiter.api.BeforeAll;

// set values in 'integration.properties' to enable the tests
public abstract class BaseCommandTest {


public static final Map<String, Object> VDC_COMMAND_PARAMS = new HashMap<>();
public static final Map<String, Object> RDC_COMMAND_PARAMS = new HashMap<>();
public static final String VDC_JOB_ID = "vdcJobId";
public static final String RDC_JOB_ID = "rdcJobId";
public static final Integration INTEGRATION = new Integration();

BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();

@BeforeAll
protected static void before() {
Properties integrationProps = getTestProperties("integration.properties");
Map<String, Object> params = new HashMap<>();
integrationProps.keySet()
.stream()
.map(String::valueOf)
.forEach(key -> params.put(key, integrationProps.getProperty(key)));
INTEGRATION.setParams(new IntegrationParams(params));

Properties jobProps = getTestProperties("jobs.properties");
VDC_COMMAND_PARAMS.put(JOB_ID, jobProps.get(VDC_JOB_ID));
RDC_COMMAND_PARAMS.put(JOB_ID, jobProps.get(RDC_JOB_ID));

}

protected boolean disabled() {
return INTEGRATION.getParams().getParams().values()
.stream()
.map(String::valueOf)
.anyMatch(StringUtils::isEmpty);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.epam.reportportal.saucelabs.command;

import static org.junit.jupiter.api.Assertions.assertNotNull;

import com.epam.reportportal.saucelabs.client.RestClientBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;

class GetLogsCommandTest extends BaseCommandTest {

@Test
@DisabledIf("disabled")
void getVirtualDeviceLogs() {
GetLogsCommand command = new GetLogsCommand(
new RestClientBuilder(basicTextEncryptor));
Object response = command.executeCommand(INTEGRATION, VDC_COMMAND_PARAMS);

assertNotNull(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.epam.reportportal.saucelabs.command;

import static org.junit.jupiter.api.Assertions.assertNotNull;

import com.epam.reportportal.saucelabs.client.RestClientBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;

class GetRealDeviceJobCommandTest extends BaseCommandTest {

@Test
@DisabledIf("disabled")
void getRealDeviceJob() {
GetRealDeviceJobCommand command = new GetRealDeviceJobCommand(
new RestClientBuilder(basicTextEncryptor));
Object response = command.executeCommand(INTEGRATION, RDC_COMMAND_PARAMS);

assertNotNull(response);
}
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,66 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.saucelabs.command;


import static com.epam.reportportal.saucelabs.model.Constants.JOB_ID;
import static com.epam.reportportal.saucelabs.model.IntegrationParametersNames.ACCESS_TOKEN;
import static com.epam.reportportal.saucelabs.model.IntegrationParametersNames.DATA_CENTER;
import static com.epam.reportportal.saucelabs.model.IntegrationParametersNames.USERNAME;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.reportportal.saucelabs.client.RestClientBuilder;
import com.epam.ta.reportportal.entity.integration.Integration;
import com.epam.ta.reportportal.entity.integration.IntegrationParams;
import java.util.HashMap;
import java.util.Map;
import org.jasypt.util.text.BasicTextEncryptor;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;

public class GetVirtualDeviceJobCommandTest {
public class GetVirtualDeviceJobCommandTest extends BaseCommandTest {

private static final Map<String, Object> COMMAND_PARAMS = new HashMap<>();
private static final Map<String, Object> INTEGRATION_PARAMS = new HashMap<>();
@Test
@DisabledIf("disabled")
void getVirtualDeviceJob() {
GetVirtualDeviceJobCommand command = new GetVirtualDeviceJobCommand(
new RestClientBuilder(basicTextEncryptor));
Object response = command.executeCommand(INTEGRATION, VDC_COMMAND_PARAMS);

static {
INTEGRATION_PARAMS.put(USERNAME.getName(), "");
INTEGRATION_PARAMS.put(ACCESS_TOKEN.getName(), "");
INTEGRATION_PARAMS.put(DATA_CENTER.getName(), "EU");
assertNotNull(response);
}

COMMAND_PARAMS.put(JOB_ID, "03afb43944b849e1a9cf68989222037c");
@Test
@DisabledIf("disabled")
void getVirtualDeviceJobLogs() {
GetLogsCommand command = new GetLogsCommand(new RestClientBuilder(basicTextEncryptor));
Object response = command.executeCommand(INTEGRATION, VDC_COMMAND_PARAMS);

assertNotNull(response);
}

@Test
void executeCommand() {
BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
Integration integration = new Integration();
@DisabledIf("disabled")
void getVirtualDeviceJobNotExists() {
Map<String, Object> params = new HashMap<>();
params.put(JOB_ID, "not-exists-job-id");

integration.setParams(new IntegrationParams(INTEGRATION_PARAMS));
BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();

GetVirtualDeviceJobCommand command = new GetVirtualDeviceJobCommand(
new RestClientBuilder(basicTextEncryptor));
Object o = command.executeCommand(integration, COMMAND_PARAMS);
GetLogsCommand command = new GetLogsCommand(new RestClientBuilder(basicTextEncryptor));
Assertions.assertThrows(ReportPortalException.class,
() -> command.executeCommand(INTEGRATION, params));

assertNotNull(o);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.epam.reportportal.saucelabs.command;

import static org.junit.jupiter.api.Assertions.assertTrue;

import com.epam.reportportal.saucelabs.client.RestClientBuilder;
import java.util.HashMap;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;

class TestConnectionCommandTest extends BaseCommandTest {

@Test
@DisabledIf("disabled")
void testConnection() {
TestConnectionCommand command = new TestConnectionCommand(
new RestClientBuilder(basicTextEncryptor));
assertTrue(command.executeCommand(INTEGRATION, new HashMap<String, Object>()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.saucelabs.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import lombok.SneakyThrows;

public class TestProperties {

private TestProperties() {
}

@SneakyThrows
public static Properties getTestProperties(String path) {
Properties properties = new Properties();
try (var inputStream = TestProperties.class.getClassLoader()
.getResourceAsStream(path)) {
if (inputStream == null) {
throw new FileNotFoundException(path);
}
properties.load(inputStream);
} catch (IOException e) {
throw new RuntimeException(
"Could not read resource file: " + e);
}
return properties;
}

}
4 changes: 4 additions & 0 deletions src/test/resources/integration.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# populate properties to run the tests
username=
accessToken=
dataCenter=
2 changes: 2 additions & 0 deletions src/test/resources/jobs.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vdcJobId=
rdcJobId=

0 comments on commit 3dfab40

Please sign in to comment.