Slide 22
Slide 22 text
New: GlassFishTestEnvironment
class ManagedExecutorDefinitionWebTest {
private static final Logger LOG = System.getLogger(ManagedExecutorDefinitionWebTest.class.getName());
private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin();
private static final String APP_NAME = ManagedExecutorDefinitionServlet.class.getSimpleName();
@BeforeAll
static void deploy() {
File war = createDeployment();
try {
AsadminResult result = ASADMIN.exec("deploy", "--contextroot", "/", "--name", APP_NAME,
war.getAbsolutePath());
assertThat(result, AsadminResultMatcher.asadminOK());
} finally {
war.delete();
}
}
@AfterAll
static void undeploy() {
AsadminResult result = ASADMIN.exec("undeploy", APP_NAME);
assertThat(result, AsadminResultMatcher.asadminOK());
}
@Test
void testCopyCompletableFutureTwice() throws Exception {
HttpURLConnection connection = GlassFishTestEnvironment.openConnection(8080, "/");
connection.setRequestMethod("GET");
assertEquals(200, connection.getResponseCode());
}
private static File createDeployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "ManagedExecutorDefinitionWebTest.war")
.addClasses(ManagedExecutorDefinitionServlet.class, IntContextProvider.class, StringContextProvider.class)
.addAsServiceProvider(ThreadContextProvider.class, IntContextProvider.class, StringContextProvider.class);
LOG.log(INFO, war.toString(true));
try {
File tempFile = File.createTempFile(APP_NAME, ".war");
war.as(ZipExporter.class).exportTo(tempFile, true);
return tempFile;
} catch (IOException e) {
throw new IllegalStateException("Deployment failed - cannot load the input archive!", e);
}
}
}