All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.gatling.charts.template.PageTemplate.scala Maven / Gradle / Ivy

There is a newer version: 3.13.1
Show newest version
/*
 * Copyright 2011-2024 GatlingCorp (https://gatling.io)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.gatling.charts.template

import java.time.{ ZoneOffset, ZonedDateTime }

import io.gatling.charts.FileNamingConventions
import io.gatling.charts.component.Component
import io.gatling.charts.config.ChartsFiles._
import io.gatling.charts.stats.{ Group, RunInfo }
import io.gatling.commons.util.GatlingVersion
import io.gatling.commons.util.StringHelper._

private[charts] abstract class PageTemplate(
    runInfo: RunInfo,
    title: String,
    isDetails: Boolean,
    requestName: Option[String],
    group: Option[Group],
    components: Component*
) {
  def jsFiles: Seq[String] = (CommonJsFiles ++ components.flatMap(_.jsFiles)).distinct

  @SuppressWarnings(Array("org.wartremover.warts.ListAppend"))
  def getOutput: String = {
    val simulationClassSimpleName = runInfo.simulationClassName.lastIndexOf(".") match {
      case -1 => runInfo.simulationClassName
      case i  => runInfo.simulationClassName.substring(i + 1)
    }

    val pageStats =
      if (isDetails) {
        val groupHierarchy = group.map(_.hierarchy).getOrElse(Nil).map(_.toGroupFileName)

        val groupAndRequestHierarchy = requestName match {
          case Some(req) => groupHierarchy :+ req.toRequestFileName
          case _         => groupHierarchy
        }

        s"""var pageStats = stats.contents['${groupAndRequestHierarchy.mkString("'].contents['")}'].stats;"""
      } else {
        "var pageStats = stats.stats;"
      }

    val deprecationWarning = {
      val thisReleaseDate = GatlingVersion.ThisVersion.releaseDate
      val thisReleaseDatePlus1Year = thisReleaseDate.plusYears(1)

      val deprecationMessage = GatlingVersion.LatestRelease match {
        case Some(GatlingVersion(number, releaseDate)) if releaseDate.isAfter(thisReleaseDatePlus1Year) =>
          Some(s"""
                  |You are using Gatling ${GatlingVersion.ThisVersion.fullVersion}
                  | released on ${thisReleaseDate.toLocalDate.toString}, more than 1 year ago.
                  | Gatling $number is available since ${releaseDate.toLocalDate.toString}.
                  |""".stripMargin)
        case None if ZonedDateTime.now(ZoneOffset.UTC).isAfter(thisReleaseDatePlus1Year) =>
          Some(s"""You are using Gatling ${GatlingVersion.ThisVersion.fullVersion}
                  | released on ${thisReleaseDate.toLocalDate.toString}, more than 1 year ago.
                  |""".stripMargin)
        case _ =>
          None
      }

      deprecationMessage
        .map(m => s"""
| $m | Please check the new features, | the upgrade guides, | and consider upgrading. |
""".stripMargin) .getOrElse("") } s""" ${jsFiles.map(jsFile => s"""""").mkString(Eol)} Gatling Stats - $title
$simulationClassSimpleName
$deprecationWarning ${components.map(_.html).mkString}
""" } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy