Failed test in jenkins maven - maven

i have a problem with maven in jenkins. When I building application using maven in jenkis, I got error:
[ERROR] Failures:
[ERROR] MessageResourceIT.Should add Message to Room:49 Condition not satisfied:
response.getStatusCode() == HttpStatus.CREATED
| | | |
| 403 FORBIDDEN false 201 CREATED
It looks like a normal failed test, but when I building application in my computer, test is correct.
My test:
def "Should add Message to Room"() {
given:
Room room = roomHelper.room()
participantHelper.participant(room.id, user.id)
AddMessageRequest request = messageHelper.addMessageRequest()
String url = UriComponentsBuilder.fromPath('/room/{roomId}/message')
.buildAndExpand(room.id)
HttpEntity payload = new HttpEntity<>(request, userHeaders)
when:
ResponseEntity<MessageResponse> response = restTemplate.exchange(url, HttpMethod.POST, payload, MessageResponse.class)
then:
response.getStatusCode() == HttpStatus.CREATED
response.body
MessageResponse messageResponse = response.body
messageResponse.content == request.content
}
my setup:
def setup() {
String userLogin = 'test'
String userPassword = 'test'
user = userHelper.user(userPassword, userLogin)
userHeaders = securityHelper.securityHeader(userLogin, userPassword)
}
It's look as jenkins running tests asynchronously and another test removed users when this test is running.
I using maven-failsafe-plugin:
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<skipITs>false</skipITs>
<includes>
<include>%regex[.*IT.*]</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
Anyone have an idea what can happen and how to fix it?

Related

OpenApi generator generates spring boot 2 server controller interface with incorrect(?) Flux / Mono response types

I'm trying to generate controller interface with Flux / Mono types(I'm doing refactor to WebFlux).
Here is my openapi spec part:
/api/courses:
get:
tags:
- RestCourse
summary: Provides all courses
operationId: getAll
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ApiCourse'
Part of pom.xml:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>6.0.1</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<generatorName>spring</generatorName>
<!--<templateDirectory>${project.basedir}/templates</templateDirectory>-->
<configOptions>
<dateLibrary>java8</dateLibrary>
<!--<useSpringController>true</useSpringController>-->
<interfaceOnly>true</interfaceOnly>
<sourceFolder>src/java/main</sourceFolder>
<modelPackage>spring.learn.api.model</modelPackage>
<apiPackage>spring.learn.api.controller</apiPackage>
<useTags>true</useTags>
<unhandledException>true</unhandledException>
<openApiNullable>false</openApiNullable>
<reactive>true</reactive>
<!--<library>spring-boot</library>-->
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Generated result is:
default Mono<ResponseEntity<Flux<ApiCourse>>> getAll(...
But i think should be:
default Flux<ResponseEntity<ApiCourse>> getAll(...
Or I'm wrong?
These types are correct, I had the same question. Here's what the documentation has to say about it:
Mono<ResponseEntity<Mono<T>>> or Mono<ResponseEntity<Flux<T>>> are yet another possible, albeit less common alternative. They provide the response status and headers asynchronously first and then the response body, also asynchronously, second.

Maven Exec Plugin : Can't write a command output to a file

I want to use Maven Exec Plugin in order to write a command output to a file,
I was only able to do it by running a shell command that the plugin is invoking.
This is the shell script:
git rev-parse --abbrev-ref HEAD > branch.txt
This is my pom.xml:
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<inherited>false</inherited>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>5.3.21</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>gitbranch.sh</executable>
<workingDirectory>${basedir}</workingDirectory>
</configuration>
</plugin>
When trying to run it as a command and not using a script , I can't get to be written into a file:
<configuration>
<executable>git</executable>
<outputFile>branching.txt</outputFile>
<arguments>
<argument>rev-parse</argument>
<argument>--abbrev-ref</argument>
<argument>HEAD</argument>
</arguments>
<workingDirectory>${basedir}</workingDirectory>
</configuration>
I also tried to run echo "something" > file.txt using this plugin, but nothing is writing anything in to a file.
This may not directly answer your question but I use maven git commit id plugin to do the same thing you want to do. I have:
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<useNativeGit>true</useNativeGit>
<dateFormat>yyyy-MM-dd'T'HH:mm:ssXXX</dateFormat>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
</configuration>
</plugin>
in my build/plugins section of my pom.xml. When I run this I get the file named git.properties generated in my target/classes directory that contains:
#Generated by Git-Commit-Id-Plugin
#Wed Jul 06 11:51:45 MDT 2022
git.branch=feature/test-branch
git.build.host=bluerock
git.build.time=2022-07-06T11\:51\:45-06\:00
git.build.user.email=
git.build.user.name=
git.build.version=1.0
git.closest.tag.commit.count=
git.closest.tag.name=
git.commit.id=c991301b1a88e6cd138d347c46e3479d34b6f24d
git.commit.id.abbrev=c991301
git.commit.id.describe=c991301
git.commit.id.describe-short=c991301
git.commit.message.full=cleaned up a bit
git.commit.message.short=cleaned up a bit
git.commit.time=2020-09-29T11\:48\:58-06\:00
git.commit.user.email=myemail#example.tld
git.commit.user.name=First Last
git.dirty=false
git.remote.origin.url=<the git url>
git.tags=
git.total.commit.count=4
Then, in my code base I have:
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class VersionInfo {
public String getVersionString() {
try {
Properties properties = getGitProperties();
boolean isDirty = false;
String gitDirty = properties.getProperty( "git.dirty" );
if( gitDirty != null )
isDirty = Boolean.parseBoolean(gitDirty);
return "built \"" + properties.getProperty("git.build.time") +
"\" in branch \"" + properties.getProperty("git.branch") +
"\" with short commit id \"" + properties.getProperty("git.commit.id.describe-short") + "\"" +
", isDirty is " + isDirty +
" remote url is \"" + properties.getProperty("git.remote.origin.url") + "\"";
}
catch( IOException ioe ) {
return( "can't locate git.properties on the class path");
}
}
private Properties getGitProperties() throws IOException {
Properties properties = new Properties();
try (InputStream inputStream = this.getClass().getResourceAsStream("/git.properties")) {
if (inputStream == null)
throw new IOException("Can't locate properties file to generate version info");
properties.load(inputStream);
return properties;
}
}
}
This allows me to print out information about the git environment as part of a startup string or do what you want with it. Again

OpenApi generator not generating the "description" tag

Given the below (snippet) of my spec
paths:
/login:
post:
summary: "Method to login to obtain a JWT token"
description: "Some description"
operationId: login
tags:
- login
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Credentials"
application/xml:
schema:
$ref: "#/components/schemas/Credentials"
and using the maven plugin with following config
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.4.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/resources/spec.yaml
</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.company.api</apiPackage>
<modelPackage>com.company.model</modelPackage>
<modelNameSuffix>DTO</modelNameSuffix>
<typeMappings>
<typeMapping>Pageable=org.springframework.data.domain.Pageable</typeMapping>
<typeMapping>OffsetDateTime=LocalDateTime</typeMapping>
</typeMappings>
<importMappings>
<importMapping>java.time.OffsetDateTime=java.time.LocalDateTime</importMapping>
</importMappings>
<configOptions>
<dateLibrary>java8</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
The generated code looks like (cleaned up a bit to the relevant parts)
/**
* POST /login : Method to login to obtain a JWT token
* Some description
*
* #param credentialsDTO (optional)
* #return Login success (status code 200)
* or Unexpected error (status code 500)
*/
#Operation(
operationId = "login",
summary = "Method to login to obtain a JWT token",
tags = { "login" }
)
#RequestMapping(
method = RequestMethod.POST,
value = "/login",
produces = { "application/json", "application/xml" },
consumes = { "application/json", "application/xml" }
)
ResponseEntity<JWTTokenDTO> login(...)
);
As shown, the 'description' from the spec is used to generate the JavaDoc, but in fact I'm expecting it to generate the 'description' attribute on #Operation tag.
I've searched for solutions, but I could not find the solution.
How can I correct this ?
Thanks in advance.
Unfortunately that can not be done simply by adjusting plugin configuration. Instead one must modify templates.
In this specific case it can be done as follows:
Fetch original template from: https://github.com/OpenAPITools/openapi-generator/blob/v5.4.0/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache
Store it to src/main/resources/openapi/templates/api.mustache
Add templateDirectory to plugin configuration:
<configuration>
...
<templateDirectory>${project.basedir}/src/main/resources/openapi/templates</templateDirectory>
</configuration>
Locate part of api.mustache that is template for #Operation from api.mustache (starts from line 130)
#Operation(
operationId = "{{{operationId}}}",
{{#summary}}
summary = "{{{.}}}",
{{/summary}}
Add description attribute there (value comes from notes):
#Operation(
operationId = "{{{operationId}}}",
{{#summary}}
summary = "{{{.}}}",
{{/summary}}
{{#notes}}
description = "{{{.}}}",
{{/notes}}
More information about templating is available here: Using Templates

swagger-maven-plugin no definition generated of input objects

I try to generate the swagger.json of the following, using swagger-maven-plugin:
#Timed
#Path("_list")
#POST
#Produces(UTF8JSON)
#Consumes(UTF8JSON)
#ApiOperation(value = "List", produces = UTF8JSON, notes = "List the Scenes, given the filters", consumes = UTF8JSON, response = Scene.class)
#ApiResponses(value =
{#ApiResponse(code = 200, message = "Successful operation", response = Scene.class, responseContainer = "Object"),
#ApiResponse(code = 500, message = "Server Error.", response = Error.class),
#ApiResponse(code = 400, message = "Bad request.", response = Error.class)})
public Response list(
// --------------------------------------------------------
// ----------------------- FORM -----------------------
// --------------------------------------------------------
#ApiParam(name = "pretty", value = Documentation.FORM_PRETTY,
allowMultiple = false,
defaultValue = "false",
required = true,
type = "Search")
#QueryParam(value = "pretty") Boolean pretty,
// --------------------------------------------------------
// ----------------------- SEARCH -----------------------
// --------------------------------------------------------
#ApiParam(name = "search",
value = "The search",
allowMultiple = false,
required = true)
#QueryParam(value = "search")
Search search
) throws InterruptedException, ExecutionException, IOException, NotFoundException, IllegalArgumentException {
Then in maven I simply set:
<plugin>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>${swagger-maven-plugin.version}</version>
<configuration>
<apiSources>
<apiSource>
<locations>
<location>com.my.project.rest.server</location>
</locations>
<info>
<title>${swagger.rest.title}</title>
<version>${project.version}</version>
</info>
<swaggerDirectory>${project.build.directory}</swaggerDirectory>
</apiSource>
</apiSources>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
My problem is that, in the produced swagger.json, the Search object definition isn't the present. When I generate the client code with swagger-codegen-maven-plugin, I cannot request because Search is missing.
When I look at the swagger runtime generated swagger.json, the definition is yet OK with. What am I missing to make it generate also the input paramaters objects?
Thx.

Maven yuicompressor-plugin generates minified js encoded in ANSI

I'm trying to minify a group of js files with maven's yuicompressor-plugin. One of this files has to be encoded in UTF-8 because it has special characters:
String.prototype.removeTicks = function (/*thisArg */) {
var __r =
{
'À':'A','Á':'A','Â':'A','Ã':'A','Ä':'A','Å':'A','Æ':'E',
'È':'E','É':'E','Ê':'E','Ë':'E',
'Ì':'I','Í':'I','Î':'I',
'Ò':'O','Ó':'O','Ô':'O','Ö':'O',
'Ù':'U','Ú':'U','Û':'U','Ü':'U',
'N':'N'
};
return this.replace(/[ÀÁÂÃÄÅÆÈÉÊËÌÍÎÒÓÔÖÙÚÛÜÑ]/gi, function(m)
{
var ret = __r[m.toUpperCase()];
if (ret && m === m.toLowerCase())
ret = ret.toLowerCase();
return ret;
});
};
But, when I run the compressor the output file is encoded in ANSI and all special characters are broken. I tried to configure the charset encoding in the plugin configuration and change all files to UTF-8, but none of this work. Here is the pom extract:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<nosuffix>true</nosuffix>
<nocompress>true</nocompress>
<sourceDirectory>${basedir}/../../public</sourceDirectory>
<outputDirectory>${basedir}/target</outputDirectory>
<encoding>UTF-8</encoding>
<aggregations>
<aggregation>
<removeIncluded>true</removeIncluded>
<output>${basedir}/target/${project.build.finalName}/js/custom.js</output>
<inputDir>${basedir}/target/js</inputDir>
<includes>
<include>util/string/string.js</include>
<include>...</include>
</includes>
</aggregation>
</aggregations>
</configuration>
</plugin>
Anyone ever had this problem and solved it?
Make sure you placed the correct charset in tag for the script you are injecting. This might work.
<script src="foo.js" type="text/javascript" charset="utf-8"></script>

Resources