Search in sources :

Example 1 with MockBundle

use of org.apache.sling.testing.mock.osgi.MockBundle in project sling by apache.

the class BundleMetricsMapperTest method mappedName_Header.

@Test
public void mappedName_Header() throws Exception {
    MockBundle bundle = new MockBundle(context.bundleContext());
    bundle.setSymbolicName("com.example");
    bundle.setHeaders(ImmutableMap.of(BundleMetricsMapper.HEADER_DOMAIN_NAME, "com.test"));
    mapper.addMapping("bar", bundle);
    ObjectName name = mapper.createName("counter", "foo", "bar");
    assertEquals("com.test", name.getDomain());
}
Also used : MockBundle(org.apache.sling.testing.mock.osgi.MockBundle) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 2 with MockBundle

use of org.apache.sling.testing.mock.osgi.MockBundle in project sling by apache.

the class InternalMetricsServiceFactoryTest method cb.

private Bundle cb(String name) {
    MockBundle bundle = new MockBundle(context.bundleContext());
    bundle.setSymbolicName(name);
    return bundle;
}
Also used : MockBundle(org.apache.sling.testing.mock.osgi.MockBundle)

Example 3 with MockBundle

use of org.apache.sling.testing.mock.osgi.MockBundle in project sling by apache.

the class BundleContentLoaderTest method loadXmlAsIs.

@Test
@Ignore("TODO - unregister or somehow ignore the XmlReader component for this test")
public void loadXmlAsIs() throws Exception {
    dumpRepo("/", 2);
    Bundle mockBundle = newBundleWithInitialContent("SLING-INF/libs/app;path:=/libs/app;ignoreImportProviders:=xml");
    contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
    Resource imported = context.resourceResolver().getResource("/libs/app");
    assertThat("Resource was not imported", imported, notNullValue());
    assertThat("sling:resourceType was not properly set", imported.getResourceType(), equalTo("sling:Folder"));
    Resource xmlFile = context.resourceResolver().getResource("/libs/app.xml");
    dumpRepo("/", 2);
    assertThat("XML file was was not imported", xmlFile, notNullValue());
}
Also used : MockBundle(org.apache.sling.testing.mock.osgi.MockBundle) Bundle(org.osgi.framework.Bundle) Resource(org.apache.sling.api.resource.Resource) Session(javax.jcr.Session) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with MockBundle

use of org.apache.sling.testing.mock.osgi.MockBundle in project sling by apache.

the class ContentLoaderServiceTest method createNewBundle.

private Bundle createNewBundle() {
    MockBundle b = new MockBundle(context.bundleContext());
    b.setSymbolicName(uniqueId());
    return b;
}
Also used : MockBundle(org.apache.sling.testing.mock.osgi.MockBundle)

Example 5 with MockBundle

use of org.apache.sling.testing.mock.osgi.MockBundle in project sling by apache.

the class BundleContentLoaderTest method loadContentWithRootPath.

@Test
public void loadContentWithRootPath() throws Exception {
    Bundle mockBundle = newBundleWithInitialContent("SLING-INF/");
    contentLoader.registerBundle(context.resourceResolver().adaptTo(Session.class), mockBundle, false);
    Resource imported = context.resourceResolver().getResource("/libs/app");
    assertThat("Resource was not imported", imported, notNullValue());
    assertThat("sling:resourceType was not properly set", imported.getResourceType(), equalTo("sling:Folder"));
}
Also used : MockBundle(org.apache.sling.testing.mock.osgi.MockBundle) Bundle(org.osgi.framework.Bundle) Resource(org.apache.sling.api.resource.Resource) Session(javax.jcr.Session) Test(org.junit.Test)

Aggregations

MockBundle (org.apache.sling.testing.mock.osgi.MockBundle)8 Test (org.junit.Test)5 Session (javax.jcr.Session)3 Resource (org.apache.sling.api.resource.Resource)3 Bundle (org.osgi.framework.Bundle)3 ObjectName (javax.management.ObjectName)2 Ignore (org.junit.Ignore)1