unageanu-jiji 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/ChangeLog +3 -0
  2. data/bin/jiji +1 -1
  3. data/html/swf/chart.swf +0 -0
  4. data/lib/jiji/agent/agent.rb +0 -1
  5. data/lib/jiji/agent/agent_manager.rb +0 -1
  6. data/lib/jiji/collector.rb +14 -17
  7. data/lib/jiji/command.rb +40 -12
  8. data/lib/jiji/configuration.rb +8 -2
  9. data/lib/jiji/dao/trade_result_dao.rb +1 -1
  10. data/lib/jiji/migration/migrator1_1_0.rb +46 -0
  11. data/lib/jiji/models.rb +1 -5
  12. data/lib/jiji/operator.rb +12 -30
  13. data/lib/jiji/plugin/embedded/click_securities_demo_plugin.rb +140 -0
  14. data/lib/jiji/plugin/embedded/single_click_client.rb +107 -0
  15. data/lib/jiji/plugin/plugin_loader.rb +53 -0
  16. data/lib/jiji/plugin/securities_plugin.rb +135 -0
  17. data/lib/jiji/registry.rb +24 -19
  18. data/lib/jiji/server.rb +3 -1
  19. data/lib/jiji/service/rate_service.rb +7 -2
  20. data/lib/jiji/util/block_to_session.rb +4 -4
  21. data/lib/jiji/util/util.rb +0 -67
  22. data/lib/jiji_plugin.rb +6 -0
  23. data/swf/build.xml +1 -1
  24. data/swf/chart/fx/chart/Chart.as +6 -4
  25. data/swf/chart/fx/chart/ctrl/Controller.as +12 -0
  26. data/swf/chart/fx/chart/model/Model.as +3 -1
  27. data/swf/chart/fx/chart/ui/RangeInfoWindow.as +1 -1
  28. data/swf/chart/fx/chart/ui/ScaleSelector.as +6 -17
  29. data/test/OutputregistryTest/conf/configuration.yaml +3 -0
  30. data/test/ProcessManagerTest/conf/configuration.yaml +4 -17
  31. data/test/{test_AgentManager.rb → agent/test_AgentManager.rb} +37 -39
  32. data/test/{test_AgentRegistry.rb → agent/test_AgentRegistry.rb} +3 -2
  33. data/test/{test_PeriodicallyAgent.rb → agent/test_PeriodicallyAgent.rb} +7 -6
  34. data/test/{test_Permitter.rb → agent/test_Permitter.rb} +10 -9
  35. data/test/all_tests.rb +31 -24
  36. data/test/{test_RateDao.rb → dao/test_RateDao.rb} +5 -5
  37. data/test/{test_TradeResultDao.rb → dao/test_TradeResultDao.rb} +12 -11
  38. data/test/jiji_plugin.rb +7 -0
  39. data/test/migration/migrator1_1_0test_data/configuration.yaml +11 -0
  40. data/test/migration/test_Migrator1_1_0.rb +56 -0
  41. data/test/{test_SingleClickClient.rb → plugin/embedded/test_SingleClickClient.rb} +44 -14
  42. data/test/plugin/error_test/jiji_plugin.rb +2 -0
  43. data/test/plugin/test/foo_plugin.rb +1 -0
  44. data/test/plugin/test/jiji_plugin.rb +2 -0
  45. data/test/plugin/test_Loader.rb +33 -0
  46. data/test/plugin/test_gem/a/jiji_plugin_test_gem_a-1.0.0.gem +0 -0
  47. data/test/plugin/test_gem/a/jiji_plugin_test_gem_a.gemspec +10 -0
  48. data/test/plugin/test_gem/a/lib/jiji_plugin.rb +2 -0
  49. data/test/plugin/test_gem/a/lib/jiji_plugin_test.rb +6 -0
  50. data/test/plugin/test_gem/b/jiji_plugin_test_gem_b-1.0.0.gem +0 -0
  51. data/test/plugin/test_gem/b/jiji_plugin_test_gem_b.gemspec +9 -0
  52. data/test/plugin/test_gem/b/lib/jiji_plugin.rb +2 -0
  53. data/test/test_BackTestCollector.rb +12 -20
  54. data/test/test_Collector.rb +16 -32
  55. data/test/test_Configuration.rb +3 -3
  56. data/test/test_Operator.rb +9 -9
  57. data/test/test_Output.rb +2 -3
  58. data/test/test_Output_registry.rb +9 -9
  59. data/test/test_Process.rb +6 -6
  60. data/test/test_ProcessManager.rb +11 -9
  61. data/test/test_utils.rb +49 -0
  62. data/test/{test_BlockToSession.rb → util/test_BlockToSession.rb} +57 -9
  63. data/test/{test_CSV.rb → util/test_CSV.rb} +5 -5
  64. data/test/{test_SynchronizeInterceptor.rb → util/test_SynchronizeInterceptor.rb} +5 -3
  65. metadata +59 -26
  66. data/lib/jiji/single_click_client.rb +0 -95
  67. data/test/test_configuration.yaml +0 -16
  68. data/test/testutils.rb +0 -37
@@ -1,21 +1,22 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- $: << "../lib"
3
+ $: << "../../lib"
4
+ $: << "../"
4
5
 
5
-
6
- require "runit/testcase"
7
- require "runit/cui/testrunner"
6
+ require 'rubygems'
7
+ require 'runit/testcase'
8
+ require 'runit/cui/testrunner'
8
9
  require 'jiji/agent/agent'
9
10
  require 'jiji/agent/agent_manager'
10
11
  require 'jiji/agent/agent_registry'
11
12
  require 'jiji/agent/permitter'
12
13
  require 'jiji/agent/util'
13
- require "jiji/configuration"
14
- require "jiji/collector"
15
- require "jiji/dao/trade_result_dao"
16
- require "fileutils"
17
- require "testutils"
18
- require "logger"
14
+ require 'jiji/configuration'
15
+ require 'jiji/collector'
16
+ require 'jiji/dao/trade_result_dao'
17
+ require 'fileutils'
18
+ require 'test_utils'
19
+ require 'logger'
19
20
 
20
21
  # AgentManager のテスト
21
22
  class AgentManagerTest < RUNIT::TestCase
@@ -33,12 +34,11 @@ class AgentManagerTest < RUNIT::TestCase
33
34
  @permitter = JIJI::Permitter.new( 5, 0 )
34
35
  logger = Logger.new STDOUT
35
36
  logger = @permitter.proxy( logger, [/^(info|debug|warn|error|fatal)$/] )
36
- @client = JIJI::SingleClickClient.new( ACCOUNT, CONF, logger )
37
-
37
+
38
38
  @registry_mock = Object.new
39
39
  class << @registry_mock
40
40
  def output( agent_name, dir )
41
- output = JIJI::Output.new( agent_name, "#{dir}/out" )
41
+ output = JIJI::Output.new( agent_name, "#{@dir}/#{dir}/out" )
42
42
  output = @permitter.proxy( output, [/^(get|each|put|<<)$/], [/^get$/] )
43
43
  return output
44
44
  end
@@ -48,21 +48,19 @@ class AgentManagerTest < RUNIT::TestCase
48
48
  end
49
49
  @registry_mock.permitter = @permitter
50
50
 
51
- operator = JIJI::RmtOperator.new( @client, logger, nil )
51
+ trade_result_dao = JIJI::Dao::TradeResultDao.new( "#{@dir}/trade_result" )
52
+ operator = JIJI::Operator.new( trade_result_dao )
52
53
  operator.conf = CONF
53
54
  operator = @permitter.proxy( operator, [/^(sell|buy|commit)$/],[/^(sell|buy)$/])
54
- trade_result_dao = JIJI::Dao::TradeResultDao.new( "#{@dir}/trade_result" )
55
-
55
+
56
56
  @m = JIJI::AgentManager.new( "test_agentManager", @registry, logger)
57
57
  @m.operator = operator
58
58
  @m.conf = CONF
59
59
  @m.trade_result_dao = trade_result_dao
60
- @m.client = @client
61
60
  @m.registry = @registry_mock
62
61
  end
63
62
 
64
63
  def teardown
65
- @client.close
66
64
  @permitter.close
67
65
  FileUtils.rm_rf @dir
68
66
  end
@@ -86,15 +84,15 @@ class AgentManagerTest < RUNIT::TestCase
86
84
  agent1 = @registry.create( "Foo@foo.rb" )
87
85
  agent2 = @registry.create( "Foo@foo.rb" )
88
86
 
89
- @m.add( "テスト", agent1 )
90
- @m.add( "テスト2", agent2 )
87
+ @m.add( "test", agent1 )
88
+ @m.add( "test2", agent2 )
91
89
 
92
90
  # 追加直後はactive
93
- assert_equals @m.on?( "テスト" ), true
94
- assert_equals @m.on?( "テスト2" ), true
91
+ assert_equals @m.on?( "test" ), true
92
+ assert_equals @m.on?( "test2" ), true
95
93
 
96
94
  pair_infos = {
97
- ClickClient::FX::EURJPY => Info.new( 10000 )
95
+ :EURJPY => Info.new( 10000 )
98
96
  }
99
97
  @m.next_rates( JIJI::Rates.new( pair_infos, {
100
98
  :EURJPY => Rate.new( 100.0,100.05,-200,200,100 )
@@ -110,9 +108,9 @@ class AgentManagerTest < RUNIT::TestCase
110
108
  }
111
109
 
112
110
  # agent1をoff
113
- @m.off( "テスト" )
114
- assert_equals @m.on?( "テスト" ), false
115
- assert_equals @m.on?( "テスト2" ), true
111
+ @m.off( "test" )
112
+ assert_equals @m.on?( "test" ), false
113
+ assert_equals @m.on?( "test2" ), true
116
114
  @m.next_rates( JIJI::Rates.new( pair_infos, {
117
115
  :EURJPY => Rate.new( 100.0,100.05,-200,200,100 )
118
116
  }))
@@ -124,9 +122,9 @@ class AgentManagerTest < RUNIT::TestCase
124
122
  }
125
123
 
126
124
  # agent1を再度onにする
127
- @m.on( "テスト" )
128
- assert_equals @m.on?( "テスト" ), true
129
- assert_equals @m.on?( "テスト2" ), true
125
+ @m.on( "test" )
126
+ assert_equals @m.on?( "test" ), true
127
+ assert_equals @m.on?( "test2" ), true
130
128
  @m.next_rates( JIJI::Rates.new( pair_infos, {
131
129
  :EURJPY => Rate.new( 100.0,100.05,-200,200,100 )
132
130
  }))
@@ -138,8 +136,8 @@ class AgentManagerTest < RUNIT::TestCase
138
136
  }
139
137
 
140
138
  # agent1を削除
141
- @m.remove( "テスト" )
142
- assert_equals @m.on?( "テスト2" ), true
139
+ @m.remove( "test" )
140
+ assert_equals @m.on?( "test2" ), true
143
141
  @m.next_rates( JIJI::Rates.new( pair_infos, {
144
142
  :EURJPY => Rate.new( 100.0,100.05,-200,200,100 )
145
143
  }))
@@ -180,9 +178,9 @@ class AgentManagerTest < RUNIT::TestCase
180
178
  end
181
179
 
182
180
  # エージェントの2重登録
183
- @m.add( "テスト", TestAgent.new.taint )
181
+ @m.add( "test", TestAgent.new.taint )
184
182
  begin
185
- @m.add( "テスト", TestAgent.new.taint )
183
+ @m.add( "test", TestAgent.new.taint )
186
184
  fail
187
185
  rescue JIJI::UserError
188
186
  assert_equals JIJI::ERROR_ALREADY_EXIST, $!.code
@@ -216,10 +214,10 @@ class AgentManagerTest < RUNIT::TestCase
216
214
  logger.error IOError.new
217
215
  logger.debug "test"
218
216
 
219
- # p1 = operator.sell(1)
220
- # p1.commit
221
- # p2 = operator.buy(1)
222
- # p2.commit
217
+ p1 = operator.sell(1)
218
+ p1.commit
219
+ p2 = operator.buy(1)
220
+ p2.commit
223
221
  end
224
222
  attr :log, true
225
223
  end
@@ -227,10 +225,10 @@ class AgentManagerTest < RUNIT::TestCase
227
225
  @registry.add_file( "foo.rb", str )
228
226
 
229
227
  agent = @registry.create( "Foo@foo.rb" )
230
- @m.add( "テスト", agent )
228
+ @m.add( "test", agent )
231
229
 
232
230
  pair_infos = {
233
- ClickClient::FX::EURJPY => Info.new( 10000 )
231
+ :EURJPY => Info.new( 10000 )
234
232
  }
235
233
  2.times {
236
234
  @m.next_rates( JIJI::Rates.new( pair_infos, {
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- $: << "../lib"
4
-
3
+ $: << "../../lib"
4
+ $: << "../"
5
5
 
6
+ require 'rubygems'
6
7
  require "runit/testcase"
7
8
  require "runit/cui/testrunner"
8
9
  require 'jiji/agent/agent'
@@ -1,16 +1,17 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- $: << "../lib"
3
+ $: << "../../lib"
4
+ $: << "../"
4
5
 
5
-
6
- require "runit/testcase"
7
- require "runit/cui/testrunner"
6
+ require 'rubygems'
7
+ require 'runit/testcase'
8
+ require 'runit/cui/testrunner'
8
9
  require 'jiji/agent/agent'
9
10
  require 'jiji/agent/agent_manager'
10
11
  require 'jiji/agent/agent_registry'
11
12
  require 'jiji/agent/permitter'
12
13
  require 'jiji/agent/util'
13
- require "jiji/collector"
14
+ require 'jiji/collector'
14
15
 
15
16
  # PeriodicallyAgent のテスト
16
17
  class PeriodicallyAgentTest < RUNIT::TestCase
@@ -27,7 +28,7 @@ class PeriodicallyAgentTest < RUNIT::TestCase
27
28
  agent = TestAgent.new( 2 )
28
29
  assert_equals agent.log, []
29
30
 
30
- pair_infos = {ClickClient::FX::USDJPY=>"info"}
31
+ pair_infos = {:USDJPY=>"info"}
31
32
 
32
33
  agent.next_rates( JIJI::Rates.new( pair_infos, {
33
34
  :USDJPY => R.new( 100.0, 100.05, -200, 222 ),
@@ -1,20 +1,21 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- $: << "../lib"
3
+ $: << "../../lib"
4
+ $: << "../"
4
5
 
5
-
6
- require "runit/testcase"
7
- require "runit/cui/testrunner"
6
+ require 'rubygems'
7
+ require 'runit/testcase'
8
+ require 'runit/cui/testrunner'
8
9
  require 'jiji/agent/agent'
9
10
  require 'jiji/agent/agent_manager'
10
11
  require 'jiji/agent/agent_registry'
11
12
  require 'jiji/agent/permitter'
12
13
  require 'jiji/agent/util'
13
- require "jiji/configuration"
14
- require "jiji/collector"
15
- require "fileutils"
16
- require "testutils"
17
- require "logger"
14
+ require 'jiji/configuration'
15
+ require 'jiji/collector'
16
+ require 'fileutils'
17
+ require 'test_utils'
18
+ require 'logger'
18
19
 
19
20
  # Permitter のテスト
20
21
  class PermitterTest < RUNIT::TestCase
data/test/all_tests.rb CHANGED
@@ -2,28 +2,35 @@
2
2
 
3
3
  $: << "../lib"
4
4
 
5
+ require 'rubygems'
6
+ require 'runit/testcase'
7
+ require 'runit/cui/testrunner'
8
+
9
+ require 'test_ProcessManager'
10
+ require 'test_BackTestCollector'
11
+ require 'test_Collector'
12
+ require 'test_Configuration'
13
+ require 'test_Operator'
14
+ require 'test_Output'
15
+ require 'test_Output_registry'
16
+ require 'test_Process'
17
+
18
+ require 'util/test_BlockToSession'
19
+ require 'util/test_CSV'
20
+ require 'util/test_SynchronizeInterceptor'
21
+
22
+ require 'dao/test_RateDao'
23
+ require 'dao/test_TradeResultDao'
24
+
25
+ require 'agent/test_AgentManager'
26
+ require 'agent/test_AgentRegistry'
27
+ require 'agent/test_PeriodicallyAgent'
28
+ require 'agent/test_Permitter'
29
+
30
+ require 'migration/test_Migrator'
31
+ require 'migration/test_Migrator1_0_3'
32
+ require 'migration/test_Migrator1_1_0'
33
+
34
+ require 'plugin/test_Loader'
35
+ require 'plugin/embedded/test_SingleClickClient'
5
36
 
6
- require "runit/testcase"
7
- require "runit/cui/testrunner"
8
-
9
- require "test_BackTestCollector"
10
- require "test_Collector"
11
- require "test_SingleClickClient"
12
- require "test_BlockToSession"
13
- require "test_AgentManager"
14
-
15
- require "test_AgentRegistry"
16
- require "test_Configuration"
17
- require "test_CSV"
18
- require "test_Operator"
19
- require "test_Output"
20
- require "test_Output_registry"
21
- require "test_PeriodicallyAgent"
22
- require "test_Process"
23
- require "test_ProcessManager"
24
- require "test_RateDao"
25
- require "test_Permitter"
26
- require "test_TradeResultDao"
27
-
28
- require "migration/test_Migrator"
29
- require "migration/test_Migrator1_0_3"
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- $: << "../lib"
3
+ $: << "../../lib"
4
+ $: << "../"
4
5
 
5
-
6
- require "runit/testcase"
7
- require "runit/cui/testrunner"
6
+ require 'runit/testcase'
7
+ require 'runit/cui/testrunner'
8
8
  require 'jiji/dao/rate_dao'
9
9
  require 'fileutils'
10
10
  require 'rubygems'
11
11
  require 'clickclient'
12
- require "testutils"
12
+ require 'test_utils'
13
13
 
14
14
  class RateDaoTest < RUNIT::TestCase
15
15
 
@@ -1,15 +1,16 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- $: << "../lib"
3
+ $: << "../../lib"
4
+ $: << "../"
4
5
 
5
-
6
- require "runit/testcase"
7
- require "runit/cui/testrunner"
6
+ require 'rubygems'
7
+ require 'runit/testcase'
8
+ require 'runit/cui/testrunner'
8
9
  require 'jiji/dao/trade_result_dao'
9
10
  require 'jiji/operator'
10
11
  require 'fileutils'
11
12
  require 'rubygems'
12
- require "testutils"
13
+ require 'test_utils'
13
14
 
14
15
  class TradeResultDaoTest < RUNIT::TestCase
15
16
 
@@ -29,8 +30,8 @@ class TradeResultDaoTest < RUNIT::TestCase
29
30
  def test_basic
30
31
 
31
32
  pair_infos = {
32
- ClickClient::FX::USDJPY => Info.new( 10000 ),
33
- ClickClient::FX::AUDUSD => Info.new( 10000 )
33
+ :USDJPY => Info.new( 10000 ),
34
+ :AUDUSD => Info.new( 10000 )
34
35
  }
35
36
 
36
37
  op = JIJI::Operator.new @dao
@@ -68,7 +69,6 @@ class TradeResultDaoTest < RUNIT::TestCase
68
69
  }, Time.local(2008,8,7,0,1,1) ))
69
70
 
70
71
  p1_props = {
71
- :open_interest_no=>"",
72
72
  :count=>1,
73
73
  :rate=>101.08,
74
74
  :state=>1,
@@ -80,6 +80,7 @@ class TradeResultDaoTest < RUNIT::TestCase
80
80
  :price=>1010800.0,
81
81
  :trader=>"a",
82
82
  :position_id=>p1.position_id,
83
+ :raw_position_id=>nil,
83
84
  :profit_or_loss=>-500.0,
84
85
  :swap=>0
85
86
  }
@@ -390,8 +391,8 @@ class TradeResultDaoTest < RUNIT::TestCase
390
391
  # flush のテスト。
391
392
  def test_flush()
392
393
  pair_infos = {
393
- ClickClient::FX::USDJPY => Info.new( 10000 ),
394
- ClickClient::FX::AUDUSD => Info.new( 10000 )
394
+ :USDJPY => Info.new( 10000 ),
395
+ :AUDUSD => Info.new( 10000 )
395
396
  }
396
397
 
397
398
  op = JIJI::Operator.new @dao
@@ -428,7 +429,6 @@ class TradeResultDaoTest < RUNIT::TestCase
428
429
 
429
430
  # 1mは経過していないので、バッファ内のデータは保存されていない。
430
431
  p1_props = {
431
- :open_interest_no=>"",
432
432
  :count=>1,
433
433
  :rate=>101.08,
434
434
  :state=>1,
@@ -440,6 +440,7 @@ class TradeResultDaoTest < RUNIT::TestCase
440
440
  :price=>1010800.0,
441
441
  :trader=>"a",
442
442
  :position_id=>p1.position_id,
443
+ :raw_position_id=>nil,
443
444
  :profit_or_loss=>-500.0,
444
445
  :swap=>0
445
446
  }
@@ -0,0 +1,7 @@
1
+
2
+ require 'jiji/plugin/securities_plugin'
3
+ require 'test_utils'
4
+
5
+ JIJI::Plugin.register(
6
+ JIJI::Plugin::SecuritiesPlugin::FUTURE_NAME,
7
+ Test::MockClient.new )
@@ -0,0 +1,11 @@
1
+ ---
2
+ server:
3
+ port: 8080
4
+
5
+ securities:
6
+ account:
7
+ user: "foo"
8
+ password: "xxxx"
9
+
10
+ foo:
11
+ var: aaa
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $: << "../../lib"
4
+
5
+ require 'rubygems'
6
+ require 'runit/testcase'
7
+ require 'runit/cui/testrunner'
8
+ require 'fileutils'
9
+ require 'jiji/configuration'
10
+ require 'jiji/migration/migrator1_1_0'
11
+
12
+ # Migrator1_1_0 のテスト
13
+ class Migrator1_1_0Test < RUNIT::TestCase
14
+
15
+ def setup
16
+ @dir = File.dirname(__FILE__) + "/migrator1_1_0_test"
17
+ FileUtils.rm_rf @dir
18
+ FileUtils.mkdir_p "#{@dir}/conf"
19
+
20
+ @registry = {}
21
+ end
22
+
23
+ def teardown
24
+ FileUtils.rm_rf @dir
25
+ end
26
+
27
+ # 実際のデータを変更するテスト
28
+ def test_real_data
29
+ FileUtils.cp_r File.dirname(__FILE__) + "/migrator1_1_0test_data/configuration.yaml", "#{@dir}/conf"
30
+
31
+ assert_equals( YAML.load_file("#{@dir}/conf/configuration.yaml"), {
32
+ "server"=>{ "port"=>8080 },
33
+ "securities"=>{ "account"=>{
34
+ "user"=>"foo",
35
+ "password"=>"xxxx"
36
+ }},
37
+ "foo"=>{"var"=>"aaa"}
38
+ })
39
+
40
+ # データ移行
41
+ m = JIJI::Migration::Migrator1_1_0.new
42
+ m.migrate( Struct.new( :base_dir, :conf ).new( @dir, JIJI::Configuration.new ) )
43
+
44
+ assert_equals( YAML.load_file("#{@dir}/conf/configuration.yaml"), {
45
+ :server=>{ :port=>8080 },
46
+ :securities=>{
47
+ :type=>:click_securities_demo,
48
+ :user=>"foo",
49
+ :password=>"xxxx"
50
+ },
51
+ :foo=>{:var=>"aaa"}
52
+ })
53
+ end
54
+
55
+ end
56
+
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- $: << "../lib"
4
-
3
+ $: << "../../"
4
+ $: << "../../../lib"
5
5
 
6
6
  require "runit/testcase"
7
7
  require "runit/cui/testrunner"
8
8
  require "jiji/configuration"
9
- require "jiji/single_click_client"
10
- require "testutils.rb"
9
+ require 'jiji/plugin/embedded/single_click_client'
10
+ require "test_utils"
11
11
  require 'logger'
12
12
  require 'csv'
13
13
 
@@ -19,7 +19,10 @@ class SingleClickClientTest < RUNIT::TestCase
19
19
 
20
20
  def setup
21
21
  l = Logger.new STDOUT
22
- @c = JIJI::SingleClickClient.new( ACCOUNT, CONF, l )
22
+ @c = JIJI::Plugin::SingleClickClient.new( {
23
+ :user=>Test::Constants::USER,
24
+ :password=>Test::Constants::PASSWORD
25
+ }, l )
23
26
  end
24
27
 
25
28
  def teardown
@@ -40,7 +43,7 @@ class SingleClickClientTest < RUNIT::TestCase
40
43
  def test_request_error
41
44
  begin
42
45
  @c.request {|fx|
43
- fx.list_orders( 1000 ) # エラーコードが不正。
46
+ fx.list_orders( 1000 ) # 通貨ペアコードが不正。
44
47
  }
45
48
  fail
46
49
  rescue RuntimeError
@@ -81,9 +84,12 @@ class SingleClickClientTest < RUNIT::TestCase
81
84
  l = Logger.new STDOUT
82
85
 
83
86
  # 接続先が不正
84
- conf = JIJI::Configuration.new
85
- conf.set [:securities,:host], "notfound.com"
86
- c = JIJI::SingleClickClient.new( ACCOUNT, conf, l ) # エラーは発生しない。
87
+ conf = {
88
+ :user=>Test::Constants::USER,
89
+ :password=>Test::Constants::PASSWORD,
90
+ :host=>"notfound.com"
91
+ }
92
+ c = JIJI::Plugin::SingleClickClient.new( conf, l ) # エラーは発生しない。
87
93
 
88
94
  # 接続失敗状態でリクエストを送付すると、常に接続失敗の例外が返される。
89
95
  3.times {
@@ -94,12 +100,19 @@ class SingleClickClientTest < RUNIT::TestCase
94
100
  assert_equals JIJI::ERROR_NOT_CONNECTED, $!.code
95
101
  end
96
102
  }
103
+ # 接続できるようになると復帰する。
104
+ conf[:host] = nil
105
+ 3.times {
106
+ c.request {|fx| fx.list_currency_pairs }
107
+ }
97
108
  c.close
98
-
109
+
99
110
  # アカウントが不正
100
- account = Struct.new(:user,:password).new( "illegal", "illegal" )
101
- c = JIJI::SingleClickClient.new( account, CONF, l )
102
-
111
+ c = JIJI::Plugin::SingleClickClient.new( {
112
+ :user=>"illegal",
113
+ :password=>Test::Constants::PASSWORD
114
+ }, l )
115
+
103
116
  # 接続失敗状態でリクエストを送付すると、常に接続失敗の例外が返される。
104
117
  3.times {
105
118
  begin
@@ -110,6 +123,23 @@ class SingleClickClientTest < RUNIT::TestCase
110
123
  end
111
124
  }
112
125
  c.close
113
-
126
+
127
+ # パスワードが不正
128
+ c = JIJI::Plugin::SingleClickClient.new( {
129
+ :user=>Test::Constants::USER,
130
+ :password=>"illegal"
131
+ }, l )
132
+
133
+ # 接続失敗状態でリクエストを送付すると、常に接続失敗の例外が返される。
134
+ 3.times {
135
+ begin
136
+ c.request {|fx| fx.list_currency_pairs }
137
+ fail
138
+ rescue JIJI::FatalError
139
+ assert_equals JIJI::ERROR_NOT_CONNECTED, $!.code
140
+ end
141
+ }
142
+ c.close
143
+
114
144
  end
115
145
  end
@@ -0,0 +1,2 @@
1
+
2
+ raise "test"
@@ -0,0 +1 @@
1
+ JIJI::Plugin.register( :test, "foo" )
@@ -0,0 +1,2 @@
1
+
2
+ JIJI::Plugin.register( :test, "test" )
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $: << "../../lib"
4
+ $: << File.dirname(__FILE__) + "/test"
5
+ $: << File.dirname(__FILE__) + "/error_test"
6
+
7
+ require 'rubygems'
8
+ require 'runit/testcase'
9
+ require 'runit/cui/testrunner'
10
+ require 'logger'
11
+ require 'jiji/plugin/plugin_loader'
12
+
13
+ # Loader のテスト
14
+ class LoaderTest < RUNIT::TestCase
15
+
16
+ # 基本動作のテスト
17
+ def test_basic
18
+ # ロード前は空
19
+ assert_equals [], JIJI::Plugin.get(:test)
20
+
21
+ # ロード
22
+ loader = JIJI::Plugin::Loader.new
23
+ loader.server_logger = Logger.new STDOUT
24
+ loader.load
25
+
26
+ # ./test以下の"jiji_plugin.rb"がロードされる。
27
+ assert_equals ["test"], JIJI::Plugin.get(:test)
28
+
29
+ # テスト用のplugin gemがインストールされていれば aaa,bbb が表示される。
30
+ puts JIJI::Plugin.get(:test_gem)
31
+ end
32
+ end
33
+
@@ -0,0 +1,10 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "jiji_plugin_test_gem_a"
3
+ spec.version = "1.0.0"
4
+ spec.summary = "jiji_plugin_test_gem_a."
5
+ spec.files = [
6
+ "lib/jiji_plugin.rb",
7
+ "lib/jiji_plugin_test.rb"
8
+ ]
9
+ spec.test_files = []
10
+ end
@@ -0,0 +1,2 @@
1
+ require 'jiji_plugin_test'
2
+ JIJI::Plugin.register( :test_gem, JIJIPluginTest.aaa )
@@ -0,0 +1,6 @@
1
+
2
+ module JIJIPluginTest
3
+ def self.aaa
4
+ "aaa"
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "jiji_plugin_test_gem_b"
3
+ spec.version = "1.0.0"
4
+ spec.summary = "jiji_plugin_test_gem_b."
5
+ spec.files = [
6
+ "lib/jiji_plugin.rb"
7
+ ]
8
+ spec.test_files = []
9
+ end
@@ -0,0 +1,2 @@
1
+ require 'logger'
2
+ JIJI::Plugin.register( :test_gem, "bbb" )