Search in sources :

Example 6 with MockResourceResolverFactory

use of org.apache.sling.testing.resourceresolver.MockResourceResolverFactory in project sling by apache.

the class DistributingEventHandlerTest method setup.

@SuppressWarnings("unchecked")
@Before
public void setup() throws Exception {
    final BundleContext bc = Mockito.mock(BundleContext.class);
    Mockito.when(bc.registerService(Mockito.any(String[].class), Mockito.any(), Mockito.any(Dictionary.class))).thenReturn(null);
    final SlingSettingsService otherSettings = Mockito.mock(SlingSettingsService.class);
    Mockito.when(otherSettings.getSlingId()).thenReturn(OTHER_APP_ID);
    final EventAdmin ea = new EventAdmin() {

        @Override
        public void sendEvent(final Event event) {
            this.postEvent(event);
        }

        @Override
        public void postEvent(final Event event) {
            final String topic = event.getTopic();
            if (topic.equals(SlingConstants.TOPIC_RESOURCE_ADDED)) {
                final ResourceChange change = new ResourceChange(ChangeType.ADDED, (String) event.getProperty(SlingConstants.PROPERTY_PATH), false, null, null, null);
                sender.onChange(Collections.singletonList(change));
            } else if (topic.startsWith(TOPIC_PREFIX)) {
                events.add(event);
            }
        }
    };
    final MockResourceResolverFactoryOptions opts = new MockResourceResolverFactoryOptions();
    opts.setEventAdmin(ea);
    final ResourceResolverFactory factory = new MockResourceResolverFactory(opts);
    this.sender = new DistributedEventSender(bc, DistributedEventAdminImpl.DEFAULT_REPOSITORY_PATH, DistributedEventAdminImpl.DEFAULT_REPOSITORY_PATH + "/" + MY_APP_ID, factory, ea);
    this.receiver = new DistributedEventReceiver(bc, DistributedEventAdminImpl.DEFAULT_REPOSITORY_PATH, DistributedEventAdminImpl.DEFAULT_REPOSITORY_PATH + "/" + OTHER_APP_ID, 15, factory, otherSettings);
}
Also used : Dictionary(java.util.Dictionary) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) MockResourceResolverFactory(org.apache.sling.testing.resourceresolver.MockResourceResolverFactory) EventAdmin(org.osgi.service.event.EventAdmin) MockResourceResolverFactoryOptions(org.apache.sling.testing.resourceresolver.MockResourceResolverFactoryOptions) Event(org.osgi.service.event.Event) MockResourceResolverFactory(org.apache.sling.testing.resourceresolver.MockResourceResolverFactory) ResourceChange(org.apache.sling.api.resource.observation.ResourceChange) SlingSettingsService(org.apache.sling.settings.SlingSettingsService) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 7 with MockResourceResolverFactory

use of org.apache.sling.testing.resourceresolver.MockResourceResolverFactory in project sling by apache.

the class AbstractJcrEventTriggerTest method setUp.

@Before
public void setUp() throws Exception {
    rrf = new MockResourceResolverFactory();
    ResourceResolver resourceResolver = rrf.getResourceResolver(null);
    MockHelper helper = MockHelper.create(resourceResolver).resource("/a").resource("b").resource("c").resource("d").resource("e").resource("f").resource("g").p("foo", true).resource(".h").p("foo", false);
    helper.commit();
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) MockHelper(org.apache.sling.testing.resourceresolver.MockHelper) MockResourceResolverFactory(org.apache.sling.testing.resourceresolver.MockResourceResolverFactory) Before(org.junit.Before)

Example 8 with MockResourceResolverFactory

use of org.apache.sling.testing.resourceresolver.MockResourceResolverFactory in project sling by apache.

the class MergedResourceProviderTestForMergingPicker method setup.

@Before
public void setup() throws Exception {
    final MockResourceResolverFactoryOptions options = new MockResourceResolverFactoryOptions();
    options.setSearchPaths(new String[] { "/apps/", "/libs/" });
    final ResourceResolverFactory factory = new MockResourceResolverFactory(options);
    this.resolver = factory.getResourceResolver(null);
    MockHelper.create(this.resolver).resource("/apps").resource("a").p(MergedResourceConstants.PN_HIDE_CHILDREN, new String[] { "Z", "x", "y" }).resource("1").p("a", "1").p("b", "2").resource(".2").p(ResourceResolver.PROPERTY_RESOURCE_TYPE, "apps").resource(".3").p("e", "2").p(MergedResourceConstants.PN_HIDE_PROPERTIES, "*").p("b", "x").p("d", "1").resource(".4").p("e", "2").p(MergedResourceConstants.PN_HIDE_PROPERTIES, new String[] { "a", "c" }).p("b", "x").p("d", "1").resource(".X").resource("/apps/b").resource("c").resource("d").resource("e").resource("f").resource("/libs").resource("deleteTest").resource(".mvmTest").p("a", "1").p("b", "2").resource(".a").resource("1").p("a", "5").p("c", "2").resource(".2").p(ResourceResolver.PROPERTY_RESOURCE_TYPE, "libs").resource(".3").p("a", "1").p("b", "2").p("c", "3").resource(".4").p("a", "1").p("b", "2").p("c", "3").resource(".Y").resource(".Z").resource("/libs/a/Y/a").resource("/libs/a/Y/b").resource("/libs/a/Y/c").resource("/libs/b").resource("c").resource("d").resource("e").resource("f").commit();
    this.provider = new CRUDMergingResourceProvider("/merged", new MergingResourcePicker(), false);
    this.ctx = new BasicResolveContext(resolver);
}
Also used : ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) MockResourceResolverFactory(org.apache.sling.testing.resourceresolver.MockResourceResolverFactory) MockResourceResolverFactoryOptions(org.apache.sling.testing.resourceresolver.MockResourceResolverFactoryOptions) MockResourceResolverFactory(org.apache.sling.testing.resourceresolver.MockResourceResolverFactory) MergingResourcePicker(org.apache.sling.resourcemerger.impl.picker.MergingResourcePicker) Before(org.junit.Before)

Example 9 with MockResourceResolverFactory

use of org.apache.sling.testing.resourceresolver.MockResourceResolverFactory in project sling by apache.

the class FileVaultContentSerializerTest method setUp.

@Before
public void setUp() throws Exception {
    ResourceResolver resourceResolver = new MockResourceResolverFactory().getResourceResolver(null);
    MockHelper helper = MockHelper.create(resourceResolver).resource("/libs").p("prop", "value").resource("sub").p("sub", "hello").resource(".sameLevel").resource("/apps").p("foo", "baa");
    helper.commit();
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) MockHelper(org.apache.sling.testing.resourceresolver.MockHelper) MockResourceResolverFactory(org.apache.sling.testing.resourceresolver.MockResourceResolverFactory) Before(org.junit.Before)

Aggregations

MockResourceResolverFactory (org.apache.sling.testing.resourceresolver.MockResourceResolverFactory)9 Before (org.junit.Before)9 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)4 MockHelper (org.apache.sling.testing.resourceresolver.MockHelper)4 MockResourceResolverFactoryOptions (org.apache.sling.testing.resourceresolver.MockResourceResolverFactoryOptions)3 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 Dictionary (java.util.Dictionary)1 ResourceChange (org.apache.sling.api.resource.observation.ResourceChange)1 ResourceAssertions (org.apache.sling.resourcebuilder.test.ResourceAssertions)1 MergingResourcePicker (org.apache.sling.resourcemerger.impl.picker.MergingResourcePicker)1 OverridingResourcePicker (org.apache.sling.resourcemerger.impl.picker.OverridingResourcePicker)1 SlingSettingsService (org.apache.sling.settings.SlingSettingsService)1 BundleContext (org.osgi.framework.BundleContext)1 Event (org.osgi.service.event.Event)1 EventAdmin (org.osgi.service.event.EventAdmin)1