JAVA-19964 Move code from spring-core-5 to spring-core-2 (#13856)

* JAVA-19964 Move code from spring-core-5 to spring-core-2

* JAVA-19964 Move code from spring-core-6 to spring-core-2

* JAVA-19964 Move code from spring-core-4 to spring-core-3
This commit is contained in:
anuragkumawat
2023-04-22 13:23:07 +05:30
committed by GitHub
parent b0116c225e
commit a5fa999031
51 changed files with 75 additions and 261 deletions
@@ -1,71 +0,0 @@
package com.baeldung.applicationcontext;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class ApplicationContextUnitTest {
@Test
public void givenAnnotationConfigAppContext_whenSpringConfig_thenMappingSuccess() {
ApplicationContext context = new AnnotationConfigApplicationContext(AccountConfig.class);
AccountService accountService = context.getBean(AccountService.class);
assertNotNull(accountService);
assertNotNull(accountService.getAccountRepository());
((AnnotationConfigApplicationContext) context).close();
}
@Test
public void givenClasspathXmlAppContext_whenAnnotationConfig_thenMappingSuccess() {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationcontext/user-bean-config.xml");
UserService userService = context.getBean(UserService.class);
assertNotNull(userService);
((ClassPathXmlApplicationContext) context).close();
}
@Test
@Ignore
public void givenFileXmlAppContext_whenXMLConfig_thenMappingSuccess() {
String path = "D:/workspaces/Baeldung/tutorials/spring-core-4/src/test/resources/applicationcontext/account-bean-config.xml";
ApplicationContext context = new FileSystemXmlApplicationContext(path);
AccountService accountService = context.getBean("accountService", AccountService.class);
assertNotNull(accountService);
assertNotNull(accountService.getAccountRepository());
((FileSystemXmlApplicationContext) context).close();
}
@Test
public void givenClasspathXmlAppContext_whenXMLConfig_thenMappingSuccess() {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationcontext/account-bean-config.xml");
AccountService accountService = context.getBean("accountService", AccountService.class);
assertNotNull(accountService);
assertNotNull(accountService.getAccountRepository());
((ClassPathXmlApplicationContext) context).close();
}
@Test
public void givenMessagesInFile_whenMessageResourceUsed_thenReadMessage() {
ApplicationContext context = new AnnotationConfigApplicationContext(AccountConfig.class);
AccountService accountService = context.getBean(AccountService.class);
assertEquals("TestAccount", accountService.getAccountName());
((AnnotationConfigApplicationContext) context).close();
}
}
@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="accountService" class="com.baeldung.applicationcontext.AccountService">
<constructor-arg name="accountRepository" ref="accountRepository" />
</bean>
<bean id="accountRepository" class="com.baeldung.applicationcontext.AccountRepository" />
</beans>
@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config />
<context:component-scan
base-package="com.baeldung.applicationcontext" />
</beans>
@@ -1 +0,0 @@
account.name=TestAccount