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

com.avito.reportviewer.ReportViewerLinksGeneratorImpl.kt Maven / Gradle / Ivy

Go to download

Collection of infrastructure libraries and gradle plugins of Avito Android project

There is a newer version: 2023.22
Show newest version
package com.avito.reportviewer

import com.avito.report.ReportLinksGenerator
import com.avito.report.TestSuiteNameProvider
import com.avito.report.model.Team
import com.avito.reportviewer.model.ReportCoordinates
import com.avito.test.model.TestName
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl

public class ReportViewerLinksGeneratorImpl(
    reportViewerUrl: String,
    private val reportCoordinates: ReportCoordinates,
    private val reportViewerQuery: ReportViewerQuery = ReportViewerQuery()
) : ReportLinksGenerator, TestSuiteNameProvider {

    private val host = reportViewerUrl.removeSuffix("/")

    override fun getName(): String = "${reportCoordinates.planSlug}_${reportCoordinates.jobSlug}"

    override fun generateReportLink(filterOnlyFailures: Boolean, team: String?): String {
        return generateReportUrl(
            reportCoordinates,
            onlyFailures = filterOnlyFailures,
            team = team?.let { Team(it) } ?: Team.UNDEFINED
        ).toString()
    }

    override fun generateTestLink(testName: TestName): String {
        return generateSingleTestRunUrl(
            reportCoordinates = reportCoordinates,
            testClass = testName.className,
            testMethod = testName.methodName
        ).toString()
    }

    private fun generateReportUrl(
        reportCoordinates: ReportCoordinates,
        onlyFailures: Boolean,
        team: Team
    ): HttpUrl {
        val url =
            "$host/report/${reportCoordinates.planSlug}/${reportCoordinates.jobSlug}/${reportCoordinates.runId}" +
                reportViewerQuery.createQuery(onlyFailures, team)

        return requireNotNull(url.toHttpUrl()) { "Invalid url: $url" }
    }

    private fun generateSingleTestRunUrl(
        reportCoordinates: ReportCoordinates,
        testClass: String,
        testMethod: String
    ): HttpUrl {
        val url =
            "$host/report/${reportCoordinates.planSlug}/${reportCoordinates.jobSlug}/${reportCoordinates.runId}" +
                reportViewerQuery.createQuery(testClass, testMethod)

        return requireNotNull(url.toHttpUrl()) { "Invalid url: $url" }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy