001/* 002 Licensed to the Apache Software Foundation (ASF) under one 003 or more contributor license agreements. See the NOTICE file 004 distributed with this work for additional information 005 regarding copyright ownership. The ASF licenses this file 006 to you under the Apache License, Version 2.0 (the 007 "License"); you may not use this file except in compliance 008 with the License. You may obtain a copy of the License at 009 010 http://www.apache.org/licenses/LICENSE-2.0 011 012 Unless required by applicable law or agreed to in writing, 013 software distributed under the License is distributed on an 014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 KIND, either express or implied. See the License for the 016 specific language governing permissions and limitations 017 under the License. 018 */ 019package org.apache.wiki.its; 020 021import org.apache.wiki.pages.Page; 022import org.apache.wiki.pages.haddock.LoginPage; 023import org.apache.wiki.pages.haddock.ReadWikiPage; 024import org.junit.jupiter.api.Assertions; 025import org.junit.jupiter.api.Test; 026import org.junit.jupiter.api.extension.ExtendWith; 027 028import com.codeborne.selenide.junit5.ScreenShooterExtension; 029 030 031/** 032 * Login-related tests for Apache JSPWiki 033 */ 034@ExtendWith( ScreenShooterExtension.class ) 035public class LoginIT { 036 037 @Test 038 void loginAndLogout() throws Exception { 039 ReadWikiPage main = Page.withUrl( Page.baseUrl() + "/Wiki.jsp?page=Main" ).openAs( new ReadWikiPage() ); 040 Assertions.assertEquals( "JSPWiki: Main", main.title() ); 041 Assertions.assertEquals( "Main", main.wikiTitle() ); 042 Assertions.assertEquals( "G’day (anonymous guest)", main.hoverLoginArea().authenticatedText() ); 043 044 final LoginPage login = main.hoverLoginArea().clickOnLogin(); 045 Assertions.assertEquals( "JSPWiki: Login", login.title() ); 046 Assertions.assertEquals( "Login", login.wikiTitle() ); 047 048 main = login.performLogin(); 049 Assertions.assertEquals( "JSPWiki: Main", main.title() ); 050 Assertions.assertEquals( "G’day, Janne Jalkanen (authenticated)", main.hoverLoginArea().authenticatedText() ); 051 052 main.hoverLoginArea().logout(); 053 Assertions.assertEquals( "G’day (anonymous guest)", main.hoverLoginArea().authenticatedText() ); 054 } 055 056 @Test 057 void loginKO() throws Exception { 058 ReadWikiPage main = Page.withUrl( Page.baseUrl() + "/Wiki.jsp?page=Main" ).openAs( new ReadWikiPage() ); 059 Assertions.assertEquals( "JSPWiki: Main", main.title() ); 060 Assertions.assertEquals( "Main", main.wikiTitle() ); 061 Assertions.assertEquals( "G’day (anonymous guest)", main.hoverLoginArea().authenticatedText() ); 062 063 final LoginPage login = main.hoverLoginArea().clickOnLogin(); 064 Assertions.assertEquals( "JSPWiki: Login", login.title() ); 065 Assertions.assertEquals( "Login", login.wikiTitle() ); 066 067 main = login.performLogin( "perry", "mason" ); 068 Assertions.assertEquals( "JSPWiki: Login", main.title() ); 069 Assertions.assertEquals( "G’day (anonymous guest)", main.hoverLoginArea().authenticatedText() ); 070 } 071 072}