Skip to content

Commit

Permalink
fix(test): Upgrade test harness to Kotlin and JUnit5
Browse files Browse the repository at this point in the history
  • Loading branch information
djansen-redhat committed Aug 29, 2018
1 parent 360d720 commit 830876a
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 108 deletions.
Expand Up @@ -20,19 +20,17 @@
*/
package org.zanata

import org.junit.Rule
import org.junit.Test
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.zanata.util.SampleDataExtension

/**
* This is a class for experiment some things i.e. populate cargo instance with
* some example users and languages so that a manual test can be performed.
* Under normal circumstances it will have no active tests in it.
*/
@ExtendWith(SampleDataExtension::class)
class ExperimentTest {
@get:Rule
var sampleDataRule = SampleDataExtension()

@Test
fun test() {
// we need at least a non-empty test to apply the rule
Expand Down
@@ -0,0 +1,43 @@
/*
* Copyright 2018, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This 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 2.1 of the License, or (at your option)
* any later version.
*
* This software 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 software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.feature.testharness

import org.junit.jupiter.api.Tag
import kotlin.annotation.Retention

/**
* Interface for the execution of the Basic Acceptance Tests (BAT) category.
*
* Tests in this category exercise features only so far as to demonstrate
* that the feature works, and perhaps have a single handled negative case.
* BAT suites should not exceed an agreed interval, e.g. approximately
* 10 minutes, in order to maintain a positive GitHub workflow.
* Tests in this category provide a "review readiness" status for Github
* Pull Requests, and must pass for said request to be accepted and merged.
*
* @author Damian Jansen [djansen@redhat.com](mailto:djansen@redhat.com)
*/
@Target(AnnotationTarget.CLASS, AnnotationTarget.FILE,
AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER)
@Retention
@Tag("BasicAcceptancetest")
annotation class BasicAcceptanceTest
@@ -0,0 +1,40 @@
/*
* Copyright 2018, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This 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 2.1 of the License, or (at your option)
* any later version.
*
* This software 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 software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.feature.testharness

import org.junit.jupiter.api.Tag
import kotlin.annotation.Retention

/**
* Interface for the execution of the Comprehensive Tests category.
*
* Tests in this category include as many tests as feasible covering boundaries,
* negative paths and various other considerations. These act as an Early
* Warning System for QA, and are wholly managed and maintained by QA.
*
* @author Damian Jansen [djansen@redhat.com](mailto:djansen@redhat.com)
*/
@Target(AnnotationTarget.CLASS, AnnotationTarget.FILE,
AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER)
@Retention
@Tag("ComprehensiveTest")
annotation class ComprehensiveTest
@@ -1,5 +1,5 @@
/*
* Copyright 2017, Red Hat, Inc. and individual contributors as indicated by the
* Copyright 2018, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
Expand All @@ -18,15 +18,23 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.feature.endtoend;
package org.zanata.feature.testharness

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.jupiter.api.Tag
import kotlin.annotation.Retention

@RunWith(Suite.class)
@Suite.SuiteClasses({
AdminEndToEndTest.class,
UserEndToEndTest.class
})
public class EndToEndTestSuite {
}
/**
* Interface for the execution of the Detailed Tests category.
*
* Tests that fall under this category exercise features more so than the
* Basic Acceptance Tests (BAT), and form part of the Release Candidate
* acceptance criteria.
*
* @author Damian Jansen [djansen@redhat.com](mailto:djansen@redhat.com)
*/
@Target(AnnotationTarget.CLASS, AnnotationTarget.FILE,
AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER)
@Retention
@Tag("DetailedTest")
annotation class DetailedTest
Expand Up @@ -21,8 +21,7 @@
package org.zanata.feature.testharness

import org.junit.jupiter.api.Tag
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
import kotlin.annotation.Retention

/**
* Interface for the execution of the Unstable Test category.
Expand All @@ -35,6 +34,7 @@ import java.lang.annotation.RetentionPolicy
* @author Damian Jansen [djansen@redhat.com](mailto:djansen@redhat.com)
*/
@Target(AnnotationTarget.CLASS, AnnotationTarget.FILE, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
@Retention(RetentionPolicy.RUNTIME)
@Retention
@Tag("UnstableTest")
@Suppress("unused")
annotation class UnstableTest
Expand Up @@ -20,40 +20,36 @@
*/
package org.zanata.feature.testharness

import org.apache.log4j.LogManager
import org.apache.log4j.Logger
import org.junit.Rule
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName

import org.joda.time.DateTime
import org.joda.time.Duration
import org.joda.time.format.PeriodFormatter
import org.joda.time.format.PeriodFormatterBuilder
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.api.extension.RegisterExtension
import org.junit.jupiter.api.extension.TestInstancePostProcessor
import org.junit.rules.RuleChain
import org.openqa.selenium.WebDriver
import org.zanata.page.WebDriverFactory
import org.zanata.util.*

import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport
import org.zanata.util.AllowAnonymousExtension
import org.zanata.util.LoggingExtension
import org.zanata.util.HasEmailExtension
import org.zanata.util.EnsureLogoutExtension
import org.zanata.util.SampleDataExtension
import org.zanata.util.ZanataRestCaller

/**
* Global application of rules to Zanata functional tests
*
* @author Damian Jansen
* [djansen@redhat.com](mailto:djansen@redhat.com)
* @author Damian Jansen [djansen@redhat.com](mailto:djansen@redhat.com)
*/
@EnableRuleMigrationSupport
@ExtendWith(AllowAnonymousExtension::class, LoggingExtension::class, SampleDataExtension::class, EnsureLogoutExtension::class)
@ExtendWith(LoggingExtension::class,
SampleDataExtension::class,
AllowAnonymousExtension::class,
EnsureLogoutExtension::class)
@DisplayName("Zanata Functional Test")
open class ZanataTestCase {

var testFunctionStart: DateTime
private var testFunctionStart = DateTime()
var zanataRestCaller = ZanataRestCaller()

private val testDescription: String
Expand Down Expand Up @@ -108,9 +104,6 @@ open class ZanataTestCase {

@RegisterExtension
var hasEmailExtension = HasEmailExtension()

val MAX_SHORT_TEST_DURATION = 180000
val SHORT_TEST: java.time.Duration = java.time.Duration.ofMillis(MAX_SHORT_TEST_DURATION.toLong())
private var mainWindowHandle: String? = null
private lateinit var mainWindowHandle: String
}
}
@@ -0,0 +1,38 @@
/*
* Copyright 2018, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This 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 2.1 of the License, or (at your option)
* any later version.
*
* This software 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 software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.util;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;

public class LoggingExtension implements TestInstancePostProcessor {

@Override
public void postProcessTestInstance(Object testInstance,
ExtensionContext context) throws Exception {
Logger logger = LogManager.getLogger(testInstance.getClass());
// testInstance.getClass()
// .getMethod("setLogger", Logger.class)
// .invoke(testInstance, logger);
}
}

This file was deleted.

@@ -0,0 +1,58 @@
/*
* Copyright 2013, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This 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 2.1 of the License, or (at your option)
* any later version.
*
* This software 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 software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.util

import org.junit.jupiter.api.extension.BeforeEachCallback
import org.junit.jupiter.api.extension.ExtensionContext
import org.zanata.util.SampleDataResourceClient.deleteExceptEssentialData
import org.zanata.util.SampleDataResourceClient.makeSampleLanguages
import org.zanata.util.SampleDataResourceClient.makeSampleProject
import org.zanata.util.SampleDataResourceClient.makeSampleUsers
import org.zanata.util.SampleDataResourceClient.setRateLimit
import org.zanata.util.SampleDataResourceClient.userJoinsLanguageTeam

/**
* Create sample data for tests
*
* @see org.junit.jupiter.api.extension.Extension
*
* @author Patrick Huang [pahuang@redhat.com](mailto:pahuang@redhat.com)
* @author Damian Jansen [djansen@redhat.com](mailto:djansen@redhat.com)
*/
class SampleDataExtension : BeforeEachCallback {

@Throws(Exception::class)
override fun beforeEach(context: ExtensionContext) {
deleteExceptEssentialData()
makeSampleUsers()
makeSampleLanguages()
val locales = "fr,hi,pl"
userJoinsLanguageTeam("translator", locales)
userJoinsLanguageTeam("glossarist", locales)
makeSampleProject()
setRateLimit(ACTIVE_RATE_LIMIT, CONCURRENT_RATE_LIMIT)
}

companion object {
val CONCURRENT_RATE_LIMIT = 20
val ACTIVE_RATE_LIMIT = 10
}
}

0 comments on commit 830876a

Please sign in to comment.