java ee - struts2 junit 2.3.12 plugin - unable to write successful test in struts2 junit4 -
i'm using struts2 junit 2.3.12 plugin.
- if run test directly, :
java.lang.noclassdeffounderror: javax/servlet/servletcontext
so include
<dependency> <groupid>javax</groupid> <artifactid>javaee-web-api</artifactid> <version>6.0</version> <scope>provided</scope> </dependency>
in pom, after :
java.lang.classformaterror: absent code attribute in method not native or abstract in class file javax/servlet/servletexception
so, remove above dependency , add :
<dependency> <groupid>org.jboss.spec</groupid> <artifactid>jboss-javaee-6.0</artifactid> <version>1.0.0.final</version> <type>pom</type> <scope>provided</scope> </dependency>
after
severe: [53:22.549] dispatcher initialization failed
below test :
public class testaction extends strutstestcase { @test public void testregister() throws exception { actionproxy proxy = getactionproxy("/gotoregister"); assertnotnull(proxy); proxy = getactionproxy("/registeraction"); useraction action = (useraction) proxy.getaction(); assertnotnull(action); request.setparameter("usernameexists", "true"); request.setparameter("emailexists", "false"); request.setparameter("basicinfo.firstname", "fname"); request.setparameter("basicinfo.lastname", "lname"); request.setparameter("user.username", "test"); request.setparameter("user.email", "nitin.cool4urchat@gmail.com"); request.setparameter("user.passwd", "nn"); request.setparameter("repasswd", "nn"); request.setparameter("gender", "nn"); request.setparameter("basicinfo.country", "india"); string result = action.execute(); assertequals("input", result); system.out.println(action.getactionerrors()); system.out.println(action.getactionmessages()); } }
please me in writing successful test.
[edit] - thought should add complete pom, below maximum part of pom :
<repositories> <repository> <id>java.net2</id> <name>repository hosting jee6 artifacts</name> <url>http://download.java.net/maven/2</url> </repository> <repository> <id>jboss repository</id> <url>http://repository.jboss.org/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupid>net.sourceforge.htmlunit</groupid> <artifactid>htmlunit</artifactid> <version>2.12</version> <scope>compile</scope> </dependency> <dependency> <groupid>org.apache.commons</groupid> <artifactid>commons-lang3</artifactid> <version>3.0</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupid>javax.mail</groupid> <artifactid>mail</artifactid> <version>1.4.5</version> </dependency> <dependency> <groupid>commons-lang</groupid> <artifactid>commons-lang</artifactid> <version>2.4</version> </dependency> <dependency> <groupid>javax.persistence</groupid> <artifactid>persistence-api</artifactid> <version>1.0</version> <type>jar</type> <scope>compile</scope> </dependency> <!-- <dependency> <groupid>c3p0</groupid> <artifactid>c3p0</artifactid> <version>0.9.1.2</version> <type>jar</type> <scope>compile</scope> </dependency>--> <!-- <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-annotations</artifactid> <version>3.5.6-final</version> </dependency>--> <!-- <dependency> <groupid>org.apache.poi</groupid> <artifactid>poi-ooxml</artifactid> <version>3.8-beta4</version> </dependency>--> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.6</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-entitymanager</artifactid> <version>${hibernate.version}</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-c3p0</artifactid> <version>${hibernate.version}</version> </dependency> <!-- <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> <version>1.6.1</version> </dependency>--> <!-- <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-simple</artifactid> <version>1.6.1</version> </dependency>--> <!-- <dependency> <groupid>org.apache.tiles</groupid> <artifactid>tiles-servlet</artifactid> <version>2.1.4</version> </dependency> <dependency> <groupid>org.apache.tiles</groupid> <artifactid>tiles-jsp</artifactid> <version>2.1.4</version> </dependency>--> <dependency> <groupid>org.apache.struts</groupid> <artifactid>struts2-core</artifactid> <version>${struts.version}</version> </dependency> <dependency> <groupid>org.apache.struts</groupid> <artifactid>struts2-json-plugin</artifactid> <version>${struts.version}</version> </dependency> <dependency> <groupid>org.apache.struts</groupid> <artifactid>struts2-tiles-plugin</artifactid> <version>${struts.version}</version> </dependency> <dependency> <groupid>org.apache.struts</groupid> <artifactid>struts2-junit-plugin</artifactid> <version>${struts.version}</version> </dependency> <dependency> <groupid>joda-time</groupid> <artifactid>joda-time</artifactid> <version>2.1</version> </dependency> <!-- <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate</artifactid> <version>3.2.5.ga</version> </dependency>--> <!-- <dependency> <groupid>javax.sql</groupid> <artifactid>jdbc-stdext</artifactid> <version>2.0</version> </dependency> <dependency> <groupid>javax.transaction</groupid> <artifactid>jta</artifactid> <version>1.0.1b</version> </dependency>--> <!-- <dependency> <groupid>javax</groupid> <artifactid>javaee-web-api</artifactid> <version>6.0</version> <scope>provided</scope> </dependency>--> <!-- <dependency> <groupid>javax.validation</groupid> <artifactid>validation-api</artifactid> <version>1.0.0.ga</version> <scope>test</scope> </dependency>--> <dependency> <groupid>org.jboss.spec</groupid> <artifactid>jboss-javaee-6.0</artifactid> <version>1.0.0.final</version> <type>pom</type> <scope>provided</scope> </dependency> <!-- <dependency> <groupid>junit</groupid> <artifactid>junit-dep</artifactid> <version>4.1</version> <scope>test</scope> </dependency> <dependency> <groupid>org.jmock</groupid> <artifactid>jmock-junit4</artifactid> <version>2.6.0</version> <scope>test</scope> </dependency>--> <!-- <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>4.11</version> <version>3.8.2</version> <scope>test</scope> </dependency>--> </dependencies> <build> <plugins> <!-- <plugin> <groupid>org.mortbay.jetty</groupid> <artifactid>maven-jetty-plugin</artifactid> <version>6.1.14</version> <configuration> <scanintervalseconds>5</scanintervalseconds> <webdefaultxml>src/main/resources/webdefault.xml</webdefaultxml> <connectors> <connector implementation="org.eclipse.jetty.server.bio.socketconnector"> <port>8080</port> </connector> </connectors> </configuration> </plugin>--> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>2.0.2</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>${project.build.sourceencoding}</encoding> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-war-plugin</artifactid> <version>2.1-beta-1</version> <configuration> <failonmissingwebxml>false</failonmissingwebxml> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-resources-plugin</artifactid> <version>2.2</version> <configuration> <encoding>${project.build.sourceencoding}</encoding> </configuration> </plugin> </plugins> <finalname>goldentradermaven</finalname> </build> <profiles> <profile> <id>endorsed</id> <activation> <property> <name>sun.boot.class.path</name> </property> </activation> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>2.0.2</version> <configuration> javaee6 contains upgrades of apis contained within jdk itself. such these need placed on bootclasspath, rather classpath of compiler. if don't make use of these new updated api, can delete profile. on non-sun jdk, need create similar profile jdk, similar property sun.boot.class.path in sun's jdk. <compilerarguments> <bootclasspath>${settings.localrepository}/javax/javaee-endorsed-api/6.0/javaee-endorsed-api-6.0.jar${path.separator}${sun.boot.class.path}</bootclasspath> </compilerarguments> </configuration> <dependencies> <dependency> <groupid>javax</groupid> <artifactid>javaee-endorsed-api</artifactid> <version>6.0</version> </dependency> </dependencies> </plugin> </plugins> </build> </profile> </profiles> <properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> <netbeans.hint.deploy.server>tomcat60</netbeans.hint.deploy.server> <struts.version>2.3.12</struts.version> <hibernate.version>3.6.10.final</hibernate.version> </properties> </project>
you need add dependencies of javax.servlet:servlet-api
, javax.servlet.jsp:jsp-api
project pom.xml file.
<dependency> <groupid>javax.servlet</groupid> <artifactid>servlet-api</artifactid> <version>2.4</version> <type>jar</type> <scope>provided</scope> </dependency> <dependency> <groupid>javax.servlet.jsp</groupid> <artifactid>jsp-api</artifactid> <version>2.1</version> <type>jar</type> <scope>test</scope> </dependency>
Comments
Post a Comment