Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ default JsonNodeStringBuilder withPropertyEscaped(String name, String value) {
JsonNodeStringBuilder withProperty(String name, long value);

JsonNodeStringBuilder withObject();

JsonNodeStringBuilder closeObject();

JsonNodeStringBuilder withArray(List<String> items);

default JsonNodeStringBuilder withArray(Map<String, Object> items) {
JsonNodeStringBuilder builder = withArray();
items.forEach((key, value) -> {
builder.withObject()
.withProperty("name", key)
.withPropertyEscaped("value", String.valueOf(value))
.closeObject();
});
items.forEach((key, value) -> builder.withObject()
.withProperty("name", key)
.withPropertyEscaped("value", String.valueOf(value))
.closeObject());
builder.closeArray();
return this;
}

JsonNodeStringBuilder withArray();

JsonNodeStringBuilder closeArray();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.citrusframework.dsl.script;

import org.citrusframework.actions.groovy.GroovyActionBuilder;
import org.citrusframework.actions.script.ScriptActionBuilder;
import org.citrusframework.actions.script.ScriptTestActions;
import org.citrusframework.dsl.TestActionLookupSupport;
Expand All @@ -25,11 +24,6 @@ public interface ScriptTestActionSupport extends ScriptTestActions, TestActionLo

@Override
default ScriptActionBuilder script() {
return new ScriptActionBuilder() {
@Override
public GroovyActionBuilder<?, ?> groovy() {
return lookup("groovy");
}
};
return () -> lookup("groovy");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ default DefaultScriptValidationContext.Builder script() {

@Override
default SoapMessageValidationContextBuilder soap() {
return new SoapMessageValidationContextBuilder() {
@Override
public SoapFaultValidationContext.Builder fault() {
return new SoapFaultValidationContext.Builder();
}
};
return SoapFaultValidationContext.Builder::new;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

package org.citrusframework.script;

import java.io.IOException;
import java.nio.charset.Charset;
import java.security.AccessController;
import java.security.PrivilegedAction;

import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyObject;
import org.citrusframework.AbstractTestActionBuilder;
Expand All @@ -36,34 +31,50 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.charset.Charset;
import java.security.AccessController;
import java.security.PrivilegedAction;

/**
* Action executes groovy scripts either specified inline or from external file resource.
*
* @since 2006
*/
public class GroovyAction extends AbstractTestAction {

/** Inline groovy script */
/**
* Inline groovy script
*/
private final String script;

/** External script file resource path */
/**
* External script file resource path
*/
private final String scriptResourcePath;

/** Script template code */
/**
* Script template code
*/
private final String scriptTemplate;

/** Static code snippet for basic groovy action implementation */
/**
* Static code snippet for basic groovy action implementation
*/
private final String scriptTemplatePath;

/** Manage automatic groovy template usage */
/**
* Manage automatic groovy template usage
*/
private final boolean useScriptTemplate;

/** Executes a script using the TestContext */
/**
* Executes a script using the TestContext
*/
public interface ScriptExecutor {
void execute(TestContext context);
}

/** Logger */
private static final Logger logger = LoggerFactory.getLogger(GroovyAction.class);

/**
Expand Down Expand Up @@ -118,7 +129,7 @@ public void doExecute(TestContext context) {
if (groovyObject instanceof ScriptExecutor) {
((ScriptExecutor) groovyObject).execute(context);
} else {
groovyObject.invokeMethod("run", new Object[] {});
groovyObject.invokeMethod("run", new Object[]{});
}

logger.info("Groovy script execution successful");
Expand All @@ -130,23 +141,22 @@ public void doExecute(TestContext context) {
}

private GroovyClassLoader getPrivilegedGroovyLoader() {
return AccessController.doPrivileged(new PrivilegedAction<>() {
public GroovyClassLoader run() {
ClassLoader parent = ClassLoaderHelper.getClassLoader();
return new GroovyClassLoader(parent);
}
return AccessController.doPrivileged((PrivilegedAction<GroovyClassLoader>) () -> {
ClassLoader parent = ClassLoaderHelper.getClassLoader();
return new GroovyClassLoader(parent);
});
}

private void assertScriptProvided() {
if (!StringUtils.hasText(script) && scriptResourcePath == null) {
throw new CitrusRuntimeException("Neither inline script nor " +
"external script resource is defined. Unable to execute groovy script.");
"external script resource is defined. Unable to execute groovy script.");
}
}

/**
* Get the groovy script.
*
* @return the script
*/
public String getScript() {
Expand All @@ -155,6 +165,7 @@ public String getScript() {

/**
* Get the file resource.
*
* @return the fileResource
*/
public String getScriptResourcePath() {
Expand All @@ -163,6 +174,7 @@ public String getScriptResourcePath() {

/**
* Gets the useScriptTemplate.
*
* @return the useScriptTemplate
*/
public boolean isUseScriptTemplate() {
Expand All @@ -171,6 +183,7 @@ public boolean isUseScriptTemplate() {

/**
* Gets the scriptTemplatePath.
*
* @return the scriptTemplatePath
*/
public String getScriptTemplatePath() {
Expand All @@ -179,7 +192,6 @@ public String getScriptTemplatePath() {

/**
* Gets the script template.
* @return
*/
public String getScriptTemplate() {
return scriptTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@

package org.citrusframework.agent;

import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.Stream;

import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
Expand Down Expand Up @@ -68,9 +52,24 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.Stream;

public class CitrusAgentApplication extends AbstractVerticle implements CitrusInstanceProcessor {

/** Logger */
private static final Logger logger = LoggerFactory.getLogger(CitrusAgentApplication.class);

private final AgentTestListener agentTestListener = new AgentTestListener();
Expand All @@ -79,20 +78,24 @@ public class CitrusAgentApplication extends AbstractVerticle implements CitrusIn

private final CitrusAgentConfiguration configuration;

/** Single thread job scheduler */
/**
* Single thread job scheduler
*/
private Future<TestResults> remoteResultFuture;

/** Router customizations */
/**
* Router customizations
*/
private final List<Consumer<Router>> routerCustomizations;

private final ExecutorService executorService = Executors.newCachedThreadPool();

private TemplateEngine templateEngine;

static {
System.setOut(IoBuilder
.forLogger(LogManager.getLogger("system.out"))
.buildPrintStream());
System.setOut(IoBuilder
.forLogger(LogManager.getLogger("system.out"))
.buildPrintStream());
}

/**
Expand Down Expand Up @@ -130,9 +133,7 @@ public void start() {
addConfigEndpoints(router);

router.get("/logs")
.handler(wrapThrowingHandler(ctx -> {
ctx.response().end(agentTestListener.getLogs());
}));
.handler(wrapThrowingHandler(ctx -> ctx.response().end(agentTestListener.getLogs())));

routerCustomizations.forEach(customization -> customization.accept(router));

Expand Down Expand Up @@ -257,7 +258,7 @@ private void addResultsEndpoints(Router router) {
.handler(wrapThrowingHandler(ctx -> {
HttpServerResponse response = ctx.response();
if (ctx.request().headers().contains(HttpHeaders.ACCEPT) &&
ctx.request().headers().get(HttpHeaders.ACCEPT).equals("application/yaml")) {
ctx.request().headers().get(HttpHeaders.ACCEPT).equals("application/yaml")) {
response.putHeader(HttpHeaders.CONTENT_TYPE, "application/yaml")
.end(agentTestListener.getYamlReport());
} else {
Expand Down Expand Up @@ -351,9 +352,7 @@ private void addRunEndpoints(Router router) {

private void addExecuteEndpoints(Router router) {
router.post("/execute/:name")
.handler(wrapThrowingHandler(ctx -> {
runTests(ConfigurationHelper.fromExecutionRequest(ctx, configuration), ctx.response());
}));
.handler(wrapThrowingHandler(ctx -> runTests(ConfigurationHelper.fromExecutionRequest(ctx, configuration), ctx.response())));
router.put("/execute/:name")
.handler(wrapThrowingHandler(ctx -> {
remoteResultFuture = startTestsAsync(ConfigurationHelper.fromExecutionRequest(ctx, configuration));
Expand Down Expand Up @@ -390,8 +389,8 @@ private void runTests(TestRunConfiguration runConfiguration, HttpServerResponse
error.printStackTrace(new PrintWriter(stackTrace));
logger.error(stackTrace.toString());
response
.setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code())
.end(error.getMessage());
.setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code())
.end(error.getMessage());
}
}

Expand Down
Loading