Skip to content

Commit

Permalink
Merge pull request #206 from anup-nehe/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
aranaravi authored Jul 19, 2023
2 parents b9f3761 + 20880fc commit 27d093e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
Expand All @@ -17,6 +18,7 @@
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.google.common.collect.ImmutableMap;

//import io.mosip.kernel.core.util.StringUtils;

Expand Down Expand Up @@ -93,7 +95,8 @@ private AmazonS3 getConnection(String bucketName) {
* connection.putObject(bucketName, finalObjectName, file); return true; }
*/

public boolean putObject(String account, final String container, String source, String process, String objectName, File file) {
public boolean
putObject(String account, final String container, String source, String process, String objectName, File repotFile) {
String finalObjectName = null;
String bucketName = null;
boolean bReturn = false;
Expand All @@ -113,7 +116,7 @@ public boolean putObject(String account, final String container, String source,
if (useAccountAsBucketname)
existingBuckets.add(bucketName);
}
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, finalObjectName, file);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, finalObjectName, repotFile);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setHttpExpiresDate(new DateTime().plusDays(reportExpirationInDays).toDate());
putObjectRequest.setMetadata(objectMetadata);
Expand Down Expand Up @@ -184,4 +187,35 @@ public static String getName(String source, String process, String objectName) {

return finalObjectName;
}

public boolean putObjectWithMetadata(String account, final String container, String source, String process, String objectName, File sourcefile, ObjectMetadata metadata) {
String finalObjectName = null;
String bucketName = null;
boolean bReturn = false;

if (useAccountAsBucketname) {
finalObjectName = getName(container, source, process, objectName);
bucketName = account;
} else {
finalObjectName = getName(source, process, objectName);
bucketName = container;
}

AmazonS3 connection = getConnection(bucketName);
if (connection != null) {
if (!doesBucketExists(bucketName)) {
connection.createBucket(bucketName);
if (useAccountAsBucketname)
existingBuckets.add(bucketName);
}

PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, finalObjectName, sourcefile);
putObjectRequest.setMetadata(metadata);
connection.putObject(putObjectRequest);
bReturn = true;
}

return bReturn;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.testng.ITest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
Expand Down Expand Up @@ -52,17 +53,24 @@ public class BaseClass {
protected JavascriptExecutor js;
protected String langcode;
protected String envPath = System.getProperty("path");
protected String env=System.getProperty("env.user");
protected String userid = KeycloakUserManager.moduleSpecificUser;
protected String[] allpassword = ConfigManager.getIAMUsersPassword().split(",");
protected String password = allpassword[0];
protected String data = Commons.appendDate;
protected String data = Commons.appendDate;
public static ExtentSparkReporter html;


public static ExtentReports extent;
public static ExtentTest test;

public void setLangcode(String langcode) throws Exception {
this.langcode = Commons.getFieldData("langcode");
}

@BeforeSuite



@BeforeMethod
public void set() {
Expand All @@ -76,30 +84,14 @@ public void setUp() throws Exception {
ChromeOptions options = new ChromeOptions();
String headless=JsonUtil.JsonObjParsing(Commons.getTestData(),"headless");

//logger.info(WebDriverManager.getInstance().getBrowserPath());
// options.addArguments("no-sandbox");
// options.addArguments("disable-gpu");

if(headless.equalsIgnoreCase("yes")) {
options.addArguments("--headless=new");
}
WebDriverManager.chromedriver().setup();
driver=new ChromeDriver(options);

// logger.info(System.getProperty("user.dir"));
// String configFilePath = System.getProperty("user.dir") + "\\chromedriver\\chromedriver.exe";
// System.setProperty("webdriver.chrome.driver", configFilePath);
// ChromeOptions options = new ChromeOptions();
// try {
// String headless=JsonUtil.JsonObjParsing(Commons.getTestData(),"headless");
// if(headless.equalsIgnoreCase("yes")) {
// options.addArguments("--headless=new");
// }
// } catch (Exception e1) {
//
// e1.printStackTrace();
// }
//
// driver = new ChromeDriver(options);
//
js = (JavascriptExecutor) driver;
vars = new HashMap<String, Object>();
driver.get(envPath);
Expand Down Expand Up @@ -132,34 +124,38 @@ public void tearDown() {

driver.quit();
extent.flush();
// if (ConfigManager.getPushReportsToS3().equalsIgnoreCase("yes")) {
// // EXTENT REPORT
// File repotFile2 = new File(System.getProperty("user.dir") + "/" + "Reports"
// + "/" + System.getProperty("emailable.reports.name"));
// System.out.println("reportFile is::" + System.getProperty("user.dir") + "/"
// + System.getProperty("test-output.dir") + "/" + System.getProperty("emailable-report.html.name"));
//
// S3Adapter s3Adapter = new S3Adapter();
// boolean isStoreSuccess = false;
// try {
// isStoreSuccess = s3Adapter.putObject(ConfigManager.getS3Account(), BaseTestCaseFunc.testLevel, null,
// null, System.getProperty("emailable.report3.name"), repotFile2);
//
// isStoreSuccess = s3Adapter.putObject(ConfigManager.getS3Account(), BaseTestCaseFunc.testLevel, null,
// null, System.getProperty("emailable.report3.name"), repotFile2);
//
// System.out.println("isStoreSuccess:: " + isStoreSuccess);
// } catch (Exception e) {
// System.out.println("error occured while pushing the object" + e.getLocalizedMessage());
// e.printStackTrace();
// }
// if (isStoreSuccess) {
// System.out.println("Pushed file to S3");
// } else {
// System.out.println("Failed while pushing file to S3");
// }
// }
}

@AfterSuite
public void pushFileToS3() {
if (ConfigManager.getPushReportsToS3().equalsIgnoreCase("yes")) {
// EXTENT REPORT
File repotFile = new File(ExtentReportManager.Filepath);
System.out.println("reportFile is::" + repotFile);
String reportname = repotFile.getName();


S3Adapter s3Adapter = new S3Adapter();
boolean isStoreSuccess = false;
try {
isStoreSuccess = s3Adapter.putObject(ConfigManager.getS3Account(), BaseTestCaseFunc.testLevel, null,
"AdminUi",env+BaseTestCaseFunc.currentModule+data+".html", repotFile);

System.out.println("isStoreSuccess:: " + isStoreSuccess);
} catch (Exception e) {
System.out.println("error occured while pushing the object" + e.getLocalizedMessage());
e.printStackTrace();
}
if (isStoreSuccess) {
System.out.println("Pushed file to S3");
} else {
System.out.println("Failed while pushing file to S3");
}
}

}



@DataProvider(name = "data-provider")
public Object[] dpMethod() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@

import com.aventstack.extentreports.reporter.ExtentSparkReporter;

public class ExtentReportManager {
public class ExtentReportManager extends BaseClass {
public static ExtentSparkReporter html;
public static ExtentReports extent;
public static String Filepath;
//public static WebDriver driver;
public static ExtentTest test;
public static ExtentReports getReports() {
if(extent==null) {
extent=new ExtentReports();
extent=new ExtentReports();
String path=System.getProperty("user.dir")+"/Reports/"+"AdminReports"+Commons.getDateTime()+".html";
html=new ExtentSparkReporter(path);
Filepath=System.getProperty("user.dir")+"/Reports/"+"AdminReports"+Commons.appendDate+".html";
html=new ExtentSparkReporter(Filepath);
extent.attachReporter(html);
}

Expand Down
2 changes: 1 addition & 1 deletion admintest/src/main/resources/config/Kernel.properties
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ tokenEndpoint=/v1/esignet/oauth/token
validateBindingEndpoint=esignet-binding

#To run in Docker
authCertsPath=/home/mosip/authcerts
#authCertsPath=/home/mosip/authcerts

#To run locally
authCertsPath=

0 comments on commit 27d093e

Please sign in to comment.