I'm working on a Spring-Boot project with Job Scheduling inside the project. I have job schedule class like this,
#Component
public class JobScheduleService {
#Scheduled(fixedDelay = 300000)
public void excutePaymentJob(){
// Do Something
}
}
While I'm building a project through "mvn clean install" command. The "excutePaymentJob()" function will be executed on a building process.
Is there anyway to disable this on a building phase ?
Thanks a lot !
Related
How to execute parallel Serenity + JBehave + Maven tests?
I tried with settings:
serenity.batch.size = 3
serenity.batch.count = 2
but tests are still not executed in parallel.
My AcceptanceTestSute:
public class AcceptanceTestSuite extends SerenityStories {
private static final String STORY_FILE_NAME = "story.file.name";
public AcceptanceTestSuite() {
super();
Optional.ofNullable(System.getProperty(STORY_FILE_NAME)).ifPresent(this::findStoriesCalled);
configuration().useParameterControls(new ParameterControls().useDelimiterNamedParameters(true));
configuration().usePendingStepStrategy(new FailingUponPendingStep());
}
}
The batch size and batch count parameters are for running batches across multiple machines, not for running tests in parallel on a single machine, and in any case do not work with JBehave. The best strategy is to create a separate runner class for each of your story files and use Maven or Gradle to run the runner classes in parallel.
I managed to do it as John Smart advised, using separate runner classes. Thanks.
Trying to use the new cypress framework with a maven project - the documentation has only an npm module setup example (npm install cypress) and a package.json usage example.
How would this be converted to usage in a maven dependency?
You can also download Cypress directly without npm.
There are instructions as well as the direct download here.
Here's a great article on using maven to run Cypress tests.
You should be able to use a Docker container for Cypress via the maven Testcontainers plugin.
Here is a good article that allows you to execute cypress tests as a part of mvn build, so you can have your backend app up and running during the cypress testing. But I did a slight change because the solution in the article doesn't take any feedback about tests execution into consideration. So, this is what I've changed:
Container creation part:
#SneakyThrows
#NotNull
private GenericContainer<?> createCypressContainer()
{
var container = new GenericContainer<>(DockerImageName.parse("cypress/included:3.4.0"));
container.withClasspathResourceMapping("e2e", "/e2e", BindMode.READ_WRITE);
container.setWorkingDirectory("/e2e");
container.withCreateContainerCmdModifier(it -> it.withEntrypoint("cypress", "open").withWorkingDir("/e2e"));
container.addEnv("CYPRESS_baseUrl", "http://host.testcontainers.internal:" + port);
return container;
}
Test execution and results evaluation:
#Test
public void runCypressTests() throws InterruptedException, IOException
{
Testcontainers.exposeHostPorts(port);
try (GenericContainer<?> container = createCypressContainer()) {
container.start();
Container.ExecResult execResult = container.execInContainer("/bin/sh", "-c", "cypress run");
log.warn(execResult.getStdout());
assertEquals("End to end tests are failed. Execution exit code returned non 0 value",
0, execResult.getExitCode());
}
}
I have a Maven project that builds a very simple OSGi bundle. No activator; it's only job is to deliver some shared code to an OSGi project. I want to test that I have got the dependencies all set up and embedded correctly.
So, I've added pax-exam to the situation.
I'll paste a unit test shell at the end of this. Is my #Test method in fact running inside of a bundle that is in turn depending on the bundle built in my project?
#RunWith(PaxExam.class)
#ExamReactorStrategy(PerClass.class)
public class CommonBundleTest {
#Configuration
public Option[] config() {
return options(
// this is the current project's result artifact
mavenBundle("com.basistech.osgi", "rosette-common-java-lib"),
junitBundles()
);
}
#Test
public void atest() {
}
}
Are the tests running inside of a bundle: yes
Pax Exam creates a TinyBundle for the Unit test itself. But it doesn't add extra dependencies on any bundle declared in the config method.
If you want to make sure those packages are imported you can alter the way the TinyBundle is build.
#ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
// makes sure the generated Test-Bundle contains this import!
probe.setHeader(Constants.IMPORT_PACKAGE, "*,your.extra.package");
return probe;
}
The so-called probe bundle created by Pax Exam on the fly contains all classes from the src/test/java folder containing your test class. The probe bundle manifest has a Dynamic-ImportPackage: * header, so it is not normally required to add explicit imports by means of a probe builder.
Any bundles required by your tests must be provisioned by a configuration option in the #COnfiguration method.
If you want your test to fail immediately when a bundle does not resolve, you can set a config property:
pax.exam.osgi.unresolved.fail = true
I have a Configuration bean.
#Component
public class Config {
#Value("classpath:${app.file.name.srgbicc}")
public Resource icc;
#PostConstruct
void init(){
try {
tempdir = Files.createTempDir();
newIcc = copyIccFileToTemp();
}catch (IOException e){
throw new RuntimeException(e);
}
}
private File copyIccFileToTemp() throws IOException {
File tempIcc = new File(tempdir, icc.getFilename());
FileUtils.copyFile(icc.getFile(),tempIcc);
return tempIcc;
}
}
On icc.getFile() there is a FileNotFoundException
application.properties
app.file.name.srgbicc = sRGB.icc
I looked in my classpath and found the following situation:
build/classes/main (no icc file)
build/resources/main (icc file, application.properties)
When printed out my classpath during application start I only found ...myApp/build/classes/main.
No ../build/resources/main or ../src/main/resources entries there.
So I was wondering why is the resources not on the classpath?
according to http://docs.spring.io/spring-boot/docs/1.1.5.RELEASE/reference/htmlsingle/#build-tool-plugins-gradle-running-applications
this should be.
Of course if I put the icc file in build/classes/main its all working as expected, but it is not supposed to be there. right?
I tried to run the application with gradle run or gradle bootRun in intellij I use static main. The good thing is that the application fails consistently independent of how I start it.
My Project layout
myApp
src
main
java
pkg
Config.java
resources
sRGB.icc
application.properties
For the reference:
IntelliJ 13
spring-boot 1.1.5
Fgradle 2.0
Update
Here is a stripped down example of my code
https://gist.github.com/Vad1mo/bb5d23ca251341236fbd
I removed #PostConstruct in the config.init and run the application with gradle build all test are success when i rund from intellij the tests fail. this is strange that i know have different behavior
I solved the problem now.
What helped me was just to do a simple clean build and rebuild project in intellij. I was using to much eclipse and maven so I expected it to happen automagically.
I'm developing tests using junit, maven and Selenium inside Netbeans IDE. I don't have any main class inside the src folder. I can run the tests easily from the IDE, but I'm trying to pack all of them into one jar file (so I can later use with linux cron and schedule daily tests). I've searched around the web but so far my search hasn't been successful. Can anyone point me in some enlightment path please?
Add a class in your project that contains the main function and accepts test class names as parameter.
class RunTest
{
public static void main(String args[])
{
// Run the tests contained in the classes named in the args.
org.junit.runner.JUnitCore.main(args);
}
}
Now create the jar using maven including all the dependancies in pom.xml. you will be able to run tests through jar by passing test class names
for more information read this