Skip to content

Commit

Permalink
Merge branch 'authorjapps:master' into java17
Browse files Browse the repository at this point in the history
  • Loading branch information
baulea authored Feb 27, 2024
2 parents c237684 + 61e8752 commit a17bbb1
Show file tree
Hide file tree
Showing 72 changed files with 2,063 additions and 475 deletions.
8 changes: 8 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ or
mvn -pl core clean test
```

## Runing Only The Integration tests(core)
Right click and run the "integrationtests" package. It picks the tests ending with "*Test.java"
<img width="632" alt="integration_tests_only_running_" src="https://github.com/authorjapps/zerocode/assets/12598420/6b6e8e33-16c1-43ce-8179-62a18e9a2290">


## With tests executed(kafka)
Some tests require a running Kafka (and some related components like kafka-rest, and kafka-schema-registry).

Location:
https://github.com/authorjapps/zerocode/blob/master/docker/compose/kafka-schema-registry.yml

Download the file, and run(or `cd to the docker/compose` dir and run)
```
docker-compose -f kafka-schema-registry.yml up -d
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Documentation
===
For a quick introduction to Zerocode and its features, visit the
+ [Zerocode TDD Doc Site](https://zerocode-tdd-docs.pages.dev)
+ [Wan to contribute or Improve](https://github.com/authorjapps/zerocode/wiki/Documentation-How-To-Fix-Steps)? Steps and guidelines are [here](https://github.com/authorjapps/zerocode/wiki/Documentation-How-To-Fix-Steps)

IDE Support By
===
Expand Down
32 changes: 6 additions & 26 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>zerocode-tdd-parent</artifactId>
<groupId>org.jsmart</groupId>
<version>1.3.36-SNAPSHOT</version>
<version>1.3.38-SNAPSHOT</version>
</parent>

<artifactId>zerocode-tdd</artifactId>
Expand Down Expand Up @@ -50,7 +50,6 @@
<properties>
<!-- This project properties -->
<junit.version>4.12</junit.version>
<version.gson>2.6.2</version.gson>
</properties>

<repositories>
Expand Down Expand Up @@ -103,10 +102,6 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.resteasy</groupId>
Expand All @@ -127,6 +122,7 @@
<dependency>
<groupId>org.jukito</groupId>
<artifactId>jukito</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
Expand All @@ -152,10 +148,6 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -164,7 +156,10 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
</dependency>
<dependency>
<groupId>org.jsmart</groupId>
Expand Down Expand Up @@ -201,11 +196,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java-compiler-source.version}</source>
<target>${java-compiler-target.version}</target>
</configuration>
</plugin>
</plugins>
</build>
Expand All @@ -218,20 +208,13 @@
</activation>
<build>
<plugins>
<!-- oss-parent has got all these below, but little outdated. Hence overwritten. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java-compiler-source.version}</source>
<target>${java-compiler-target.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -244,7 +227,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<!--<version>2.9.1</version>-->
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -257,7 +239,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand All @@ -283,7 +264,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface ZeroCodeReportConstants {
String REPORT_TITLE_DEFAULT = "Zerocode Test Report";
String REPORT_DISPLAY_NAME_DEFAULT = "Zerocode Interactive Report";
String DEFAULT_REGRESSION_CATEGORY = "Regression";
String DEFAULT_REGRESSION_AUTHOR = "All";
String LINK_LABEL_NAME = "Spike Chart(Click here)";
String ZEROCODE_JUNIT = "zerocode.junit";
String CHARTS_AND_CSV = "gen-smart-charts-csv-reports";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
package org.jsmart.zerocode.core.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class Parameterized {
private final List<Object> valueSource;
private final List<String> csvSource;
private final Boolean ignoreHeader;

public Parameterized(
@JsonProperty("valueSource") List<Object> valueSource,
@JsonProperty("csvSource") List<String> csvSource) {
@JsonProperty("csvSource") JsonNode csvSourceJsonNode,
@JsonProperty("ignoreHeader") Boolean ignoreHeader) {
this.valueSource = valueSource;
this.csvSource = csvSource;
this.ignoreHeader = Optional.ofNullable(ignoreHeader).orElse(false);
this.csvSource = getCsvSourceFrom(csvSourceJsonNode);
}

public List<Object> getValueSource() {
Expand All @@ -22,6 +38,43 @@ public List<String> getCsvSource() {
return csvSource;
}

private List<String> getCsvSourceFrom(JsonNode csvSourceJsonNode) {
try {
if (csvSourceJsonNode.isArray()) {
return readCsvSourceFromJson(csvSourceJsonNode);

} else {
return readCsvSourceFromExternalCsvFile(csvSourceJsonNode);
}
} catch (IOException e) {
throw new RuntimeException("Error deserializing csvSource", e);
}
}

private List<String> readCsvSourceFromJson(JsonNode csvSourceJsonNode) throws IOException {
ObjectMapper mapper = new ObjectMapper();
ObjectReader reader = mapper.readerFor(new TypeReference<List<String>>() {
});
return reader.readValue(csvSourceJsonNode);
}

private List<String> readCsvSourceFromExternalCsvFile(JsonNode csvSourceJsonNode) throws IOException {
String csvSourceFilePath = csvSourceJsonNode.textValue();
if (StringUtils.isNotBlank(csvSourceFilePath)) {
Path path = Paths.get("./src/test/resources/",csvSourceFilePath);
List<String> csvSourceFileLines = Files.lines(path)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toList());
if (this.ignoreHeader) {
return csvSourceFileLines.stream()
.skip(1)
.collect(Collectors.toList());
}
return csvSourceFileLines;
}
return Collections.emptyList();
}

@Override
public String toString() {
return "Parameterized{" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.jsmart.zerocode.core.domain.builders;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
Expand All @@ -14,14 +15,14 @@
public class ExtentReportsFactory {
private static final org.slf4j.Logger LOGGER = getLogger(ExtentReportsFactory.class);

private static ExtentHtmlReporter extentHtmlReporter;
private static ExtentSparkReporter extentSparkReporter;

private static ExtentReports extentReports;

private static Map<Object, String> systemProperties = new HashMap<>();

public static ExtentReports createReportTheme(String reportFileName) {
ExtentHtmlReporter extentHtmlReporter = createExtentHtmlReporter(reportFileName);
ExtentSparkReporter extentHtmlReporter = createExtentHtmlReporter(reportFileName);

extentReports = new ExtentReports();

Expand Down Expand Up @@ -52,14 +53,14 @@ public static void attachSystemInfo() {
extentReports.setSystemInfo("Java Vendor : ", javaVendor);
}

public static ExtentHtmlReporter createExtentHtmlReporter(String reportFileName) {
extentHtmlReporter = new ExtentHtmlReporter(reportFileName);
public static ExtentSparkReporter createExtentHtmlReporter(String reportFileName) {
extentSparkReporter = new ExtentSparkReporter(reportFileName);


extentHtmlReporter.config().setDocumentTitle(REPORT_TITLE_DEFAULT);
extentHtmlReporter.config().setReportName(REPORT_DISPLAY_NAME_DEFAULT);
extentSparkReporter.config().setDocumentTitle(REPORT_TITLE_DEFAULT);
extentSparkReporter.config().setReportName(REPORT_DISPLAY_NAME_DEFAULT);

return extentHtmlReporter;
return extentSparkReporter;
}


Expand Down Expand Up @@ -88,11 +89,11 @@ public static Map<Object, String> getSystemProperties() {
}

public static void reportName(String reportName) {
extentHtmlReporter.config().setReportName(reportName);
extentSparkReporter.config().setReportName(reportName);
}

public static String getReportName() {
return extentHtmlReporter.config().getReportName();
return extentSparkReporter.config().getReportName();
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@

package org.jsmart.zerocode.core.engine.executor.javaapi;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.Inject;
import com.google.inject.Injector;
import java.lang.reflect.Method;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.lang.Class.forName;
import static java.lang.String.format;
import static java.util.Arrays.asList;
import static org.jsmart.zerocode.core.utils.SmartUtils.prettyPrintJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

public class JavaMethodExecutorImpl implements JavaMethodExecutor {
private static final Logger LOGGER = LoggerFactory.getLogger(JavaMethodExecutorImpl.class);
Expand All @@ -38,14 +42,17 @@ public String execute(String qualifiedClassName, String methodName, String reque

Object result;

if (parameterTypes == null || parameterTypes.size() == 0) {
if (parameterTypes == null || parameterTypes.isEmpty()) {

result = executeWithParams(qualifiedClassName, methodName);

} else {
} else if (parameterTypes.size() == 1) {

Object request = objectMapper.readValue(requestJson, parameterTypes.get(0));
result = executeWithParams(qualifiedClassName, methodName, request);
} else {
Object[] requestArgs = getRequestArgs(parameterTypes, requestJson);
result = executeWithParams(qualifiedClassName, methodName, requestArgs);
}

final String resultJson = objectMapper.writeValueAsString(result);
Expand All @@ -58,6 +65,24 @@ public String execute(String qualifiedClassName, String methodName, String reque
}
}

private Object[] getRequestArgs(List<Class<?>> parameterTypes, String requestJson) {
List<Object> args = new ArrayList<>();
JsonNode root = null;
try {
root = objectMapper.readTree(requestJson);
} catch (JsonProcessingException e) {
throw new RuntimeException("Could not parse Java method request Json ", e);
}
for (int i = 0; i < parameterTypes.size(); i++) {
try {
args.add(objectMapper.treeToValue(root.get(String.valueOf(i)), parameterTypes.get(i)));
} catch (JsonProcessingException e) {
throw new RuntimeException("Could not convert value " + i + " to type " + parameterTypes.get(i), e);
}
}
return args.toArray();
}

/*
*
* @param qualifiedClassName : including package name: e.g. "org.jsmart.zerocode.core.AddService"
Expand All @@ -67,16 +92,22 @@ public String execute(String qualifiedClassName, String methodName, String reque
*/
Object executeWithParams(String qualifiedClassName, String methodName, Object... params) {

/**
/*
* Refer SOF example:
* Q. How do I invoke a Java method when given the method name as a string?
* Link: https://stackoverflow.com/questions/160970/how-do-i-invoke-a-java-method-when-given-the-method-name-as-a-string
*/
try {
Method method = findMatchingMethod(qualifiedClassName, methodName);
Object objectToInvokeOn = injector.getInstance(forName(qualifiedClassName));

return method.invoke(objectToInvokeOn, params);
if (Modifier.isStatic(method.getModifiers())) {
return method.invoke(null, params);
} else {
Object objectToInvokeOn = injector.getInstance(forName(qualifiedClassName));
return method.invoke(objectToInvokeOn, params);
}


} catch (Exception e) {
String errMsg = format("Java exec(): Invocation failed for method %s in class %s", methodName, qualifiedClassName);
LOGGER.error(errMsg + ". Exception - " + e);
Expand Down
Loading

0 comments on commit a17bbb1

Please sign in to comment.