Add TCF smoke test

See gh-142
This commit is contained in:
Moritz Halbritter
2022-10-31 15:57:22 +01:00
parent 145b4981fa
commit a0a1b4bee8
10 changed files with 103 additions and 28 deletions

View File

@@ -9,33 +9,11 @@ import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.UseMainMethod;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = WebEnvironment.NONE, useMainMethod = UseMainMethod.ALWAYS, args = "--test.args=1")
class CommandlinerunnerApplicationTests implements ApplicationContextAware {
private ApplicationContext applicationContext;
@Autowired
private CLR clr;
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Test
void contextIsInjected() {
assertThat(this.applicationContext).as("ApplicationContextAware").isNotNull();
}
@Test
void autowiringWorks() {
assertThat(this.clr).as("@Autowired field").isNotNull();
}
class CommandlinerunnerApplicationTests {
@Test
void mainShouldRun() {

View File

@@ -4,7 +4,7 @@ groups:
- batch
- name: boot
smoke_tests:
- actuator-webflux
- actuator-webflux
- actuator-webflux-mgmt-port
- actuator-webmvc
- actuator-webmvc-mgmt-port
@@ -79,6 +79,7 @@ groups:
- rest-template
- rsocket
- scheduled
- tcf
- transactional
- transactional-event-listener
- validation

View File

@@ -0,0 +1 @@
Tests if Spring's TestContext Framework is working

View File

@@ -0,0 +1,16 @@
plugins {
id 'java'
id 'org.springframework.boot'
id 'org.springframework.aot.smoke-test'
id 'org.graalvm.buildtools.native'
}
dependencies {
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
implementation("org.springframework.boot:spring-boot-starter")
testImplementation("org.springframework.boot:spring-boot-starter-test")
appTestImplementation(project(":aot-smoke-test-support"))
appTestImplementation("org.awaitility:awaitility:4.2.0")
}

View File

@@ -0,0 +1,7 @@
package com.example.tcf;
public interface MyService {
void sayHello();
}

View File

@@ -0,0 +1,14 @@
package com.example.tcf;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
class MyServiceConfiguration {
@Bean
MyService myService() {
return new MyServiceImpl();
}
}

View File

@@ -0,0 +1,10 @@
package com.example.tcf;
class MyServiceImpl implements MyService {
@Override
public void sayHello() {
System.out.println("Hello from MyServiceImpl");
}
}

View File

@@ -0,0 +1,13 @@
package com.example.tcf;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TcfApplication {
public static void main(String[] args) {
SpringApplication.run(TcfApplication.class, args);
}
}

View File

@@ -1,15 +1,14 @@
package com.example.commandlinerunner;
package com.example.tcf;
import com.example.commandlinerunner.service.MyService;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@SpringBootTest
@SpringJUnitConfig(MyServiceConfiguration.class)
class MockBeanTests {
@MockBean

View File

@@ -0,0 +1,36 @@
package com.example.tcf;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import static org.assertj.core.api.Assertions.assertThat;
@SpringJUnitConfig(MyServiceConfiguration.class)
class TcfApplicationTests implements ApplicationContextAware {
private ApplicationContext applicationContext;
@Autowired
private MyService myService;
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Test
void contextIsInjected() {
assertThat(this.applicationContext).as("ApplicationContextAware").isNotNull();
}
@Test
void autowiringWorks() {
assertThat(this.myService).as("@Autowired field").isNotNull();
assertThat(this.myService).isInstanceOf(MyServiceImpl.class);
}
}