mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Refactored to use the constructor instead of the class/static method to load properties - makes unit test runtime cleaning
This commit is contained in:
@ -51,8 +51,21 @@ public class SimpleFileSystemDirectoryRouter implements QJavalinRouteProviderInt
|
|||||||
private static final QLogger LOG = QLogger.getLogger(SimpleFileSystemDirectoryRouter.class);
|
private static final QLogger LOG = QLogger.getLogger(SimpleFileSystemDirectoryRouter.class);
|
||||||
public static boolean loadStaticFilesFromJar = false;
|
public static boolean loadStaticFilesFromJar = false;
|
||||||
|
|
||||||
static
|
|
||||||
|
private final String hostedPath;
|
||||||
|
private final String fileSystemPath;
|
||||||
|
private QCodeReference routeAuthenticator;
|
||||||
|
private QInstance qInstance;
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Constructor
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public SimpleFileSystemDirectoryRouter(String hostedPath, String fileSystemPath)
|
||||||
{
|
{
|
||||||
|
this.hostedPath = hostedPath;
|
||||||
|
this.fileSystemPath = fileSystemPath;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// read the property to see if we should load static files from the jar file or from the file system //
|
// read the property to see if we should load static files from the jar file or from the file system //
|
||||||
// Javan only supports loading via one method per path, so its a choice of one or the other... //
|
// Javan only supports loading via one method per path, so its a choice of one or the other... //
|
||||||
@ -72,21 +85,6 @@ public class SimpleFileSystemDirectoryRouter implements QJavalinRouteProviderInt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String hostedPath;
|
|
||||||
private final String fileSystemPath;
|
|
||||||
private QCodeReference routeAuthenticator;
|
|
||||||
private QInstance qInstance;
|
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
** Constructor
|
|
||||||
**
|
|
||||||
*******************************************************************************/
|
|
||||||
public SimpleFileSystemDirectoryRouter(String hostedPath, String fileSystemPath)
|
|
||||||
{
|
|
||||||
this.hostedPath = hostedPath;
|
|
||||||
this.fileSystemPath = fileSystemPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
|
@ -29,6 +29,7 @@ import com.kingsrook.qqq.backend.core.exceptions.QException;
|
|||||||
import com.kingsrook.qqq.backend.core.instances.AbstractQQQApplication;
|
import com.kingsrook.qqq.backend.core.instances.AbstractQQQApplication;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||||
import com.kingsrook.qqq.backend.javalin.TestUtils;
|
import com.kingsrook.qqq.backend.javalin.TestUtils;
|
||||||
|
import com.kingsrook.qqq.middleware.javalin.routeproviders.SimpleFileSystemDirectoryRouter;
|
||||||
import com.kingsrook.qqq.middleware.javalin.specs.v1.MiddlewareVersionV1;
|
import com.kingsrook.qqq.middleware.javalin.specs.v1.MiddlewareVersionV1;
|
||||||
import io.javalin.http.HttpStatus;
|
import io.javalin.http.HttpStatus;
|
||||||
import kong.unirest.HttpResponse;
|
import kong.unirest.HttpResponse;
|
||||||
@ -70,6 +71,7 @@ class QApplicationJavalinServerTest
|
|||||||
{
|
{
|
||||||
javalinServer.stop();
|
javalinServer.stop();
|
||||||
TestApplication.callCount = 0;
|
TestApplication.callCount = 0;
|
||||||
|
System.clearProperty("qqq.javalin.enableStaticFilesFromJar");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -226,6 +228,28 @@ class QApplicationJavalinServerTest
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
void testStaticRouterFilesFromClasspath() throws Exception
|
||||||
|
{
|
||||||
|
System.setProperty("qqq.javalin.enableStaticFilesFromJar", "true");
|
||||||
|
|
||||||
|
javalinServer = new QApplicationJavalinServer(new QApplicationJavalinServerTest.TestApplication())
|
||||||
|
.withServeFrontendMaterialDashboard(false)
|
||||||
|
.withPort(PORT)
|
||||||
|
.withAdditionalRouteProvider(new SimpleFileSystemDirectoryRouter("/statically-served-from-jar", "static-site-from-jar/"));
|
||||||
|
|
||||||
|
javalinServer.start();
|
||||||
|
|
||||||
|
Unirest.config().setDefaultResponseEncoding("UTF-8");
|
||||||
|
HttpResponse<String> response = Unirest.get("http://localhost:" + PORT + "/statically-served-from-jar/foo-in-jar.html").asString();
|
||||||
|
assertEquals("Foo in a Jar!\n", response.getBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
Reference in New Issue
Block a user