-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic ability to create hsqldb TEXT tables using
@Csv
annotatio…
…n and then adding the file source for the class. bump groovy version. Coincidentally both groovy and hsqldb are 2.3.2 :)
- Loading branch information
Showing
11 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package gstorm | ||
|
||
import java.lang.annotation.Retention | ||
|
||
import static java.lang.annotation.RetentionPolicy.RUNTIME | ||
|
||
@Retention(RUNTIME) | ||
@interface Csv { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package gstorm | ||
|
||
import directree.DirTree | ||
import groovy.sql.Sql | ||
import models.ClassWithCsvAnnotation | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class GstormCsvIntgTest { | ||
|
||
Gstorm gstorm | ||
Sql sql | ||
|
||
@Before | ||
void setUp() { | ||
DirTree.create("tmp") { | ||
dir("csvtest") { | ||
file("test1.csv") { | ||
"""|id,name | ||
|1,test | ||
""".stripMargin("|") | ||
} | ||
} | ||
} | ||
sql = Sql.newInstance("jdbc:hsqldb:file:tmp/csvtest/db", "sa", "", "org.hsqldb.jdbc.JDBCDriver") | ||
gstorm = new Gstorm(sql) | ||
gstorm.stormify(ClassWithCsvAnnotation) | ||
} | ||
|
||
@After | ||
void tearDown() { | ||
sql.execute("drop table ClassWithCsvAnnotation if exists") | ||
sql.close() | ||
} | ||
|
||
@Test | ||
void "should load the data from CSV"() { | ||
gstorm.setCsvFile(ClassWithCsvAnnotation, 'test1.csv;ignore_first=true') | ||
|
||
assert ClassWithCsvAnnotation.all.size() == 1 | ||
} | ||
|
||
@Test | ||
void "should write the data to CSV"() { | ||
gstorm.setCsvFile(ClassWithCsvAnnotation, 'test1.csv;ignore_first=true') | ||
new ClassWithCsvAnnotation(name: "another_text_123").save() | ||
|
||
assert ClassWithCsvAnnotation.all.size() == 2 | ||
assert new File("tmp/csvtest/test1.csv").text.contains("another_text_123") | ||
} | ||
|
||
@Test(expected = java.sql.SQLException) | ||
void "should be able to open csv as read only"() { | ||
gstorm.setCsvFile(ClassWithCsvAnnotation, 'test1.csv;ignore_first=true', true) | ||
new ClassWithCsvAnnotation(name: "another_text_123").save() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package models | ||
|
||
import gstorm.Csv | ||
|
||
@Csv | ||
class ClassWithCsvAnnotation { | ||
String name | ||
} |