I'm exporting my mapping (hbm.xml) to pojo classes using ant task.
It generates the POJO files in the mapped directory. But the Classes miss the Package statement. It simply creates all files in default package
// default package
// Generated Aug 23, 2012 12:34:40 PM by Hibernate Tools 3.2.2.GA
Here is my ant build file for the task.
<project name="Hibernate Tools for Ant - hbm2java" default="gensrc">
<path id="tools">
<path location="lib/hibernate-tools-3.2.3.GA.jar"/>
<path location="lib/hibernate3.6.10.jar"/>
<path location="lib/freemarker-2.3.8.jar"/>
<path location="lib/hsqldb-2.2.4.jar"/>
<path location="lib/commons-logging.jar"/>
<path location="lib/dom4j-1.6.1.jar"/>
<path location="lib/slf4j-api-1.6.1.jar"/>
<path location="lib/hibernate-jpa-2.0-api-1.0.1.Final.jar"/>
</path>
<taskdef name="gen-src" classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="tools"/>
<target name="gensrc">
<gen-src destdir="src/main/java">
<configuration
configurationfile="src/main/resources/hibernate.cfg.xml">
<fileset dir="src/main/java/com/kee/example/domain/maps">
<include name="Event.hbm.xml"/>
</fileset>
</configuration>
<hbm2java destdir="src/main/java/com/kee/example/domain"/>
</gen-src>
</target>
</project>
the default Pojo.ftl (inside hibernate-tools.jar) has the declaration as below
${pojo.getPackageDeclaration()}
// Generated ${date} by Hibernate Tools ${version}
what should i be changing in order to have correct package declaration in the generated POJO.
Update:
Here is my Mapping file
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.kee.example.domain">
<meta attribute="generated-class">EventBase</meta>
<meta attribute="implement-equals">true</meta>
<meta attribute="scope-field">protected</meta>
<class name="com.kee.example.domain.Event" table="event">
<id name="id" type="java.lang.Long">
<generator class="native"/>
</id>
<property name="eventDate" type="timestamp"/>
<property name="eventString" type="java.lang.String"/>
</class>
</hibernate-mapping>
I was getting the same problem in maven and not sure about the reason but it was resolved once I started using annotationconfiguration instead of jdbcconfiguration.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>annotationconfiguration</implementation>
<outputDirectory>${db.src.dir}</outputDirectory>
</component>
<component>
<name>hbm2java</name>
<implementation>annotationconfiguration</implementation>
<outputDirectory>src/main/java</outputDirectory>
</component>
</components>
<componentProperties>
<drop>true</drop>
<create>true</create>
<export>false</export>
<format>true</format>
<jdk5>true</jdk5>
<ejb3>true</ejb3>
<outputfilename>${ddl.file}</outputfilename>
<templatepath>src/main/resources/hibernate-template</templatepath>
<delimiter>;</delimiter>
<configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>${jdbc.groupId}</groupId>
<artifactId>${jdbc.artifactId}</artifactId>
<version>${jdbc.version}</version>
</dependency>
</dependencies>
</plugin>
I did not want the annotated pojo classes so I had commented codes in *.ftl files.
Related
I have 2 groups of test cases as mentioend below.
#Test(groups="one", dataProvider = "TestData")
public void firstTest(String data){
//Code
}
#Test(groups="one", dataProvider = "TestData")
public void secondTest(String data){
//Code
}
#Test(groups="two", dataProvider = "TestData")
public void thirdTest(String data){
//Code
}
Below is the XML file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test-Automation" parallel="methods" thread-count="2" verbose="1">
<test name="Suite Test" parallel="methods" thread-count="2" verbose="1">
<listeners>
<listener class-name="GroupByInstanceEnabler"></listener>
</listeners>
<classes>
<class name="SampleTest">
<methods>
<include name="firstTest"/>
<include name="secondTest"/>
<include name="thirdTest"/>
</methods>
</class>
</classes>
</test>
</suite>
Below is the pom.xml build details.
<build>
<finalName>Automation</finalName>
<filters>
<filter>profiles/${build.profile.id}/config.properties</filter>
</filters>
<resources>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/test/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${project.basedir}/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<parallel>method</parallel>
<threadCount>2</threadCount>
</configuration>
</plugin>
</plugins>
</build>
My Question:
Using Maven, how do I run the group "one" and group "two" separately.
I tried "mvn test -Dgroups=two" but it only runs as normal(all tests).
Note: I use 2 different profiles to run the group "one" twice with different values. This is the reason you see profile configuration in the pom.xml file.
You can make use of a beanshell expression for getting this done.
You first add a beanshell expression as below to your suite xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="false">
<test name="Test">
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[whatGroup = System.getProperty("groupToRun");
groups.containsKey(whatGroup);
]]>
</script>
</method-selector>
</method-selectors>
<classes>
<class name="organized.chaos.GroupsPlayGround" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
This way you can make use of the suite xml from your IDE and still choose which groups to be executed. You can enrich this beanshell to run everything by default if no value is provided via the JVM argument -DgroupToRun=one
For more information on beanshell execution refer:
Official TestNG documentation here
My blog post link
I would like to run my selenium test suite which contains 2 tests(test1 and test2) on 2 different browsers.
I want to run the 2 tests in order so i used dependsOnMethods to specify the order
I created a data provider containing the browsers as parameters (i used 2 browser names as strings) but i could not pass it to #BeforeSuite
when i passed the data provider to test1 ,test1 ran 2 times then test2 ran 1 time.
This is not what i need , i need test1 and test2 to run in order on each browser.
Any suggestion how i can achieve this?
Thanks In advance
#Test( groups = { "login-positive"},dataProvider="browserList")
public void loginTest(String browser)throws MalformedURLException{
PageUtils.initializeBrowser(browser);
loginPage= PageUtils.getHomePage().goToLoginPage(PageUtils.getWebDriver());
String username="raghda";
String password="I123123";
loginPage.fillUserName(username);
loginPage.fillPassword(password);
loggedInPage=loginPage.clickSubmit();
Assert.assertEquals("raghda", loggedInPage.getDisplayedUserName());
}
#Test( groups = { "login- positive"},dataProvider="browserList",dependsOnMethods= {"loginTest"})
public void ValidateGeneralDonation(String browser)throws MalformedURLException{
generalDonPage=loggedInPage.clickGeneralDonation();
generalDonPage.selectCharity(1);
generalDonPage.checkDonationItem(0);
assertTrue(generalDonPage.getDonateButton());
}
POM.xml
<profile>
<id>RegressionTest</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<!-- Suite testng xml file to consider for test execution -->
<suiteXmlFiles>
<suiteXmlFile>testngregression.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>parallel</name>
<value>methods</value>
</property>
<property>
<name>threadCount</name>
<value>1</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
testngregression.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1" verbose="1">
<test name="regression">
<parameter name="loggedIn" value="false"></parameter>
<groups>
<define name="login-all">
<include name="login-positive" />
<include name="login-negative" />
</define>
<define name="login-positive-only">
<include name="login-positive" />
</define>
<run>
<include name="login-positive-only" />
</run>
</groups>
<classes>
<class name="basicportal.automation.TestDriver" />
</classes>
</test>
</suite>
I have integrated enunciate framework to generate the API document for the Spring RESTful project. I have followed the steps from https://github.com/stoicflame/enunciate/wiki/Executables and deployed the war created from the enunciate configuration in the tomcat server(http://localhost:8080/sample_enunciate) but its displaying the empty document. Here I have provided the configuration details used in the sample project.
NOTE: But the similar configuration is working with Jersey restful project. I really stuck here. Please let me know, is this bug with the enunciate framework integration with Spring project. Thanks in advance.
Project configuration:
java -1.7.0
tomcat -6.0 &7.0
ant -1.9.4
spring -4.0.5
enunciate -1.30
jars:
enunciate-core-1.30-RC1.jar
enunciate-core-annotations-1.30-RC1.j
enunciate-core-rt-1.30-RC1.jar
enunciate-java-client-1.30-RC1.jar
enunciate-docs-1.30-RC1.jar
enunciate-rt-1.30-RC1.jar
enunciate-spring-app-rt-1.30-RC1.jar
enunciate-spring-jaxws-rt-1.30-RC1.ja
spring-aop-4.0.5.RELEASE.jar
spring-beans-4.0.5.RELEASE.jar
spring-context-4.0.5.RELEASE.jar
spring-context-support-2.5.4.jar
spring-core-4.0.5.RELEASE.jar
spring-expression-4.0.5.RELEASE.jar
spring-jdbc-4.0.5.RELEASE.jar
spring-test-4.0.5.RELEASE.jar
spring-tx-4.0.5.RELEASE.jar
spring-web-4.0.5.RELEASE.jar
spring-webmvc-4.0.5.RELEASE.jar
This is my enunciate.xml.
enunciate.xml
<?xml version="1.0"?>
<api-classes>
<include pattern="com.sample.controller.*" />
</api-classes>
<modules>
<!-- Docs -->
<docs title="example" copyright="Example.com"/>
<webapp mergeWebXML="WebContent/WEB-INF/web.xml" />
<spring-app disabled="false" springVersion="4.0.5">
<springImport file="resources/dev/applicationContext.xml" />
<springImport file="WebContent/WEB-INF/rest-servlet.xml" />
</spring-app>
<c disabled="true" />
<csharp disabled="true" />
<java-client disabled="false" />
<cxf disabled="false" />
<gwt disabled="false" />
<jaxws-client disabled="true" />
<jaxws-ri disabled="true" />
<jaxws-support disabled="true" />
<jersey disabled="true" />
<xml disabled="false" />
<obj-c disabled="true" />
<rest disabled="false" />
</modules>
properties file for build.xml
enunciate_build.properties
JAVA_HOME=C:/Java/jdk1.7.0/
tomcat.home=D:/xampp/tomcat
This is my build.xml
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project default = "enunciate">
<property file ="enunciate_build.properties"/>
<property name="lib.dir" value="../libs" />
<property name="src.dir" value="src"/>
<target name = "enunciate">
<path id= "enunciate.classpath">
<fileset dir = "${lib.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir ="${lib.dir}/modules/spring">
<include name="*.jar"/>
</fileset>
<fileset dir = "${JAVA_HOME}">
<include name = "lib/tools.jar"/>
</fileset>
</path>
<taskdef name="enunciate" classname = "org.codehaus.enunciate.main.EnunciateTask">
<classpath refid = "enunciate.classpath"/>
</taskdef>
<enunciate javacSourceVersion="1.7" javacTargetVersion="1.7" basedir = "${src.dir}" configFile="enunciate.xml">
<include name = "**/*.java"/>
<classpath refid= "enunciate.classpath"/>
<export artifactId="war.file" destination="${tomcat.home}/webapps/sample_enunciate.war"/>
</enunciate>
</target>
</project>
Enunciate only recognizes JAX-RS annotations right now. For further information follow this link.https://github.com/stoicflame/enunciate/issues/60
Exception:
Caused by: org.springframework.core.NestedIOException: Failed to parse config resource: ServletContext resource [/WEB-INF/SqlMapConfig.xml]; nested exception is com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'. Cause: java.io.IOException: Could not find resource WEB-INF/ADCampaignDetailsSQLMap.xml
SqlMapConfig.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL MAP Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings useStatementNamespaces="true"/>
<sqlMap resource="WEB-INF/ADCampaignDetailsSQLMap.xml"/>
</sqlMapConfig>
ADCampaignDetailsSQLMap.xml is placed inside WEB-INF of my project folder
And the Above exception is raised when i copied the war file to webapps folder ..
Can any one give me solution for this?
thanks in advance
Edit:
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project
name="adblendservice"
default="war" >
<property environment="env" />
<property
name="builddir"
value="build/" />
<property
name="srcdir"
value="src/main/java/" />
<property
name="deploydir"
value="deploy/" />
<property
name="wardir"
value="src/main/webapp/" />
<property
name="libdir"
value="${wardir}/WEB-INF/lib/" />
<property file="build.properties" />
<path id="project-classpath" >
<fileset
dir="web/WEB-INF/lib"
includes="*.jar" />
<fileset
dir="${tomcat-home}/lib"
includes="*.jar" />
<!--
<fileset dir="${tomcat-home}/common/lib" includes="*.jar" />
<fileset dir="${tomcat-home}/server/lib" includes="*.jar" />
-->
</path>
<target name="clean" >
<delete
dir="${builddir}"
failonerror="true" />
<echo message="Creating build directories" />
</target>
<target name="war" >
<mkdir dir="${builddir}" />
<mkdir dir="${builddir}/adblendservice/WEB-INF/classes" />
<mkdir dir="${deploydir}" />
<path id="basepath" >
<fileset dir="${wardir}/WEB-INF/lib" >
<include name="**/*.jar" />
</fileset>
</path>
<javac
destdir="${builddir}/adblendservice/WEB-INF/classes"
includeantruntime="false"
srcdir="${srcdir}" >
<classpath refid="basepath" />
</javac>
<war
update="update"
warfile="${builddir}/adblendservice.war"
webxml="${wardir}/WEB-INF/web.xml" >
<classes dir="${builddir}/adblendservice/WEB-INF/classes" />
<fileset dir="${srcdir}" >
<include name="**/*.xml" />
</fileset>
<lib dir="${wardir}/WEB-INF/lib" />
<fileset dir="${wardir}" >
<include name="**/*.xml" />
</fileset>
</war>
</target>
<target
name="deploy"
depends="clean, war" >
<copy
file="${builddir}/adblendservice.war"
todir="${deploydir}" >
</copy>
</target>
</project>
The root of the classpath where iBatis searches for xml files is WEB-INF/classes, not the root of the public web site.
Try to move your xml into the classes directory and point to it without path.
Move your XML files to class path or if it is outside class path, then specify path like <sqlMap resource="../WEB-INF/ADCampaignDetailsSQLMap.xml"/>
I have a question in regards to consuming a web service based on a third party wsdl file.
I've taken the given wsdl and generated the 120+ java files required. This process was done by using xjc. Within the Sping environment, I was able to successfully create a couple of JUnit tests by calling a couple of the exposed services.
But, in order to successfully test those services I had to add the #XmlRootElement annotation to the generated java files. Otherwise, I would encounter an error stating
"com.sun.istack.SAXException2: unable to marshal type
"com.beam.services.client.UserGetRequestData" as an element because it
is missing an #XmlRootElement annotation"
.
I've exhausted my search… I have no control as to how the wsdl file is created/structured. How can I go about generating the java files to ensure that the #XmlRootElement annotation is included or go about writing the client side code in way to avoid the error above?
Thank you.
If you really need the #XmlRootElement you could use simple binding mode if your type is used for only one element. The reason why JAXB does not include the annotation by default and how to use simple binding is explained here: https://community.oracle.com/blogs/kohsuke/2006/03/03/why-does-jaxb-put-xmlrootelement-sometimes-not-always:
your schema might be used by other schemas that XJC isn't compiling
right now
and
Such notion isn't defined in the spec, but as an experiment we have
such aggressive optimization mode in XJC, tentatively called
"simple-minded binding mode".
The sample seems to got lost when the moved the blog, but it looked like this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="1.0" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionbindingprefixes="xjc">
<xs:annotation>
<xs:appinfo>
<jaxb:globalbindings>
<xjc:simple/>
</jaxb:globalbindings>
</xs:appinfo>
</xs:annotation>
<xs:element name="foo" type="bar"/>
<xs:complextype name="bar"/>
</xs:schema>
The other possibilty is to wrap it in a JAXBElement. The ObjectFactory should include a method for creating these wrapped objects.
If you are using mavem then check this link it worked for me.
Create Maven project. Below you can see the POM:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.zmeu</groupId>
<artifactId>zmeu-blog-maven-jaxb</artifactId>
<version>1.0-SNAPSHOT</version>
<name>ZMEU Blog Maven JAXB</name>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.0</version>
<configuration>
<schemaDirectory>src/main/resources/schema</schemaDirectory>
<bindingDirectory>src/main/resources/schema</bindingDirectory>
<generatePackage>org.zmeu.blog.jaxb</generatePackage>
<strict>false</strict>
<extension>true</extension>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.2</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.2</version>
</plugin>
</plugins>
<args>
<arg>-Xannotate</arg>
<arg>-XtoString</arg>
</args>
</configuration>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
<version>0.6.2</version>
</dependency>
</dependencies>
</project>
Write XML Schema (schema.xsd):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="user" type="user" />
<xs:element name="userList" type="userList" />
<xs:complexType name="user">
<xs:all>
<xs:element name="id" type="xs:long" minOccurs="0" />
<xs:element name="name" type="xs:string" />
<xs:element name="registrationDate" type="xs:dateTime" />
</xs:all>
</xs:complexType>
<xs:complexType name="userList">
<xs:sequence>
<xs:element name="user" type="user" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:schema>
Customize JAXB Bindings (binding.xjb):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:annox="http://annox.dev.java.net"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">
<jaxb:globalBindings>
<!-- Use java.util.Calendar instead of javax.xml.datatype.XMLGregorianCalendar for xs:dateTime -->
<jaxb:javaType name="java.util.Calendar" xmlType="xs:dateTime"
parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime"
printMethod="javax.xml.bind.DatatypeConverter.printDateTime" />
<!-- Force all classes implements Serializable -->
<xjc:serializable uid="1" />
</jaxb:globalBindings>
<!-- Annotate the following classes with XmlRootElement -->
<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
<jaxb:bindings node="xs:complexType[#name='user']">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="user" />
</annox:annotate>
</jaxb:bindings>
<jaxb:bindings node="xs:complexType[#name='userList']">
<annox:annotate>
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="userList" />
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
Run the build using mvn clean install command. Build must be successful. Generated classes will be located in target/generated-sources/xjc directory. Below is a snippet from generated User class:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "user", propOrder = {})
#XmlRootElement(name = "user")
public class User implements Serializable, ToString {
private final static long serialVersionUID = 1L;
protected Long id;
#XmlElement(required = true)
protected String name;
#XmlElement(required = true, type = String.class)
#XmlJavaTypeAdapter(Adapter1 .class)
#XmlSchemaType(name = "dateTime")
protected Calendar registrationDate;
}
You are done!