1 package com.atlassian.plugin.osgi.spring;
2
3 import com.atlassian.plugin.osgi.spring.external.ApplicationContextPreProcessor;
4 import junit.framework.TestCase;
5 import org.osgi.framework.Bundle;
6 import org.eclipse.gemini.blueprint.extender.support.ApplicationContextConfiguration;
7
8 import java.util.Arrays;
9 import java.util.Collections;
10
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.when;
13
14
15
16
17 public class TestNonValidatingOsgiApplicationContextCreator extends TestCase
18 {
19 public void testIsSpringPoweredNormal()
20 {
21 ApplicationContextConfiguration config = mock(ApplicationContextConfiguration.class);
22 Bundle bundle = mock(Bundle.class);
23
24 NonValidatingOsgiApplicationContextCreator creator = new NonValidatingOsgiApplicationContextCreator(Collections.<ApplicationContextPreProcessor>emptyList());
25 when(config.isSpringPoweredBundle()).thenReturn(true);
26 assertTrue(creator.isSpringPoweredBundle(bundle, config));
27 }
28
29 public void testIsSpringPoweredFalseNoProcessors()
30 {
31 ApplicationContextConfiguration config = mock(ApplicationContextConfiguration.class);
32 Bundle bundle = mock(Bundle.class);
33
34 NonValidatingOsgiApplicationContextCreator creator = new NonValidatingOsgiApplicationContextCreator(Collections.<ApplicationContextPreProcessor>emptyList());
35 when(config.isSpringPoweredBundle()).thenReturn(false);
36 assertFalse(creator.isSpringPoweredBundle(bundle, config));
37 }
38
39 public void testIsSpringPoweredFromPreProcessor()
40 {
41 ApplicationContextConfiguration config = mock(ApplicationContextConfiguration.class);
42 Bundle bundle = mock(Bundle.class);
43 ApplicationContextPreProcessor processor = mock(ApplicationContextPreProcessor.class);
44
45 NonValidatingOsgiApplicationContextCreator creator = new NonValidatingOsgiApplicationContextCreator(Arrays.asList(processor));
46 when(config.isSpringPoweredBundle()).thenReturn(false);
47 when(processor.isSpringPoweredBundle(bundle)).thenReturn(true);
48 assertTrue(creator.isSpringPoweredBundle(bundle, config));
49 }
50
51 public void testIsSpringPoweredFalseWithPreProcessor()
52 {
53 ApplicationContextConfiguration config = mock(ApplicationContextConfiguration.class);
54 Bundle bundle = mock(Bundle.class);
55 ApplicationContextPreProcessor processor = mock(ApplicationContextPreProcessor.class);
56
57 NonValidatingOsgiApplicationContextCreator creator = new NonValidatingOsgiApplicationContextCreator(Arrays.asList(processor));
58 when(config.isSpringPoweredBundle()).thenReturn(false);
59 when(processor.isSpringPoweredBundle(bundle)).thenReturn(false);
60 assertFalse(creator.isSpringPoweredBundle(bundle, config));
61 }
62 }