Search in sources :

Example 6 with MockBundle

use of org.apache.sling.commons.testing.osgi.MockBundle in project acs-aem-commons by Adobe-Consulting-Services.

the class StaticReferenceRewriteTransformerFactoryTest method test_without_config_is_noop.

@Test
public void test_without_config_is_noop() throws Exception {
    MockBundle bundle = new MockBundle(-1);
    MockComponentContext ctx = new MockComponentContext(bundle);
    StaticReferenceRewriteTransformerFactory factory = new StaticReferenceRewriteTransformerFactory();
    factory.activate(ctx);
    Transformer transformer = factory.createTransformer();
    transformer.setContentHandler(handler);
    AttributesImpl in = new AttributesImpl();
    in.addAttribute(null, "href", null, "CDATA", "/etc/clientlib/test.css");
    transformer.startElement(null, "link", null, in);
    verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class), attributesCaptor.capture());
    Attributes out = attributesCaptor.getValue();
    assertEquals("/etc/clientlib/test.css", out.getValue(0));
}
Also used : MockComponentContext(org.apache.sling.commons.testing.osgi.MockComponentContext) Transformer(org.apache.sling.rewriter.Transformer) AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) MockBundle(org.apache.sling.commons.testing.osgi.MockBundle) Test(org.junit.Test)

Example 7 with MockBundle

use of org.apache.sling.commons.testing.osgi.MockBundle in project acs-aem-commons by Adobe-Consulting-Services.

the class StaticReferenceRewriteTransformerFactoryTest method test_with_nonrewritten_attribute.

@Test
public void test_with_nonrewritten_attribute() throws Exception {
    MockBundle bundle = new MockBundle(-1);
    MockComponentContext ctx = new MockComponentContext(bundle);
    ctx.setProperty("prefixes", new String[] { "/etc/clientlib" });
    ctx.setProperty("host.pattern", "static{}.host.com");
    ctx.setProperty("host.count", 2);
    StaticReferenceRewriteTransformerFactory factory = new StaticReferenceRewriteTransformerFactory();
    factory.activate(ctx);
    Transformer transformer = factory.createTransformer();
    transformer.setContentHandler(handler);
    AttributesImpl in = new AttributesImpl();
    in.addAttribute(null, "src", null, "CDATA", "/etc/clientlib/testABC.css");
    transformer.startElement(null, "link", null, in);
    verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class), attributesCaptor.capture());
    Attributes out = attributesCaptor.getValue();
    assertEquals("/etc/clientlib/testABC.css", out.getValue(0));
}
Also used : MockComponentContext(org.apache.sling.commons.testing.osgi.MockComponentContext) Transformer(org.apache.sling.rewriter.Transformer) AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) MockBundle(org.apache.sling.commons.testing.osgi.MockBundle) Test(org.junit.Test)

Example 8 with MockBundle

use of org.apache.sling.commons.testing.osgi.MockBundle in project acs-aem-commons by Adobe-Consulting-Services.

the class StaticReferenceRewriteTransformerFactoryTest method test_with_prefix_and_multiple_named_hosts.

@Test
public void test_with_prefix_and_multiple_named_hosts() throws Exception {
    MockBundle bundle = new MockBundle(-1);
    MockComponentContext ctx = new MockComponentContext(bundle);
    ctx.setProperty("prefixes", new String[] { "/etc/clientlib" });
    ctx.setProperty("host.pattern", new String[] { "staticA.host.com", "staticB.host.com" });
    ctx.setProperty("host.count", 2);
    StaticReferenceRewriteTransformerFactory factory = new StaticReferenceRewriteTransformerFactory();
    factory.activate(ctx);
    Transformer transformer = factory.createTransformer();
    transformer.setContentHandler(handler);
    AttributesImpl in = new AttributesImpl();
    in.addAttribute(null, "href", null, "CDATA", "/etc/clientlib/testA.css");
    transformer.startElement(null, "link", null, in);
    verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class), attributesCaptor.capture());
    Attributes out = attributesCaptor.getValue();
    assertEquals("//staticB.host.com/etc/clientlib/testA.css", out.getValue(0));
}
Also used : MockComponentContext(org.apache.sling.commons.testing.osgi.MockComponentContext) Transformer(org.apache.sling.rewriter.Transformer) AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) MockBundle(org.apache.sling.commons.testing.osgi.MockBundle) Test(org.junit.Test)

Example 9 with MockBundle

use of org.apache.sling.commons.testing.osgi.MockBundle in project acs-aem-commons by Adobe-Consulting-Services.

the class StaticReferenceRewriteTransformerFactoryTest method test_with_non_matching_prefix_and_single_host.

@Test
public void test_with_non_matching_prefix_and_single_host() throws Exception {
    MockBundle bundle = new MockBundle(-1);
    MockComponentContext ctx = new MockComponentContext(bundle);
    ctx.setProperty("prefixes", new String[] { "/etc/clientlib" });
    ctx.setProperty("host.pattern", "static.host.com");
    StaticReferenceRewriteTransformerFactory factory = new StaticReferenceRewriteTransformerFactory();
    factory.activate(ctx);
    Transformer transformer = factory.createTransformer();
    transformer.setContentHandler(handler);
    AttributesImpl in = new AttributesImpl();
    in.addAttribute(null, "href", null, "CDATA", "/content/clientlib/test.css");
    transformer.startElement(null, "link", null, in);
    verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class), attributesCaptor.capture());
    Attributes out = attributesCaptor.getValue();
    assertEquals("/content/clientlib/test.css", out.getValue(0));
}
Also used : MockComponentContext(org.apache.sling.commons.testing.osgi.MockComponentContext) Transformer(org.apache.sling.rewriter.Transformer) AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) MockBundle(org.apache.sling.commons.testing.osgi.MockBundle) Test(org.junit.Test)

Example 10 with MockBundle

use of org.apache.sling.commons.testing.osgi.MockBundle in project acs-aem-commons by Adobe-Consulting-Services.

the class StaticReferenceRewriteTransformerFactoryTest method test_with_nostatic_class.

@Test
public void test_with_nostatic_class() throws Exception {
    MockBundle bundle = new MockBundle(-1);
    MockComponentContext ctx = new MockComponentContext(bundle);
    ctx.setProperty("prefixes", new String[] { "/etc/clientlib" });
    ctx.setProperty("host.pattern", "static.host.com");
    StaticReferenceRewriteTransformerFactory factory = new StaticReferenceRewriteTransformerFactory();
    factory.activate(ctx);
    Transformer transformer = factory.createTransformer();
    transformer.setContentHandler(handler);
    AttributesImpl in = new AttributesImpl();
    in.addAttribute(null, "href", null, "CDATA", "/etc/clientlib/test.css");
    in.addAttribute(null, "class", null, "CDATA", "something nostatic");
    transformer.startElement(null, "link", null, in);
    verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class), attributesCaptor.capture());
    Attributes out = attributesCaptor.getValue();
    assertEquals("/etc/clientlib/test.css", out.getValue(0));
}
Also used : MockComponentContext(org.apache.sling.commons.testing.osgi.MockComponentContext) Transformer(org.apache.sling.rewriter.Transformer) AttributesImpl(org.xml.sax.helpers.AttributesImpl) Attributes(org.xml.sax.Attributes) MockBundle(org.apache.sling.commons.testing.osgi.MockBundle) Test(org.junit.Test)

Aggregations

MockBundle (org.apache.sling.commons.testing.osgi.MockBundle)10 MockComponentContext (org.apache.sling.commons.testing.osgi.MockComponentContext)9 Transformer (org.apache.sling.rewriter.Transformer)9 Test (org.junit.Test)9 Attributes (org.xml.sax.Attributes)9 AttributesImpl (org.xml.sax.helpers.AttributesImpl)9 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)1 Map (java.util.Map)1 LoginException (org.apache.sling.api.resource.LoginException)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)1 MockBundleContext (org.apache.sling.commons.testing.osgi.MockBundleContext)1 MockServiceReference (org.apache.sling.commons.testing.osgi.MockServiceReference)1 MockResource (org.apache.sling.commons.testing.sling.MockResource)1 MockResourceResolver (org.apache.sling.commons.testing.sling.MockResourceResolver)1 MockServletResource (org.apache.sling.servlets.resolver.internal.resource.MockServletResource)1