package Ġuk . ac . war wick . cam cat . mvc Ċ Ċ import Ġcom . g argo yle software . html unit . html . Html Anchor Ċ import Ġcom . g argo yle software . html unit . html . Html Page Ċ import Ġcom . g argo yle software . html unit . html . Html Table Ċ import Ġorg . hamcrest . Matchers .* Ċ import Ġorg . junit . Assert . assertThat Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Mockito .` when ` Ċ import Ġorg . springframework . beans . factory . annotation . Autowired Ċ import Ġorg . springframework . security . test . context . support . With Mock User Ċ import Ġorg . springframework . test . web . servlet . get Ċ import Ġuk . ac . war wick . cam cat . system . security . Role Ċ import Ġuk . ac . war wick . user lookup . User Ċ import Ġuk . ac . war wick . user lookup . User Lookup Interface Ċ Ċ class ĠModule IntegrationTest Ġ: ĠIntegration Test () Ġ{ ĊĠ Ġ@ Autowired ĊĠ Ġlateinit Ġvar Ġuser Lookup : ĠUser Lookup Interface ĊĊĠ Ġ@ Before ĊĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠ Ġval Ġuser Ġ= ĠUser () ĊĠĠĠ Ġuser . fullName Ġ= Ġ" John ĠSmith " ĊĊĠĠĠ Ġ` when `( user Lookup . getUser By War wick Uni Id (" 0 0 0 0 1 2 6 ")). thenReturn ( user ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ With Mock User ( roles Ġ= Ġ[ Role . user ]) ĊĠ Ġfun Ġtest () Ġ{ ĊĠĠĠ Ġval Ġpage : ĠHtml Page Ġ= Ġweb Client . getPage (" http :// localhost / modules / 2 0 2 0 / CS 1 2 6 - 1 5 ") ĊĊĠĠĠ Ġfun Ġcontent ( id : ĠString ): ĠString Ġ= Ġpage . getElementById ( id ). textContent ĊĠĠĠ Ġfun Ġtable Cells ( table Id : ĠString ): ĠList < String > Ġ= ĊĠĠĠĠĠ Ġ( page . get Html Element ById ( table Id ) Ġas ĠHtml Table ). bodies . first (). rows . flatMap Ġ{ Ġit . cells Ġ} ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġit . textContent . trim () Ġ} ĊĊĠĠĠ ĠassertThat ( content (" module - code "), ĠequalTo Compress ing WhiteSpace (" CS 1 2 6 - 1 5 ")) ĊĠĠĠ ĠassertThat ( content (" module - title "), ĠequalTo Compress ing WhiteSpace (" Design Ġof ĠInformation ĠStruct ures ")) ĊĠĠĠ ĠassertThat ( content (" module - department - name "), ĠequalTo Compress ing WhiteSpace (" Computer ĠScience ")) ĊĠĠĠ ĠassertThat ( content (" module - fac ulty - name "), ĠequalTo Compress ing WhiteSpace (" Science , ĠEngineering Ġand ĠMed icine ")) ĊĠĠĠ ĠassertThat ( content (" module - level - name "), ĠequalTo Compress ing WhiteSpace (" Under grad uate ĠLevel Ġ 1 ")) ĊĠĠĠ ĠassertThat ( content (" module - leader "), ĠequalTo Compress ing WhiteSpace (" John ĠSmith ")) ĊĠĠĠ ĠassertThat ( content (" module - credit - value "), ĠequalTo Compress ing WhiteSpace (" 1 5 ")) ĊĠĠĠ ĠassertThat ( content (" module - duration - value "), ĠequalTo Compress ing WhiteSpace (" 3 Ġweeks ")) Ġ Ġ// P 2 1 D ĊĠĠĠ ĠassertThat ( ĊĠĠĠĠĠ Ġ( page . get Html Element ById (" module - web - page ") Ġas ĠHtml Anchor ). href Attribute , ĊĠĠĠĠĠ ĠequalTo (" https :// war wick . ac . uk / fac / sci / d cs / te aching / material / cs 1 2 6 /") ĊĠĠĠ Ġ) ĊĊĠĠĠ ĠassertThat ( ĊĠĠĠĠĠ Ġcontent (" module - aim s "), ĊĠĠĠĠĠ Ġstring Contains In Order (" standard Ġabstract Ġdata Ġtypes Ġ( AD Ts ) Ġsuch Ġas Ġlinked Ġlists ") ĊĠĠĠ Ġ) ĊĊĠĠĠ ĠassertThat ( ĊĠĠĠĠĠ Ġcontent (" module - pre - requis ite - modules "), ĊĠĠĠĠĠ ĠequalTo Compress ing WhiteSpace (" CS 1 1 8 - 1 5 ĠProgramming Ġfor ĠComputer ĠSc ient ists ") ĊĠĠĠ Ġ) ĊĊĠĠĠ ĠassertThat ( ĊĠĠĠĠĠ Ġcontent (" module - post - requis ite - modules "), ĊĠĠĠĠĠ ĠequalTo Compress ing WhiteSpace (" CS 2 6 1 - 1 5 ĠSoftware ĠEngineering ") ĊĠĠĠ Ġ) ĊĊĠĠĠ ĠassertThat ( ĊĠĠĠĠĠ Ġtable Cells (" module - te aching - split "), ĊĠĠĠĠĠ Ġcontains In Relative Order ( ĊĠĠĠĠĠĠĠ Ġ" Computer ĠScience ", Ġ" 8 0 %", ĊĠĠĠĠĠĠĠ Ġ" War wick ĠMathematic s ĠInstitute ", Ġ" 2 0 %" ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĊĠĠĠ ĠassertThat ( ĊĠĠĠĠĠ Ġtable Cells (" module - study - time "), ĊĠĠĠĠĠ Ġcontains In Relative Order ( ĊĠĠĠĠĠĠĠ Ġ" L ect ures ", Ġ" 3 0 Ġsessions Ġof Ġ 1 Ġhour ", ĊĠĠĠĠĠĠĠ Ġ" Pract ical Ġclasses ", Ġ" 8 Ġsessions Ġof Ġ 2 Ġhours ", ĊĠĠĠĠĠĠĠ Ġ" Private Ġstudy ", Ġ" 2 0 Ġhours " ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĠĠĠ ĠassertThat ( ĊĠĠĠĠĠ Ġcontent (" module - total - study - hours "), ĊĠĠĠĠĠ ĠequalTo Compress ing WhiteSpace (" 6 6 Ġhours ") ĊĠĠĠ Ġ) ĊĊĠĠĠ ĠassertThat ( ĊĠĠĠĠĠ Ġtable Cells (" module - assessment "), ĊĠĠĠĠĠ Ġcontains In Relative Order ( ĊĠĠĠĠĠĠĠ Ġ" 1 0 0 0 Ġword Ġess ay ", Ġ" 5 0 %", ĊĠĠĠĠĠĠĠ Ġ" Students Ġwrite Ġan Ġess ay ", ĊĠĠĠĠĠĠĠ Ġ" 2 Ġhour Ġexam ", Ġ" 5 0 %", ĊĠĠĠĠĠĠĠ Ġ" Students Ġsit Ġan Ġexam " ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĊĠĠĠ ĠassertThat ( ĊĠĠĠĠĠ Ġcontent (" module - core - availability "), ĊĠĠĠĠĠ Ġstring Contains In Order (" Year Ġ 1 Ġof ", Ġ" UC SA - G 5 0 0 ", Ġ" Computer ĠScience ") ĊĠĠĠ Ġ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ With Mock User ( roles Ġ= Ġ[ Role . user ]) ĊĠ Ġfun Ġtest NotFound When No Occurrence () Ġ{ ĊĠĠĠ Ġm vc . get ("/ modules / 2 0 3 0 / CS 1 2 6 - 1 5 "). andExpect Ġ{ ĊĠĠĠĠĠ Ġstatus Ġ{ Ġis NotFound Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġ@ With Mock User ( roles Ġ= Ġ[ Role . user ]) ĊĠ Ġfun Ġtest NotFound When Module Code DoesNotExist () Ġ{ ĊĠĠĠ Ġm vc . get ("/ modules / 2 0 2 0 / AB 1 2 3 - 4 5 "). andExpect Ġ{ ĊĠĠĠĠĠ Ġstatus Ġ{ Ġis NotFound Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ