1919import com .djrapitops .plan .PlanSystem ;
2020import com .djrapitops .plan .delivery .domain .auth .User ;
2121import com .djrapitops .plan .delivery .domain .auth .WebPermission ;
22- import com .djrapitops .plan .delivery .export .ExportTestUtilities ;
2322import com .djrapitops .plan .identification .Server ;
2423import com .djrapitops .plan .identification .ServerUUID ;
2524import com .djrapitops .plan .settings .config .PlanConfig ;
4847import org .openqa .selenium .NoSuchElementException ;
4948import org .openqa .selenium .WebDriver ;
5049import org .openqa .selenium .chrome .ChromeDriver ;
51- import org .openqa .selenium .logging .LogEntry ;
52- import org .openqa .selenium .logging .LogType ;
5350import utilities .RandomData ;
5451import utilities .TestConstants ;
5552import utilities .TestResources ;
5855import java .nio .file .Files ;
5956import java .nio .file .Path ;
6057import java .nio .file .StandardCopyOption ;
61- import java .util .*;
58+ import java .util .Arrays ;
59+ import java .util .Collections ;
60+ import java .util .UUID ;
6261import java .util .concurrent .ExecutionException ;
6362import java .util .concurrent .TimeUnit ;
6463import java .util .stream .Collectors ;
6564import java .util .stream .Stream ;
6665
66+ import static com .djrapitops .plan .delivery .export .ExportTestUtilities .assertNoLogs ;
6767import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
6868import static org .junit .jupiter .api .Assertions .assertThrows ;
6969
@@ -93,33 +93,11 @@ static void setUp(PlanSystem system, @TempDir Path tempDir, PlanConfig config) t
9393 system .enable ();
9494 }
9595
96- @ AfterEach
97- void tearDownTest (WebDriver driver ) {
98- String address = "https://localhost:" + TEST_PORT_NUMBER + "/auth/logout" ;
99- driver .get (address );
100- SeleniumExtension .newTab (driver );
101- driver .manage ().deleteAllCookies ();
102- }
103-
10496 @ AfterAll
10597 static void tearDown (PlanSystem system ) {
10698 system .disable ();
10799 }
108100
109- User registerUser (Database db , WebPermission ... permissions ) throws Exception {
110- String groupName = RandomData .randomString (75 );
111- db .executeTransaction (
112- new StoreWebGroupTransaction (groupName , Arrays .stream (permissions )
113- .map (WebPermission ::getPermission )
114- .collect (Collectors .toList ()))
115- ).get ();
116-
117- User user = new User (RandomData .randomString (45 ), "console" , null , PassEncryptUtil .createHash (PASSWORD ), groupName , Collections .emptyList ());
118- db .executeTransaction (new StoreWebUserTransaction (user )).get ();
119-
120- return user ;
121- }
122-
123101 static Stream <Arguments > serverPageElementVisibleCases () {
124102 return Stream .of (
125103 Arguments .arguments (WebPermission .PAGE_SERVER_OVERVIEW_PLAYERS_ONLINE_GRAPH , "players-online-graph" , "overview" ),
@@ -208,6 +186,37 @@ static Stream<Arguments> pageLevelVisibleCases() {
208186 );
209187 }
210188
189+ private static void storePlayer (Database database , ServerUUID serverUUID ) throws ExecutionException , InterruptedException {
190+ storePlayer (database , serverUUID , TestConstants .PLAYER_ONE_UUID , TestConstants .PLAYER_ONE_NAME );
191+ }
192+
193+ private static void storePlayer (Database database , ServerUUID serverUUID , UUID playerUUID , String playerName ) throws ExecutionException , InterruptedException {
194+ database .executeTransaction (new StoreServerPlayerTransaction (playerUUID , System .currentTimeMillis (), playerName , serverUUID , TestConstants .GET_PLAYER_HOSTNAME .get ()))
195+ .get ();
196+ }
197+
198+ @ AfterEach
199+ void tearDownTest (WebDriver driver ) {
200+ String address = "https://localhost:" + TEST_PORT_NUMBER + "/auth/logout" ;
201+ driver .get (address );
202+ SeleniumExtension .newTab (driver );
203+ driver .manage ().deleteAllCookies ();
204+ }
205+
206+ User registerUser (Database db , WebPermission ... permissions ) throws Exception {
207+ String groupName = RandomData .randomString (75 );
208+ db .executeTransaction (
209+ new StoreWebGroupTransaction (groupName , Arrays .stream (permissions )
210+ .map (WebPermission ::getPermission )
211+ .collect (Collectors .toList ()))
212+ ).get ();
213+
214+ User user = new User (RandomData .randomString (45 ), "console" , null , PassEncryptUtil .createHash (PASSWORD ), groupName , Collections .emptyList ());
215+ db .executeTransaction (new StoreWebUserTransaction (user )).get ();
216+
217+ return user ;
218+ }
219+
211220 @ DisplayName ("Whole page is visible with permission" )
212221 @ ParameterizedTest (name = "Access with visibility {0} can see element #{1} in /{2}" )
213222 @ MethodSource ("pageLevelVisibleCases" )
@@ -225,13 +234,6 @@ void pageVisible(WebPermission permission, String element, String page, Database
225234 assertNoLogs (driver , address );
226235 }
227236
228- private static void assertNoLogs (ChromeDriver driver , String address ) {
229- List <LogEntry > logs = new ArrayList <>();
230- logs .addAll (driver .manage ().logs ().get (LogType .CLIENT ).getAll ());
231- logs .addAll (driver .manage ().logs ().get (LogType .BROWSER ).getAll ());
232- ExportTestUtilities .assertNoLogs (logs , address );
233- }
234-
235237 @ DisplayName ("Whole page is not visible with permission" )
236238 @ ParameterizedTest (name = "Access with no visibility needs {0} can't see element #{1} in /{2}" )
237239 @ MethodSource ("pageLevelVisibleCases" )
@@ -274,15 +276,6 @@ void serverPageElementVisible(WebPermission permission, String element, String s
274276 assertNoLogs (driver , address );
275277 }
276278
277- private static void storePlayer (Database database , ServerUUID serverUUID ) throws ExecutionException , InterruptedException {
278- storePlayer (database , serverUUID , TestConstants .PLAYER_ONE_UUID , TestConstants .PLAYER_ONE_NAME );
279- }
280-
281- private static void storePlayer (Database database , ServerUUID serverUUID , UUID playerUUID , String playerName ) throws ExecutionException , InterruptedException {
282- database .executeTransaction (new StoreServerPlayerTransaction (playerUUID , System .currentTimeMillis (), playerName , serverUUID , TestConstants .GET_PLAYER_HOSTNAME .get ()))
283- .get ();
284- }
285-
286279 @ DisplayName ("Server element is not visible without permission" )
287280 @ ParameterizedTest (name = "Access to server page with no visibility needs {0} can't see element #{1} in section /server/uuid/{2}" )
288281 @ MethodSource ("serverPageElementVisibleCases" )
0 commit comments