mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-17 20:50:44 +00:00
Increase tests on ProcessBasedRouter (which of course led to some improvements!)
This commit is contained in:
@ -31,7 +31,6 @@ import com.kingsrook.qqq.backend.core.actions.customizers.QCodeLoader;
|
||||
import com.kingsrook.qqq.backend.core.actions.processes.RunProcessAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.StorageAction;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessOutput;
|
||||
@ -258,7 +257,7 @@ public class ProcessBasedRouter implements QJavalinRouteProviderInterface
|
||||
return;
|
||||
}
|
||||
|
||||
throw (new QException("No response value was set in the process output state."));
|
||||
LOG.debug("No response value was set in the process output state.");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
@ -22,6 +22,7 @@
|
||||
package com.kingsrook.qqq.middleware.javalin.routeproviders;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.ProcessState;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.QProcessPayload;
|
||||
@ -34,12 +35,12 @@ import com.kingsrook.qqq.backend.core.model.actions.processes.QProcessPayload;
|
||||
*******************************************************************************/
|
||||
public class ProcessBasedRouterPayload extends QProcessPayload
|
||||
{
|
||||
private String path;
|
||||
private String method;
|
||||
private Map<String, String> pathParams;
|
||||
private Map<String, String> queryParams;
|
||||
private Map<String, String> formParams;
|
||||
private Map<String, String> cookies;
|
||||
private String path;
|
||||
private String method;
|
||||
private Map<String, String> pathParams;
|
||||
private Map<String, List<String>> queryParams;
|
||||
private Map<String, List<String>> formParams;
|
||||
private Map<String, String> cookies;
|
||||
|
||||
private Integer statusCode;
|
||||
private String redirectURL;
|
||||
@ -163,68 +164,6 @@ public class ProcessBasedRouterPayload extends QProcessPayload
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for queryParams
|
||||
*******************************************************************************/
|
||||
public Map<String, String> getQueryParams()
|
||||
{
|
||||
return (this.queryParams);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for queryParams
|
||||
*******************************************************************************/
|
||||
public void setQueryParams(Map<String, String> queryParams)
|
||||
{
|
||||
this.queryParams = queryParams;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for queryParams
|
||||
*******************************************************************************/
|
||||
public ProcessBasedRouterPayload withQueryParams(Map<String, String> queryParams)
|
||||
{
|
||||
this.queryParams = queryParams;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for formParams
|
||||
*******************************************************************************/
|
||||
public Map<String, String> getFormParams()
|
||||
{
|
||||
return (this.formParams);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for formParams
|
||||
*******************************************************************************/
|
||||
public void setFormParams(Map<String, String> formParams)
|
||||
{
|
||||
this.formParams = formParams;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for formParams
|
||||
*******************************************************************************/
|
||||
public ProcessBasedRouterPayload withFormParams(Map<String, String> formParams)
|
||||
{
|
||||
this.formParams = formParams;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for cookies
|
||||
*******************************************************************************/
|
||||
@ -409,4 +348,66 @@ public class ProcessBasedRouterPayload extends QProcessPayload
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for queryParams
|
||||
*******************************************************************************/
|
||||
public Map<String, List<String>> getQueryParams()
|
||||
{
|
||||
return (this.queryParams);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for queryParams
|
||||
*******************************************************************************/
|
||||
public void setQueryParams(Map<String, List<String>> queryParams)
|
||||
{
|
||||
this.queryParams = queryParams;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for queryParams
|
||||
*******************************************************************************/
|
||||
public ProcessBasedRouterPayload withQueryParams(Map<String, List<String>> queryParams)
|
||||
{
|
||||
this.queryParams = queryParams;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for formParams
|
||||
*******************************************************************************/
|
||||
public Map<String, List<String>> getFormParams()
|
||||
{
|
||||
return (this.formParams);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for formParams
|
||||
*******************************************************************************/
|
||||
public void setFormParams(Map<String, List<String>> formParams)
|
||||
{
|
||||
this.formParams = formParams;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for formParams
|
||||
*******************************************************************************/
|
||||
public ProcessBasedRouterPayload withFormParams(Map<String, List<String>> formParams)
|
||||
{
|
||||
this.formParams = formParams;
|
||||
return (this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import com.kingsrook.qqq.backend.core.actions.customizers.TableCustomizerInterface;
|
||||
@ -202,6 +203,7 @@ public class TestUtils
|
||||
|
||||
routeProviders.add(new JavalinRouteProviderMetaData()
|
||||
.withHostedPath("/served-by-process/<pagePath>")
|
||||
.withMethods(List.of("GET", "POST", "PUT", "PATCH", "DELETE"))
|
||||
.withProcessName("routerProcess"));
|
||||
|
||||
routeProviders.add(new JavalinRouteProviderMetaData()
|
||||
@ -242,7 +244,35 @@ public class TestUtils
|
||||
{
|
||||
ProcessBasedRouterPayload processPayload = runBackendStepInput.getProcessPayload(ProcessBasedRouterPayload.class);
|
||||
String path = processPayload.getPath();
|
||||
processPayload.setResponseString("So you've asked for: " + path);
|
||||
|
||||
if(processPayload.getQueryParams().containsKey("requestedRedirect"))
|
||||
{
|
||||
processPayload.setRedirectURL(processPayload.getQueryParams().get("requestedRedirect").get(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
String response = "So you've done a " + processPayload.getMethod() + " for: " + path;
|
||||
if(processPayload.getQueryParams().containsKey("respondInBytes"))
|
||||
{
|
||||
processPayload.setResponseBytes(response.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
else if(processPayload.getQueryParams().containsKey("noResponse"))
|
||||
{
|
||||
///////////////////////////////////////
|
||||
// don't call any setResponse method //
|
||||
///////////////////////////////////////
|
||||
}
|
||||
else if(processPayload.getQueryParams().containsKey("doThrow"))
|
||||
{
|
||||
throw (new QException("Test Exception"));
|
||||
}
|
||||
else
|
||||
{
|
||||
processPayload.setResponseString(response);
|
||||
}
|
||||
processPayload.setResponseHeaders(Map.of("X-Test", "Yes, Test"));
|
||||
processPayload.setStatusCode(200);
|
||||
}
|
||||
runBackendStepOutput.setProcessPayload(processPayload);
|
||||
}))
|
||||
));
|
||||
|
@ -23,6 +23,7 @@ package com.kingsrook.qqq.middleware.javalin;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.instances.AbstractQQQApplication;
|
||||
@ -36,6 +37,7 @@ import org.json.JSONObject;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
@ -237,7 +239,29 @@ class QApplicationJavalinServerTest
|
||||
|
||||
HttpResponse<String> response = Unirest.get("http://localhost:" + PORT + "/served-by-process/foo.html").asString();
|
||||
assertEquals(200, response.getStatus());
|
||||
assertEquals("So you've asked for: /served-by-process/foo.html", response.getBody());
|
||||
assertEquals("So you've done a GET for: /served-by-process/foo.html", response.getBody());
|
||||
|
||||
response = Unirest.post("http://localhost:" + PORT + "/served-by-process/foo.html").asString();
|
||||
assertEquals(200, response.getStatus());
|
||||
assertEquals("So you've done a POST for: /served-by-process/foo.html", response.getBody());
|
||||
assertEquals("Yes, Test", response.getHeaders().getFirst("X-Test"));
|
||||
|
||||
response = Unirest.put("http://localhost:" + PORT + "/served-by-process/foo.html?requestedRedirect=google.com").asString();
|
||||
assertEquals(302, response.getStatus());
|
||||
assertEquals("google.com", response.getHeaders().getFirst("Location"));
|
||||
|
||||
HttpResponse<byte[]> responseBytes = Unirest.delete("http://localhost:" + PORT + "/served-by-process/foo.html?respondInBytes=true").asBytes();
|
||||
assertEquals(200, responseBytes.getStatus());
|
||||
assertArrayEquals("So you've done a DELETE for: /served-by-process/foo.html".getBytes(StandardCharsets.UTF_8), responseBytes.getBody());
|
||||
|
||||
response = Unirest.get("http://localhost:" + PORT + "/served-by-process/foo.html?noResponse=true").asString();
|
||||
assertEquals(200, response.getStatus());
|
||||
assertEquals("", response.getBody());
|
||||
|
||||
response = Unirest.get("http://localhost:" + PORT + "/served-by-process/foo.html?doThrow=true").asString();
|
||||
assertEquals(500, response.getStatus());
|
||||
assertThat(response.getBody()).contains("Test Exception");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user