AssertJ Swagger test is stuck on executing - spring-mvc

I'm trying to adopt Swagger in REST API development (Spring Boot web application). API documenting process and code generation based on swagger spec works good, and now I've faced a problem writing integration tests using assertj-swagger and SpringFox libraries.
A few little words about these libraries. Springfox works by examining an application, once, at runtime to infer API semantics based on Spring configurations, class structure and various compile time java annotations. The swagger-assertj test library should compare a contract-first Swagger YAML file with a code-first Swagger JSON generated by SpringFox. For Consumer Driven Contract tests, assertj-swagger fails a test if it finds missing resources, methods, models, or properties in the implementation which are required by the consumer specification.
My test looks like (test code is taken from GitHub example):
#RunWith(SpringRunner.class)
#SpringBootTest
public class AssertJSwaggerConsumerDrivenTest {
#Test
public void validateThatImplementationSatisfiesConsumerSpecification() {
String designFirstSwagger = AssertJSwaggerConsumerDrivenTest.class.getResource("/swagger.yaml").getPath();
SwaggerAssertions.assertThat("http://localhost:8080/v2/api-docs")
.satisfiesContract(designFirstSwagger);
}
}
The problem is that this test is executed for a long time and seems to get stuck cause I don't see any log output after this line:
INFO c.s.e.AssertJSwaggerConsumerDrivenTest : Started AssertJSwaggerConsumerDrivenTest in 24.03 seconds (JVM running for 26.774)
I'm sure that SpringFox is working, cause I see JSON after opening GET http://localhost:8080/v2/api-docs in my browser.
I have no compile-time or build-time errors when running test, cause Maven resolved dependencies and Spring Boot context is initialized successfully.
Is there anybody experienced in using assertj-swagger cause it looks like I'm doing something wrong?

I've managed to run my AssertJSwaggerConsumerDrivenTest! I think I've never been so happy to see a lot of red test results before =) Anyway it's better than running test forever.
AssertJ-Swagger's readme is a little bit outdated. Here's what I changed to fix the problem.
Test code:
#RunWith(SpringRunner.class)
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class AssertJSwaggerConsumerDrivenTest {
#LocalServerPort
int randomPort;
#Test
public void validateThatImplementationSatisfiesConsumerSpecification() {
File designFirstSwagger = new File(AssertJSwaggerConsumerDrivenTest.class.getResource("/swagger.yaml").getFile());
SwaggerAssertions.assertThat("http://localhost:" + randomPort + "/v2/api-docs")
.satisfiesContract(designFirstSwagger.getAbsolutePath());
}
}
pom.xml:
<dependency>
<groupId>io.github.robwin</groupId>
<artifactId>assertj-swagger</artifactId>
<version>0.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-parser</artifactId>
<version>1.0.30</version>
<scope>test</scope>
</dependency>
Also I got java.lang.OutOfMemoryError: Permgen space so I had to add this -XX:MaxPermSize=384m to VM options.

Related

fallbackTag doesn't work and code throws NoPactsFoundException

I am using 4.1.11 version of junit5 provider.
<dependency>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>junit5</artifactId>
<version>4.1.11</version>
</dependency>
As per the documentation, I am specifying both tag and fallbackTag in my provider test class.
consumerVersionSelectors = {
#VersionSelector(tag = "branch123", fallbackTag = "master")
}
Now its supposed to use master tag contract if branch123 tag contract doesn't exist. However it doesn't work me and throws following error:
au.com.dius.pact.provider.junitsupport.loader.NoPactsFoundException: No Pact files were found to verify
I can confirm that master tag does exist from pact broker as well as using that in tag field and running the test successfully.
Is this a bug in library? Or am I missing anything?
Looking at code of VersionSelector, it seems that does have fallbackTag() method, however when I go into PactBroker, consumerVersionSelectors() method doesn't seem to have any reference of fallbackTag:
https://github.com/pact-foundation/pact-jvm/blob/4_1_11/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/VersionSelector.java
https://github.com/pact-foundation/pact-jvm/blob/4_1_11/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/PactBroker.java
Thanks.
It looks and sounds like a bug - could you please raise it on the Pact JVM issues register?

I want to use CDI with Java SE 12, but start up failes (Main Class, JBoss or Payara, all the same error)

I got completely stuck. I want to use CDI2 with Servlets to write a simple web app. However, the beans not get loaded.
I get the following error in JBoss or Payara or Weld (if running as Main Application):
WELD-001524: Unable to load proxy class for bean Managed Bean [class MyBean] with qualifiers [#Any #Default]
Does anyone still use CDI2 or has a running modern example?
I compile with maven.
warm regards,
Alex
I found it out myself. I had the wrong dependencies. I got confused because of Jakarta. I used the CDI-2 maven dependency. So I updated to Jakarta. Right? This is the way to go, right?
I can deploy. Payara-Micro works. JBoss (WildFly should do the same)
However, Payara Micro does not get track of the URL patterns of simple Servlets, although still, one can call it over the client. (Intellij has a CDI tab, gives a nice overview itself)
...
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>

can we deploy wiremock code in jboss server

I am trying to mock the objects returning from the server to the client. So I need to deploy my Wiremock Code in Server. So is this possible or is there any other way to achieve this scenario?
And I am completely new to Wiremock. So How can I run this on JBoss?
I followed the method of running wiremock-standalone jar and I am able to capture my request and response.
But my main question is, can I able to get mock responses from #Test methods?
You could use Arquillian to test JBoss. You can test microservices using this approach and use Jboss Forge ~ another tool, to speed up the testing/dev. The start guide with Forge is here.
You will just need to add on the pom.xml the dependency for Arquillian:
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
<version>1.0.0.CR9</version>
<scope>test</scope>
</dependency>
To avoid any library clash you can use the standalone version of WireMock. I used it with wildly (JBoss AS) adding the following dependency:
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8-standalone</artifactId>
<version>2.27.2</version>
<scope>test</scope>
</dependency>
For further information see http://wiremock.org/docs/download-and-installation/
What you've done with wiremock-standalone is very similar to what arquillian does in an integration test. You write your server code then you test it inside a container using a client extension.
Try reading the documentation at http://arquillian.org/arquillian-core/

Throwing Validation Exception in Spring boot

I am creating a Spring boot project for testing my rest API (Very Very tiny Project). The Project contains three files.
1) App.java (Main Program)
2) AppConfig (Configuration file)
3) Main Controller (Simple Rest controller)
I added Spring-boot-starter-parent (1.4.0.RELEASE) and spring-boot-starter-web as dependency.
But While executing,getting an exception like follows.
"javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath."
I added the following dependency and the error gone.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.4.Final</version>
</dependency>
My question is, what is the root cause of the specific error message?
Why we are adding the validator?
It means the classloader could only find the API of bean validator. You have to add some implementation package into the classpath.
Like:
org.glassfish.jersey.ext:jersey-bean-validation

When Spring Boot application running by Intelij Idea views can`t be resolved

I have encountered a strange situation, the decision which I cant find.
I`m runnig simple demo application using Spring Boot 1.3.0 and Intelij Idea 14.1.3
The problem is that Spring MVC cant resolve the view:
javax.servlet.ServletException: Could not resolve view with name 'home' in servlet with name 'dispatcherServlet'
Oddity is that when I run application by Maven Spring Boot-plugin
mvn clean spring-boot:run
everythig works fine.
Both views ("home.jsp" - returning from Controller and "start.jsp" - described in Configuration class) resolve correctly.
Full source code you can see here
I`ve downloaded another demo project - the same situation.
So, I think that something wrong with my IDE configuration.
But what is going wrong - I don`t know.
In File->Project Structure
I have added Spring and web module in "Modules" tab, the same I`ve made in "Facets" tab.
What is possible to do to make application run correctly using IDE?
Problem was in dependecies configuration in pom.xml
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
I have change <scope>provided</scope> to <scope>compile</scope> and it works well.

Resources