2013-12-18 36 views
1

我想用角度做端到端測試,所以我嘗試運行嵌入式碼頭。嵌入式碼頭不工作的集成測試

首先,我已經在pom.xml中創建這個CONF:

<plugin> 
    <groupId>org.mortbay.jetty</groupId> 
    <artifactId>maven-jetty-plugin</artifactId> 
    <version>6.1.26</version> 
    <configuration> 
    <scanIntervalSeconds>10</scanIntervalSeconds> 
    <stopKey>foo</stopKey> 
    <stopPort>9999</stopPort> 
    <contextPath>/</contextPath> 
    <connectors> 
     <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> 
     <port>29439</port> 
     <maxIdleTime>60000</maxIdleTime> 
     </connector> 
    </connectors> 
    </configuration> 
    <dependencies> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>${slf4j.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>ch.qos.logback</groupId> 
     <artifactId>logback-classic</artifactId> 
     <version>${logback.version}</version> 
    </dependency> 
    </dependencies> 
    <executions> 
    <execution> 
     <id>start-jetty</id> 
     <phase>pre-integration-test</phase> 
     <goals> 
     <goal>run</goal> 
     </goals> 
     <configuration> 
     <scanIntervalSeconds>0</scanIntervalSeconds> 
     <daemon>true</daemon> 
     </configuration> 
    </execution> 
    <execution> 
     <id>stop-jetty</id> 
     <phase>post-integration-test</phase> 
     <goals> 
     <goal>stop</goal> 
     </goals> 
    </execution> 
    </executions> 
</plugin> 

但測試被阻止與業力E2E等待從碼頭的響應。如果我嘗試瀏覽本地主機:29439,則什麼也沒有。

,因爲它是非常難以調試,我試圖升級到新碼頭的版本,但它是通向地獄的道路:(

對於爲例,下面的conf一直給我NoClassDefFound錯誤:

<plugin> 
    <groupId>org.mortbay.jetty</groupId> 
    <artifactId>jetty-maven-plugin</artifactId> 
    <version>7.6.14.v20131031</version> 
    <configuration> 
    <scanIntervalSeconds>10</scanIntervalSeconds> 
    <stopKey>STOP</stopKey> 
    <stopPort>9999</stopPort> 
    <webApp> 
     <contextPath>/</contextPath> 
    </webApp> 
    <connectors> 
     <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"> 
     <port>29439</port> 
     <maxIdleTime>60000</maxIdleTime> 
     </connector> 
    </connectors> 
    </configuration> 
    <dependencies> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>${slf4j.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>ch.qos.logback</groupId> 
     <artifactId>logback-classic</artifactId> 
     <version>${logback.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-jsp</artifactId> 
     <version>7.6.14.v20131031</version> 
    </dependency> 
    </dependencies> 
    <executions> 
    <execution> 
     <id>start-jetty</id> 
     <phase>pre-integration-test</phase> 
     <goals> 
     <goal>start</goal> 
     </goals> 
     <configuration> 
     <scanIntervalSeconds>0</scanIntervalSeconds> 
     <daemon>true</daemon> 
     </configuration> 
    </execution> 
    <execution> 
     <id>stop-jetty</id> 
     <phase>post-integration-test</phase> 
     <goals> 
     <goal>stop</goal> 
     </goals> 
    </execution> 
    </executions> 
</plugin> 

任何解決方案或建議將幫助,無論是與調試第1版,或使第二個版本的作品。

回答

1

的工作pom.xml的爲您服務。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>org.eclipse.jetty.demo</groupId> 
    <artifactId>webapp-2.5</artifactId> 
    <packaging>war</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <name>webapp-2.5 Maven Webapp</name> 
    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <jetty-version>7.6.14.v20131031</jetty-version> 
    <slf4j-version>1.7.5</slf4j-version> 
    <logback-version>1.0.13</logback-version> 
    </properties> 
    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.11</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
     <scope>provided</scope> 
    </dependency> 
    </dependencies> 
    <build> 
    <finalName>webapp-2.5</finalName> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.1</version> 
     <configuration> 
      <source>1.5</source> 
      <target>1.5</target> 
     </configuration> 
     </plugin> 
     <plugin> 
     <groupId>org.mortbay.jetty</groupId> 
     <artifactId>jetty-maven-plugin</artifactId> 
     <version>${jetty-version}</version> 
     <configuration> 
      <scanIntervalSeconds>10</scanIntervalSeconds> 
      <stopKey>STOP</stopKey> 
      <stopPort>9999</stopPort> 
      <webApp> 
      <contextPath>/</contextPath> 
      </webApp> 
      <connectors> 
      <connector 
       implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"> 
       <port>28080</port> 
       <maxIdleTime>60000</maxIdleTime> 
      </connector> 
      </connectors> 
     </configuration> 
     <dependencies> 
      <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>${slf4j-version}</version> 
      </dependency> 
      <dependency> 
      <groupId>ch.qos.logback</groupId> 
      <artifactId>logback-classic</artifactId> 
      <version>${logback-version}</version> 
      </dependency> 
      <dependency> 
      <groupId>org.eclipse.jetty</groupId> 
      <artifactId>jetty-jsp</artifactId> 
      <version>${jetty-version}</version> 
      </dependency> 
     </dependencies> 
     <executions> 
      <execution> 
      <id>start-jetty</id> 
      <phase>pre-integration-test</phase> 
      <goals> 
       <goal>start</goal> 
      </goals> 
      <configuration> 
       <scanIntervalSeconds>0</scanIntervalSeconds> 
       <daemon>true</daemon> 
      </configuration> 
      </execution> 
      <execution> 
      <id>stop-jetty</id> 
      <phase>post-integration-test</phase> 
      <goals> 
       <goal>stop</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

這將執行集成階段開始/停止,配置日誌記錄,以及Servlet 2.5 webapp上的支持$ mvn jetty:run

工作實施例

工作示例web應用已上傳到github上。

https://github.com/jetty-project/jetty-maven-plugin-examples

見的webapp-2.5子項目

要構建戰爭

$ mvn clean install 

要使用您的碼頭 - Maven的插件配置運行碼頭服務器

$ mvn jetty:run 

轉到您的瀏覽器,並點擊以下任意網址查看它工作。

  • http://localhost:28080/ - 從src/main/webapp/index.html
  • http://localhost:28080/time簡單的HTML響應 - 簡單的servlet響應從org.eclipse.demo.TimeServlet
  • http://localhost:28080/flarnsworth - 無效引用,所以這將觸發<error-page>處理並返回從org.eclipse.jetty.demo.ErrorServlet
  • http://localhost:28080/dump.jsp的迴應 - 來自src/main/webapp/dump.jsp的jsp響應
+0

Ahhhh ...我的E2E測試被阻止在: karma start /Users/ygrenzinger/Xebia/SFR/sibo360/src/test/resources/karma.e2e.conf --single-run 如果我嘗試去localhost 29439沒有響應。 當我用Ctrl-C殺死Maven運行時,我看到這個錯誤: [WARNING] FAILED jsp:java.lang.NoClassDefFoundError:org/apache/jasper/runtime/JspApplicationContextImpl java.lang。NoClassDefFoundError:org/apache/jasper/runtime/JspApplicationContextImpl – user358501

+0

您看到的JSP錯誤不是來自該示例的pom。 (幾乎)相同的pom在示例項目中爲您上傳。 –