mule funciton test cases giving error with maven - java

When I run my testcase using righclick on project Run as Junit test Its running fine.
But when I try to run with maven(maven clean install)
I am getting timeout exception.
[![INFO 2016-02-01 16:48:28,900 \[Thread-5\] org.mule.module.xml.filters.SchemaValidationFilter: Schema factory implementation: com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory#3074311d][1]][1]
I am getting continuous above log.

Related

Run jhipster test case individually in STS

I created a spring-boot application using jhipster and open in Spring Studio Tool.
To run Junit cases when I click on any Test File and Run as JUnit, it shows DEBUG : [onnection adder] org.postgresql.ssl.MakeSSL : converting regular socket connection to ssl in console window in JUnit shows Runs 0/0 ,Errors 0, Failures 0 .
How I can run each test case in Jhipster. I write test case like below
#Test
public void saveApplication() throws Exception {
restMockMvc.perform(post("/api/application")
.contentType(MediaType.APPLICATION_JSON)
.content(asJsonString(App)))
.andExpect(status().isOk());
}
and junit only shows Run 1/21 , failed 1 when liquibase lock error comes.

Intellij feature Rerun failed Test giving error

I am running cucumber test cases in bulk.
Suppose I have 5 feature files to run in bulk and one failed out of it.
So in next execution I'm trying to run failed test cases, for that I'm trying to use Intellij provided feature, i.e. Rerun failed Test. So when I click on it, it gives me below error.
Error:
0 test classes found in package 'test.java'
Picked up JAVA_TOOL_OPTIONS: -'path of JAVA_TOOL_OPTION'
Process finished with exit code -2
Empty test suite.

Application context throws error when using spock framework for integration testing in grails 2.5.5 [duplicate]

We have a plugin project with some domain classes and services etc.
We have an application project which uses the plugin project.
This is a common pattern.
Integration test (which hit the DB) cant run in the plugin project, as it has no application context, so we run the integration tests in the main application project.
We have a very simple integration test:
/*#TestFor(Site)*/
class SiteIntegrationSpec extends IntegrationSpec {
static transactional=false;
def setup() {
}
def cleanup() {
}
void "test something"() {
Site site
when:
site = Site.get(1L)
then:
site.name == "root"
}
}
The site is just a domain object, similar to this:
class Site {
String name
// some more fields here
}
NOTE: tried it with TestFor(Site) un-commented also - same error.
If I look in the DB, there are site entries there.
OK, just found another clue. SiteIntegrationSpec test used to work. It worked before we added a second test, ParamIntegrationSpec. If we run either of these tests on their own thusly:
test-app --stacktrace --verbose ParamIntegrationSpec
works
test-app --stacktrace --verbose SiteIntegrationSpec
works
but if we run both of them:
test-app --stacktrace --verbose *IntegrationSpec
The SiteIntegrationSpec test always fails with the above exception.
any ideas?
Full stack trace:
java.lang.IllegalStateException: Could not find ApplicationContext, configure Grails correctly first
at grails.util.Holders.getApplicationContext(Holders.java:97)
at grails.test.spock.IntegrationSpec.$spock_initializeSharedFields(IntegrationSpec.groovy:41)
Note2:
test-app --stacktrace --verbose -integration
gives the same error on Site test.
Thanks to user1690588 I found the problem. Grails IntegrationSpec IllegalStateException gave me the clue: the probem was not in the test which failed, but in the test which passed!
Basically, the ParamIntegrationSpec test had:
#TestFor(ParamService)
This kills any subsequent test. I have no idea what TestFor does, only seen it in all examples.
To fix, just removed that line from the working test.

Integration Tests fail to connect, Manual Browser Test succeeds with Java RESTful Web Service with SpringBoot/Jsoup Integration Test

I'm trying to run the sample code in this book: Building RESTful Web Services with Spring 5 - Second Edition. You can download the sample code for free. In chapter 7, they have some sample code that includes some integration tests and unit tests all in same directory "chapter7\ticketmanagement/src/test/java/com/packtpub/restapp/ticketmanagement/". The unit tests work fine. The integration tests fail with "testUsersJsoup(com.packtpub.restapp.ticketmanagement.JsoupUserTest) Time elapsed: 1.011 sec <<< ERROR!
java.net.ConnectException: Connection refused: connect"
I experimented with changing the port from 8080 to 9090 in "ticket-management\src\main\resources\application.properties" (I also changed the hardcoded values in the integration test) and this did not help.
So "mvn test" produces the above error.
So does running them in spring tool suite.
I edited the original pom.xml and added the "maven-compiler-plugin" to specify java version 1.8. I'm running windows 10.
So the failing code is in "chapter 7\ticket-management\src\test\java\com\packtpub\restapp\ticketmanagement\JsoupUserTest.java".
Here is the failing code:
public void testUsersJsoup() throws IOException {
String doc = Jsoup.connect("http://localhost:9090/user").ignoreContentType(true).get().body().text();
_log.info("{test} doc : " + doc);
JsonParser parser = new JsonParser();
JsonElement userElement = parser.parse(doc);
JsonArray userArray = userElement.getAsJsonArray();
_log.info("{test} size : " + userArray.size());
assertEquals(4, userArray.size());
}
HOWEVER, when I type
mvn spring-boot:run
it starts successfully and I point my chrome browser to http://localhost:9090/user (or http://localhost:8080/user if I am using the original code) I see
[{"userid":100,"username":"David"},{"userid":101,"username":"Peter"},{"userid":102,"username":"John"}]
No connection error! The results look correct.
We know this is not a firewall problem because it is just with localhost and it works with chrome.
There is no proxy involved.
I think the ports are correct: I presently have 9090 in the application.properities file, and in the source code and in the browser.
"mvn clean" and then "mvn test" again did not help.
There are annotations to start the web app as exemplified here:
Spring Live Lessons Tutorial and they work. See %JAVA_BUILDINGMICROSERVICES%\livelessons-security\livelessons-security-basic\src\test\java\basic\BasicSecurityApplicationTests.java.
These annotations have been deprecated, and replaced by newer ones. The problem is that the author of this tutorial is not using theses new annotations correctly: he needs to also use #WebAppConfiguration and this requires some configuration arguments from the #SpringBootTest (which he is missing). Therefor it necessary to manually start the web server with "mvn spring-boot:run" in a separate process and then run the tests.
When I tried to use #WebAppConfiguation, I got other errors. I will document these errors in another post (some day).

Terminating an AWS Code Deployment with Java jar return value

I have an aws instance running with webservices that I want to test with a java application running JUnit. If I have a script that runs the jar during the validate services step of the code deploy process how does the code deployment handle the return value of the jar if a test fails?
Is it required that I catch exceptions thrown by the jar for the failing tests and call system.exit(-1) to have the script terminate the code deployment or does the exception thrown automatically give the return value of non-zero?
If you are running JUnit using JunitCore, it should return a non-zero exit code if any of the tests fail.
main
public static void main(String... args)
Run the tests contained in the classes named in the args. If all tests run successfully, exit with a status of 0. Otherwise exit with a status of 1. Write feedback while tests are running and write stack traces for all failed tests after the tests all complete.
Parameters:
args - names of classes in which to find tests to run
From: http://junit.org/apidocs/org/junit/runner/JUnitCore.html#main%28java.lang.String...%29

Categories