Creating the database in Ant. Placing it on a test classpath. Test test now checks real DB content.
1.1 --- a/samples/livedb/build.xml Thu Jul 15 00:40:37 2010 +0200
1.2 +++ b/samples/livedb/build.xml Fri Jul 16 23:35:08 2010 +0200
1.3 @@ -71,4 +71,39 @@
1.4 nbproject/build-impl.xml file.
1.5
1.6 -->
1.7 +
1.8 + <target name="-pre-compile-test">
1.9 + <antcall target="create-db"/>
1.10 + </target>
1.11 +
1.12 + <!-- BEGIN: livedb.derby.create -->
1.13 + <target name="-check-db">
1.14 + <property name="db" location="build/classes/db"/>
1.15 + <available property="db.exists" file="${db}"/>
1.16 + </target>
1.17 + <target name="create-db" unless="db.exists" depends="init,-check-db">
1.18 + <mkdir dir="${db}"/>
1.19 + <delete dir="${db}"/>
1.20 + <echo message="Creating DB in ${db}"/>
1.21 + <sql classpath="${file.reference.derby.jar}" userid="j1" password="j1"
1.22 + url="jdbc:derby:${db};create=true"
1.23 + driver="org.apache.derby.jdbc.EmbeddedDriver"
1.24 + >
1.25 + create table APP.AGE (
1.26 + NAME VARCHAR(30),
1.27 + AGE NUMERIC(3)
1.28 + );
1.29 + insert into APP.AGE values ('apidesign', 3);
1.30 + </sql>
1.31 + <!-- don't forget to shutdown the DB -->
1.32 + <sql classpath="${file.reference.derby.jar}" userid="j1" password="j1"
1.33 + url="jdbc:derby:${db};shutdown=true"
1.34 + driver="org.apache.derby.jdbc.EmbeddedDriver"
1.35 + onerror="continue"
1.36 + errorproperty="ignore.error"
1.37 + failonconnectionerror="false"
1.38 + >none</sql>
1.39 + <echo message="DB created OK."/>
1.40 + </target>
1.41 + <!-- END: livedb.derby.create -->
1.42 </project>
2.1 --- a/samples/livedb/nbproject/project.properties Thu Jul 15 00:40:37 2010 +0200
2.2 +++ b/samples/livedb/nbproject/project.properties Fri Jul 16 23:35:08 2010 +0200
2.3 @@ -26,7 +26,7 @@
2.4 dist.javadoc.dir=${dist.dir}/javadoc
2.5 endorsed.classpath=
2.6 excludes=
2.7 -file.reference.derby.jar=../libs/dist/derbyclient.jar
2.8 +file.reference.derby.jar=../libs/dist/derby.jar
2.9 file.reference.junit-4.4.jar=../libs/dist/junit-4.4.jar
2.10 file.reference.org-openide-util-lookup.jar=../libs/dist/org-openide-util-lookup.jar
2.11 includes=**
3.1 --- a/samples/livedb/test/org/apidesign/livedb/example/LiveDBTest.java Thu Jul 15 00:40:37 2010 +0200
3.2 +++ b/samples/livedb/test/org/apidesign/livedb/example/LiveDBTest.java Fri Jul 16 23:35:08 2010 +0200
3.3 @@ -21,9 +21,10 @@
3.4
3.5 public void testSomeMethod() throws SQLException {
3.6 List<Age> ages = Age.query();
3.7 - for (Age age : ages) {
3.8 - System.out.printf("%s is %s years old\n", age.NAME, age.AGE);
3.9 - }
3.10 + assertEquals("One record", 1, ages.size());
3.11 + Age age = ages.get(0);
3.12 + assertEquals("name is apidesign", "apidesign", age.NAME);
3.13 + assertEquals("it is three years old", 3, age.AGE.intValue());
3.14 }
3.15
3.16 }
4.1 --- a/samples/livedb/test/org/apidesign/livedb/example/package-info.java Thu Jul 15 00:40:37 2010 +0200
4.2 +++ b/samples/livedb/test/org/apidesign/livedb/example/package-info.java Fri Jul 16 23:35:08 2010 +0200
4.3 @@ -3,7 +3,7 @@
4.4 @LiveDB(
4.5 classname="Age", password="j1", user="j1",
4.6 query="select * from APP.AGE",
4.7 - url="jdbc:derby://localhost:1527/livedb"
4.8 + url="jdbc:derby:classpath:db"
4.9 )
4.10 package org.apidesign.livedb.example;
4.11