Search in sources :

Example 11 with PrivateWebserverForTest

use of org.webpieces.webserver.PrivateWebserverForTest in project webpieces by deanhiller.

the class TestDomainMatching method setUp.

@Before
public void setUp() throws InterruptedException, ExecutionException, TimeoutException {
    VirtualFileClasspath metaFile = new VirtualFileClasspath("domainsMeta2.txt", PrivateWebserverForTest.class.getClassLoader());
    PrivateWebserverForTest webserver = new PrivateWebserverForTest(getOverrides(false, new SimpleMeterRegistry()), null, false, metaFile);
    webserver.start();
    httpsSocket = connectHttps(false, null, webserver.getUnderlyingHttpsChannel().getLocalAddress());
}
Also used : PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) VirtualFileClasspath(org.webpieces.util.file.VirtualFileClasspath) Before(org.junit.Before)

Example 12 with PrivateWebserverForTest

use of org.webpieces.webserver.PrivateWebserverForTest in project webpieces by deanhiller.

the class TestDevRefreshPageWithNoRestarting method setUp.

@Before
public void setUp() throws ClassNotFoundException, IOException, InterruptedException, ExecutionException, TimeoutException {
    Asserts.assertWasCompiledWithParamNames("test");
    userDir = System.getProperty("user.dir");
    log.info("running from dir=" + userDir);
    existingCodeLoc = FileFactory.newBaseFile("src/test/java/org/webpieces/webserver/dev/app");
    // developers tend to exit their test leaving the code in a bad state so if they run it again, restore the original
    // version for them(if we change the original version, we have to copy it to this directory as well though :(
    File original = FileFactory.newBaseFile("src/test/devServerTest/devServerOriginal");
    FileUtils.copyDirectory(original, existingCodeLoc, null);
    // cache existing code for use by teardown...
    stashedExistingCodeDir = FileFactory.newCacheLocation("webpieces/" + getClass().getSimpleName() + "/javaFiles");
    FileUtils.copyDirectory(existingCodeLoc, stashedExistingCodeDir);
    // list all source paths here as you add them(or just create for loop)
    // These are the list of directories that we detect java file changes under
    List<VirtualFile> srcPaths = new ArrayList<>();
    srcPaths.add(VirtualFileFactory.newBaseFile("src/test/java"));
    VirtualFile metaFile = VirtualFileFactory.newBaseFile("src/test/resources/devMeta.txt");
    log.info("LOADING from meta file=" + metaFile.getCanonicalPath());
    // html and json template file encoding...
    TemplateCompileConfig templateConfig = new TemplateCompileConfig(srcPaths);
    VirtualFile cacheLocation = new VirtualFileImpl(FileFactory.newCacheLocation("webpieces/" + getClass().getSimpleName() + "/bytecode"));
    // java source files encoding...
    CompileConfig devConfig = new CompileConfig(srcPaths, cacheLocation);
    SimpleMeterRegistry metrics = new SimpleMeterRegistry();
    Module platformOverrides = Modules.combine(new DevRouterModule(devConfig), new OverridesForEmbeddedSvrWithParsing(mgr, time, mockTimer, templateConfig, metrics));
    PrivateWebserverForTest webserver = new PrivateWebserverForTest(platformOverrides, null, false, metaFile);
    webserver.start();
    http11Socket = connectHttp(false, webserver.getUnderlyingHttpChannel().getLocalAddress());
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) DevRouterModule(org.webpieces.devrouter.api.DevRouterModule) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ArrayList(java.util.ArrayList) TemplateCompileConfig(org.webpieces.templatingdev.api.TemplateCompileConfig) CompileConfig(org.webpieces.compiler.api.CompileConfig) TemplateCompileConfig(org.webpieces.templatingdev.api.TemplateCompileConfig) VirtualFileImpl(org.webpieces.util.file.VirtualFileImpl) Module(com.google.inject.Module) DevRouterModule(org.webpieces.devrouter.api.DevRouterModule) File(java.io.File) VirtualFile(org.webpieces.util.file.VirtualFile) OverridesForEmbeddedSvrWithParsing(org.webpieces.webserver.test.OverridesForEmbeddedSvrWithParsing) Before(org.junit.Before)

Example 13 with PrivateWebserverForTest

use of org.webpieces.webserver.PrivateWebserverForTest in project webpieces by deanhiller.

the class TestDevSynchronousErrors method setUp.

@Before
public void setUp() throws InterruptedException, ClassNotFoundException, ExecutionException, TimeoutException {
    Asserts.assertWasCompiledWithParamNames("test");
    String filePath1 = System.getProperty("user.dir");
    log.info("running from dir=" + filePath1);
    List<VirtualFile> srcPaths = new ArrayList<>();
    srcPaths.add(VirtualFileFactory.newBaseFile("src/test/java"));
    TemplateCompileConfig templateConfig = new TemplateCompileConfig(false);
    SimpleMeterRegistry metrics = new SimpleMeterRegistry();
    Module platformOverrides = Modules.combine(new OverridesForEmbeddedSvrWithParsing(mgr, time, mockTimer, templateConfig, metrics), new ForTestingStaticDevelopmentModeModule());
    // you may want to create this server ONCE in a static method BUT if you do, also remember to clear out all your
    // mocks after every test AND you can no longer run single threaded(tradeoffs, tradeoffs)
    // This is however pretty fast to do in many systems...
    PrivateWebserverForTest webserver = new PrivateWebserverForTest(platformOverrides, new AppOverridesModule(), false, null);
    webserver.start();
    http11Socket = connectHttp(false, webserver.getUnderlyingHttpChannel().getLocalAddress());
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ArrayList(java.util.ArrayList) TemplateCompileConfig(org.webpieces.templatingdev.api.TemplateCompileConfig) Module(com.google.inject.Module) OverridesForEmbeddedSvrWithParsing(org.webpieces.webserver.test.OverridesForEmbeddedSvrWithParsing) Before(org.junit.Before)

Example 14 with PrivateWebserverForTest

use of org.webpieces.webserver.PrivateWebserverForTest in project webpieces by deanhiller.

the class TestSyncWebServer method setUp.

@Before
public void setUp() throws InterruptedException, ExecutionException, TimeoutException {
    meterRegistry = new SimpleMeterRegistry();
    Module platformOverrides = getOverrides(false, meterRegistry);
    PrivateWebserverForTest webserver = new PrivateWebserverForTest(platformOverrides, null, false, null);
    webserver.start();
    http11Socket = connectHttp(false, webserver.getUnderlyingHttpChannel().getLocalAddress());
}
Also used : PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Module(com.google.inject.Module) Before(org.junit.Before)

Example 15 with PrivateWebserverForTest

use of org.webpieces.webserver.PrivateWebserverForTest in project webpieces by deanhiller.

the class BasicStartWithNoHttps method testNoHttps.

@Test
public void testNoHttps() throws InterruptedException, ExecutionException, TimeoutException {
    String[] arguments = new String[] { "-http.port=:0", "-https.port=" };
    PrivateWebserverForTest webserver = new PrivateWebserverForTest(getOverrides(false, new SimpleMeterRegistry()), null, null, arguments);
    webserver.start();
    // connecting http still works
    HttpSocket http11Socket = connectHttp(false, webserver.getUnderlyingHttpChannel().getLocalAddress());
    // https has no channel in webserver
    Assert.assertNull(webserver.getUnderlyingHttpsChannel());
}
Also used : HttpSocket(org.webpieces.httpclient11.api.HttpSocket) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

Aggregations

SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)43 PrivateWebserverForTest (org.webpieces.webserver.PrivateWebserverForTest)43 Before (org.junit.Before)42 VirtualFileClasspath (org.webpieces.util.file.VirtualFileClasspath)37 Module (com.google.inject.Module)4 JdbcApi (org.webpieces.ddl.api.JdbcApi)4 PrivateTestConfig (org.webpieces.webserver.PrivateTestConfig)4 OverridesForTestRealServer (org.webpieces.webserver.test.OverridesForTestRealServer)4 ArrayList (java.util.ArrayList)2 TemplateCompileConfig (org.webpieces.templatingdev.api.TemplateCompileConfig)2 VirtualFile (org.webpieces.util.file.VirtualFile)2 OverridesForEmbeddedSvrWithParsing (org.webpieces.webserver.test.OverridesForEmbeddedSvrWithParsing)2 File (java.io.File)1 Test (org.junit.Test)1 CompileConfig (org.webpieces.compiler.api.CompileConfig)1 TwoPools (org.webpieces.data.api.TwoPools)1 DevRouterModule (org.webpieces.devrouter.api.DevRouterModule)1 HttpSocket (org.webpieces.httpclient11.api.HttpSocket)1 ConnectionListener (org.webpieces.nio.api.handlers.ConnectionListener)1 DataListener (org.webpieces.nio.api.handlers.DataListener)1