Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#464): Add Integration Test For Spring Boot Application That Still Fails #476

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/it/spring-fat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Spring Fat Jar Integration Test

Integration test that checks the correct transformation of an application
written with using of the Springs Framework. This integration test starts the
application with several beans and prints results to the console.
This is a similar integration test with the "spring" test in
the [spring](../spring) test.

The only difference is that in this test we download all the dependencies,
unpack them, transform using jeo-maven-plugin and then pack them back. In other
words, we test the fat jar transformation.

If you need to run only this test, use the following command:
```shell
mvn clean integration-test invoker:run -Dinvoker.test=spring-fat -DskipTests
```
1 change: 1 addition & 0 deletions src/it/spring-fat/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=clean process-classes -e
135 changes: 135 additions & 0 deletions src/it/spring-fat/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License (MIT)

Copyright (c) 2016-2023 Objectionary.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!--
The version of 3.2.0 and similar requires rather high java
version: 17 or higher. So we intentionally use the version 2.7.18
here that requires java 11 since our plugin should be compatible with
java 11.
-->
<version>2.7.18</version>
<relativePath/>
</parent>
<groupId>org.eolang</groupId>
<artifactId>jeo-spring-fat-it</artifactId>
<version>@project.version@</version>
<packaging>jar</packaging>
<description>
Integration test that checks correct transformation of an application written with using of the Springs Framework.
This integration test starts the application with several beans and prints results to the console.
This is a similar integration test with the "spring" test in the "src/it/spring" test.
The only difference is that in this test we download all the dependencies, unpack them, transform using jeo-maven-plugin
and then pack them back. In other words, we test the fat jar transformation.
If you need to run only this test, use the following command:
"mvn clean integration-test invoker:run -Dinvoker.test=spring-fat -DskipTests"
</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eolang</groupId>
<artifactId>jeo-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<!--
@todo #464:90min Enable 'spring-fat' Integration Test.
Currently, the 'spring-fat' integration test is disabled because
it fails. The reason is that the 'jeo-maven-plugin' does not
support many java features. We need to implement them and enable
the test.
-->
<disabled>true</disabled>
</configuration>
<executions>
<execution>
<id>bytecode-to-eo</id>
<goals>
<goal>disassemble</goal>
</goals>
</execution>
<execution>
<id>eo-to-bytecode</id>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>
process-classes
</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<argument>${project.build.outputDirectory}</argument>
<argument>org.eolang.jeo.spring.Application</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2023 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.jeo.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Spring Application Entry Point.
* @since 0.2
*/
@SpringBootApplication
public class Application implements CommandLineRunner {

@Autowired
private Receptionist receptionist;

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

@Override
public void run(final String... args) {
this.receptionist.sayHello("Fat Spring");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2023 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.jeo.spring;

import org.springframework.stereotype.Component;

/**
* Greeter bean.
* @since 0.2
*/
@Component
public class Receptionist {
public void sayHello(final String who) {
System.out.printf("Glad to see you, %s...%n", who);
}
}
31 changes: 31 additions & 0 deletions src/it/spring-fat/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2016-2023 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
//Check logs first.
String log = new File(basedir, 'build.log').text;
assert log.contains("BUILD SUCCESS")
assert log.contains("Glad to see you, Fat Spring...")
//Check that we have generated EO object files.
//assert new File(basedir, 'target/generated-sources/jeo-xmir/org/eolang/jeo/spring/Application.xmir').exists()
//assert new File(basedir, 'target/generated-sources/jeo-xmir/org/eolang/jeo/spring/Receptionist.xmir').exists()
true
11 changes: 11 additions & 0 deletions src/it/spring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Spring Fat Jar Integration Test

Integration test that checks the correct transformation of an application
written with using of the Springs Framework. This integration test starts the
application with several beans and prints results to the console.

If you need to run only this test, use the following command:

```shell
mvn clean integration-test invoker:run -Dinvoker.test=spring -DskipTests
```
2 changes: 1 addition & 1 deletion src/it/spring/invoker.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
invoker.goals = clean spring-boot:run -e
invoker.goals=clean spring-boot:run -e
5 changes: 2 additions & 3 deletions src/it/spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ SOFTWARE.
<version>@project.version@</version>
<packaging>jar</packaging>
<description>
Integration test that checks correct transformation simple Java application
written with using Springs Framework. This application starts application
with several beans and prints results to the console.
Integration test that checks correct transformation of an application written with using of the Springs Framework.
This integration test starts the application with several beans and prints results to the console.
If you need to run only this test, use the following command:
"mvn clean integration-test invoker:run -Dinvoker.test=spring -DskipTests"
</description>
Expand Down
28 changes: 23 additions & 5 deletions src/main/java/org/eolang/jeo/AssembleMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.eolang.jeo;

import com.jcabi.log.Logger;
import java.io.File;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.AbstractMojo;
Expand Down Expand Up @@ -89,15 +90,32 @@ public final class AssembleMojo extends AbstractMojo {
)
private boolean skipVerification;

/**
* Whether the plugin is disabled.
* If it's disabled, then it won't do anything.
*
* @since 0.2.0
* @checkstyle MemberNameCheck (6 lines)
*/
@Parameter(
property = "jeo.disassemble.disabled",
defaultValue = "false"
)
private boolean disabled;

@Override
public void execute() throws MojoExecutionException {
try {
new PluginStartup(this.project).init();
new Assembler(
this.sourcesDir.toPath(),
this.outputDir.toPath(),
!this.skipVerification
).assemble();
if (this.disabled) {
Logger.info(this, "Assemble mojo is disabled. Skipping.");
} else {
new Assembler(
this.sourcesDir.toPath(),
this.outputDir.toPath(),
!this.skipVerification
).assemble();
}
} catch (final DependencyResolutionRequiredException exception) {
throw new MojoExecutionException(exception);
}
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/org/eolang/jeo/DisassembleMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.eolang.jeo;

import com.jcabi.log.Logger;
import java.io.File;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.AbstractMojo;
Expand Down Expand Up @@ -78,13 +79,30 @@ public final class DisassembleMojo extends AbstractMojo {
)
private File outputDir;

/**
* Whether the plugin is disabled.
* If it's disabled, then it won't do anything.
*
* @since 0.2.0
* @checkstyle MemberNameCheck (6 lines)
*/
@Parameter(
property = "jeo.disassemble.disabled",
defaultValue = "false"
)
private boolean disabled;

@Override
public void execute() throws MojoExecutionException {
try {
new PluginStartup(this.project).init();
new Disassembler(
this.sourcesDir.toPath(), this.outputDir.toPath()
).disassemble();
if (this.disabled) {
Logger.info(this, "Disassemble mojo is disabled. Skipping.");
} else {
new Disassembler(
this.sourcesDir.toPath(), this.outputDir.toPath()
).disassemble();
}
} catch (final DependencyResolutionRequiredException exception) {
throw new MojoExecutionException(
String.format(
Expand Down
Loading