1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.blossom.context; |
35 |
|
|
36 |
|
import java.io.IOException; |
37 |
|
import javax.jcr.Node; |
38 |
|
import javax.jcr.RepositoryException; |
39 |
|
import javax.jcr.observation.Event; |
40 |
|
|
41 |
|
import org.junit.Test; |
42 |
|
import org.springframework.aop.support.AopUtils; |
43 |
|
import org.springframework.context.support.ClassPathXmlApplicationContext; |
44 |
|
import static org.junit.Assert.assertEquals; |
45 |
|
import static org.junit.Assert.assertFalse; |
46 |
|
import static org.junit.Assert.assertSame; |
47 |
|
import static org.junit.Assert.assertTrue; |
48 |
|
|
49 |
|
import info.magnolia.module.blossom.content2bean.TestService; |
50 |
|
import info.magnolia.module.blossom.content2bean.TestServiceImpl; |
51 |
|
import info.magnolia.repository.RepositoryConstants; |
52 |
|
import info.magnolia.test.MgnlTestCase; |
53 |
|
import info.magnolia.test.mock.MockUtil; |
54 |
|
import info.magnolia.test.mock.jcr.MockEvent; |
55 |
|
import info.magnolia.test.mock.jcr.MockObservationManager; |
56 |
|
import info.magnolia.test.mock.jcr.MockSession; |
57 |
|
import info.magnolia.test.mock.jcr.SessionTestUtil; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
@since |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (53) |
Complexity: 3 |
Complexity Density: 0.06 |
|
64 |
|
public class ObservedBeanFactoryBeanTest extends MgnlTestCase { |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
66 |
1 |
@Test... |
67 |
|
public void testInstantiationInitializationReloadingAndDestruction() throws RepositoryException, IOException, InterruptedException { |
68 |
|
|
69 |
1 |
MockSession session = SessionTestUtil.createSession(RepositoryConstants.CONFIG, |
70 |
|
"/modules/testcase/beans/testService.class=info.magnolia.module.blossom.content2bean.TestServiceImpl\n" + |
71 |
|
"/modules/testcase/beans/testService.shoeSize=long:41\n" + |
72 |
|
"/modules/testcase/beans/testService.servicePort=string:9001\n" + |
73 |
|
"/modules/testcase/beans/testService/innerBean.class=string:info.magnolia.module.blossom.content2bean.SimpleInnerBean\n" + |
74 |
|
"/modules/testcase/beans/testService/innerBean.innerProperty=string:qwerty"); |
75 |
|
|
76 |
1 |
MockUtil.setSystemContextSessionAndHierarchyManager(session); |
77 |
|
|
78 |
1 |
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"classpath:info/magnolia/module/blossom/context/ObservedBeanFactoryBean-test.xml"}); |
79 |
|
|
80 |
1 |
TestServiceImpl testService = (TestServiceImpl) context.getBean("testService"); |
81 |
|
|
82 |
1 |
assertEquals("testService", testService.getBeanName()); |
83 |
1 |
assertEquals(41, testService.getShoeSize()); |
84 |
1 |
assertEquals(9001, testService.getServicePort()); |
85 |
1 |
assertTrue(testService.isInitialized()); |
86 |
1 |
assertTrue(testService.isPostConstructed()); |
87 |
1 |
assertSame(context, testService.getApplicationContext()); |
88 |
|
|
89 |
1 |
assertTrue(AopUtils.isAopProxy(testService)); |
90 |
1 |
assertTrue(AopUtils.isCglibProxy(testService)); |
91 |
1 |
assertEquals(TestServiceImpl.class, AopUtils.getTargetClass(testService)); |
92 |
|
|
93 |
1 |
assertFalse("testService".equals(testService.getInnerBean().getBeanName())); |
94 |
1 |
assertEquals(testService.getInnerBean().getInnerProperty(), "qwerty"); |
95 |
1 |
assertTrue(testService.getInnerBean().isPostConstructed()); |
96 |
|
|
97 |
1 |
Node content = session.getNode("/modules/testcase/beans/testService"); |
98 |
1 |
content.getProperty("shoeSize").setValue(39); |
99 |
|
|
100 |
1 |
MockEvent event = new MockEvent(); |
101 |
1 |
event.setType(Event.PROPERTY_CHANGED); |
102 |
1 |
event.setPath("/modules/testcase/beans/testService@shoeSize"); |
103 |
1 |
event.setUserID("superuser"); |
104 |
1 |
((MockObservationManager)session.getWorkspace().getObservationManager()).fireEvent(event); |
105 |
|
|
106 |
1 |
Thread.sleep(1200); |
107 |
|
|
108 |
1 |
assertEquals(39, testService.getShoeSize()); |
109 |
|
|
110 |
1 |
testService = testService.getInstance()[0]; |
111 |
|
|
112 |
1 |
assertFalse(testService.isDisposed()); |
113 |
1 |
assertFalse(testService.isPreDestroyed()); |
114 |
1 |
context.close(); |
115 |
1 |
assertTrue(testService.isDisposed()); |
116 |
1 |
assertTrue(testService.isPreDestroyed()); |
117 |
|
} |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
119 |
1 |
@Test... |
120 |
|
public void testDefaultClass() throws RepositoryException, IOException, InterruptedException { |
121 |
|
|
122 |
1 |
MockSession session = SessionTestUtil.createSession(RepositoryConstants.CONFIG, |
123 |
|
"/modules/testcase/beans/testService.shoeSize=long:41\n" + |
124 |
|
"/modules/testcase/beans/testService.servicePort=string:9001"); |
125 |
|
|
126 |
1 |
MockUtil.setSystemContextSessionAndHierarchyManager(session); |
127 |
|
|
128 |
1 |
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"classpath:info/magnolia/module/blossom/context/ObservedBeanFactoryBean-defaultClass-test.xml"}); |
129 |
|
|
130 |
1 |
TestServiceImpl testService = (TestServiceImpl) context.getBean("testService"); |
131 |
|
|
132 |
1 |
assertEquals("testService", testService.getBeanName()); |
133 |
1 |
assertEquals(41, testService.getShoeSize()); |
134 |
1 |
assertEquals(9001, testService.getServicePort()); |
135 |
1 |
assertTrue(testService.isInitialized()); |
136 |
1 |
assertTrue(testService.isPostConstructed()); |
137 |
1 |
assertSame(context, testService.getApplicationContext()); |
138 |
1 |
assertTrue(AopUtils.isAopProxy(testService)); |
139 |
1 |
assertEquals(TestServiceImpl.class, AopUtils.getTargetClass(testService)); |
140 |
|
} |
141 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
142 |
1 |
@Test... |
143 |
|
public void testJdkProxy() throws RepositoryException, IOException, InterruptedException { |
144 |
|
|
145 |
1 |
MockSession session = SessionTestUtil.createSession(RepositoryConstants.CONFIG, |
146 |
|
"/modules/testcase/beans/testService.class=info.magnolia.module.blossom.content2bean.TestServiceImpl\n" + |
147 |
|
"/modules/testcase/beans/testService.shoeSize=long:41\n" + |
148 |
|
"/modules/testcase/beans/testService.servicePort=string:9001\n" + |
149 |
|
"/modules/testcase/beans/testService/innerBean.class=string:info.magnolia.module.blossom.content2bean.SimpleInnerBean\n" + |
150 |
|
"/modules/testcase/beans/testService/innerBean.innerProperty=string:qwerty"); |
151 |
|
|
152 |
1 |
MockUtil.setSystemContextSessionAndHierarchyManager(session); |
153 |
|
|
154 |
1 |
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"classpath:info/magnolia/module/blossom/context/ObservedBeanFactoryBean-jdkProxies-test.xml"}); |
155 |
|
|
156 |
1 |
TestService testService = (TestService) context.getBean("testService"); |
157 |
|
|
158 |
1 |
assertTrue(AopUtils.isAopProxy(testService)); |
159 |
1 |
assertFalse(AopUtils.isCglibProxy(testService)); |
160 |
1 |
assertEquals(TestServiceImpl.class, AopUtils.getTargetClass(testService)); |
161 |
|
|
162 |
|
} |
163 |
|
} |