| 1 | /**************************************************************** |
| 2 | ??*??Licensed??to??the??Apache??Software??Foundation??(ASF)??under??one??????* |
| 3 | ??*??or??more??contributor??license??agreements.????See??the??NOTICE??file??* |
| 4 | ??*??distributed??with??this??work??for??additional??information????????????????* |
| 5 | ??*??regarding??copyright??ownership.????The??ASF??licenses??this??file??????* |
| 6 | ??*??to??you??under??the??Apache??License,??Version??2.0??(the????????????????????????* |
| 7 | ??*??"License");??you??may??not??use??this??file??except??in??compliance??????* |
| 8 | ??*??with??the??License.????You??may??obtain??a??copy??of??the??License??at??????* |
| 9 | ??*????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????* |
| 10 | ??*??????http://www.apache.org/licenses/LICENSE-2.0??????????????????????????????????* |
| 11 | ??*????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????* |
| 12 | ??*??Unless??required??by??applicable??law??or??agreed??to??in??writing,??????* |
| 13 | ??*??software??distributed??under??the??License??is??distributed??on??an????* |
| 14 | ??*??"AS??IS"??BASIS,??WITHOUT??WARRANTIES??OR??CONDITIONS??OF??ANY??????????????* |
| 15 | ??*??KIND,??either??express??or??implied.????See??the??License??for??the????????* |
| 16 | ??*??specific??language??governing??permissions??and??limitations????????????* |
| 17 | ??*??under??the??License.??????????????????????????????????????????????????????????????????????????????????????* |
| 18 | ??****************************************************************/ |
| 19 | ?? |
| 20 | package??org.apache.james.mpt; |
| 21 | ?? |
| 22 | import??java.io.InputStream; |
| 23 | import??java.util.Locale; |
| 24 | ?? |
| 25 | ?? |
| 26 | /** |
| 27 | ??*??A??Protocol??test??which??reads??the??test??protocol??session??from??a??file.??The??file |
| 28 | ??*??read??is??taken??as??"<test-name>.test",??where??<test-name>??is??the??value??passed |
| 29 | ??*??into??the??constructor.??Subclasses??of??this??test??can??set??up??{@link??#preElements} |
| 30 | ??*??and??{@link??#postElements}??for??extra??elements??not??defined??in??the??protocol |
| 31 | ??*??session??file. |
| 32 | ??*/ |
| 33 | public??abstract??class??AbstractSimpleScriptedTestProtocol??extends |
| 34 | ????????????????AbstractProtocolTestFramework??{ |
| 35 | ????????private??ProtocolSessionBuilder??builder??=??new??ProtocolSessionBuilder(); |
| 36 | ?? |
| 37 | ????????private??static??final??Locale??BASE_DEFAULT_LOCALE??=??Locale.getDefault(); |
| 38 | ?? |
| 39 | ????????/** |
| 40 | ??????????*??Sets??up??a??SimpleFileProtocolTest??which??reads??the??protocol??session??from??a |
| 41 | ??????????*??file??of??name??"<fileName>.test".??This??file??should??be??available??in??the |
| 42 | ??????????*??classloader??in??the??same??location??as??this??test??class. |
| 43 | ??????????*?? |
| 44 | ??????????*??@param??fileName |
| 45 | ??????????*????????????????????????The??name??of??the??file??to??read??protocol??elements??from. |
| 46 | ??????????*/ |
| 47 | ????????public??AbstractSimpleScriptedTestProtocol(HostSystem??hostSystem,??String??userName,??String??password)??{ |
| 48 | ????????????????super(hostSystem,??userName,??password); |
| 49 | ????????} |
| 50 | ?? |
| 51 | ????????protected??void??tearDown()??throws??Exception??{ |
| 52 | ????????????????Locale.setDefault(BASE_DEFAULT_LOCALE); |
| 53 | ????????????????super.tearDown(); |
| 54 | ????????} |
| 55 | ?? |
| 56 | ????????/** |
| 57 | ??????????*??Reads??test??elements??from??the??protocol??session??file??and??adds??them??to??the |
| 58 | ??????????*??{@link??#testElements}??ProtocolSession.??Then??calls??{@link??#runSessions}. |
| 59 | ??????????*?? |
| 60 | ??????????*??@param??locale??test??under??this??default??locale,??not??null |
| 61 | ??????????*/ |
| 62 | ????????protected??void??scriptTest(String??fileName,??Locale??locale)??throws??Exception??{ |
| 63 | ????????????????Locale.setDefault(locale); |
| 64 | ????????????????addTestFile(fileName??+??".test",??runner.getTestElements()); |
| 65 | ????????????????runSessions(); |
| 66 | ????????} |
| 67 | ?? |
| 68 | ????????/** |
| 69 | ??????????*??Finds??the??protocol??session??file??identified??by??the??test??name,??and??builds |
| 70 | ??????????*??protocol??elements??from??it.??All??elements??from??the??definition??file??are |
| 71 | ??????????*??added??to??the??supplied??ProtocolSession. |
| 72 | ??????????*?? |
| 73 | ??????????*??@param??fileName |
| 74 | ??????????*????????????????????????The??name??of??the??file??to??read |
| 75 | ??????????*??@param??session |
| 76 | ??????????*????????????????????????The??ProtocolSession??to??add??elements??to. |
| 77 | ??????????*/ |
| 78 | ????????protected??void??addTestFile(String??fileName,??ProtocolInteractor??session) |
| 79 | ????????????????????????throws??Exception??{ |
| 80 | ????????????????fileName??=??"/org/apache/james/test/functional/imap/scripts/"??+??fileName; |
| 81 | ????????????????//??Need??to??find??local??resource. |
| 82 | ????????????????InputStream??is??=??this.getClass().getResourceAsStream(fileName); |
| 83 | ????????????????if??(is??==??null)??{ |
| 84 | ????????????????????????throw??new??Exception("Test??Resource??'"??+??fileName??+??"'??not??found."); |
| 85 | ????????????????} |
| 86 | ?? |
| 87 | ????????????????builder.addProtocolLines(fileName,??is,??session); |
| 88 | ????????} |
| 89 | } |