本文整理汇总了Java中org.eclipse.jetty.servlet.ServletTester类的典型用法代码示例。如果您正苦于以下问题:Java ServletTester类的具体用法?Java ServletTester怎么用?Java ServletTester使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServletTester类属于org.eclipse.jetty.servlet包,在下文中一共展示了ServletTester类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: startJetty
import org.eclipse.jetty.servlet.ServletTester; //导入依赖的package包/类
@Before
public void startJetty() throws Exception {
servletTester = new ServletTester();
servletTester.getContext().addEventListener(new GuiceServletContextListener()
{
final Injector injector = Guice.createInjector(new TestModule());
@Override
protected Injector getInjector() {
return injector;
}
});
url = servletTester.createConnector(true) + TestModule.MOUNT_POINT;
servletTester.addFilter(GuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
servletTester.addServlet(DummyServlet.class, "/*");
servletTester.start();
client = ClientBuilder.newClient();
}
开发者ID:sonatype,项目名称:nexus-public,代码行数:21,代码来源:SiestaTestSupport.java
示例2: testSetRESTGetMBeanLocal
import org.eclipse.jetty.servlet.ServletTester; //导入依赖的package包/类
/**
* Set the Configuration property via REST interface and check whether the JMX interface returns the same value
*
* @throws Exception
*/
//TODO: Use the web target JAXRS API to execute these request possibly ?
@Ignore
@Test
public void testSetRESTGetMBeanLocal() throws Exception {
LOGGER.debug("testSetRESTGetMBeanLocal");
ObjectName name = new ObjectName(MMX_MBEAN_OBJECT_NAME);
ServletTester tester = new ServletTester();
tester.addServlet(LaxConfigServlet.class, "/config");
tester.start();
for (Triple<String, String, String> triple : mbeanAttributes) {
String attrName = triple.getLeft();
String attrType = triple.getRight();
String attrValueStr;
if (attrType.equals("int"))
attrValueStr = Integer.toString(RandomUtils.nextInt(30000, 65535));
else if (attrType.equals("long"))
attrValueStr = Long.toString(RandomUtils.nextLong(10, 1000));
else
attrValueStr = RandomStringUtils.randomAlphabetic(10);
String str = constructGson(triple.getMiddle(), attrValueStr);
HttpTester request = new HttpTester();
request.setMethod("POST");
request.setHeader("Host", "tester");
request.setContent(str);
request.setHeader("Content-Type", "application/json");
request.setURI("/config");
HttpTester response = new HttpTester();
//response = response.parse(tester.getResponses(request.generate()));
response.parse(tester.getResponses(request.generate()));
assertEquals("Values do not match", server.getAttribute(name, triple.getLeft()).toString(), attrValueStr);
}
}
开发者ID:magnetsystems,项目名称:message-server,代码行数:44,代码来源:MMXConfigurationTest.java
示例3: startServer
import org.eclipse.jetty.servlet.ServletTester; //导入依赖的package包/类
@BeforeClass
public static void startServer() throws Exception {
tester = new ServletTester();
ServletContextHandler ctx = tester.getContext();
// set up ServletContext
ctx.setContextPath("/");
ctx.setResourceBase("src/main/webapp");
ctx.setClassLoader(ServletTester.class.getClassLoader());
// add digilib ContextListener
DigilibServlet3Configuration dlConfig = new DigilibServlet3Configuration();
ctx.addEventListener(dlConfig);
tester.addServlet(Scaler.class, "/Scaler/*");
// start the servlet
tester.start();
}
开发者ID:robcast,项目名称:digilib,代码行数:16,代码来源:ScalerTest.java
示例4: testSetMBeanLocalGetREST
import org.eclipse.jetty.servlet.ServletTester; //导入依赖的package包/类
/**
* Set the Configuration property via JMX and check whether the REST interface returns the same value
*
* @throws Exception
*/
//TODO: Use the web target JAXRS API to execute these request possibly ?
@Ignore
@Test
public void testSetMBeanLocalGetREST() throws Exception {
ObjectName name = new ObjectName(MMX_MBEAN_OBJECT_NAME);
ServletTester tester = new ServletTester();
tester.addServlet(LaxConfigServlet.class, "/config");
tester.start();
for (Triple<String, String, String> triple : mbeanAttributes) {
String attrName = triple.getLeft();
String attrType = triple.getRight();
Object attrValue;
if (attrType.equals("int")) {
attrValue = RandomUtils.nextInt(30000, 65535);
} else if(attrType.equals("long")) {
attrValue = RandomUtils.nextLong(10, 1000);
} else {
attrValue = RandomStringUtils.randomAlphabetic(10);
}
Attribute attr1 = new Attribute(attrName, attrValue);
server.setAttribute(name, attr1);
Object attr2 = server.getAttribute(name, attrName);
assertEquals("Attribute values do not match", attrValue, attr2);
HttpTester request = new HttpTester();
// HttpTester.Request request = HttpTester.newRequest();
request.setMethod("GET");
request.setHeader("Host", "tester");
request.setURI("/config");
request.setContent("");
HttpTester response = new HttpTester();
response.parse(tester.getResponses(request.generate()));
JsonElement jelement = new JsonParser().parse(response.getContent());
JsonObject jobject = jelement.getAsJsonObject();
jobject = jobject.getAsJsonObject("configs");
String attrValueRest = jobject.get(triple.getMiddle()).getAsString();
if (attrType.equals("int"))
assertEquals("Values do not match", attrValue, Integer.parseInt(attrValueRest));
else if(attrType.equals("long"))
assertEquals("Values do not match", attrValue, Long.parseLong(attrValueRest));
else
assertEquals("Values do not match", attrValue, attrValueRest);
}
}
开发者ID:magnetsystems,项目名称:message-server,代码行数:50,代码来源:MMXConfigurationTest.java
注:本文中的org.eclipse.jetty.servlet.ServletTester类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论