Skip to content

Commit

Permalink
Version 2023.01.17: Moved base methods of StepLogger to core module, …
Browse files Browse the repository at this point in the history
…extend BFLogger with warning
  • Loading branch information
KMariusz committed Jan 17, 2023
1 parent 66c8fff commit 8bcc4c6
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 176 deletions.
6 changes: 3 additions & 3 deletions mrchecker-framework-modules/mrchecker-cli-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.01.16</version>
<version>2023.01.17</version>
</parent>

<artifactId>mrchecker-cli-module</artifactId>
<version>2023.01.16</version>
<version>2023.01.17</version>
<packaging>jar</packaging>
<name>MrChecker - CLI - Module</name>
<description>MrChecker CLI Module supports:
Expand Down Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-core-module</artifactId>
<version>2023.01.16</version>
<version>2023.01.17</version>
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions mrchecker-framework-modules/mrchecker-core-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.01.16</version>
<version>2023.01.17</version>
</parent>

<artifactId>mrchecker-core-module</artifactId>
<version>2023.01.16</version>
<version>2023.01.17</version>
<packaging>jar</packaging>
<name>MrChecker - Test core - Module</name>
<description>MrChecker Test Framework Core is responsible for:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static void logFunctionEnd() {
getLog().logFunctionEnd();
}

public static void logWarning(String message) {
getLog().logWarning(message);
}

// logger - log ERROR message
public static void logError(String message) {
getLog().logError(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public void logInfo(String message) {
log(Level.INFO, message);
}

public void logWarning(String message) {
log(Level.WARN, message);
}

public void logError(String message) {
log(Level.ERROR, message);
}
Expand Down Expand Up @@ -95,4 +99,4 @@ public String dumpSeparateLog() {
return "";
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package com.capgemini.mrchecker.test.core.utils;

import com.capgemini.mrchecker.test.core.logger.BFLogger;
import io.qameta.allure.Allure;
import io.qameta.allure.Attachment;
import io.qameta.allure.Step;
import io.qameta.allure.model.Link;
import io.qameta.allure.model.Status;
import io.qameta.allure.util.ResultsUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import static java.nio.file.StandardOpenOption.APPEND;

public class StepLogger {
protected StepLogger() {
}

public static void step(String step) {
step(step, Status.PASSED);
}

public static void error(String error) {
step(error, Status.FAILED);
}

public static void warning(String warning) {
step(warning, Status.BROKEN);
}

public static void info(String info) {
step("[INFO] " + info);
}

public static void step(String step, Status status) {
switch (status) {
case BROKEN:
BFLogger.logWarning(step);
break;
case FAILED:
BFLogger.logError(step);
break;
default:
BFLogger.logInfo(step);
}
Allure.step(step, status);
}

public static void issue(String name, String url) {
link(ResultsUtils.ISSUE_LINK_TYPE, name, url);
}

public static void tmsLink(String name, String url) {
link(ResultsUtils.TMS_LINK_TYPE, name, url);
}

public static void link(String type, String name, String url) {
try {
Allure.addLinks(new Link().setType(type).setName(name).setUrl(url));
} catch (NullPointerException e) {
// Catch when no allure report
step(MessageFormat.format("[{0}][{1}] {2}", type, name, url));
}
}

@Step("{step}")
public static void stepsTree(String step, List<String> subSteps) {
for (String s : subSteps) {
step(s);
}
}

@Step("{step}")
public static void stepsTree(String step, List<String> subSteps, Status status) {
for (String s : subSteps) {
step(s, status);
}
}

@Attachment(value = "{attachName}", type = "text/plain")
public static String saveTextAttachmentToLog(String attachName, String message) {
BFLogger.logInfo("Saved attachment: " + attachName);
return message;
}

@Attachment(value = "{name}", type = "text/csv")
public static byte[] attachCSVFile(File file, String name) throws IOException {
return Files.readAllBytes(Paths.get(file.getAbsolutePath()));
}

@Attachment(value = "{name}", type = "text/plain")
public static byte[] attachTXTFile(File file, String name) throws IOException {
return Files.readAllBytes(Paths.get(file.getAbsolutePath()));
}

@Attachment("Zipped [{name}]")
public static byte[] attachZippedFile(File fileToAttach, String name) throws IOException {
String tempPath = System.getProperty("java.io.tmpdir");
String zipFileName = "attachement.zip";
File zipFile = new File(tempPath, zipFileName);
byte[] buffer = new byte[1024];
try (FileOutputStream fos = new FileOutputStream(zipFile); ZipOutputStream zos = new ZipOutputStream(
fos); FileInputStream fis = new FileInputStream(fileToAttach)) {
zos.putNextEntry(new ZipEntry(fileToAttach.getName()));
int length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
}
return Files.readAllBytes(Paths.get(zipFile.getAbsolutePath()));
}

@Attachment(value = "{name}", type = "application/pdf")
public static byte[] attachPDFFile(File file, String name) throws IOException {
return Files.readAllBytes(Paths.get(file.getAbsolutePath()));
}

@Attachment(value = "{name}", type = "image/png")
public static byte[] attachPNGFile(File file, String name) throws IOException {
return Files.readAllBytes(Paths.get(file.getAbsolutePath()));
}

@Attachment(value = "{name}", type = "application/zip")
public static byte[] attachZIPFile(File file, String name) throws IOException {
return Files.readAllBytes(Paths.get(file.getAbsolutePath()));
}

public static void attachFile(File file, String name) throws IOException {
String fileName = file.getName();
String extension = fileName.substring(fileName.lastIndexOf(".") + 1);
if (file.length() == 0) {
Files.write(Paths.get(file.toURI()), " ".getBytes(), APPEND);
}
switch (extension.toLowerCase()) {
case "pdf": {
attachPDFFile(file, name);
break;
}
case "xlsx": {
attachZippedFile(file, name);
break;
}
case "csv": {
attachCSVFile(file, name);
break;
}
case "png": {
attachPNGFile(file, name);
break;
}
case "zip": {
attachZIPFile(file, name);
break;
}
case "txt": {
attachTXTFile(file, name);
break;
}
default:
error("Couldn't attach file with extension: " + extension);
}
}
}
6 changes: 3 additions & 3 deletions mrchecker-framework-modules/mrchecker-database-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.01.16</version>
<version>2023.01.17</version>
</parent>

<artifactId>mrchecker-database-module</artifactId>
<version>2023.01.16</version>
<version>2023.01.17</version>
<packaging>jar</packaging>
<name>MrChecker - Database - Module</name>
<description>MrChecker Database Module:
Expand Down Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-core-module</artifactId>
<version>2023.01.16</version>
<version>2023.01.17</version>
</dependency>

<!-- JPA dependencies -->
Expand Down
8 changes: 4 additions & 4 deletions mrchecker-framework-modules/mrchecker-mobile-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.01.16</version>
<version>2023.01.17</version>
</parent>

<artifactId>mrchecker-mobile-module</artifactId>
<version>2023.01.16</version>
<version>2023.01.17</version>
<packaging>jar</packaging>
<name>MrChecker - Mobile - Module</name>
<description>MrChecker Test Framework name supports:
Expand Down Expand Up @@ -52,12 +52,12 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-core-module</artifactId>
<version>2023.01.16</version>
<version>2023.01.17</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-selenium-module</artifactId>
<version>2023.01.16</version>
<version>2023.01.17</version>
</dependency>

<!--This dependency is necessary for Appium plugin. -->
Expand Down
6 changes: 3 additions & 3 deletions mrchecker-framework-modules/mrchecker-security-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.01.16</version>
<version>2023.01.17</version>
</parent>

<artifactId>mrchecker-security-module</artifactId>
<version>2023.01.16</version>
<version>2023.01.17</version>
<packaging>jar</packaging>
<name>MrChecker - Security - Module</name>
<description>MrChecker Test Framework Security supports:
Expand Down Expand Up @@ -63,7 +63,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-core-module</artifactId>
<version>2023.01.16</version>
<version>2023.01.17</version>
</dependency>

<!-- Needed to perform all API calls -->
Expand Down
6 changes: 3 additions & 3 deletions mrchecker-framework-modules/mrchecker-selenium-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<artifactId>mrchecker-test-framework</artifactId>
<groupId>com.capgemini.mrchecker</groupId>
<version>2023.01.16</version>
<version>2023.01.17</version>
</parent>

<artifactId>mrchecker-selenium-module</artifactId>
<version>2023.01.16</version>
<version>2023.01.17</version>
<packaging>jar</packaging>
<name>MrChecker - Selenium - Module</name>
<description>MrChecker Test Framework Selenium supports:
Expand Down Expand Up @@ -98,7 +98,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mrchecker-core-module</artifactId>
<version>2023.01.16</version>
<version>2023.01.17</version>
</dependency>

<!--This dependency is necessary for Selenium plugin. -->
Expand Down
Loading

0 comments on commit 8bcc4c6

Please sign in to comment.