1

私はこれをグーグルで検索しましたが、運がありません。JUnitでテストできるようにするために、embedded-jettyに必要なすべてのサービスをロードする方法の例を見たいだけです。だから、私の目標はこのようなものになるでしょう。


private String url = "SERVICE_URL";

@Before
public void before() {
   // start jetty with all the services I need
}

@Test
public void shouldDoSthIWant() {
   // invoke SERVICE_URL and test.
}

4

1 に答える 1

1

ここにあるサンプルアプリは、単純なJavaアプリで埋め込みJettyを使用してHttpInvokerを実行する方法を示しています。そのコードを調整して、junitで機能させることができるはずです。
http://code.google.com/p/jianwikis/wiki/SpringHttpRemotingWithEmbeddedJettyServer

コード/構成の関連するセクションをそのペアからここに複製します

Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(port);

Context context = new Context(server, "/", Context.SESSIONS);

DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setContextConfigLocation("classpath:com/mycompany/config/DefaultServlet-servlet.xml");

ServletHolder servletHolder = new ServletHolder(dispatcherServlet);
context.addServlet(servletHolder, "/*")

DefaultServlet-servlet.xml

<!-- This default handler takes care of each of the services enumerated below -->
<bean id="defaultHandlerMapping"
    class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />

<bean id="helloService" class="com.mycompany.service.impl.HelloServiceImpl"/>

<!-- SpringHTTP Service Exposure -->

<bean name="/HelloService"
    class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"
    lazy-init="true">
    <property name="service" ref="helloService" />
    <property name="serviceInterface"
            value="com.mycompany.service.iface.HelloService" />
</bean>
于 2012-07-16T16:38:48.987 に答える