rbatch 1.6.3 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/Rakefile +2 -5
  2. data/doc/rdoc/CHANGELOG.html +182 -0
  3. data/doc/rdoc/LICENSE.html +98 -0
  4. data/doc/rdoc/RBatch/Cmd.html +333 -0
  5. data/doc/rdoc/RBatch/CmdException.html +158 -0
  6. data/doc/rdoc/RBatch/CmdResult.html +496 -0
  7. data/doc/rdoc/RBatch/Config/Exception.html +158 -0
  8. data/doc/rdoc/RBatch/Config.html +355 -0
  9. data/doc/rdoc/RBatch/Log.html +743 -0
  10. data/doc/rdoc/RBatch.html +457 -0
  11. data/doc/rdoc/created.rid +8 -0
  12. data/doc/rdoc/images/brick.png +0 -0
  13. data/doc/rdoc/images/brick_link.png +0 -0
  14. data/doc/rdoc/images/bug.png +0 -0
  15. data/doc/rdoc/images/bullet_black.png +0 -0
  16. data/doc/rdoc/images/bullet_toggle_minus.png +0 -0
  17. data/doc/rdoc/images/bullet_toggle_plus.png +0 -0
  18. data/doc/rdoc/images/date.png +0 -0
  19. data/doc/rdoc/images/find.png +0 -0
  20. data/doc/rdoc/images/loadingAnimation.gif +0 -0
  21. data/doc/rdoc/images/macFFBgHack.png +0 -0
  22. data/doc/rdoc/images/package.png +0 -0
  23. data/doc/rdoc/images/page_green.png +0 -0
  24. data/doc/rdoc/images/page_white_text.png +0 -0
  25. data/doc/rdoc/images/page_white_width.png +0 -0
  26. data/doc/rdoc/images/plugin.png +0 -0
  27. data/doc/rdoc/images/ruby.png +0 -0
  28. data/doc/rdoc/images/tag_green.png +0 -0
  29. data/doc/rdoc/images/wrench.png +0 -0
  30. data/doc/rdoc/images/wrench_orange.png +0 -0
  31. data/doc/rdoc/images/zoom.png +0 -0
  32. data/doc/rdoc/index.html +136 -0
  33. data/doc/rdoc/js/darkfish.js +116 -0
  34. data/doc/rdoc/js/jquery.js +32 -0
  35. data/doc/rdoc/js/quicksearch.js +114 -0
  36. data/doc/rdoc/js/thickbox-compressed.js +10 -0
  37. data/doc/rdoc/lib/rbatch/cmd_rb.html +56 -0
  38. data/doc/rdoc/lib/rbatch/config_rb.html +56 -0
  39. data/doc/rdoc/lib/rbatch/log_rb.html +58 -0
  40. data/doc/rdoc/lib/rbatch_rb.html +58 -0
  41. data/doc/rdoc/rdoc.css +706 -0
  42. data/sample/bin/apache_log_insert.rb +108 -0
  43. data/sample/bin/file_batch_copy.rb +13 -0
  44. data/sample/bin/mysql_data_backup.rb +42 -0
  45. data/sample/bin/openam_log_insert.rb +105 -0
  46. data/sample/bin/openldap_backup.rb +7 -0
  47. data/sample/bin/webagent_log_insert.rb +108 -0
  48. data/sample/conf/apache_log_insert.yaml +8 -0
  49. data/sample/conf/file_batch_copy.yaml +5 -0
  50. data/sample/conf/mysql_data_backup.yaml +5 -0
  51. data/sample/conf/openam_log_insert.yaml +35 -0
  52. data/sample/conf/openldap_backup.yaml +2 -0
  53. data/sample/conf/rbatch.yaml +68 -0
  54. data/sample/conf/test.yaml +5 -0
  55. data/sample/conf/webagent_log_insert.yaml +16 -0
  56. data/sample/data/access_log.1 +50 -0
  57. data/sample/data/access_log.2012-07-10 +50 -0
  58. data/sample/data/amAgent_localhost_80.log.1 +39 -0
  59. data/sample/data/amAgent_localhost_80.log.2012-07-10 +40 -0
  60. data/sample/data/amAuthentication.access.1 +30 -0
  61. data/sample/data/amAuthentication.access.2012-07-10 +30 -0
  62. data/sample/data/amAuthentication.error.1 +10 -0
  63. data/sample/data/amAuthentication.error.2012-07-10 +6 -0
  64. data/sample/log/20130120_apache_log_insert.log +171 -0
  65. data/sample/log/20130120_openam_log_insert.log +143 -0
  66. data/sample/log/20130121_apache_log_insert.log +103 -0
  67. data/sample/log/20130121_file_batch_copy.log +15 -0
  68. data/sample/log/20130121_openam_log_insert.log +39 -0
  69. data/sample/log/20130121_webagent_log_insert.log +432 -0
  70. data/sample/log/empty +0 -0
  71. data/sample/moto/README +16 -0
  72. data/sample/moto/auditlog.src.zip +0 -0
  73. data/sample/moto/build.gradle +106 -0
  74. data/sample/moto/gradle/wrapper/gradle-wrapper.jar +0 -0
  75. data/sample/moto/gradle/wrapper/gradle-wrapper.properties +7 -0
  76. data/sample/moto/gradle.properties +12 -0
  77. data/sample/moto/gradlew +164 -0
  78. data/sample/moto/gradlew.bat +90 -0
  79. data/sample/moto/settings.gradle +1 -0
  80. data/sample/moto/src/main/bin/delete_auditlog.sh +176 -0
  81. data/sample/moto/src/main/bin/delete_workflowinstances.sh +315 -0
  82. data/sample/moto/src/main/bin/import_auth_log.sh +23 -0
  83. data/sample/moto/src/main/etc/delete_auditlog.param +39 -0
  84. data/sample/moto/src/main/etc/delete_workflowinstances.param +30 -0
  85. data/sample/moto/src/main/etc/log4j.xml +28 -0
  86. data/sample/moto/src/main/etc/status.properties +27 -0
  87. data/sample/moto/src/main/etc/sysparam.properties +54 -0
  88. data/sample/moto/src/main/java/jp/ossc/imortAuditlog/DateUtil.java +48 -0
  89. data/sample/moto/src/main/java/jp/ossc/imortAuditlog/ImportAuthLogMain.java +36 -0
  90. data/sample/moto/src/main/java/jp/ossc/imortAuditlog/LogReader.java +521 -0
  91. data/sample/moto/src/main/java/jp/ossc/imortAuditlog/MysqlController.java +315 -0
  92. data/sample/moto/src/main/logrotate/delete_auditlog +6 -0
  93. data/sample/moto/src/main/logrotate/delete_workflowinstanceslog +6 -0
  94. data/sample/moto/src/main/sql/tables.sql +36 -0
  95. data/test/cases/test_cmd.rb +120 -0
  96. data/test/cases/test_config.rb +41 -0
  97. data/test/cases/test_log.rb +599 -0
  98. data/test/conf/rbatch.yaml +0 -0
  99. data/test/mocks/PrintArgs.exe +0 -0
  100. data/test/mocks/win_cmd.exe +0 -0
  101. metadata +100 -1
@@ -0,0 +1,315 @@
1
+ package jp.ossc.imortAuditlog;
2
+
3
+ import java.net.InetAddress;
4
+ import java.net.UnknownHostException;
5
+ import java.sql.Connection;
6
+ import java.sql.DriverManager;
7
+ import java.sql.SQLException;
8
+ import java.sql.Timestamp;
9
+ import java.util.Map;
10
+ import java.util.PropertyResourceBundle;
11
+ import java.util.ResourceBundle;
12
+
13
+ import java.sql.PreparedStatement;
14
+
15
+ import org.apache.log4j.Logger;
16
+
17
+ public class MysqlController {
18
+ private static Logger logger = Logger.getLogger(MysqlController.class);
19
+
20
+ private static Connection con = null;
21
+ private static InetAddress addr = null;
22
+ private static PreparedStatement pstmtAuthBatch = null;
23
+ private static PreparedStatement pstmtAgentAuthBatch = null;
24
+ private static PreparedStatement pstmtBatch = null;
25
+ ResourceBundle sysResource = PropertyResourceBundle.getBundle("sysparam");
26
+
27
+ //処理件数
28
+ public int excuteAuthCount =0;
29
+ public int excuteAgentAuthCount =0;
30
+ public int excuteCount =0;
31
+
32
+ /*
33
+ * MySqlへ接続を行う。
34
+ */
35
+ public Boolean connect(){
36
+
37
+ if(con == null){
38
+ try {
39
+ // JDBCドライバの登録
40
+ String driver = "com.mysql.jdbc.Driver";
41
+ // Host名
42
+ String server = sysResource.getString("mysql.host");
43
+ // port番号
44
+ String port = sysResource.getString("mysql.port");
45
+ // ユーザー
46
+ String user = sysResource.getString("mysql.user");
47
+ // パスワード
48
+ String password = sysResource.getString("mysql.password");
49
+ // データベース名
50
+ String dbname =sysResource.getString("mysql.dbname");
51
+ // オプション
52
+ String option =sysResource.getString("mysql.option");
53
+ // データベースの指定
54
+ String url = "jdbc:mysql://" + server +":" + port + "/"+ dbname + "?" + option;
55
+ Class.forName (driver);
56
+ // データベースとの接続
57
+ con = DriverManager.getConnection(url, user, password);
58
+ con.setAutoCommit(false);
59
+ } catch (SQLException e) {
60
+ logger.error("dbconect error");
61
+ e.printStackTrace ();
62
+ } catch (ClassNotFoundException ex) {
63
+ logger.error("driver class not found");
64
+ ex.printStackTrace ();
65
+ }
66
+ }
67
+ return true;
68
+ }
69
+
70
+ /*
71
+ * MySqlへの接続を切断する。
72
+ */
73
+ public void disconnect() {
74
+ try {
75
+ con.close();
76
+ if (con != null)
77
+ con = null;
78
+ } catch (SQLException e) {
79
+ //logger.warn("", e);
80
+ }
81
+ }
82
+
83
+ /*
84
+ * コミットを行う。
85
+ */
86
+ public void commit() {
87
+ try {
88
+ con.commit();
89
+ } catch (SQLException e) {
90
+ //logger.warn("", e);
91
+ }
92
+ }
93
+
94
+ /*
95
+ * 認証ログ登録SQLのパラメータをセットする。
96
+ */
97
+ public boolean insertAuth(Map authLog){
98
+ try {
99
+ if(addr == null){
100
+ addr = InetAddress.getLocalHost();
101
+ }
102
+ // 各カラムに登録するデータをセット
103
+ int companyId = Integer.valueOf(sysResource.getString("companyid.value"));
104
+ String date = authLog.get("DATE").toString();
105
+ java.util.Date dateTime = DateUtil.toCalendar(date).getTime();
106
+ Timestamp sqlDate = new Timestamp(dateTime.getTime());
107
+ pstmtAuthBatch.setInt(1,companyId);
108
+ pstmtAuthBatch.setTimestamp(2, sqlDate);
109
+ pstmtAuthBatch.setString(3, authLog.get("USERID").toString());
110
+ pstmtAuthBatch.setString(4, authLog.get("CLIENTIP").toString());
111
+ pstmtAuthBatch.setString(5, addr.getHostName());
112
+ pstmtAuthBatch.setString(6, authLog.get("STATUS").toString());
113
+
114
+ pstmtAuthBatch.addBatch();
115
+ } catch (SQLException e) {
116
+ e.printStackTrace();
117
+ try {
118
+ con.rollback();
119
+ } catch (SQLException e1) {
120
+ e1.printStackTrace();
121
+ }
122
+ } catch (UnknownHostException e1) {
123
+ e1.printStackTrace();
124
+ }
125
+ return false;
126
+ }
127
+
128
+ /*
129
+ * 認証ログ登録SQLをセットする。
130
+ */
131
+ public void setAuthQuery(){
132
+ String query = "INSERT INTO authentication_log(companyId,date,login_id,access_ip,host_name,status) VALUES (?,?,?,?,?,?)";
133
+ try {
134
+ pstmtAuthBatch = con.prepareStatement(query);
135
+ } catch (SQLException e) {
136
+ try {
137
+ con.rollback();
138
+ } catch (SQLException e1) {
139
+ e1.printStackTrace();
140
+ }
141
+ e.printStackTrace();
142
+ }
143
+ }
144
+
145
+ /*
146
+ * 認証ログ登録SQLを実行する。
147
+ */
148
+ public boolean executeAuthBatch(){
149
+ // SQL文を発行し、結果を取得
150
+ try {
151
+ int[] numInsert = pstmtAuthBatch.executeBatch();
152
+ excuteAuthCount = excuteAuthCount + numInsert.length;
153
+ } catch (SQLException e) {
154
+ try {
155
+ con.rollback();
156
+ } catch (SQLException e1) {
157
+ e1.printStackTrace();
158
+ }
159
+ e.printStackTrace();
160
+ }
161
+ // データ作成が正常か判定
162
+ return true;
163
+ }
164
+
165
+ /*
166
+ * アクセスログ登録SQLをセットする。
167
+ */
168
+ public void setQuery(){
169
+ String query = "INSERT INTO access_log(companyId,date,login_id,access_ip,host_name,access_url,forward_time,httpstatus,user_agent,referer) VALUES (?,?,?,?,?,?,?,?,?,?)";
170
+ try {
171
+ pstmtBatch = con.prepareStatement(query);
172
+ } catch (SQLException e) {
173
+ try {
174
+ con.rollback();
175
+ } catch (SQLException e1) {
176
+ e1.printStackTrace();
177
+ }
178
+ e.printStackTrace();
179
+ }
180
+ }
181
+
182
+ /*
183
+ * アクセスログ登録SQLのパラメータをセットする。
184
+ */
185
+ public boolean insertAccessBatch(Map accessLog){
186
+ // ステートメント生成
187
+ try {
188
+ if(addr == null){
189
+ addr = InetAddress.getLocalHost();
190
+ }
191
+ // 各カラムに登録するデータをセット
192
+ int companyId = Integer.valueOf(sysResource.getString("companyid.value"));
193
+ String date = accessLog.get("DATE").toString();
194
+ java.util.Date dateTime = DateUtil.toCalendar(date).getTime();
195
+ Timestamp sqlDate = new Timestamp(dateTime.getTime());
196
+ pstmtBatch.setInt(1,companyId);
197
+ pstmtBatch.setObject(2, sqlDate);
198
+ pstmtBatch.setObject(3, accessLog.get("USERID"));
199
+ pstmtBatch.setObject(4, accessLog.get("CLIENTIP"));
200
+ pstmtBatch.setObject(5, addr.getHostName());
201
+ pstmtBatch.setObject(6, accessLog.get("REQUEST"));
202
+ pstmtBatch.setObject(7, accessLog.get("PROCESSINGTIME"));
203
+ pstmtBatch.setObject(8, accessLog.get("STATUS"));
204
+ pstmtBatch.setObject(9, accessLog.get("AGENT"));
205
+ pstmtBatch.setObject(10, accessLog.get("REFERER"));
206
+
207
+ pstmtBatch.addBatch();
208
+
209
+ } catch (SQLException e) {
210
+ try {
211
+ con.rollback();
212
+ } catch (SQLException e1) {
213
+ e1.printStackTrace();
214
+ }
215
+ e.printStackTrace();
216
+ } catch (UnknownHostException e1) {
217
+ e1.printStackTrace();
218
+ }
219
+ return false;
220
+ }
221
+
222
+ /*
223
+ * アクセスログ登録SQLを実行する。
224
+ */
225
+ public boolean executeBatch() throws SQLException{
226
+ // SQL文を発行し、結果を取得
227
+ try {
228
+ int [] numInsert = pstmtBatch.executeBatch();
229
+ excuteCount = excuteCount + numInsert.length;
230
+ } catch (SQLException e) {
231
+ try {
232
+ con.rollback();
233
+ } catch (SQLException e1) {
234
+ e1.printStackTrace();
235
+ throw e;
236
+ }
237
+ e.printStackTrace();
238
+ throw e;
239
+ }
240
+ // データ作成が正常か判定
241
+ return true;
242
+ }
243
+
244
+ /*
245
+ * 認可ログ登録SQLのパラメータをセットする。
246
+ */
247
+ public boolean insertAgentAuth(Map agentAuthLog){
248
+ try {
249
+ if(addr == null){
250
+ addr = InetAddress.getLocalHost();
251
+ }
252
+ // 各カラムに登録するデータをセット
253
+ int companyId = Integer.valueOf(sysResource.getString("companyid.value"));
254
+ String date = agentAuthLog.get("DATE").toString();
255
+ java.util.Date dateTime = DateUtil.toCalendar(date).getTime();
256
+ Timestamp sqlDate = new Timestamp(dateTime.getTime());
257
+ pstmtAgentAuthBatch.setInt(1,companyId);
258
+ pstmtAgentAuthBatch.setTimestamp(2, sqlDate);
259
+ pstmtAgentAuthBatch.setString(3, agentAuthLog.get("USERID").toString());
260
+ pstmtAgentAuthBatch.setString(4, addr.getHostName());
261
+ pstmtAgentAuthBatch.setObject(5, agentAuthLog.get("REQUEST"));
262
+ pstmtAgentAuthBatch.setString(6, agentAuthLog.get("STATUS").toString());
263
+
264
+ pstmtAgentAuthBatch.addBatch();
265
+ } catch (SQLException e) {
266
+ e.printStackTrace();
267
+ try {
268
+ con.rollback();
269
+ } catch (SQLException e1) {
270
+ e1.printStackTrace();
271
+ }
272
+ } catch (UnknownHostException e1) {
273
+ e1.printStackTrace();
274
+ }
275
+ return false;
276
+ }
277
+
278
+ /*
279
+ * 認可ログ登録SQLをセットする。
280
+ */
281
+ public void setAgentAuthQuery(){
282
+ String query = "INSERT INTO authorization_log(companyId,date,login_id,host_name,access_url,status) VALUES (?,?,?,?,?,?)";
283
+ try {
284
+ pstmtAgentAuthBatch = con.prepareStatement(query);
285
+ } catch (SQLException e) {
286
+ try {
287
+ con.rollback();
288
+ } catch (SQLException e1) {
289
+ e1.printStackTrace();
290
+ }
291
+ e.printStackTrace();
292
+ }
293
+ }
294
+
295
+ /*
296
+ * 認可ログ登録SQLを実行する。
297
+ */
298
+ public boolean executeAgentAuthBatch(){
299
+ // SQL文を発行し、結果を取得
300
+ try {
301
+ int[] numInsert = pstmtAgentAuthBatch.executeBatch();
302
+ excuteAgentAuthCount = excuteAgentAuthCount + numInsert.length;
303
+ } catch (SQLException e) {
304
+ try {
305
+ con.rollback();
306
+ } catch (SQLException e1) {
307
+ e1.printStackTrace();
308
+ }
309
+ e.printStackTrace();
310
+ }
311
+ // データ作成が正常か判定
312
+ return true;
313
+ }
314
+
315
+ }
@@ -0,0 +1,6 @@
1
+ /home/job/delete_auditlog/log/delete_auditlog.log {
2
+ copytruncate
3
+ rotate 31
4
+ daily
5
+ missingok
6
+ }
@@ -0,0 +1,6 @@
1
+ /root/delete_auditlog/log/delete_workflowinstances.log {
2
+ copytruncate
3
+ rotate 31
4
+ daily
5
+ missingok
6
+ }
@@ -0,0 +1,36 @@
1
+ CREATE TABLE IF NOT EXISTS `authentication_log` (
2
+ `id` int(10) NOT NULL AUTO_INCREMENT,
3
+ `companyId` bigint(20) NOT NULL,
4
+ `date` datetime NOT NULL,
5
+ `login_id` varchar(75) NOT NULL,
6
+ `access_ip` varchar(15) NOT NULL,
7
+ `host_name` varchar(75) NOT NULL,
8
+ `status` varchar(50) NOT NULL,
9
+ PRIMARY KEY (`id`)
10
+ );
11
+
12
+ CREATE TABLE IF NOT EXISTS `access_log` (
13
+ `id` int(10) NOT NULL AUTO_INCREMENT,
14
+ `companyId` bigint(20) NOT NULL,
15
+ `date` datetime NOT NULL,
16
+ `login_id` varchar(75) NOT NULL,
17
+ `access_ip` varchar(15) NOT NULL,
18
+ `host_name` varchar(75) NOT NULL,
19
+ `access_url` varchar(2048) NOT NULL,
20
+ `forward_time` int(5) NOT NULL,
21
+ `httpstatus` int(3) NOT NULL,
22
+ `user_agent` varchar(512) NOT NULL,
23
+ `referer` varchar(2048),
24
+ PRIMARY KEY (`id`)
25
+ );
26
+
27
+ CREATE TABLE IF NOT EXISTS `authorization_log` (
28
+ `id` int(10) NOT NULL AUTO_INCREMENT,
29
+ `companyId` bigint(20) NOT NULL,
30
+ `date` datetime NOT NULL,
31
+ `login_id` varchar(75) NOT NULL,
32
+ `host_name` varchar(75) NOT NULL,
33
+ `access_url` varchar(2048) NOT NULL,
34
+ `status` varchar(50) NOT NULL,
35
+ PRIMARY KEY (`id`)
36
+ );
@@ -0,0 +1,120 @@
1
+ require 'test/unit'
2
+ require 'rbatch'
3
+
4
+ class RuncherTest < Test::Unit::TestCase
5
+ def setup
6
+ @config_dir = File.join(File.dirname(RBatch.program_name), "..", "conf")
7
+ Dir::mkdir(@config_dir) if ! Dir.exists? @config_dir
8
+ confstr = ""
9
+ open( RBatch.common_config_path , "w" ){|f| f.write(confstr)}
10
+ end
11
+
12
+ def test_cmd_exists
13
+ result = RBatch::cmd "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 0;'"
14
+ assert_equal "1", result.stdout.chomp
15
+ assert_equal "2", result.stderr.chomp
16
+ assert_equal 0, result.status
17
+ end
18
+ def test_cmd_does_not_exist
19
+ assert_raise(Errno::ENOENT){
20
+ RBatch::cmd "not_exist_command"
21
+ }
22
+ end
23
+ def test_stdout_size_greater_than_65534
24
+ result = RBatch::cmd "ruby -e '100000.times{print 0}'"
25
+ assert_equal 100000, result.stdout.chomp.size
26
+ assert_equal "", result.stderr.chomp
27
+ assert_equal 0, result.status
28
+ end
29
+ def test_stdout_size_greater_than_65534_with_status_1
30
+ result = RBatch::cmd "ruby -e '100000.times{print 0}; exit 1'"
31
+ assert_equal 100000, result.stdout.chomp.size
32
+ assert_equal "", result.stderr.chomp
33
+ assert_equal 1, result.status
34
+ end
35
+ def test_status_code_is_1
36
+ result = RBatch::cmd "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'"
37
+ assert_equal "1", result.stdout.chomp
38
+ assert_equal "2", result.stderr.chomp
39
+ assert_equal 1, result.status
40
+ end
41
+ def test_status_code_is_greater_than_256
42
+ returncode = 300
43
+ result = RBatch::cmd "ruby -e 'STDOUT.print 1; STDERR.print 2; exit #{returncode};'"
44
+ assert_equal "1", result.stdout.chomp
45
+ assert_equal "2", result.stderr.chomp
46
+ case RUBY_PLATFORM
47
+ when /mswin|mingw/
48
+ assert_equal returncode, result.status
49
+ when /cygwin|linux/
50
+ assert_equal returncode % 256, result.status
51
+ end
52
+ end
53
+ def test_to_h
54
+ result = RBatch::cmd "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'"
55
+ assert_equal "1", result.to_h[:stdout]
56
+ assert_equal "2", result.to_h[:stderr]
57
+ assert_equal 1 , result.to_h[:status]
58
+ end
59
+ def test_to_s
60
+ result = RBatch::cmd "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'"
61
+ assert_equal "{:cmd_str=>\"ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'\", :stdout=>\"1\", :stderr=>\"2\", :status=>1}", result.to_s
62
+ end
63
+ def test_nil_command
64
+ assert_raise(RBatch::CmdException){
65
+ RBatch::Cmd.new(nil)
66
+ }
67
+ end
68
+ def test_fullcmd_exists
69
+ result = RBatch::Cmd.new("ruby -e 'STDOUT.print 1; STDERR.print 2; exit 0;'").run
70
+ assert_equal "1", result.stdout.chomp
71
+ assert_equal "2", result.stderr.chomp
72
+ assert_equal 0, result.status
73
+ end
74
+ def test_opt_raise_true_status_1
75
+ cmd_str = "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'"
76
+ opt = {:raise => true}
77
+ assert_raise(RBatch::CmdException){
78
+ RBatch::Cmd.new(cmd_str,opt).run
79
+ }
80
+ end
81
+ def test_opt_raise_false_status_1
82
+ cmd_str = "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'"
83
+ opt = {:raise => false}
84
+ result = RBatch::Cmd.new(cmd_str,opt).run
85
+ assert_equal "1", result.stdout.chomp
86
+ assert_equal "2", result.stderr.chomp
87
+ assert_equal 1, result.status
88
+ end
89
+ def test_opt_raise_true_status_0
90
+ cmd_str = "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 0;'"
91
+ opt = {:raise => true}
92
+ result = RBatch::Cmd.new(cmd_str,opt).run
93
+ assert_equal "1", result.stdout.chomp
94
+ assert_equal "2", result.stderr.chomp
95
+ assert_equal 0, result.status
96
+ end
97
+ def test_opt_raise_false_status_0
98
+ cmd_str = "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 0;'"
99
+ opt = {:raise => false}
100
+ result = RBatch::Cmd.new(cmd_str,opt).run
101
+ assert_equal "1", result.stdout.chomp
102
+ assert_equal "2", result.stderr.chomp
103
+ assert_equal 0, result.status
104
+ end
105
+ def test_opt_raise_true_status_1_by_conf
106
+ confstr = "cmd_raise: true "
107
+ open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
108
+ cmd_str = "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'"
109
+ assert_raise(RBatch::CmdException){
110
+ RBatch::Cmd.new(cmd_str).run
111
+ }
112
+ end
113
+ def test_opt_raise_true_status_1_shortcut
114
+ cmd_str = "ruby -e 'STDOUT.print 1; STDERR.print 2; exit 1;'"
115
+ opt = {:raise => true}
116
+ assert_raise(RBatch::CmdException){
117
+ RBatch::cmd(cmd_str,opt)
118
+ }
119
+ end
120
+ end
@@ -0,0 +1,41 @@
1
+ require 'test/unit'
2
+ require 'rbatch'
3
+
4
+ class RuncherTest < Test::Unit::TestCase
5
+ def setup
6
+ @config_dir = File.join(File.dirname(RBatch.program_name), "..", "conf")
7
+ @config_file = File.join(@config_dir , "test_config.yaml")
8
+ Dir::mkdir(@config_dir) if ! Dir.exists? @config_dir
9
+ end
10
+
11
+ def teardown
12
+ File.delete @config_file if File.exist? @config_file
13
+ end
14
+
15
+ def test_require
16
+ end
17
+
18
+ def test_config
19
+ open( @config_file , "w" ){|f| f.write("key: value")}
20
+ assert_equal "value", RBatch.config["key"]
21
+ end
22
+
23
+ def test_read_error
24
+ assert_raise(Errno::ENOENT){
25
+ RBatch.config
26
+ }
27
+ end
28
+
29
+ def test_double_read
30
+ open( @config_file , "w" ){|f| f.write("key: value")}
31
+ assert_equal "value", RBatch.config["key"]
32
+ assert_equal "value", RBatch.config["key"]
33
+ end
34
+
35
+ def test_not_exist_key
36
+ open( @config_file , "w" ){|f| f.write("key: value")}
37
+ assert_raise(RBatch::Config::Exception){
38
+ RBatch.config["not_exist"]
39
+ }
40
+ end
41
+ end