What is the activator command to generate application secret? - playframework-2.3

I'm using Play Framework 2.3.6. Since Play 2.3.x play commands are replaced with activator commands. Play's documentation for 2.3.x as well as latest 2.4.x mentions commands play-generate-secret and play-update-secret but I am not able to find corresponding activator commands.
We may not choose to use these secrets for production environment but would like play to generate secrets for integration and pre-prod environments - which we can change frequently.
Has anyone done this before? What are the proper activator commands?

Both
activator play-generate-secret
and
activator play-update-secret
work well for the Activator.
You can find their definition here in the sources. And as you can see they are part of Play and not the Activator.
val generateSecret = TaskKey[String]("play-generate-secret", "Generate a new application secret", KeyRanks.BTask)
val updateSecret = TaskKey[File]("play-update-secret", "Update the application conf to generate an application secret", KeyRanks.BTask)

As the comment from #john mentions, this is
activator playGenerateSecret
from Play 2.4 onwards.

Related

UnknownClass.Cucumber while running JUnit engine + Cucumber + Gradle tests from command line

Me and my team just moved from JUnit4 to JUnit5 and we faced with parallelism issues. With 4th version we used -Dcucumber.options="--threads 5" to run in tests several threads, but after deprecation and removing of cucumber options it's obviously doesn't work anymore. I set up (at least I think so) junit platform engine for the project (https://github.com/cucumber/cucumber-jvm/tree/main/cucumber-junit-platform-engine#configuration-options), but when I try to run tests via comand line (using Gradle task), I receive following error:
UnknownClass.Cucumber > UnknownClass.initializationError FAILED
org.junit.platform.commons.JUnitException at EngineExecutionOrchestrator.java:114
Caused by: org.junit.platform.commons.JUnitException at HierarchicalTestEngine.java:57
Caused by: org.junit.platform.commons.JUnitException at DefaultParallelExecutionConfigurationStrategy.java:41
Unfortunately, didn't find something in the internet, maybe someone can help with it?
What we use:
Spring boot 2.7.3
Gradle 7.5.1
Cucumber java, junit, spring, junit-platform-engine 5.7.0
junit-platform-suite-api 1.3.2
Tasks in build.gradle that I have now:
useJUnitPlatform()
systemProperty("cucumber.junit-platform.naming-strategy", "long")
systemProperty("cucumber.execution.parallel.enabled", true)
systemProperty("cucumber.execution.parallel.config.strategy", "fixed")
systemProperty("cucumber.plugin", "html:reports/html")
systemProperty("cucumber.plugin", "pretty")
systemProperty("cucumber.plugin", "junit:reports/junit")
doLast {
javaexec {
mainClass.set("io.cucumber.core.cli.Main")
classpath = cucumberRuntime + sourceSets.test.get().output + sourceSets.main.get().output
}
}
}
tasks {
val consoleLauncherTest by registering(JavaExec::class) {
dependsOn(testClasses)
val reportsDir = file("$buildDir/test-results")
outputs.dir(reportsDir)
classpath = sourceSets["test"].runtimeClasspath
mainClass.set("org.junit.platform.console.ConsoleLauncher")
args("--scan-classpath")
args("--include-engine", "cucumber")
args("--reports-dir", reportsDir)
}
test {
dependsOn(consoleLauncherTest)
exclude("**/*")
}
}
Configuration class:
#CucumberContextConfiguration
#Suite
#IncludeEngines("cucumber")
#SelectClasspathResource("com/example")
#ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example")
#SpringBootTest
#ContextConfiguration(classes = [IntegrationContext::class], loader = SpringBootContextLoader::class)
class Application() {}
Your question is pretty much impossible to answer because you didn't go through the process of making a minimal reproducer. For your next question please read the "Help others reproduce the problem" section in How do I ask a good question?.
With 4th version we used -Dcucumber.options="--threads 5" to run in tests several threads, but after deprecation and removing of cucumber options it's obviously doesn't work anymore.
Project typically include a CHANGELOG and release notes documenting all relevant changes.
What we use:
Spring boot 2.7.3
Cucumber java, junit, spring, junit-platform-engine 5.7.0
junit-platform-suite-api 1.3.2
These dependencies don't converge and aren't quite correct. You'll want to use Cucumber's and JUnit's Bill of Materials to avoid having to specify the version for every module.
If you're using Spring Boot in the recommended way you may also be able to omit the junit-bom altogether.
dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation(platform("io.cucumber:cucumber-bom:7.9.0"))
testImplementation("io.cucumber:cucumber-java")
testImplementation("io.cucumber:cucumber-junit-platform-engine")
testImplementation("org.junit.platform:junit-platform-suite")
testImplementation("org.junit.jupiter:junit-jupiter")
}
Tasks in build.gradle that I have now:
So in this build file it appears that you are trying to run Cucumber in 3 different ways. Through the JUnit Platform, through Cucumbers CLI and through the JUnit 5 ConsoleLauncher.
I don't know which solution you are trying use but suppose that you want to use the JUnit Platform, then you look at cucumber-java-skeleton for a working example.
Then afterwards you should clean up your build file. :D

Sonar Unit tests report parameter - sonar.junit.reportPath vs sonar.java.junit.reportPath

I found that my Sonar instance 5.1 or 5.1.1 (with latest sonar-runner 2.x) stopped showing part of the Unit test info (Unit test widget) on the project's dashboard.
The properties I had were (in Gradle's sonarRunner > sonarProperties section):
property "sonar.junit.reportsPath", "build/test-results/UT"
property "sonar.surefire.reportsPath", "build/test-results/UT"
To fix it, I had to include the following properties as well:
property "sonar.java.junit.reportsPath", "build/test-results/UT"
property "sonar.java.surefire.reportsPath", "build/test-results/UT"
Just FYI: All my Unit tests reports go under build/test-results/UT folder, all Integration Tests result files go unedr build/test-results/IT folder and etc.
I'm wondering if this is due to Gradle version that I'm using (2.3) or is it due to a later version of SonarQube (4.5+) as I have both SQ 5.1 and 5.1.1 instance.
I know SonarQube team started Multi language support since SonarQube version 4.12
Since SonarQube 4.2, it is possible to run an analysis on a multi-language project.
Now, it raises a question. For Getting the same Unit test info for Groovy based projects, do I need to use:
property "sonar.groovy.junit.reportsPath", "build/test-results/UT"
property "sonar.groovy.surefire.reportsPath", "build/test-results/UT"
something like that if my project has Groovy code instead of java?
Searching "**sonar.java.junit.reportPath"** with using double quotes shows No results found in Google and it forces me to try and see google results if I can run the search again without using " double quotes (for this property).
Doing the same in SonarQube site "search box" shows:
No results found for sonar.java.junit.reportPath. Please try one of the following suggestions:
Though in Gradle, inside
sonarRunner task {
.. inside ..
sonarProperties {
... section ... where I define various sonar props..
}
...
}
I can define both sonar.junit.reportPath, sonar.java.junit.reportPath and similarly, sonar.surefire.reporPath and sonar.java.surefire.reportPath and while running sonarRunner task in Gradle, it doesn't error out. Thus it makes me believe that the property variables are valid.
There are also issues with running sonarRunner or stand alone sonar-runner command for a mixed Java and Groovy based project (i.e. source code in Java but tests in Groovy). Setting sonar.language=java,grvy didn't help. I posted this question on stackoverflow but so far I have no perfect result/answer on how to get a full fledged sonar dashboard up and running for a Groovy projects like I get for a Java project.
Groovy project - Sonar - Publish project and Unit + Integration Test code coverage data
PS: I have tried various values for setting sonar.. variables (as far a sonar source, tests, etc, etc properties are concerned, which they have mentioned on their site's docs section)
The only valid property to use as of now is sonar.junit.reportsPath which will tell the java sonarqube plugin where to import your result of unit tests.
For groovy, this is work in progress, see : http://jira.sonarsource.com/browse/SONARGROOV-2
All the other properties you mentioned do not exist and are not taken into account.

JUnit Testing with bean injection

I am trying to test my web application using JUnit. I saw that there is cdi-unit which seems pretty nice or Arquillian with JBoss (I am on Seam3, JBoss 7.1.3) but I can't make it work.
As soon as I try to inject a bean (and I need to inject multiple beans for my tests), it isn't working. I get "unsatisfied injection for type[...] with qualifiers [#default] at injection point".
Especially for the EntityManager which I need to inject. Is there some easy plugin I can add to my pom file in order to get this working ?
Thanks !
You should have a look at the DeltaSpike Test Control module. This will start an embedded CDI container in your test. It is really simple to set up.
Have a look at the module documentation here:
http://deltaspike.apache.org/documentation/test-control.html

Debugging and troubleshooting Apache Karaf 3

So I've OSGI-ified a war file. It still works in Tomcat. I have all the requisite fields in the manifest and the libraries are all embedded for now. I'll externalize them later. There are two which are not OSGI enabled. The war file has log4j2 embedded BTW. It will be removed later.
The war file in question is 3 simple Jersey based REST/JSON services.
It starts and goes to Active state but I can't hit it with SoapUI where I expect to find it. The logs show it starting but that is all they show.
How can I squeeze more info out of Karaf so that I can properly figure out what is going on?
Is there something special I have to do in the Activator to get it to fire up?
Note: This is a simple REST / JSON service that wraps WURFL. By license, it's Open Source but it hasn't been released yet.
karaf#root()> bundle:headers MobileWURFL
MobileWURFL Maven Webapp (104)
-------------------------------
Manifest-Version = 1.0
Bnd-LastModified = 1395276484402
Archiver-Version = Plexus Archiver
Tool = Bnd-2.1.0.20130426-122213
Embed-Directory = WEB-INF/lib
Embedded-Artifacts = WEB-INF/lib/org.osgi.core-4.3.0.jar;g="org.osgi";a="org.osgi.core";v="4.3.0",WEB-INF/lib/org.osgi.compendium-1.4.0.jar;g="org.apache.felix";a="org.osgi.compend
ium";v="1.4.0",WEB-INF/lib/org.osgi.core-1.4.0.jar;g="org.apache.felix";a="org.osgi.core";v="1.4.0",WEB-INF/lib/javax.servlet-1.0.0.jar;g="org.apache.felix";a="javax.servlet";v="1.
0.0",WEB-INF/lib/org.osgi.foundation-1.2.0.jar;g="org.apache.felix";a="org.osgi.foundation";v="1.2.0",WEB-INF/lib/servlet-api-2.5.jar;g="javax.servlet";a="servlet-api";v="2.5",WEB-
INF/lib/log4j-api-2.0-rc1.jar;g="org.apache.logging.log4j";a="log4j-api";v="2.0-rc1",WEB-INF/lib/log4j-core-2.0-rc1.jar;g="org.apache.logging.log4j";a="log4j-core";v="2.0-rc1",WEB-
INF/lib/disruptor-3.0.1.jar;g="com.lmax";a="disruptor";v="3.0.1",WEB-INF/lib/commons-lang-2.6.jar;g="commons-lang";a="commons-lang";v="2.6",WEB-INF/lib/log4j-slf4j-impl-2.0-rc1.jar
;g="org.apache.logging.log4j";a="log4j-slf4j-impl";v="2.0-rc1",WEB-INF/lib/slf4j-api-1.7.5.jar;g="org.slf4j";a="slf4j-api";v="1.7.5",WEB-INF/lib/commons-collections-3.2.1.jar;g="co
mmons-collections";a="commons-collections";v="3.2.1",WEB-INF/lib/wurfl-1.5.1.jar;g="net.sourceforge.wurfl";a="wurfl";v="1.5.1",WEB-INF/lib/json-20140107.jar;g="org.json";a="json";v
="20140107",WEB-INF/lib/jersey-server-1.8.jar;g="com.sun.jersey";a="jersey-server";v="1.8",WEB-INF/lib/asm-3.1.jar;g="asm";a="asm";v="3.1",WEB-INF/lib/jersey-core-1.8.jar;g="com.su
n.jersey";a="jersey-core";v="1.8"
Built-By = Coder_Guy
Embed-Dependency = *;scope=compile|runtime
Embed-Transitive = true
Webapp-Context = MobileWURFL
Web-ContextPath = MobileWURFL
Build-Jdk = 1.7.0_51
Created-By = Apache Maven Bundle Plugin
Bundle-Name = MobileWURFL Maven Webapp
Bundle-SymbolicName = MobileWURFL
Bundle-Version = 0.0.1.SNAPSHOT
Bundle-ManifestVersion = 2
Bundle-ClassPath = .,WEB-INF/classes,WEB-INF/lib/org.osgi.core-4.3.0.jar,WEB-INF/lib/org.osgi.compendium-1.4.0.jar,WEB-INF/lib/org.osgi.core-1.4.0.jar,WEB-INF/lib/javax.servlet-1.0
.0.jar,WEB-INF/lib/org.osgi.foundation-1.2.0.jar,WEB-INF/lib/servlet-api-2.5.jar,WEB-INF/lib/log4j-api-2.0-rc1.jar,WEB-INF/lib/log4j-core-2.0-rc1.jar,WEB-INF/lib/disruptor-3.0.1.ja
r,WEB-INF/lib/commons-lang-2.6.jar,WEB-INF/lib/log4j-slf4j-impl-2.0-rc1.jar,WEB-INF/lib/slf4j-api-1.7.5.jar,WEB-INF/lib/commons-collections-3.2.1.jar,WEB-INF/lib/wurfl-1.5.1.jar,WE
B-INF/lib/json-20140107.jar,WEB-INF/lib/jersey-server-1.8.jar,WEB-INF/lib/asm-3.1.jar,WEB-INF/lib/jersey-core-1.8.jar
As you are using a OSGi-fied war the war-extender of Pax Web will kick in. Therefore no activator needed. For debugging just start the karaf container with karaf debug, attach your debuger to port 8787.
Depending on your embedded jars there might be an issue with those, for example a servlet.jar or similar will result in errors with deployment. Also possible the log4j2.jar could cause an issue.
What's the result of bundle:header for this war?
With the command
web:list
you also receive the info of the state of the web bundle.
UPDATE:
It is right there in your Bundle-ClassPath. The servlet jar is not allowed to be in a WAR, per spec by the way. In OSGi it collides with the packages provided by Pax-Web. In a Tomcat, the servlet.jar is already loaded by the container therefore it does work, as First-Come-First-Serve is used by a classloader. With OSGi the first Servlet class is found inside the War and therefore the resolver doesn't use the one provided by Pax Web. It is essential that you remove that jar.
And I think adding those osgi jars doesn't help any either, this will most likely collide with the bundles provided by the container.
I strongly suggest using the maven-bundle-plugin to generate this war, so the imports are properly created. Or just neglect all OSGi meta information and deploy a standard WAR. If you use the following type URL:
webbundle:mvn:groupID/artifactID/version/war?Web-ContextPath=Mobile-WURFL
It will generate a proper OSGi Manifest for your war.

Is there a way to LOG RC Selenium test errors/failures into a database?

Im using phpunit & phpundercontrol to run the RC Selenium on every build.
PHPUnit allows you to implement your own TestListener. Custom test listeners implement the abstract methods in the PHPUnit_Framework_TestListener interface. Specifically, your listener will implement:
startTestSuite()
endTestSuite()
startTest()
endTest()
addError()
addFailure()
addSkippedTest()
addIncompleteTest()
Once you've attached the TestListner these methods will be called each time the corresponding events occur in your test suite. These methods will be written to perform the INSERTs and UPDATEs on a test results database that you'll create.
Attaching the listener class to your suite is as easy as adding a tag to the phpunit.xml configuration file. For example:
<phpunit>
<testsuites>[...]</testsuites>
<selenium>[...]</selenium>
<listeners>
<listener class="Database"
file="/usr/loocal/share/pear/PHPUnit/Util/Log/Database.php">
</listeners>
</phpunit>
That's all you need!
In fact, PHPUnit already comes with a working version of the listener I just described (PHPUnit_Util_Log_Database), as well as two different database schema definitions.
On many systems this class will live at /usr/loocal/share/pear/PHPUnit/Util/Log/Database.php, and the schemas at /usr/loocal/share/pear/PHPUnit/Util/Log/Database/MySQL.sql and /usr/loocal/share/pear/PHPUnit/Util/Log/Database/SQLite3.sql. You may have to do some tweaking depending on the DBMS you're using.
See these sections of the documentation (it wont let me post two links:
http://www.phpunit.de/manual/3.4/en/extending-phpunit.html#extending-phpunit.PHPUnit_Framework_TestListener
htp://www.phpunit.de/manual/3.4/en/api.html#api.testresult.tables.testlistener
(StackOverflow won't let me post two links, so you'll have to correct the HTTP in that second one)
I am working on the same problem.
Have asked a related question here a few days ago.
My attempt using Selenium IDE, Selenium RC and perl.
General strategy:
You can make newer releases of phpunit generate TAP output (options --tap, --log-tap).
(TAP is Test Anything Protocol - standardized output format)
Parse the logfile to obtain the suite metadata from the TAP parser object, insert into database using perl, e.g. "# Number of Passed": , "Failed", "Unexpectedly succeeded",