-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into unit-test-bot/rc2023.10
- Loading branch information
Showing
21 changed files
with
421 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
utbot-spring-framework/src/main/kotlin/org/utbot/external/api/UtBotSpringApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.utbot.external.api | ||
|
||
import org.utbot.framework.context.ApplicationContext | ||
import org.utbot.framework.context.simple.SimpleApplicationContext | ||
import org.utbot.framework.context.spring.SpringApplicationContext | ||
import org.utbot.framework.context.spring.SpringApplicationContextImpl | ||
import org.utbot.framework.plugin.api.SpringConfiguration | ||
import org.utbot.framework.plugin.api.SpringSettings | ||
import org.utbot.framework.plugin.api.SpringTestType | ||
import org.utbot.framework.process.SpringAnalyzerTask | ||
import java.io.File | ||
|
||
object UtBotSpringApi { | ||
private val springBootConfigAnnotations = setOf( | ||
"org.springframework.boot.autoconfigure.SpringBootApplication", | ||
"org.springframework.boot.SpringBootConfiguration" | ||
) | ||
|
||
/** | ||
* NOTE: [classpath] should include project under test classpath (with all dependencies) as well as | ||
* `spring-test`, `spring-boot-test`, and `spring-security-test` if respectively `spring-beans`, | ||
* `spring-boot`, and `spring-security-core` are dependencies of project under test. | ||
* | ||
* UtBot doesn't add Spring test modules to classpath automatically to let API users control their versions. | ||
*/ | ||
@JvmOverloads | ||
@JvmStatic | ||
fun createSpringApplicationContext( | ||
springSettings: SpringSettings, | ||
springTestType: SpringTestType, | ||
classpath: List<String>, | ||
delegateContext: ApplicationContext = SimpleApplicationContext() | ||
): SpringApplicationContext { | ||
if (springTestType == SpringTestType.INTEGRATION_TEST) { | ||
require(springSettings is SpringSettings.PresentSpringSettings) { | ||
"Integration tests can't be generated without Spring settings" | ||
} | ||
val configuration = springSettings.configuration | ||
require(configuration !is SpringConfiguration.XMLConfiguration) { | ||
"Integration tests aren't supported for XML configurations, consider using Java " + | ||
"configuration that imports your XML configuration with @ImportResource" | ||
} | ||
} | ||
return SpringApplicationContextImpl.internalCreate( | ||
delegateContext = delegateContext, | ||
beanDefinitions = when (springSettings) { | ||
SpringSettings.AbsentSpringSettings -> listOf() | ||
is SpringSettings.PresentSpringSettings -> SpringAnalyzerTask(classpath, springSettings).perform() | ||
}, | ||
springTestType = springTestType, | ||
springSettings = springSettings, | ||
) | ||
} | ||
|
||
@JvmStatic | ||
fun createXmlSpringConfiguration(xmlConfig: File): SpringConfiguration.XMLConfiguration = | ||
SpringConfiguration.XMLConfiguration(xmlConfig.absolutePath) | ||
|
||
@JvmStatic | ||
fun createJavaSpringConfiguration(javaConfig: Class<*>): SpringConfiguration.JavaBasedConfiguration = | ||
if (javaConfig.annotations.any { it.annotationClass.java.name in springBootConfigAnnotations }) { | ||
SpringConfiguration.SpringBootConfiguration(javaConfig.name, isDefinitelyUnique = false) | ||
} else { | ||
SpringConfiguration.JavaConfiguration(javaConfig.name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer | ||
import com.github.jengelman.gradle.plugins.shadow.transformers.PropertiesFileTransformer | ||
|
||
plugins { | ||
id("com.github.johnrengelman.shadow") version "7.1.2" | ||
id("java") | ||
} | ||
|
||
val springBootVersion: String by rootProject | ||
|
||
dependencies { | ||
implementation("org.projectlombok:lombok:1.18.20") | ||
annotationProcessor("org.projectlombok:lombok:1.18.20") | ||
|
||
implementation(group = "org.springframework.boot", name = "spring-boot-starter-web", version = springBootVersion) | ||
implementation(group = "org.springframework.boot", name = "spring-boot-starter-data-jpa", version = springBootVersion) | ||
implementation(group = "org.springframework.boot", name = "spring-boot-starter-test", version = springBootVersion) | ||
} | ||
|
||
tasks.shadowJar { | ||
isZip64 = true | ||
|
||
transform(Log4j2PluginsCacheFileTransformer::class.java) | ||
archiveFileName.set("utbot-spring-sample-shadow.jar") | ||
|
||
// Required for Spring to run properly when using shadowJar | ||
// More details: https://github.com/spring-projects/spring-boot/issues/1828 | ||
mergeServiceFiles() | ||
append("META-INF/spring.handlers") | ||
append("META-INF/spring.schemas") | ||
append("META-INF/spring.tooling") | ||
transform(PropertiesFileTransformer().apply { | ||
paths = listOf("META-INF/spring.factories") | ||
mergeStrategy = "append" | ||
}) | ||
} | ||
|
||
val springSampleJar: Configuration by configurations.creating { | ||
isCanBeResolved = false | ||
isCanBeConsumed = true | ||
} | ||
|
||
artifacts { | ||
add(springSampleJar.name, tasks.shadowJar) | ||
} |
7 changes: 7 additions & 0 deletions
7
...g-sample/src/main/java/org/utbot/examples/spring/config/boot/ExampleSpringBootConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.utbot.examples.spring.config.boot; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class ExampleSpringBootConfig { | ||
} |
11 changes: 11 additions & 0 deletions
11
...-sample/src/main/java/org/utbot/examples/spring/config/boot/ExampleSpringBootService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.utbot.examples.spring.config.boot; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.utbot.examples.spring.config.utils.SafetyUtils; | ||
|
||
@Service | ||
public class ExampleSpringBootService { | ||
public ExampleSpringBootService() { | ||
SafetyUtils.shouldNeverBeCalled(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...g-sample/src/main/java/org/utbot/examples/spring/config/pure/ExamplePureSpringConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.utbot.examples.spring.config.pure; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Profile; | ||
import org.utbot.examples.spring.config.utils.SafetyUtils; | ||
|
||
public class ExamplePureSpringConfig { | ||
@Bean(name = "exampleService0") | ||
public ExamplePureSpringService exampleService() { | ||
SafetyUtils.shouldNeverBeCalled(); | ||
return null; | ||
} | ||
|
||
@Bean(name = "exampleServiceTest1") | ||
@Profile("test1") | ||
public ExamplePureSpringService exampleServiceTest1() { | ||
SafetyUtils.shouldNeverBeCalled(); | ||
return null; | ||
} | ||
|
||
@Bean(name = "exampleServiceTest2") | ||
@Profile("test2") | ||
public ExamplePureSpringService exampleServiceTest2() { | ||
SafetyUtils.shouldNeverBeCalled(); | ||
return null; | ||
} | ||
|
||
@Bean(name = "exampleServiceTest3") | ||
@Profile("test3") | ||
public ExamplePureSpringService exampleServiceTest3() { | ||
SafetyUtils.shouldNeverBeCalled(); | ||
return null; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...-sample/src/main/java/org/utbot/examples/spring/config/pure/ExamplePureSpringService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.utbot.examples.spring.config.pure; | ||
|
||
public class ExamplePureSpringService { | ||
} |
15 changes: 15 additions & 0 deletions
15
utbot-spring-sample/src/main/java/org/utbot/examples/spring/config/utils/SafetyUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.utbot.examples.spring.config.utils; | ||
|
||
public class SafetyUtils { | ||
|
||
private static final int UNEXPECTED_CALL_EXIT_STATUS = -1182; | ||
|
||
/** | ||
* Bean constructors and factory methods should never be executed during bean analysis, | ||
* hence call to this method is added into them to ensure they are actually never called. | ||
*/ | ||
public static void shouldNeverBeCalled() { | ||
System.err.println("shouldNeverBeCalled() is unexpectedly called"); | ||
System.exit(UNEXPECTED_CALL_EXIT_STATUS); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...t-spring-sample/src/main/java/org/utbot/examples/spring/config/xml/ExampleXmlService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.utbot.examples.spring.config.xml; | ||
|
||
import org.utbot.examples.spring.config.utils.SafetyUtils; | ||
|
||
public class ExampleXmlService { | ||
public ExampleXmlService() { | ||
SafetyUtils.shouldNeverBeCalled(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" | ||
"http://www.springframework.org/dtd/spring-beans-2.0.dtd"> | ||
|
||
<beans> | ||
|
||
<bean id="xmlService" class="org.utbot.examples.spring.config.xml.ExampleXmlService"/> | ||
|
||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.