com.vanillasource.wicket.gatling.WicketTargets.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wicket-gatling Show documentation
Show all versions of wicket-gatling Show documentation
Makes Wicket links, ajax links, forms easily available for Gatling scripts.
The newest version!
/**
* Copyright (C) 2014 VanillaSource
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.vanillasource.wicket.gatling
import java.util.regex.Pattern
import org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4
import scala.util.matching.Regex
import java.net.URI
import scala.annotation.tailrec
/**
* Contains all the Wicket targets from a response body. An object of this type will be always present
* in the session object.
*/
case class WicketTargets(targets: List[(TargetSpec, String)])(val requestUri: String, val responseBody: String) {
/**
* Get all the URIs from this targets object that match the
* given type and path.
* @param targetType The type of links to get
* @param pathSpec The path components matcher specification ([[TargetSpec.matches]])
* @return The matching URIs as strings in a list, that may be empty.
*/
def getUris(targetType: TargetType, pathSpec: String*) =
targets.filter(_._1.matches(targetType, pathSpec:_*)).map(_._2).toList
}
object WicketTargets {
private val linkOnclickPattern =
"""<[^>]* wicketpath="([a-zA-Z0-9\-_]+)"[^>]*onclick="[^"]*window.location.href='(.+)'[^"]*"[^>]*>""".r
private val linkDirectPattern =
"""]* wicketpath="([a-zA-Z0-9\-_]+)"[^>]* href="([^"]+)"[^>]*>""".r
private val linkDirectPatternReverse =
"""]* href="([^"]+)"[^>]* wicketpath="([a-zA-Z0-9\-_]+)"[^>]*>""".r
private val formPattern =
"""