Author: vyemialyanchyk
Date: 2010-08-11 10:18:57 -0400 (Wed, 11 Aug 2010)
New Revision: 24045
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenInternalProps_test1.xml
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenInternalProps_test2.xml
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java
Log:
https://jira.jboss.org/browse/JBIDE-6620 - update(add) tests for internal properties case
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenInternalProps_test1.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenInternalProps_test1.xml
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenInternalProps_test1.xml 2010-08-11
14:18:57 UTC (rev 24045)
@@ -0,0 +1,44 @@
+<project name="CodeGen" default="hibernateAntCodeGeneration">
+ <property name="build.dir" location="reslocation/test"/>
+ <property name="hibernatePropFile"
value="${java.io.tmpdir}${ant.project.name}-hibernate.properties"/>
+ <target name="generateHibernatePropeties">
+ <echo
file="${hibernatePropFile}">hibernate.connection.driver_class=driverClass
+hibernate.connection.password=passw
+hibernate.connection.url=url
+hibernate.connection.username=username
+hibernate.dialect=testDialect</echo>
+ </target>
+ <path id="toolslib"/>
+ <target name="hibernateAntCodeGeneration"
depends="generateHibernatePropeties">
+ <taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib"/>
+ <hibernatetool destdir="${build.dir}">
+ <configuration configurationFile="project\src\hibernate.cfg.xml"
propertyFile="${hibernatePropFile}"/>
+ <classpath>
+ <path location="${build.dir}"/>
+ </classpath>
+ <hbm2doc>
+ <property key="ejb3" value="false"/>
+ <property key="jdk5" value="false"/>
+ </hbm2doc>
+ <hbm2cfgxml>
+ <property key="jdk5" value="false"/>
+ </hbm2cfgxml>
+ <hbm2hbmxml>
+ <property key="ejb3" value="false"/>
+ <property key="jdk5" value="false"/>
+ </hbm2hbmxml>
+ <hbmtemplate>
+ <property key="ejb3" value="false"/>
+ <property key="jdk5" value="false"/>
+ </hbmtemplate>
+ <hbm2java destdir="outputdir/test">
+ <property key="keyXXX" value="valueYYY"/>
+ </hbm2java>
+ <hbm2ddl>
+ <property key="ejb3" value="false"/>
+ <property key="jdk5" value="false"/>
+ </hbm2ddl>
+ <hbm2dao/>
+ </hibernatetool>
+ </target>
+</project>
\ No newline at end of file
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenInternalProps_test2.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenInternalProps_test2.xml
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenInternalProps_test2.xml 2010-08-11
14:18:57 UTC (rev 24045)
@@ -0,0 +1,24 @@
+<project name="CodeGen" default="hibernateAntCodeGeneration">
+ <property name="build.dir" location="reslocation/test"/>
+ <property name="hibernatePropFile"
value="${java.io.tmpdir}${ant.project.name}-hibernate.properties"/>
+ <target name="generateHibernatePropeties">
+ <echo
file="${hibernatePropFile}">hibernate.connection.driver_class=driverClass
+hibernate.connection.password=passw
+hibernate.connection.url=url
+hibernate.connection.username=username
+hibernate.dialect=testDialect</echo>
+ </target>
+ <path id="toolslib"/>
+ <target name="hibernateAntCodeGeneration"
depends="generateHibernatePropeties">
+ <taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib"/>
+ <hibernatetool destdir="${build.dir}">
+ <configuration configurationFile="project\src\hibernate.cfg.xml"
propertyFile="${hibernatePropFile}"/>
+ <classpath>
+ <path location="${build.dir}"/>
+ </classpath>
+ <hbm2java destdir="outputdir/test">
+ <property key="keyXXX" value="valueYYY"/>
+ </hbm2java>
+ </hibernatetool>
+ </target>
+</project>
\ No newline at end of file
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java 2010-08-11
14:15:26 UTC (rev 24044)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java 2010-08-11
14:18:57 UTC (rev 24045)
@@ -48,6 +48,9 @@
*/
public class CodeGenXMLFactoryTest extends TestCase {
+ public static final String LN_1 = "\n"; //$NON-NLS-1$
+ public static final String LN_2 = "\r\n"; //$NON-NLS-1$
+
public static final String SAMPLE_PATH =
"res/sample/".replaceAll("//", File.separator); //$NON-NLS-1$
//$NON-NLS-2$
public static final String PROJECT_LIB_PATH =
"res/project/lib/".replaceAll("//", File.separator); //$NON-NLS-1$
//$NON-NLS-2$
@@ -202,7 +205,7 @@
String codeGen = codeGenFactory.createCodeGenXML();
String codeGenProperties = codeGenFactory.getPropFileContentPreSave();
String specimen = getSample("AntCodeGenReveng_test1.xml"); //$NON-NLS-1$
- assertEquals(specimen.trim(), codeGen.replaceAll("\n", "\r\n"));
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(specimen.trim(), codeGen.replaceAll(LN_1, LN_2));
assertEquals(codeGenProperties.length(), 0);
}
@@ -211,7 +214,7 @@
String codeGen = codeGenFactory.createCodeGenXML();
String codeGenProperties = codeGenFactory.getPropFileContentPreSave();
String sample = getSample("AntCodeGenReveng_test2.xml"); //$NON-NLS-1$
- assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n"));
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(sample.trim(), codeGen.replaceAll(LN_1, LN_2));
assertEquals(codeGenProperties.length(), 0);
}
@@ -220,7 +223,7 @@
String codeGen = codeGenFactory.createCodeGenXML();
String codeGenProperties = codeGenFactory.getPropFileContentPreSave();
String sample = getSample("AntCodeGen_test1.xml"); //$NON-NLS-1$
- assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n"));
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(sample.trim(), codeGen.replaceAll(LN_1, LN_2));
assertEquals(codeGenProperties.length(), 0);
}
@@ -229,7 +232,7 @@
String codeGen = codeGenFactory.createCodeGenXML();
String codeGenProperties = codeGenFactory.getPropFileContentPreSave();
String sample = getSample("AntCodeGen_test2.xml"); //$NON-NLS-1$
- assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n"));
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(sample.trim(), codeGen.replaceAll(LN_1, LN_2));
assertEquals(codeGenProperties.length(), 0);
}
@@ -239,7 +242,7 @@
String codeGenProperties = codeGenFactory.getPropFileContentPreSave();
codeGen = updatePaths(codeGen);
String sample = getSample("AntCodeGenJpa_test1.xml"); //$NON-NLS-1$
- assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n"));
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(sample.trim(), codeGen.replaceAll(LN_1, LN_2));
assertEquals(codeGenProperties.length(), 0);
}
@@ -249,7 +252,7 @@
String codeGenProperties = codeGenFactory.getPropFileContentPreSave();
codeGen = updatePaths(codeGen);
String sample = getSample("AntCodeGenJpa_test2.xml"); //$NON-NLS-1$
- assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n"));
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(sample.trim(), codeGen.replaceAll(LN_1, LN_2));
assertEquals(codeGenProperties.length(), 0);
}
@@ -259,7 +262,7 @@
String codeGenProperties = codeGenFactory.getPropFileContentPreSave();
codeGen = updatePaths(codeGen);
String sample = getSample("AntCodeGenNullable_test1.xml"); //$NON-NLS-1$
- assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n"));
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(sample.trim(), codeGen.replaceAll(LN_1, LN_2));
assertEquals(codeGenProperties.length(), 0);
}
@@ -269,7 +272,7 @@
String codeGenProperties = codeGenFactory.getPropFileContentPreSave();
codeGen = updatePaths(codeGen);
String sample = getSample("AntCodeGenNullable_test2.xml"); //$NON-NLS-1$
- assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n"));
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(sample.trim(), codeGen.replaceAll(LN_1, LN_2));
assertEquals(codeGenProperties.length(), 0);
}
@@ -280,7 +283,7 @@
codeGen = updatePaths(codeGen);
String sample = getSample("AntCodeGenProps_test1.xml"); //$NON-NLS-1$
String sampleProperties = getSample("AntCodeGenProps.hibernate.properties");
//$NON-NLS-1$
- assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n"));
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(sample.trim(), codeGen.replaceAll(LN_1, LN_2));
assertEquals(sampleProperties.trim(), codeGenProperties);
}
@@ -291,9 +294,33 @@
codeGen = updatePaths(codeGen);
String sample = getSample("AntCodeGenProps_test2.xml"); //$NON-NLS-1$
String sampleProperties = getSample("AntCodeGenProps.hibernate.properties");
//$NON-NLS-1$
- assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n"));
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(sample.trim(), codeGen.replaceAll(LN_1, LN_2));
assertEquals(sampleProperties.trim(), codeGenProperties);
}
+
+ public void testCodeGenXMLFactoryInternalPropertiesAll() {
+ CodeGenXMLFactory codeGenFactory = codeGenXMLFactory(false, true,
ETestCase.properties);
+ codeGenFactory.setExternalPropFile(false);
+ String codeGen = codeGenFactory.createCodeGenXML();
+ String codeGenProperties = codeGenFactory.getPropFileContentPreSave();
+ codeGen = updatePaths(codeGen);
+ String sample = getSample("AntCodeGenInternalProps_test1.xml");
//$NON-NLS-1$
+ String sampleProperties = getSample("AntCodeGenProps.hibernate.properties");
//$NON-NLS-1$
+ assertEquals(sample.trim(), codeGen.replaceAll(LN_2, LN_1).replaceAll(LN_1, LN_2));
+ assertEquals(sampleProperties.trim(), codeGenProperties);
+ }
+
+ public void testCodeGenXMLFactoryInternalPropertiesOne() {
+ CodeGenXMLFactory codeGenFactory = codeGenXMLFactory(false, false,
ETestCase.properties);
+ codeGenFactory.setExternalPropFile(false);
+ String codeGen = codeGenFactory.createCodeGenXML();
+ String codeGenProperties = codeGenFactory.getPropFileContentPreSave();
+ codeGen = updatePaths(codeGen);
+ String sample = getSample("AntCodeGenInternalProps_test2.xml");
//$NON-NLS-1$
+ String sampleProperties = getSample("AntCodeGenProps.hibernate.properties");
//$NON-NLS-1$
+ assertEquals(sample.trim(), codeGen.replaceAll(LN_2, LN_1).replaceAll(LN_1, LN_2));
+ assertEquals(sampleProperties.trim(), codeGenProperties);
+ }
public String updatePaths(String codeGen) {
String repl = ""; //$NON-NLS-1$
@@ -361,7 +388,7 @@
}
StringBuffer cbuf = new StringBuffer((int) resourceFile.length());
try {
- String ls = System.getProperties().getProperty("line.separator",
"\n"); //$NON-NLS-1$//$NON-NLS-2$
+ String ls = System.getProperties().getProperty("line.separator", LN_1);
//$NON-NLS-1$
BufferedReader in = new BufferedReader(new FileReader(resourceFile));
String str;
while ((str = in.readLine()) != null) {