rubeus 0.0.6-java → 0.0.7-java
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +26 -0
- data/examples/jdbc_example.rb +5 -24
- data/lib/rubeus.jar +0 -0
- data/lib/rubeus.rb +18 -2
- data/lib/rubeus/component_loader.rb +25 -20
- data/lib/rubeus/extensions.rb +44 -4
- data/lib/rubeus/extensions/java/awt/dimension.rb +8 -2
- data/lib/rubeus/extensions/java/sql/driver_manager.rb +240 -1
- data/lib/rubeus/extensions/javax/swing/j_table.rb +7 -23
- data/lib/rubeus/extensions/javax/swing/table/default_table_model.rb +7 -0
- data/lib/rubeus/extensions/javax/swing/table/readonlyable_table_model.rb +10 -0
- data/lib/rubeus/jdbc.rb +5 -0
- data/lib/rubeus/swing.rb +9 -6
- data/lib/rubeus/verboseable.rb +41 -0
- data/rmaven.yml +6 -0
- data/test/rubeus/awt/test_attributes.rb +58 -0
- data/test/rubeus/awt/test_event.rb +216 -0
- data/test/rubeus/awt/test_nestable.rb +92 -0
- data/test/rubeus/awt/test_setter.rb +42 -0
- data/test/rubeus/extensions/java/awt/test_dimension.rb +67 -0
- data/test/rubeus/extensions/java/sql/test_connection.rb +50 -0
- data/test/rubeus/extensions/java/sql/test_driver_manager.rb +37 -0
- data/test/rubeus/extensions/java/sql/test_result_set.rb +67 -0
- data/test/rubeus/extensions/java/sql/test_result_set_meta_data.rb +121 -0
- data/test/rubeus/extensions/java/sql/test_statement.rb +43 -0
- data/test/rubeus/extensions/javax/swing/table/test_default_table_model.rb +359 -0
- data/test/rubeus/extensions/javax/swing/table/test_default_table_model/nhk_words.xml +15 -0
- data/test/rubeus/extensions/javax/swing/test_box_layout.rb +56 -0
- data/test/rubeus/extensions/javax/swing/test_j_component.rb +30 -0
- data/test/rubeus/extensions/javax/swing/test_j_frame.rb +42 -0
- data/test/rubeus/extensions/javax/swing/test_j_panel.rb +23 -0
- data/test/rubeus/extensions/javax/swing/test_j_scroll_pane.rb +24 -0
- data/test/rubeus/extensions/javax/swing/test_j_split_pane.rb +54 -0
- data/test/rubeus/extensions/javax/swing/test_j_tabbed_pane.rb +204 -0
- data/test/rubeus/extensions/javax/swing/test_j_table.rb +71 -0
- data/test/rubeus/extensions/javax/swing/test_j_text_field.rb +48 -0
- data/test/rubeus/extensions/javax/swing/test_timer.rb +28 -0
- data/test/rubeus/test_extensions.rb +44 -0
- data/test/test_all.rb +2 -0
- metadata +50 -16
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rubeus'
|
4
|
+
|
5
|
+
# Test for setter.rb
|
6
|
+
class TestSetter < Test::Unit::TestCase
|
7
|
+
include Rubeus::Swing
|
8
|
+
|
9
|
+
# setup method
|
10
|
+
def setup
|
11
|
+
end
|
12
|
+
|
13
|
+
# test set_preferred_size
|
14
|
+
def test_set_preferred_size
|
15
|
+
JFrame.new do |f|
|
16
|
+
txt = JTextField.new
|
17
|
+
txt.set_preferred_size "100 x 150"
|
18
|
+
|
19
|
+
f.pack
|
20
|
+
|
21
|
+
assert_equal(100, txt.get_preferred_size.width)
|
22
|
+
assert_equal(150, txt.get_preferred_size.height)
|
23
|
+
|
24
|
+
f.dispose
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# test preferred_size=
|
29
|
+
def test_preferred_size=
|
30
|
+
JFrame.new do |f|
|
31
|
+
txt = JTextField.new
|
32
|
+
txt.preferred_size = "150 x 100"
|
33
|
+
|
34
|
+
f.pack
|
35
|
+
|
36
|
+
assert_equal(150, txt.preferred_size.width)
|
37
|
+
assert_equal(100, txt.preferred_size.height)
|
38
|
+
|
39
|
+
f.dispose
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rubeus'
|
4
|
+
|
5
|
+
# Test for Rubeus::Extensions::Java::Awt
|
6
|
+
class TestDimension < Test::Unit::TestCase
|
7
|
+
include Rubeus::Awt
|
8
|
+
|
9
|
+
# setup method
|
10
|
+
def setup
|
11
|
+
end
|
12
|
+
|
13
|
+
# create with array size 0
|
14
|
+
def test_create_with_array_size_0
|
15
|
+
d = Dimension.create([])
|
16
|
+
|
17
|
+
assert_equal(0, d.width)
|
18
|
+
assert_equal(0, d.height)
|
19
|
+
end
|
20
|
+
|
21
|
+
# create with array size 1
|
22
|
+
def test_create_with_array_size_1
|
23
|
+
assert_raise(ArgumentError) do
|
24
|
+
d = Dimension.create([200])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# create with array size 2
|
29
|
+
def test_create_with_array_size_2
|
30
|
+
d = Dimension.create([200, 300])
|
31
|
+
|
32
|
+
assert_equal(200, d.width)
|
33
|
+
assert_equal(300, d.height)
|
34
|
+
end
|
35
|
+
|
36
|
+
# create with array size 3
|
37
|
+
def test_create_with_array_size_3
|
38
|
+
assert_raise(ArgumentError) do
|
39
|
+
d = Dimension.create([200, 300, 400])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# create with dimension object
|
44
|
+
def test_create_with_dimension
|
45
|
+
d = Dimension.create([300, 400])
|
46
|
+
d2 = Dimension.create(d)
|
47
|
+
|
48
|
+
assert_equal(d.width, d2.width)
|
49
|
+
assert_equal(d.height, d2.height)
|
50
|
+
end
|
51
|
+
|
52
|
+
# create with multiply expression
|
53
|
+
def test_create_with_multiply expression
|
54
|
+
d = Dimension.create("400 x 500")
|
55
|
+
|
56
|
+
assert_equal(400, d.width)
|
57
|
+
assert_equal(500, d.height)
|
58
|
+
end
|
59
|
+
|
60
|
+
# create with original constructor
|
61
|
+
def test_create_with_original_constructor
|
62
|
+
d = Dimension.create(600, 350)
|
63
|
+
|
64
|
+
assert_equal(600, d.width)
|
65
|
+
assert_equal(350, d.height)
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rubeus'
|
4
|
+
|
5
|
+
# Test for connetion.rb
|
6
|
+
class TestConnection < Test::Unit::TestCase
|
7
|
+
# setup method
|
8
|
+
def setup
|
9
|
+
@con = Rubeus::Jdbc::DriverManager.connect("jdbc:derby:test_db;create = true", "", "")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_statement
|
13
|
+
assert_nothing_raised do
|
14
|
+
@con.statement do |stmt|
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_query
|
20
|
+
# Drop test table
|
21
|
+
begin
|
22
|
+
@con.statement do |stmt|
|
23
|
+
stmt.execute_update("DROP TABLE TEST")
|
24
|
+
end
|
25
|
+
rescue
|
26
|
+
# table test is already exist
|
27
|
+
end
|
28
|
+
|
29
|
+
@con.statement do |stmt|
|
30
|
+
stmt.execute_update("CREATE TABLE TEST (ID INT, NAME CHAR(10))")
|
31
|
+
stmt.execute_update("INSERT INTO TEST VALUES(1, 'row1')")
|
32
|
+
stmt.execute_update("INSERT INTO TEST VALUES(2, 'row2')")
|
33
|
+
end
|
34
|
+
|
35
|
+
@con.query("SELECT * FROM TEST ORDER BY ID") do |rs|
|
36
|
+
i = 1
|
37
|
+
rs.each_hash do |rsNext|
|
38
|
+
assert_equal(i, rsNext["ID"])
|
39
|
+
assert_equal("row#{i} ", rsNext["NAME"])
|
40
|
+
|
41
|
+
i += 1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def teardown
|
47
|
+
@con.close
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rubeus'
|
4
|
+
|
5
|
+
# Test for driver_manager.rb
|
6
|
+
class TestDriverManager < Test::Unit::TestCase
|
7
|
+
# setup method
|
8
|
+
def setup
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_normal
|
12
|
+
assert_nothing_raised do
|
13
|
+
@con = Rubeus::Jdbc::DriverManager.connect("jdbc:derby:test_db;create = true", "", "")
|
14
|
+
end
|
15
|
+
|
16
|
+
if @con
|
17
|
+
assert_equal(false, @con.closed?)
|
18
|
+
@con.close
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_without_auto_setup_manager
|
23
|
+
assert_nothing_raised do
|
24
|
+
org.apache.derby.jdbc.EmbeddedDriver
|
25
|
+
@con = Rubeus::Jdbc::DriverManager.connect("jdbc:derby:test_db;create = true", "", "", :auto_setup_manager => false)
|
26
|
+
@con.close
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_with_block
|
31
|
+
con = Rubeus::Jdbc::DriverManager.connect("jdbc:derby:test_db;create = true") do |con|
|
32
|
+
assert_equal(false, con.closed?)
|
33
|
+
end
|
34
|
+
assert_nil(con)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rubeus'
|
4
|
+
|
5
|
+
# Test for result_set.rb
|
6
|
+
class TestResultSet < Test::Unit::TestCase
|
7
|
+
# setup method
|
8
|
+
def setup
|
9
|
+
@con = Rubeus::Jdbc::DriverManager.connect("jdbc:derby:test_db;create = true", "", "")
|
10
|
+
|
11
|
+
# Drop test table
|
12
|
+
begin
|
13
|
+
@con.statement do |stmt|
|
14
|
+
stmt.execute_update("DROP TABLE TEST")
|
15
|
+
end
|
16
|
+
rescue
|
17
|
+
# table test is already exist
|
18
|
+
end
|
19
|
+
|
20
|
+
@con.statement do |stmt|
|
21
|
+
stmt.execute_update("CREATE TABLE TEST (ID INT, NAME CHAR(10))")
|
22
|
+
stmt.execute_update("INSERT INTO TEST VALUES(1, 'row1')")
|
23
|
+
stmt.execute_update("INSERT INTO TEST VALUES(2, 'row2')")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_each
|
28
|
+
@con.query("SELECT * FROM TEST ORDER BY ID") do |rs|
|
29
|
+
i = 1
|
30
|
+
rs.each do |rsNext|
|
31
|
+
assert_equal(i, rsNext.get_int("ID"))
|
32
|
+
assert_equal("row#{i} ", rsNext.get_string("NAME"))
|
33
|
+
|
34
|
+
i += 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_each_array
|
40
|
+
@con.query("SELECT * FROM TEST ORDER BY ID") do |rs|
|
41
|
+
i = 1
|
42
|
+
rs.each_array do |rsNext|
|
43
|
+
assert_equal(i, rsNext[0])
|
44
|
+
assert_equal("row#{i} ", rsNext[1])
|
45
|
+
|
46
|
+
i += 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_each_hash
|
52
|
+
@con.query("SELECT * FROM TEST ORDER BY ID") do |rs|
|
53
|
+
i = 1
|
54
|
+
rs.each_hash do |rsNext|
|
55
|
+
assert_equal(i, rsNext["ID"])
|
56
|
+
assert_equal("row#{i} ", rsNext["NAME"])
|
57
|
+
|
58
|
+
i += 1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def teardown
|
64
|
+
@con.close
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rubeus'
|
4
|
+
|
5
|
+
# Test for result_set_meta_data.rb
|
6
|
+
class TestResultSetMetaData < Test::Unit::TestCase
|
7
|
+
# setup method
|
8
|
+
def setup
|
9
|
+
@con = Rubeus::Jdbc::DriverManager.connect("jdbc:derby:test_db;create = true", "", "")
|
10
|
+
|
11
|
+
# Drop test table
|
12
|
+
begin
|
13
|
+
@con.statement do |stmt|
|
14
|
+
stmt.execute_update("DROP TABLE TEST")
|
15
|
+
end
|
16
|
+
rescue
|
17
|
+
# table test is already exist
|
18
|
+
end
|
19
|
+
|
20
|
+
@con.statement do |stmt|
|
21
|
+
stmt.execute_update("CREATE TABLE TEST (ID INT, NAME CHAR(10))")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_each_without_block
|
26
|
+
@con.query("SELECT * FROM TEST ORDER BY ID") do |rs|
|
27
|
+
assert_nil(rs.meta_data.each)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_each_with_block
|
32
|
+
@con.query("SELECT * FROM TEST ORDER BY ID") do |rs|
|
33
|
+
i = 1
|
34
|
+
rs.meta_data.each do |rsMeta|
|
35
|
+
assert_equal(i, rsMeta)
|
36
|
+
i += 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_columns
|
42
|
+
@con.query("SELECT * FROM TEST ORDER BY ID") do |rs|
|
43
|
+
i = 1
|
44
|
+
rs.meta_data.columns.each do |column|
|
45
|
+
if i == 1
|
46
|
+
assert_equal("java.lang.Integer", column.column_class_name)
|
47
|
+
assert_equal("java.lang.Integer", column.class_name)
|
48
|
+
assert_equal(11, column.column_display_size)
|
49
|
+
assert_equal(11, column.display_size)
|
50
|
+
assert_equal("ID", column.column_label)
|
51
|
+
assert_equal("ID", column.label)
|
52
|
+
assert_equal("ID", column.column_name)
|
53
|
+
assert_equal("ID", column.name)
|
54
|
+
assert_equal("INTEGER", column.column_type_name)
|
55
|
+
assert_equal("INTEGER", column.type_name)
|
56
|
+
assert_equal(false, column.case_sensitive)
|
57
|
+
assert_equal(false, column.case_sensitive?)
|
58
|
+
assert_equal(true, column.signed)
|
59
|
+
assert_equal(true, column.signed?)
|
60
|
+
elsif i == 2
|
61
|
+
assert_equal("java.lang.String", column.column_class_name)
|
62
|
+
assert_equal("java.lang.String", column.class_name)
|
63
|
+
assert_equal(10, column.column_display_size)
|
64
|
+
assert_equal(10, column.display_size)
|
65
|
+
assert_equal("NAME", column.column_label)
|
66
|
+
assert_equal("NAME", column.label)
|
67
|
+
assert_equal("NAME", column.column_name)
|
68
|
+
assert_equal("NAME", column.name)
|
69
|
+
assert_equal("CHAR", column.column_type_name)
|
70
|
+
assert_equal("CHAR", column.type_name)
|
71
|
+
assert_equal(true, column.case_sensitive)
|
72
|
+
assert_equal(true, column.case_sensitive?)
|
73
|
+
assert_equal(false, column.signed)
|
74
|
+
assert_equal(false, column.signed?)
|
75
|
+
end
|
76
|
+
|
77
|
+
# common test
|
78
|
+
assert_equal(i, column.column_index)
|
79
|
+
assert_equal(i, column.index)
|
80
|
+
assert_equal(false, column.auto_increment)
|
81
|
+
assert_equal(false, column.auto_increment?)
|
82
|
+
assert_equal(false, column.currency)
|
83
|
+
assert_equal(false, column.currency?)
|
84
|
+
assert_equal(false, column.definitely_writable)
|
85
|
+
assert_equal(false, column.definitely_writable?)
|
86
|
+
|
87
|
+
# java.sql.ResultSetMetaData.const_get(:columnNullable) has error
|
88
|
+
assert_equal(1, column.is_nullable)
|
89
|
+
|
90
|
+
assert_equal(false, column.read_only)
|
91
|
+
assert_equal(false, column.read_only?)
|
92
|
+
assert_equal(true, column.searchable)
|
93
|
+
assert_equal(true, column.searchable?)
|
94
|
+
assert_equal(false, column.writable)
|
95
|
+
assert_equal(false, column.writable?)
|
96
|
+
|
97
|
+
i += 1
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_column_names
|
103
|
+
expected_column_names = {1 => "ID", 2 => "NAME"}
|
104
|
+
@con.query("SELECT * FROM TEST ORDER BY ID") do |rs|
|
105
|
+
assert_equal(expected_column_names, rs.meta_data.column_names)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_column_index
|
110
|
+
@con.query("SELECT * FROM TEST ORDER BY ID") do |rs|
|
111
|
+
rs.meta_data.each do |rsMeta|
|
112
|
+
assert_equal(rsMeta, rs.meta_data.column_index(rsMeta))
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def teardown
|
118
|
+
@con.close
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rubeus'
|
4
|
+
|
5
|
+
# Test for statement.rb
|
6
|
+
class TestStatement < Test::Unit::TestCase
|
7
|
+
# setup method
|
8
|
+
def setup
|
9
|
+
@con = Rubeus::Jdbc::DriverManager.connect("jdbc:derby:test_db;create = true", "", "")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_query
|
13
|
+
# Drop test table
|
14
|
+
begin
|
15
|
+
@con.statement do |stmt|
|
16
|
+
stmt.execute_update("DROP TABLE TEST")
|
17
|
+
end
|
18
|
+
rescue
|
19
|
+
# table test is already exist
|
20
|
+
end
|
21
|
+
|
22
|
+
@con.statement do |stmt|
|
23
|
+
stmt.execute_update("CREATE TABLE TEST (ID INT, NAME CHAR(10))")
|
24
|
+
stmt.execute_update("INSERT INTO TEST VALUES(1, 'row1')")
|
25
|
+
stmt.execute_update("INSERT INTO TEST VALUES(2, 'row2')")
|
26
|
+
|
27
|
+
stmt.query("SELECT * FROM TEST ORDER BY ID") do |rs|
|
28
|
+
i = 1
|
29
|
+
rs.each_hash do |rsNext|
|
30
|
+
assert_equal(i, rsNext["ID"])
|
31
|
+
assert_equal("row#{i} ", rsNext["NAME"])
|
32
|
+
|
33
|
+
i += 1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def teardown
|
40
|
+
@con.close
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,359 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rubeus'
|
5
|
+
require 'rexml/document'
|
6
|
+
|
7
|
+
# Rubeus.verbose = true
|
8
|
+
|
9
|
+
# Test for Rubeus::Extensions::Javax::Swing::Table
|
10
|
+
class TestDefaultTableModel < Test::Unit::TestCase
|
11
|
+
include Rubeus::Swing
|
12
|
+
|
13
|
+
# setup method
|
14
|
+
def setup
|
15
|
+
# Load XML File
|
16
|
+
open(File.join(File.dirname(__FILE__), 'test_default_table_model', 'nhk_words.xml')) do |f|
|
17
|
+
@xml = REXML::Document.new(f)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# normal pattern
|
22
|
+
def test_load_from_xml_normal
|
23
|
+
# Initialize JTable and model
|
24
|
+
nhk_word_table = JTable.new
|
25
|
+
nhk_word_table.model = ['ID', 'NHK語']
|
26
|
+
|
27
|
+
# load_from_xml
|
28
|
+
nhk_word_table.model.load_from_xml(@xml,
|
29
|
+
:row_path => '*/nhk-word',
|
30
|
+
:column_paths => ['id', 'expression'])
|
31
|
+
|
32
|
+
assert_for_normal(nhk_word_table)
|
33
|
+
end
|
34
|
+
|
35
|
+
# utility for assert method for normal
|
36
|
+
def assert_for_normal(nhk_word_table)
|
37
|
+
# assert row count
|
38
|
+
assert_equal(2, nhk_word_table.model.row_count)
|
39
|
+
|
40
|
+
# assert first row
|
41
|
+
assert_equal("1", nhk_word_table.model.get_value_at(0, 0))
|
42
|
+
assert_equal("ないわ~", nhk_word_table.model.get_value_at(0, 1))
|
43
|
+
|
44
|
+
# assert second row
|
45
|
+
assert_equal("2", nhk_word_table.model.get_value_at(1, 0))
|
46
|
+
assert_equal("格好いい", nhk_word_table.model.get_value_at(1, 1))
|
47
|
+
end
|
48
|
+
private :assert_for_normal
|
49
|
+
|
50
|
+
# row_path is nil
|
51
|
+
def test_load_from_xml_nil_row_path
|
52
|
+
# Initialize JTable and model
|
53
|
+
nhk_word_table = JTable.new
|
54
|
+
nhk_word_table.model = ['ID', 'NHK語']
|
55
|
+
|
56
|
+
# load_from_xml
|
57
|
+
assert_raise(ArgumentError) do
|
58
|
+
nhk_word_table.model.load_from_xml(@xml,
|
59
|
+
:column_paths => ['id', 'expression'])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# invalid row_path
|
64
|
+
def test_load_from_xml_invalid_row_path
|
65
|
+
# Initialize JTable and model
|
66
|
+
nhk_word_table = JTable.new
|
67
|
+
nhk_word_table.model = ['ID', 'NHK語']
|
68
|
+
|
69
|
+
# load_from_xml
|
70
|
+
nhk_word_table.model.load_from_xml(@xml,
|
71
|
+
:row_path => '*/nhk-words',
|
72
|
+
:column_paths => ['id', 'expression'])
|
73
|
+
|
74
|
+
# assert row count
|
75
|
+
assert_equal(0, nhk_word_table.model.row_count)
|
76
|
+
end
|
77
|
+
|
78
|
+
# nil column_paths
|
79
|
+
def test_load_from_xml_nil_column_paths
|
80
|
+
# Initialize JTable and model
|
81
|
+
nhk_word_table = JTable.new
|
82
|
+
nhk_word_table.model = ['ID', 'NHK語']
|
83
|
+
|
84
|
+
# load_from_xml
|
85
|
+
nhk_word_table.model.load_from_xml(@xml,
|
86
|
+
:row_path => '*/nhk-word')
|
87
|
+
|
88
|
+
# assert for normal
|
89
|
+
assert_for_normal(nhk_word_table)
|
90
|
+
end
|
91
|
+
|
92
|
+
# nil column_paths with refresh_columns
|
93
|
+
def test_load_from_xml_nil_column_paths_with_refresh_columns
|
94
|
+
# Initialize JTable and model
|
95
|
+
nhk_word_table = JTable.new
|
96
|
+
nhk_word_table.model = ['ID', 'NHK語']
|
97
|
+
|
98
|
+
# load_from_xml
|
99
|
+
nhk_word_table.model.load_from_xml(@xml,
|
100
|
+
:row_path => '*/nhk-word',
|
101
|
+
:refresh_columns => true)
|
102
|
+
|
103
|
+
# assert for normal
|
104
|
+
assert_for_normal(nhk_word_table)
|
105
|
+
end
|
106
|
+
|
107
|
+
# invalid column_paths
|
108
|
+
def test_load_from_xml_invalid_column_paths
|
109
|
+
# Initialize JTable and model
|
110
|
+
nhk_word_table = JTable.new
|
111
|
+
nhk_word_table.model = ['ID', 'NHK語']
|
112
|
+
|
113
|
+
# load_from_xml
|
114
|
+
assert_raise(ArgumentError) do
|
115
|
+
nhk_word_table.model.load_from_xml(@xml,
|
116
|
+
:row_path => '*/nhk-word',
|
117
|
+
:column_paths => ['ida', 'expression'])
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# less number of columns
|
122
|
+
def test_load_from_xml_less_number_of_columns
|
123
|
+
# Initialize JTable and model
|
124
|
+
nhk_word_table = JTable.new
|
125
|
+
nhk_word_table.model = ['ID', 'NHK語']
|
126
|
+
|
127
|
+
# load_from_xml
|
128
|
+
nhk_word_table.model.load_from_xml(@xml,
|
129
|
+
:row_path => '*/nhk-word',
|
130
|
+
:column_paths => ['id'])
|
131
|
+
|
132
|
+
# assert row count
|
133
|
+
assert_equal(2, nhk_word_table.model.row_count)
|
134
|
+
|
135
|
+
# assert first row
|
136
|
+
assert_equal("1", nhk_word_table.model.get_value_at(0, 0))
|
137
|
+
assert_nil(nhk_word_table.model.get_value_at(0, 1))
|
138
|
+
|
139
|
+
# assert second row
|
140
|
+
assert_equal("2", nhk_word_table.model.get_value_at(1, 0))
|
141
|
+
assert_nil(nhk_word_table.model.get_value_at(1, 1))
|
142
|
+
end
|
143
|
+
|
144
|
+
# less number of columns with refresh_columns
|
145
|
+
def test_load_from_xml_less_number_of_columns_with_refresh_columns
|
146
|
+
# Initialize JTable and model
|
147
|
+
nhk_word_table = JTable.new
|
148
|
+
nhk_word_table.model = ['ID', 'NHK語']
|
149
|
+
|
150
|
+
# load_from_xml
|
151
|
+
nhk_word_table.model.load_from_xml(@xml,
|
152
|
+
:row_path => '*/nhk-word',
|
153
|
+
:column_paths => ['id'],
|
154
|
+
:refresh_columns => true)
|
155
|
+
|
156
|
+
# assert row count
|
157
|
+
assert_equal(2, nhk_word_table.model.row_count)
|
158
|
+
assert_equal(1, nhk_word_table.model.column_count)
|
159
|
+
|
160
|
+
# assert first row
|
161
|
+
assert_equal("1", nhk_word_table.model.get_value_at(0, 0))
|
162
|
+
|
163
|
+
# assert second row
|
164
|
+
assert_equal("2", nhk_word_table.model.get_value_at(1, 0))
|
165
|
+
end
|
166
|
+
|
167
|
+
# large number of columns
|
168
|
+
def test_load_from_xml_large_number_of_columns
|
169
|
+
# Initialize JTable and model
|
170
|
+
nhk_word_table = JTable.new
|
171
|
+
nhk_word_table.model = ['ID', 'NHK語']
|
172
|
+
|
173
|
+
# load_from_xml
|
174
|
+
nhk_word_table.model.load_from_xml(@xml,
|
175
|
+
:row_path => '*/nhk-word',
|
176
|
+
:column_paths => ['id', 'expression', 'created-at'])
|
177
|
+
|
178
|
+
# assert row count
|
179
|
+
assert_equal(2, nhk_word_table.model.row_count)
|
180
|
+
end
|
181
|
+
|
182
|
+
# large number of columns with refresh_columns
|
183
|
+
def test_load_from_xml_large_number_of_columns_with_refresh_columns
|
184
|
+
# Initialize JTable and model
|
185
|
+
nhk_word_table = JTable.new
|
186
|
+
nhk_word_table.model = ['ID', 'NHK語']
|
187
|
+
|
188
|
+
# load_from_xml
|
189
|
+
nhk_word_table.model.load_from_xml(@xml,
|
190
|
+
:row_path => '*/nhk-word',
|
191
|
+
:column_paths => ['id', 'expression', 'created-at'],
|
192
|
+
:refresh_columns => true)
|
193
|
+
|
194
|
+
# assert row count
|
195
|
+
assert_equal(2, nhk_word_table.model.row_count)
|
196
|
+
assert_equal(3, nhk_word_table.model.column_count)
|
197
|
+
|
198
|
+
# assert for normal
|
199
|
+
assert_for_normal(nhk_word_table)
|
200
|
+
|
201
|
+
# assert first row
|
202
|
+
assert_equal("2008-08-13T20:35:00Z", nhk_word_table.model.get_value_at(0, 2))
|
203
|
+
|
204
|
+
# assert second row
|
205
|
+
assert_equal("2008-08-13T20:36:00Z", nhk_word_table.model.get_value_at(1, 2))
|
206
|
+
end
|
207
|
+
|
208
|
+
# insert_row
|
209
|
+
def test_insert_row
|
210
|
+
# Initialize JTable and model
|
211
|
+
nhk_word_table = JTable.new
|
212
|
+
nhk_word_table.model = ['ID', 'NHK語']
|
213
|
+
|
214
|
+
# Insert Rows
|
215
|
+
nhk_word_table.model.insert_row(0, [1, "いんさーと"])
|
216
|
+
nhk_word_table.model.insert_row(0, [2, "インサートその2"])
|
217
|
+
|
218
|
+
# assert row count
|
219
|
+
assert_equal(2, nhk_word_table.model.row_count)
|
220
|
+
|
221
|
+
# assert first row
|
222
|
+
assert_equal(2, nhk_word_table.model.get_value_at(0, 0))
|
223
|
+
assert_equal("インサートその2", nhk_word_table.model.get_value_at(0, 1))
|
224
|
+
|
225
|
+
# assert second row
|
226
|
+
assert_equal(1, nhk_word_table.model.get_value_at(1, 0))
|
227
|
+
assert_equal("いんさーと", nhk_word_table.model.get_value_at(1, 1))
|
228
|
+
end
|
229
|
+
|
230
|
+
# add_row
|
231
|
+
def test_add_row
|
232
|
+
# Initialize JTable and model
|
233
|
+
nhk_word_table = JTable.new
|
234
|
+
nhk_word_table.model = ['ID', 'NHK語']
|
235
|
+
|
236
|
+
# Insert Rows
|
237
|
+
nhk_word_table.model.add_row([1, "いんさーと"])
|
238
|
+
nhk_word_table.model.add_row([2, "インサートその2"])
|
239
|
+
|
240
|
+
# assert row count
|
241
|
+
assert_equal(2, nhk_word_table.model.row_count)
|
242
|
+
|
243
|
+
# assert first row
|
244
|
+
assert_equal(1, nhk_word_table.model.get_value_at(0, 0))
|
245
|
+
assert_equal("いんさーと", nhk_word_table.model.get_value_at(0, 1))
|
246
|
+
|
247
|
+
# assert second row
|
248
|
+
assert_equal(2, nhk_word_table.model.get_value_at(1, 0))
|
249
|
+
assert_equal("インサートその2", nhk_word_table.model.get_value_at(1, 1))
|
250
|
+
end
|
251
|
+
|
252
|
+
# new with 2d-Array
|
253
|
+
def test_new_with_2dArray
|
254
|
+
# Initialize JTable and model
|
255
|
+
nhk_word_table = JTable.new
|
256
|
+
nhk_word_table.model = [[1, "1行目"], [2, "2行目"], [3, "3行目"]]
|
257
|
+
|
258
|
+
# assert row count
|
259
|
+
assert_equal(3, nhk_word_table.model.row_count)
|
260
|
+
|
261
|
+
# assert column count
|
262
|
+
assert_equal(2, nhk_word_table.model.column_count)
|
263
|
+
|
264
|
+
# assert rows
|
265
|
+
for i in 1..nhk_word_table.model.row_count
|
266
|
+
assert_equal(i, nhk_word_table.model.get_value_at((i-1), 0))
|
267
|
+
assert_equal("#{i}行目", nhk_word_table.model.get_value_at((i-1), 1))
|
268
|
+
end
|
269
|
+
|
270
|
+
# assert columns
|
271
|
+
for i in 1..nhk_word_table.model.column_count
|
272
|
+
assert_equal(i.to_s, nhk_word_table.model.getColumnName(i-1))
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
# new with Array
|
277
|
+
def test_new_with_array
|
278
|
+
# Initialize JTable and model
|
279
|
+
nhk_word_table = JTable.new
|
280
|
+
nhk_word_table.model = ["ID", "NHK語"]
|
281
|
+
|
282
|
+
# assert row count
|
283
|
+
assert_equal(0, nhk_word_table.model.row_count)
|
284
|
+
|
285
|
+
# assert column count
|
286
|
+
assert_equal(2, nhk_word_table.model.column_count)
|
287
|
+
|
288
|
+
# assert columns
|
289
|
+
assert_equal("ID", nhk_word_table.model.get_column_name(0))
|
290
|
+
assert_equal("NHK語", nhk_word_table.model.get_column_name(1))
|
291
|
+
end
|
292
|
+
|
293
|
+
# new with Hash
|
294
|
+
def test_new_with_hash_data_column_names
|
295
|
+
# Initialize JTable and model
|
296
|
+
nhk_word_table = JTable.new
|
297
|
+
nhk_word_table.model = {:data => [["1", "ないわ~"], ["2", "格好いい"]], :column_names => ["ID", "NHK語"]}
|
298
|
+
|
299
|
+
assert_for_normal(nhk_word_table)
|
300
|
+
end
|
301
|
+
|
302
|
+
# new with Hash
|
303
|
+
def test_new_with_hash_rows_columns
|
304
|
+
# Initialize JTable and model
|
305
|
+
nhk_word_table = JTable.new
|
306
|
+
nhk_word_table.model = {:rows => [["1", "ないわ~"], ["2", "格好いい"]], :columns => ["ID", "NHK語"]}
|
307
|
+
|
308
|
+
assert_for_normal(nhk_word_table)
|
309
|
+
end
|
310
|
+
|
311
|
+
# new with Hash nil rows
|
312
|
+
def test_new_with_hash_nil_rows
|
313
|
+
# Initialize JTable and model
|
314
|
+
nhk_word_table = JTable.new
|
315
|
+
|
316
|
+
assert_raise(ArgumentError) do
|
317
|
+
nhk_word_table.model = {:columns => ["ID", "NHK語"]}
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
# new with Hash nil cols
|
322
|
+
def test_new_with_hash_nil_cols
|
323
|
+
# Initialize JTable and model
|
324
|
+
nhk_word_table = JTable.new
|
325
|
+
|
326
|
+
assert_raise(ArgumentError) do
|
327
|
+
nhk_word_table.model = {:rows => [["1", "ないわ~"], ["2", "格好いい"]]}
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
# new with XML
|
332
|
+
def test_new_with_xml
|
333
|
+
# Initialize JTable and model
|
334
|
+
nhk_word_table = JTable.new
|
335
|
+
nhk_word_table.model = DefaultTableModel.new(@xml, {:row_path => '*/nhk-word', :column_paths => ['id', 'expression']})
|
336
|
+
|
337
|
+
assert_for_normal(nhk_word_table)
|
338
|
+
end
|
339
|
+
|
340
|
+
# new with original constructor
|
341
|
+
def test_new_with_original_constructor
|
342
|
+
# Initialize JTable and model
|
343
|
+
nhk_word_table = JTable.new
|
344
|
+
nhk_word_table.model = DefaultTableModel.new(4, 3)
|
345
|
+
|
346
|
+
# assert row count
|
347
|
+
assert_equal(4, nhk_word_table.model.row_count)
|
348
|
+
|
349
|
+
# assert column count
|
350
|
+
assert_equal(3, nhk_word_table.model.column_count)
|
351
|
+
|
352
|
+
# assert cells
|
353
|
+
for i in 1..nhk_word_table.model.row_count
|
354
|
+
for j in 1..nhk_word_table.model.column_count
|
355
|
+
assert_nil(nhk_word_table.model.get_value_at((i-1), (j-1)))
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|