diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/XmlBeanApplication.java b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/XmlBeanApplication.java new file mode 100644 index 0000000000..ddf1efd396 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/XmlBeanApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.xmlapplicationcontext; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ImportResource; + +@SpringBootApplication +@ImportResource({"classpath*:application-context.xml"}) +public class XmlBeanApplication { + + public static void main(String[] args) { + SpringApplication.run(XmlBeanApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/domain/Employee.java b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/domain/Employee.java new file mode 100644 index 0000000000..f81277f027 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/domain/Employee.java @@ -0,0 +1,32 @@ +package com.baeldung.xmlapplicationcontext.domain; + +public class Employee { + + private String name; + private String role; + + public Employee() { + + } + + public Employee(String name, String role) { + this.name = name; + this.role = role; + } + + public String getName() { + return this.name; + } + + public String getRole() { + return this.role; + } + + public void setName(String name) { + this.name = name; + } + + public void setRole(String role) { + this.role = role; + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeService.java b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeService.java new file mode 100644 index 0000000000..867e9b8c9f --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeService.java @@ -0,0 +1,8 @@ +package com.baeldung.xmlapplicationcontext.service; + +import com.baeldung.xmlapplicationcontext.domain.Employee; + +public interface EmployeeService { + + Employee getEmployee(); +} diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceImpl.java b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceImpl.java new file mode 100644 index 0000000000..b541c62dcd --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceImpl.java @@ -0,0 +1,11 @@ +package com.baeldung.xmlapplicationcontext.service; + +import com.baeldung.xmlapplicationcontext.domain.Employee; + +public class EmployeeServiceImpl implements EmployeeService { + + @Override + public Employee getEmployee() { + return new Employee("Baeldung", "Admin"); + } +} diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceTestImpl.java b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceTestImpl.java new file mode 100644 index 0000000000..7cebaa399b --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/xmlapplicationcontext/service/EmployeeServiceTestImpl.java @@ -0,0 +1,11 @@ +package com.baeldung.xmlapplicationcontext.service; + +import com.baeldung.xmlapplicationcontext.domain.Employee; + +public class EmployeeServiceTestImpl implements EmployeeService { + + @Override + public Employee getEmployee() { + return new Employee("Baeldung-Test", "Admin"); + } +} diff --git a/spring-boot-modules/spring-boot-testing/src/main/resources/application-context.xml b/spring-boot-modules/spring-boot-testing/src/main/resources/application-context.xml new file mode 100644 index 0000000000..fc0e0fef25 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/main/resources/application-context.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/spring-boot-modules/spring-boot-testing/src/main/webapp/WEB-INF/application-context.xml b/spring-boot-modules/spring-boot-testing/src/main/webapp/WEB-INF/application-context.xml new file mode 100644 index 0000000000..fc0e0fef25 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/main/webapp/WEB-INF/application-context.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceAppContextIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceAppContextIntegrationTest.java new file mode 100644 index 0000000000..e9ee8f3951 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceAppContextIntegrationTest.java @@ -0,0 +1,27 @@ +package com.baeldung.xmlapplicationcontext; + +import com.baeldung.xmlapplicationcontext.service.EmployeeService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = XmlBeanApplication.class) +//@ContextConfiguration(locations = "file:src/main/webapp/WEB-INF/application-context.xml") +public class EmployeeServiceAppContextIntegrationTest { + + @Autowired + private EmployeeService service; + + @Test + public void whenContextLoads_thenServiceISNotNull() { + assertThat(service).isNotNull(); + } + +} diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceTestContextIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceTestContextIntegrationTest.java new file mode 100644 index 0000000000..0182d5dbb1 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/xmlapplicationcontext/EmployeeServiceTestContextIntegrationTest.java @@ -0,0 +1,28 @@ +package com.baeldung.xmlapplicationcontext; + +import com.baeldung.xmlapplicationcontext.service.EmployeeService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = XmlBeanApplication.class) +@ContextConfiguration(locations = "/test-context.xml") +public class EmployeeServiceTestContextIntegrationTest { + + @Autowired + @Qualifier("employeeServiceTestImpl") + private EmployeeService serviceTest; + + @Test + public void whenTestContextLoads_thenServiceTestISNotNull() { + assertThat(serviceTest).isNotNull(); + } + +} diff --git a/spring-boot-modules/spring-boot-testing/src/test/resources/test-context.xml b/spring-boot-modules/spring-boot-testing/src/test/resources/test-context.xml new file mode 100644 index 0000000000..fbd6da32ca --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/test/resources/test-context.xml @@ -0,0 +1,8 @@ + + + + +