forked from ops4j/org.ops4j.pax.web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
latest changes for a possible running Servlet 3.0, this pretty much d…
…oes the job. Only finetuning left
- Loading branch information
Showing
29 changed files
with
756 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
itest/src/test/java/org/ops4j/pax/web/itest/Servlet3WarIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package org.ops4j.pax.web.itest; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
import java.util.Dictionary; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.ops4j.pax.exam.junit.JUnit4TestRunner; | ||
import org.ops4j.pax.web.service.spi.WebEvent; | ||
import org.ops4j.pax.web.service.spi.WebListener; | ||
import org.osgi.framework.Bundle; | ||
import org.osgi.framework.BundleException; | ||
|
||
|
||
/** | ||
* @author Achim Nierbeck | ||
*/ | ||
@RunWith(JUnit4TestRunner.class) | ||
public class Servlet3WarIntegrationTest extends ITestBase { | ||
|
||
Logger LOG = LoggerFactory.getLogger(Servlet3WarIntegrationTest.class); | ||
|
||
private Bundle installWarBundle; | ||
|
||
private WebListener webListener; | ||
|
||
|
||
|
||
@Before | ||
public void setUp() throws BundleException, InterruptedException { | ||
LOG.info("Setting up test"); | ||
webListener = new WebListenerImpl(); | ||
bundleContext.registerService(WebListener.class.getName(), webListener, | ||
null); | ||
String bundlePath = WEB_BUNDLE | ||
+ "mvn:org.ops4j.pax.web.samples/helloworld-servlet3/2.0.0-SNAPSHOT/war?" | ||
+ WEB_CONTEXT_PATH + "=/servlet3"; | ||
installWarBundle = bundleContext.installBundle(bundlePath); | ||
installWarBundle.start(); | ||
|
||
int count = 0; | ||
while (!((WebListenerImpl) webListener).gotEvent() && count < 50) { | ||
synchronized (this) { | ||
this.wait(100); | ||
count++; | ||
} | ||
} | ||
} | ||
|
||
@After | ||
public void tearDown() throws BundleException { | ||
if (installWarBundle != null) { | ||
installWarBundle.stop(); | ||
installWarBundle.uninstall(); | ||
} | ||
} | ||
|
||
/** | ||
* You will get a list of bundles installed by default plus your testcase, | ||
* wrapped into a bundle called pax-exam-probe | ||
*/ | ||
@Test | ||
public void listBundles() { | ||
for (Bundle b : bundleContext.getBundles()) { | ||
if (b.getState() != Bundle.ACTIVE) | ||
fail("Bundle should be active: " + b); | ||
|
||
Dictionary headers = b.getHeaders(); | ||
String ctxtPath = (String) headers.get(WEB_CONTEXT_PATH); | ||
if (ctxtPath != null) | ||
System.out.println("Bundle " + b.getBundleId() + " : " | ||
+ b.getSymbolicName() + " : " + ctxtPath); | ||
else | ||
System.out.println("Bundle " + b.getBundleId() + " : " | ||
+ b.getSymbolicName()); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void testWC() throws Exception { | ||
|
||
testWebPath("http://127.0.0.1:8181/servlet3", "<h1>Hello World</h1>"); | ||
|
||
} | ||
|
||
@Test | ||
public void testSlash() throws Exception { | ||
|
||
|
||
testWebPath("http://127.0.0.1:8181/servlet3/", "<h1>Hello World</h1>"); | ||
|
||
} | ||
|
||
|
||
private class WebListenerImpl implements WebListener { | ||
|
||
private boolean event = false; | ||
|
||
public void webEvent(WebEvent event) { | ||
LOG.info("Got event: " + event); | ||
if (event.getType() == 2) | ||
this.event = true; | ||
} | ||
|
||
public boolean gotEvent() { | ||
return event; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.