Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LR-329 - Test Automation for CSP #1160

Merged
merged 6 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/platform-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<dependency>
<groupId>org.sunbird</groupId>
<artifactId>cloud-store-sdk</artifactId>
<version>1.4.3</version>
<version>1.4.4</version>
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ public static String upload(
public static String getSignedUrl(
String storageType, String container, String objectKey) {
IStorageService storageService = getStorageService(storageType);
return getSignedUrl(storageService, container, objectKey);
return getSignedUrl(storageService, container, objectKey,storageType);
}

public static String getSignedUrl(
IStorageService storageService,
String container,
String objectKey) {
String objectKey,String cloudType) {
int timeoutInSeconds = getTimeoutInSeconds();
return storageService.getSignedURL(
container, objectKey, Some.apply(timeoutInSeconds), Some.apply("r"));
return storageService.getSignedURLV2(
container, objectKey, Some.apply(timeoutInSeconds), Some.apply("r"), Some.apply("application/pdf"));
}

private static IStorageService getStorageService(String storageType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ sunbird_otp_allowed_attempt=2
#Telemetry producer related info
telemetry_pdata_id=local.sunbird.learning.service
telemetry_pdata_pid=learning-service
telemetry_pdata_ver=5.1.0
telemetry_pdata_ver=5.2.0
#elastic search top n result count for telemetry
searchTopN=5
ekstep.channel.update.api.url=/channel/v3/update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,33 @@
import static org.powermock.api.mockito.PowerMockito.when;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.sunbird.cloud.storage.BaseStorageService;
import org.sunbird.cloud.storage.factory.StorageServiceFactory;
import org.sunbird.keys.JsonKey;
import scala.Option;

@RunWith(PowerMockRunner.class)
@PowerMockIgnore({
"javax.management.*",
"javax.net.ssl.*",
"javax.security.*",
"jdk.internal.reflect.*"
"javax.management.*",
"javax.net.ssl.*",
"javax.security.*",
"jdk.internal.reflect.*"
})
@PrepareForTest({StorageServiceFactory.class, CloudStorageUtil.class, PropertiesCache.class})
public class CloudStorageUtilTest {

private static final String SIGNED_URL = "singedUrl";
private static final String UPLOAD_URL = "uploadUrl";
private static final String PUT_SIGNED_URL = "gcpSignedUrl";

@Before
public void initTest() {
PowerMockito.mockStatic(PropertiesCache.class);
PropertiesCache propertiesCache = mock(PropertiesCache.class);
when(PropertiesCache.getInstance()).thenReturn(propertiesCache);
PowerMockito.when(propertiesCache.getProperty(Mockito.anyString())).thenReturn("anyString");

BaseStorageService service = mock(BaseStorageService.class);
mockStatic(StorageServiceFactory.class);

Expand All @@ -52,32 +47,74 @@ public void initTest() {
Mockito.any(Option.class),
Mockito.any(Option.class),
Mockito.any(Option.class)))
.thenReturn(UPLOAD_URL);
.thenReturn(UPLOAD_URL);

when(service.getSignedURL(
Mockito.anyString(),
Mockito.anyString(),
Mockito.any(Option.class),
Mockito.any(Option.class)))
.thenReturn(SIGNED_URL);
.thenReturn(SIGNED_URL);

when(service.getPutSignedURL(
Mockito.anyString(),
Mockito.anyString(),
Mockito.any(Option.class),
Mockito.any(Option.class),
Mockito.any(Option.class)))
.thenReturn(PUT_SIGNED_URL);

when(service.getSignedURLV2(
Mockito.eq("azurecontainer"),
Mockito.anyString(),
Mockito.any(Option.class),
Mockito.any(Option.class),
Mockito.any(Option.class)))
.thenReturn(SIGNED_URL);

when(service.getSignedURLV2(
Mockito.eq("gcpcontainer"),
Mockito.anyString(),
Mockito.any(Option.class),
Mockito.any(Option.class),
Mockito.any(Option.class)))
.thenReturn(PUT_SIGNED_URL);

when(service.getSignedURLV2(
Mockito.eq("awscontainer"),
Mockito.anyString(),
Mockito.any(Option.class),
Mockito.any(Option.class),
Mockito.any(Option.class)))
.thenReturn(SIGNED_URL);

} catch (Exception e) {
Assert.fail(e.getMessage());
}
}

@Test
// @Ignore
public void testUploadSuccess() {
String result =
CloudStorageUtil.upload("azure", "container", "key", "/file/path");
CloudStorageUtil.upload("azure", "container", "key", "/file/path");
assertTrue(UPLOAD_URL.equals(result));
}

@Test
@Ignore
public void testGetSignedUrlSuccess() {
String signedUrl = CloudStorageUtil.getSignedUrl("azure", "container", "key");
public void testGetSignedUrlAZURESuccess() {
String signedUrl = CloudStorageUtil.getSignedUrl("azure", "azurecontainer", "key");
assertTrue(SIGNED_URL.equals(signedUrl));
}

@Test
public void testGetSignedUrlGCPSuccess() {
String signedUrl = CloudStorageUtil.getSignedUrl("gcloud", "gcpcontainer", "key");
assertTrue(PUT_SIGNED_URL.equals(signedUrl));
}

@Test
public void testGetSignedUrlAWSSuccess() {
String signedUrl = CloudStorageUtil.getSignedUrl("aws", "awscontainer", "key");
assertTrue(SIGNED_URL.equals(signedUrl));
}
}