Search in sources :

Example 1 with MockMimeTypeService

use of org.apache.sling.testing.mock.sling.services.MockMimeTypeService in project sling by apache.

the class SlingContextImpl method registerDefaultServices.

/**
     * Default services that should be available for every unit test
     */
protected void registerDefaultServices() {
    // scripting services (required by sling models impl since 1.3.6)
    registerInjectActivateService(new ScriptEngineManagerFactory());
    registerInjectActivateService(new BindingsValuesProvidersByContextImpl());
    // sling models
    registerInjectActivateService(new ModelAdapterFactory());
    registerInjectActivateServiceByClassName("org.apache.sling.models.impl.FirstImplementationPicker", "org.apache.sling.models.impl.ResourceTypeBasedResourcePicker", "org.apache.sling.models.impl.injectors.BindingsInjector", "org.apache.sling.models.impl.injectors.ChildResourceInjector", "org.apache.sling.models.impl.injectors.OSGiServiceInjector", "org.apache.sling.models.impl.injectors.RequestAttributeInjector", "org.apache.sling.models.impl.injectors.ResourcePathInjector", "org.apache.sling.models.impl.injectors.SelfInjector", "org.apache.sling.models.impl.injectors.SlingObjectInjector", "org.apache.sling.models.impl.injectors.ValueMapInjector", "org.apache.sling.models.impl.via.BeanPropertyViaProvider", "org.apache.sling.models.impl.via.ChildResourceViaProvider", "org.apache.sling.models.impl.via.ForcedResourceTypeViaProvider", "org.apache.sling.models.impl.via.ResourceSuperTypeViaProvider");
    // other services
    registerService(SlingSettingsService.class, new MockSlingSettingService(DEFAULT_RUN_MODES));
    registerService(MimeTypeService.class, new MockMimeTypeService());
    registerInjectActivateService(new ResourceBuilderFactoryService());
    // scan for models defined via bundle headers in classpath
    ModelAdapterFactoryUtil.addModelsForManifestEntries(this.bundleContext());
}
Also used : ModelAdapterFactory(org.apache.sling.models.impl.ModelAdapterFactory) BindingsValuesProvidersByContextImpl(org.apache.sling.scripting.core.impl.BindingsValuesProvidersByContextImpl) ScriptEngineManagerFactory(org.apache.sling.scripting.core.impl.ScriptEngineManagerFactory) MockSlingSettingService(org.apache.sling.testing.mock.sling.services.MockSlingSettingService) MockMimeTypeService(org.apache.sling.testing.mock.sling.services.MockMimeTypeService) ResourceBuilderFactoryService(org.apache.sling.resourcebuilder.impl.ResourceBuilderFactoryService)

Example 2 with MockMimeTypeService

use of org.apache.sling.testing.mock.sling.services.MockMimeTypeService in project sling by apache.

the class AbstractModelAdapterFactoryUtilTest method testOsgiService.

@Test
public void testOsgiService() {
    context().registerService(MimeTypeService.class, new MockMimeTypeService());
    OsgiServiceModel model = context().resourceResolver().adaptTo(OsgiServiceModel.class);
    assertNotNull(model);
    assertNotNull(model.getMimeTypeService());
    assertEquals("text/html", model.getMimeTypeService().getMimeType("html"));
}
Also used : OsgiServiceModel(org.apache.sling.testing.mock.sling.context.models.OsgiServiceModel) MockMimeTypeService(org.apache.sling.testing.mock.sling.services.MockMimeTypeService) Test(org.junit.Test)

Example 3 with MockMimeTypeService

use of org.apache.sling.testing.mock.sling.services.MockMimeTypeService in project sling by apache.

the class AbstractSlingContextImplTest method testSlingModelsOsgiService.

@Test
public void testSlingModelsOsgiService() {
    context.registerService(new MockMimeTypeService());
    OsgiServiceModel model = context.resourceResolver().adaptTo(OsgiServiceModel.class);
    assertNotNull(model.getMimeTypeService());
    assertEquals("text/html", model.getMimeTypeService().getMimeType("html"));
}
Also used : OsgiServiceModel(org.apache.sling.testing.mock.sling.context.models.OsgiServiceModel) MockMimeTypeService(org.apache.sling.testing.mock.sling.services.MockMimeTypeService) Test(org.junit.Test)

Aggregations

MockMimeTypeService (org.apache.sling.testing.mock.sling.services.MockMimeTypeService)3 OsgiServiceModel (org.apache.sling.testing.mock.sling.context.models.OsgiServiceModel)2 Test (org.junit.Test)2 ModelAdapterFactory (org.apache.sling.models.impl.ModelAdapterFactory)1 ResourceBuilderFactoryService (org.apache.sling.resourcebuilder.impl.ResourceBuilderFactoryService)1 BindingsValuesProvidersByContextImpl (org.apache.sling.scripting.core.impl.BindingsValuesProvidersByContextImpl)1 ScriptEngineManagerFactory (org.apache.sling.scripting.core.impl.ScriptEngineManagerFactory)1 MockSlingSettingService (org.apache.sling.testing.mock.sling.services.MockSlingSettingService)1