Search in sources :

Example 1 with MockBundle

use of org.eclipse.gemini.blueprint.mock.MockBundle in project motech by motech.

the class MotechOsgiApplicationContextCreatorTest method shouldReturnApplicationOfTypeWebApplicationContext.

@Test
public void shouldReturnApplicationOfTypeWebApplicationContext() throws Exception {
    MockBundle bundle = new MockBundle();
    MockBundleContext bundleContext = new MockBundleContext(bundle);
    ConfigurationScanner configurationScanner = mock(ConfigurationScanner.class);
    when(configurationScanner.getConfigurations(bundle)).thenReturn(new String[] { "resource.xml" });
    MotechOsgiApplicationContextCreator contextCreator = new MotechOsgiApplicationContextCreator();
    contextCreator.setConfigurationScanner(configurationScanner);
    MotechOsgiConfigurableApplicationContext applicationContext = (MotechOsgiConfigurableApplicationContext) contextCreator.createApplicationContext(bundleContext);
    assertThat(applicationContext, notNullValue());
}
Also used : MockBundleContext(org.eclipse.gemini.blueprint.mock.MockBundleContext) MockBundle(org.eclipse.gemini.blueprint.mock.MockBundle) ConfigurationScanner(org.eclipse.gemini.blueprint.extender.support.scanning.ConfigurationScanner) Test(org.junit.Test)

Example 2 with MockBundle

use of org.eclipse.gemini.blueprint.mock.MockBundle in project motech by motech.

the class HttpContextFactoryTest method shouldCreateFileSystemAwareUiHttpContext.

@Test
public void shouldCreateFileSystemAwareUiHttpContext() {
    HttpContext httpContext = mock(HttpContext.class);
    PowerMockito.mockStatic(ApplicationEnvironment.class);
    MockBundle bundle = new MockBundle("org.motechproject.com-sms-api-bundle");
    when(ApplicationEnvironment.isInDevelopmentMode()).thenReturn(true);
    when(ApplicationEnvironment.getModulePath(new BundleName("org.motechproject.com-sms-api-bundle"))).thenReturn("/Users/s/project/motech/modules/sms/src/main/resources");
    FileSystemAwareUIHttpContext fileSystemAwareUIHttpContext = (FileSystemAwareUIHttpContext) HttpContextFactory.getHttpContext(httpContext, bundle);
    assertThat(fileSystemAwareUIHttpContext, IsNot.not(notNull()));
    assertThat(fileSystemAwareUIHttpContext.getResourceRootDirectoryPath(), Is.is("/Users/s/project/motech/modules/sms/src/main/resources"));
}
Also used : FileSystemAwareUIHttpContext(org.motechproject.osgi.web.http.FileSystemAwareUIHttpContext) HttpContext(org.osgi.service.http.HttpContext) FileSystemAwareUIHttpContext(org.motechproject.osgi.web.http.FileSystemAwareUIHttpContext) BundleName(org.motechproject.osgi.web.bundle.BundleName) MockBundle(org.eclipse.gemini.blueprint.mock.MockBundle) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with MockBundle

use of org.eclipse.gemini.blueprint.mock.MockBundle in project motech by motech.

the class ApplicationContextServiceReferenceUtilsTest method shouldNotRecogniseAsApplicationContextServiceWhenObjectClassIsDifferent.

@Test
public void shouldNotRecogniseAsApplicationContextServiceWhenObjectClassIsDifferent() {
    ServiceReference serviceReference = mock(ServiceReference.class);
    when(serviceReference.getBundle()).thenReturn(new MockBundle("mock-bundle"));
    when(serviceReference.getProperty(ApplicationContextServiceReferenceUtils.SERVICE_NAME)).thenReturn("mock-bundle");
    when(serviceReference.getProperty(Constants.OBJECTCLASS)).thenReturn(new String[] { "abcd", "he.llo", "xyz" });
    assertTrue(ApplicationContextServiceReferenceUtils.isNotValid(serviceReference));
}
Also used : MockBundle(org.eclipse.gemini.blueprint.mock.MockBundle) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 4 with MockBundle

use of org.eclipse.gemini.blueprint.mock.MockBundle in project motech by motech.

the class ApplicationContextServiceReferenceUtilsTest method shouldRecogniseAsApplicationContextService.

@Test
public void shouldRecogniseAsApplicationContextService() {
    ServiceReference serviceReference = mock(ServiceReference.class);
    when(serviceReference.getBundle()).thenReturn(new MockBundle("mock-bundle"));
    when(serviceReference.getProperty(ApplicationContextServiceReferenceUtils.SERVICE_NAME)).thenReturn("mock-bundle");
    when(serviceReference.getProperty(Constants.OBJECTCLASS)).thenReturn(new String[] { "abcd", ApplicationContext.class.getName(), "xyz" });
    assertTrue(ApplicationContextServiceReferenceUtils.isValid(serviceReference));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) MockBundle(org.eclipse.gemini.blueprint.mock.MockBundle) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 5 with MockBundle

use of org.eclipse.gemini.blueprint.mock.MockBundle in project motech by motech.

the class ApplicationContextServiceReferenceUtilsTest method shouldNotRecogniseAsApplicationContextServiceWhenServiceNameIsDifferent.

@Test
public void shouldNotRecogniseAsApplicationContextServiceWhenServiceNameIsDifferent() {
    ServiceReference serviceReference = mock(ServiceReference.class);
    when(serviceReference.getBundle()).thenReturn(new MockBundle("mock-bundle"));
    when(serviceReference.getProperty(ApplicationContextServiceReferenceUtils.SERVICE_NAME)).thenReturn("another-mock-bundle");
    when(serviceReference.getProperty(Constants.OBJECTCLASS)).thenReturn(new String[] { "abcd", ApplicationContext.class.getName(), "xyz" });
    assertTrue(ApplicationContextServiceReferenceUtils.isNotValid(serviceReference));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) MockBundle(org.eclipse.gemini.blueprint.mock.MockBundle) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

MockBundle (org.eclipse.gemini.blueprint.mock.MockBundle)5 Test (org.junit.Test)5 ServiceReference (org.osgi.framework.ServiceReference)3 ApplicationContext (org.springframework.context.ApplicationContext)2 ConfigurationScanner (org.eclipse.gemini.blueprint.extender.support.scanning.ConfigurationScanner)1 MockBundleContext (org.eclipse.gemini.blueprint.mock.MockBundleContext)1 BundleName (org.motechproject.osgi.web.bundle.BundleName)1 FileSystemAwareUIHttpContext (org.motechproject.osgi.web.http.FileSystemAwareUIHttpContext)1 HttpContext (org.osgi.service.http.HttpContext)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1