View
1.284
Download
2
Category
Preview:
Citation preview
2013.10.19 CLR/H #85
自動テストにおけるSMTPモックとして
BlackJumboDogのWebAPI
自己紹介
識別子 SIN/札幌ワークス
Twitter @furuya02
仕事 某社でシステムサポート
スタッフ CLR/H
Microsoft MVP for Visual C# (2013/1~)
BlackJumboDogによるテスト自動化メール送信機能の自動テストに使用する
テスト対象プロダクト
テスト実行
//verifyAsertThat(actual,expected)
SMTP
WebAPI
//exercisevar actual = sut.mailsend()
SMTPサーバを起動「オプション」-「メールサーバ」-「SMTPサーバ」
ユーザ設定「オプション」-「メールサーバ」-「メールボックス」
他ドメイン宛のメールをキューに保持する「キュー常時処理」のチェックを外すと、外部への転送はされない
WebAPIサーバを起動「オプション」-「WebAPIサーバ」
WebAPIサーバを使用するデフォルトでポートは5050
http://localhost:5050/messageJSON形式でデータ取得できます
BlackJumboDogのメールボックス構造自ドメイン宛のメールは各ユーザ、他ドメイン宛のメールはキューに溜まる
user1 user2 mqueue
example.com 他ドメイン
…
パラメータ owner特定のユーザのメールのみを取得の対象とする
user1 user2
Example.com 他ドメイン
…
GET /mail/message //指定が無ければ全部GET /mail/message?owner=user1 //user1のみGET /mail/message?owner=user1,user2 //user1及びuser2GET /mail/message?owner=mqueue //mqueueのみ
mqueue
フィールド指定(date)data指定で日付
http://localhost:5050/mail/message?Fields=date&limit=1
{"data":[{“date":"Fri, 20 Sep 2013 04:50:43 +0900“
},]}
フィールド指定(size)size指定でメールのサイズ
http://localhost:5050/mail/message?Fields=size&limit=3
{"data":[{“size":593
},{“size":591
},{“size":587
},]}
フィールド指定(from,to)fromで送信者、toで受信者
http://localhost:5050/mail/message?Fields=from,to&owner=mqueue
{"data":[{
"from":"user1@example.com","to":“aaa@aaa.com”
},{
"from":"user1@example.com","to":“bbb@bbb.com"
}]}
フィールド指定fields=
subject 件名date 日付size サイズfrom 送信者to 受信者all メール全部body 本文uid UIDfilename ファイル名
Fieldsの指定が無い場合は、subjectのみが指定される
パラメータ limit指定した件数以上は取得しない
http://localhost:5050/mail/message
{"data":[{
"subject":"テストメール(その1)“},{
"subject":"テストメール(その2)“},{
"subject":"テストメール(その4)“}
{“subject”:“テストメール(その5)“
}{
“subject”:“テストメール(その6)“}
{“subject”:“テストメール(その7)“
http://localhost:5050/mail/message?limit=2
{"data":[{
"subject":"テストメール(その1)“},{
"subject":"テストメール(その2)“},
]}
メール削除(Delete)パラメータのowner及びlimitが使用可能
DELETE /mail/message //指定が無ければ全部削除DELETE /mail/message?owner=user1 //user1のみ削除DELETE /mail/message?owner=user1,user2 //user1及びuser2削除DELETE /mail/message?owner=mqueue //mqueueのみ削除
DELETE /mail/message?limit=30 //最大30件を削除
サーバコントロールSMTPサーバの動作の制御
PUT /mail/control?service=start //メールサーバ起動PUT /mail/control?service=stop //メールサーバ停止
PUT /mail/control?init //すべてのコントロールの初期化
レスポンス制御SMTPサーバの応答コードを制御
PUT /mail/response?mail=450 //MAILコマンドに対し450を返すPUT /mail/response?rcpt=452 //RCPTコマンドに対し452を返す
PUT /mail/response?mail=450&rcpt=452 //複数指定可能
PUT /mail/response?init //すべてのレスポンス制御の初期化
テストのためのWebAPIのテストコードがっつりTDDで作成されてます。色々な拡張要望に耐えれると思います。
WebAPIのACLは必須WebAPIの解放は危険すぎます
メールはV6対応無駄にWebAPIもIPv6対応
DNSサーバMXも引けるので、実環境のFQDNでテストできます
ご清聴ありがとうございました
札幌ワークス
http://www.sapporoworks.ne.jp/spw
Recommended