Skip to content

Commit 26b5ab8

Browse files
ahamedmpedja4
authored andcommitted
BAEL-696 - Implement OR in the REST API Query Language (eugenp#1404)
* Dependency Injection Types, XML-Config, Java-Config, Test Classes * Formatting done with Formatter Configuration in Eclipse * REST Query Lang - Adv Search Ops - Improvement - C1 * REST Query Lang - Adv Search Ops - Improvement - C2 * add update to rest api (eugenp#1401) * upgrade to spring boot 1.5.2 * add full update to REST API * BAEL-634 javassist (eugenp#1349) * BEEL-634 javassist dependency * BEEL-634 code for javassist article * BEEL-634 test refinement * BEEL-634 increment lib to newest version * add test that uses reflection to verify * add field * add bytecode to different class * adding following modules with updated testcase : DB, Filter, Json (eugenp#1410) * adding ratpack module * adding pom.xml * adding following modules with updated testcase : DB, Filter, Json * add entry points (eugenp#1413) * spring boot custom banner (eugenp#1412) * adding ratpack module * adding pom.xml * adding following modules with updated testcase : DB, Filter, Json * adding spring-boot custom banner tutorial * BALE-707 Refactoring changes (eugenp#1418) * BAEL-707 Add the changes as per review comment * BAEL-707 Refactored the code as per review comments * BAEL-696 Code formatting
1 parent de29f6a commit 26b5ab8

20 files changed

Lines changed: 901 additions & 416 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.beaninjection;
2+
3+
public class AnotherSampleDAOBean implements IAnotherSampleDAO {
4+
5+
private String propertyY;
6+
7+
public AnotherSampleDAOBean(String propertyY) {
8+
this.propertyY = propertyY;
9+
}
10+
11+
// standard setters and getters
12+
13+
public String getPropertyY() {
14+
return propertyY;
15+
}
16+
17+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.baeldung.beaninjection;
2+
3+
import java.util.List;
4+
5+
public class ExampleDAOBean implements IExampleDAO {
6+
7+
private String propertyX;
8+
9+
public ExampleDAOBean(String propertyX) {
10+
this.propertyX = propertyX;
11+
}
12+
13+
public String getPropertyX() {
14+
return propertyX;
15+
}
16+
17+
public void setPropertyX(String propertyX) {
18+
this.propertyX = propertyX;
19+
}
20+
21+
@Override
22+
public List<SampleDomainObject> getDomainList() {
23+
// TODO Auto-generated method stub
24+
return null;
25+
}
26+
27+
@Override
28+
public SampleDomainObject createNewDomain(SampleDomainObject inputDomain) {
29+
// TODO Auto-generated method stub
30+
return null;
31+
}
32+
33+
@Override
34+
public SampleDomainObject getSomeDomain() {
35+
// TODO Auto-generated method stub
36+
return new SampleDomainObject();
37+
}
38+
39+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.baeldung.beaninjection;
2+
3+
import java.util.List;
4+
5+
public class ExampleServiceBean implements IExampleService {
6+
7+
private IExampleDAO exampleDAO;
8+
private IAnotherSampleDAO anotherSampleDAO;
9+
10+
public ExampleServiceBean(IExampleDAO exampleDAO) {
11+
this.exampleDAO = exampleDAO;
12+
}
13+
14+
public void setAnotherSampleDAO(IAnotherSampleDAO anotherSampleDAO) {
15+
this.anotherSampleDAO = anotherSampleDAO;
16+
}
17+
18+
// standard setters and getters
19+
20+
public IAnotherSampleDAO getAnotherSampleDAO() {
21+
return anotherSampleDAO;
22+
}
23+
24+
public void setExampleDAO(ExampleDAOBean exampleDAO) {
25+
this.exampleDAO = exampleDAO;
26+
}
27+
28+
public IExampleDAO getExampleDAO() {
29+
return exampleDAO;
30+
}
31+
32+
private String propertyX;
33+
34+
public String getPropertyX() {
35+
return propertyX;
36+
}
37+
38+
public void setPropertyX(String propertyX) {
39+
this.propertyX = propertyX;
40+
}
41+
42+
public List<SampleDomainObject> serviceMethodX() {
43+
/*get domain list from DAO .. business logic on domain objects..return*/
44+
return exampleDAO.getDomainList();
45+
}
46+
47+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.beaninjection;
2+
3+
public interface IAnotherSampleDAO {
4+
5+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.beaninjection;
2+
3+
import java.util.List;
4+
5+
public interface IExampleDAO {
6+
7+
List<SampleDomainObject> getDomainList();
8+
9+
SampleDomainObject createNewDomain(SampleDomainObject domainObject);
10+
11+
SampleDomainObject getSomeDomain();
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.baeldung.beaninjection;
2+
3+
import java.util.List;
4+
5+
public interface IExampleService {
6+
7+
List<SampleDomainObject> serviceMethodX();
8+
9+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.baeldung.beaninjection;
2+
3+
import java.io.Serializable;
4+
5+
public class SampleDomainObject implements Serializable {
6+
7+
/**
8+
*
9+
*/
10+
private static final long serialVersionUID = 449859763481296747L;
11+
12+
private String domainPropX;
13+
private String domainPropY;
14+
15+
public String getDomainPropX() {
16+
return domainPropX;
17+
}
18+
19+
public void setDomainPropX(String domainPropX) {
20+
this.domainPropX = domainPropX;
21+
}
22+
23+
public String getDomainPropY() {
24+
return domainPropY;
25+
}
26+
27+
public void setDomainPropY(String domainPropY) {
28+
this.domainPropY = domainPropY;
29+
}
30+
31+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.baeldung.configuration;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
import com.baeldung.beaninjection.AnotherSampleDAOBean;
8+
import com.baeldung.beaninjection.ExampleDAOBean;
9+
import com.baeldung.beaninjection.ExampleServiceBean;
10+
import com.baeldung.beaninjection.IAnotherSampleDAO;
11+
import com.baeldung.beaninjection.IExampleDAO;
12+
import com.baeldung.beaninjection.IExampleService;
13+
14+
@Configuration
15+
@ComponentScan(basePackages = { "com.baeldung.beaninjection" })
16+
public class ApplicationContextTestBeanInjectionTypes {
17+
18+
@Bean
19+
public IExampleDAO exampleDAO() {
20+
return new ExampleDAOBean("Mandatory DAO Property X");
21+
}
22+
23+
@Bean
24+
public IExampleService exampleServiceBean() {
25+
ExampleServiceBean serviceBean = new ExampleServiceBean(exampleDAO());
26+
serviceBean.setAnotherSampleDAO(anotherSampleDAO());
27+
serviceBean.setPropertyX("Some Service Property X");
28+
return serviceBean;
29+
}
30+
31+
@Bean
32+
public IAnotherSampleDAO anotherSampleDAO() {
33+
return new AnotherSampleDAOBean("Mandatory DAO Property Y");
34+
}
35+
36+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://www.springframework.org/schema/beans"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
5+
6+
<bean id="exampleDAO" class="com.baeldung.beaninjection.ExampleDAOBean">
7+
<constructor-arg index="0" type="java.lang.String"
8+
value="Mandatory DAO Property X" />
9+
</bean>
10+
11+
<bean id="anotherSampleDAO" class="com.baeldung.beaninjection.AnotherSampleDAOBean">
12+
<constructor-arg index="0" type="java.lang.String"
13+
value="Mandatory DAO Property Y" />
14+
</bean>
15+
16+
<bean id="exampleService" class="com.baeldung.beaninjection.ExampleServiceBean">
17+
<constructor-arg index="0" ref="exampleDAO" />
18+
<property name="propertyX" value="Some Service Property X"></property>
19+
<property name="anotherSampleDAO" ref="anotherSampleDAO"></property>
20+
</bean>
21+
22+
</beans>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.baeldung.test.beaninjection;
2+
3+
import static org.junit.Assert.assertNotNull;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
import org.springframework.beans.BeansException;
9+
import org.springframework.context.ApplicationContext;
10+
import org.springframework.context.ApplicationContextAware;
11+
import org.springframework.test.context.ContextConfiguration;
12+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13+
14+
import com.baeldung.beaninjection.AnotherSampleDAOBean;
15+
import com.baeldung.beaninjection.ExampleDAOBean;
16+
import com.baeldung.beaninjection.ExampleServiceBean;
17+
import com.baeldung.configuration.ApplicationContextTestBeanInjectionTypes;
18+
19+
@RunWith(SpringJUnit4ClassRunner.class)
20+
@ContextConfiguration(classes = ApplicationContextTestBeanInjectionTypes.class)
21+
public class BeanInjectionJavaConfigTest implements ApplicationContextAware {
22+
23+
private ApplicationContext beanInjectedContext;
24+
25+
@Test
26+
public void testDAOInjectionByJava() {
27+
ExampleServiceBean serviceBean = beanInjectedContext.getBean(ExampleServiceBean.class);
28+
assertNotNull("Failed: Constructor Injection,Bean Reference Injection,Java Config, ExampleServiceBean", serviceBean.getExampleDAO());
29+
assertNotNull("Failed: Constructor Injection,Bean Reference Injection,Java Config, ExampleServiceBean", serviceBean.getAnotherSampleDAO());
30+
assertTrue("Failed: Constructor Injection,String Property , Java Config", serviceBean.getPropertyX()
31+
.equals("Some Service Property X"));
32+
}
33+
34+
@Test
35+
public void testPropertyInjectioninDAOByJava() {
36+
ExampleDAOBean daoBean = beanInjectedContext.getBean(ExampleDAOBean.class);
37+
assertTrue("Failed: Constructor Injection,String Property , Java Config", daoBean.getPropertyX()
38+
.equals("Mandatory DAO Property X"));
39+
40+
AnotherSampleDAOBean anotherDAOBean = beanInjectedContext.getBean(AnotherSampleDAOBean.class);
41+
assertTrue("Failed: Constructor Injection,String Property , XML Config", anotherDAOBean.getPropertyY()
42+
.equals("Mandatory DAO Property Y"));
43+
}
44+
45+
@Override
46+
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
47+
// TODO Auto-generated method stub
48+
this.beanInjectedContext = applicationContext;
49+
}
50+
}

0 commit comments

Comments
 (0)