I have a spring batch project. I would like to mock up the JobBuilderFactory for junit test. When I do a when().thenReturn I get that the JobBuilderFactory is null.
You can find a complete example of how to test a Spring Batch job in the End-To-End Testing of Batch Jobs section of the reference documentation. As you will see, there is no need to mock the JobBuilderFactory.
Related
I have a Azure DevOps release pipeline which contains 10+ stages (environments). Each release stage will run a set of test cases for example, BVT Test Stage, Performance Test Stage, etc.
Now, I would like to automatically query the test results from each of the test stage, by REST API.
I can use "Runs" API to query the test runs for this release; I can use "Release" API to query the release stages including their stage names.
But the problem is, I am not able to link the test result from the test run back to the release stage.
For example, I have release stages like "BVT Test", "Performance Test", etc. But the test result from test run is something like "VSTest_TestResults_2234523"
Thanks!
how to get release stage's test results?
Try with below api:
GET https://vstmr.dev.azure.com/{org name}/{project name}/_apis/testresults/resultdetailsbyrelease?releaseId={release id}&releaseEnvId={environment id}&api-version=5.2-preview.1
To get the test result of one specific environment, you must provide the environment id, along with its corresponding release id.
Each test run has a member points to the release's environmentId.
$stageName = $stageTable[$($oneRun.release.environmentId)]
I have set up a simple Spring Integration flow which is composed of such steps:
poll a rest api periodically then
do some processing on the payload
and land it on a Kafka topic.
Please observe the code below:
#Component
public class MyIntegrationFlow extends IntegrationFlowAdapter {
#Override
protected IntegrationFlowDefinition<?> buildFlow() {
return from(() -> List.of("pathVariable1", "pathVariable2"), c -> c.poller(Pollers.fixedDelay(5, TimeUnit.SECONDS)))
.split()
.handle(httpRequest(), c -> c.advice(new RequestHandlerRetryAdvice()))
.transform(Tranformers.fromJson(Foo.class))
.filter(payload -> payload.isValid())
.log()
.transform(Tranformers.toJson())
.channel(Source.OUTPUT); // output channel for kafka topic
}
private HttpMessageHandlerSpec httpRequest() {
return Http.outboundGateway("http://somehost:8080/{pathVariable}")
.httpMethod(GET)
.uriVariable("pathVariable", Message::getPayload)
.expectedResponseType(String.class);
}
}
This works brilliantly, however, I am struggling to come up with some good tests.
How am I supposed to mock the external REST API?
How am I supposed to test that the retry policy does kick in and the desired number of http requests are made?
How do I change the MessageSource of the flow (list of path vars) that is polled periodically?
How do I check if the payload has successfully made it to the Kafka topic?
Too much questions and some of them requires too broad explanation. Anyway I think you can start from Spring Integration Testing Framework and its documentation.
How am I supposed to mock the external REST API?
I think you can just consider to use a Mock MVC from Spring Framework and its MockMvcClientHttpRequestFactory to inject into the HttpRequestExecutingMessageHandler based on the HttpMessageHandlerSpec.
retry policy does kick
Well, I guess the same mocked MVC endpoint can verify how many times it has been called and fail for first several times to initiate that retry.
How do I change the MessageSource
This is exactly a part of Spring Integration Testing Framework with its MockIntegration.mockMessageSource() and MockIntegrationContext: https://docs.spring.io/spring-integration/docs/5.1.6.RELEASE/reference/html/#mockintegration
made it to the Kafka topic?
Or you the mentioned MockIntegration.mockMessageHandler() to verify that endpoint for Kafka is called. Or use an Embedded Kafka from Spring Kafka project: https://docs.spring.io/spring-kafka/docs/2.2.7.RELEASE/reference/html/#embedded-kafka-annotation
Have been trying to configure Reportportal withe a sample project. The following steps have been done:
1.Start a Docker and get the reportporal page up and running.
2.In the Java project, added the bintray repository, java-agent-testng, logger-java-log4j dependencies.
3.Included log4j.properties file in the project and also the log4j.appender line for reprortportal
log4j.appender.reportportal=com.epam.ta.reportportal.log4j.appender.ReportPortalAppender
log4j.appender.reportportal.layout=org.apache.log4j.PatternLayout
log4j.appender.reportportal.layout.ConversionPattern=[%d{HH:mm:ss}] %-5p (%F:%L) - %m%n
4.Included log4j info lines for one of the #Test methods.
5.Ran the Test script and made sure the log info line is seen on the console.
6.However, the reportportal dashboard still shows "No Results Found"
7.Also, added the following line for the Test Method.
#Listeners({ReportPortalTestNGListener.class})
8. This threw an exception with Jackson.
A few questions running in my mind:
1.Do we need both TestNG and Log4j to integrate with reportportal or just one of them is fine.
2. With the above steps carried out, is there anything that has been missed. Why am I not seeing data on my reportportal dashboard.
I only did this using the testNG integration. We do have log4j but didn't needed that to post the tests in RP.
I do not however, have any screenshots or attachments.I think that is log4j integration.
#Chethan Swaroop
TestNG integration will send events as testStarted, testEnded into ReportPortal.
This will help to represent structure of test cases and statuses in RP.
Log4J integration (logger appender) will forward logs output into RP server, associating log line with active test case at the moment.
You can have only testNG integration, without logs (log4j), but you can't have log4j, without testing engine integration (testNG in you case)
Please try examples with you local ReportPortal instance:
https://github.com/reportportal/example-java-TestNG/tree/master/logback/src/main/java/com/epam/rp/tests
I am using Spring Batch Integration as I have to perform certain works before invoking the batch.
I have done the work using Spring Integration and invoke the batch using job-launching-gateway and it works like a charm.
Now the question is how to pass the data from Spring Integration to Batch?
Suggestions please.
The message sent to the JobLaunchingGateway has a JobLaunchRequest payload.
When you build the request in your Spring Integration flow, you can add JobParameters which are then used within the batch job.
EDIT
For custom objects you would have to do it indirectly. For example via a Map.
If you are using XML configuration, you can use a:
<util:map id="jobParams"> ... </...>
Stuff your object into the map under some key, pass the key as a JobParameter, #Autowire the map into your batch job and retrieve/remove the object using the key.
I've set up a CCNet Server with MSBuild and MSTest.
Afterwards I've created a Test Project with some Unit Tests.
The Build is sucessfull, but two of the Unit Tests do fail (on purpose).
I receive an Email that the Build was not successfull (even only the Unit Tests failed).
Is it possible to send a seperated Email (if only the Unit Tests fail) or change the contend of the Email so I can see that only the Unit Tests failed and not the Build itsself?
I look forward to your answer,
with kind regards
Sandor D.
I've appended my ccnet.config with the following code:
<email>
...
<xslFiles>
<xslFile>xsl\header.xsl</xslFile>
<xslFile>xsl\modifications.xsl</xslFile>
<xslFile>xsl\compile-msbuild.xsl</xslFile>
<xslFile>xsl\unittests.xsl</xslFile>
<xslFile>xsl\MsTestReport2008.xsl</xslFile>
<xslFile>xsl\MsTestSummary.xsl</xslFile>
</xslFiles>
</email>
So now I get an output of the passed and failed unit tests in the report email.