use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class MappingHandlerTest method executeNothing.
@Test
public void executeNothing() throws Exception {
final ResourceKey controller = ResourceKey.from("demo:/services/test");
final ControllerMappingDescriptor mapping = ControllerMappingDescriptor.create().controller(controller).pattern("/nomatch").build();
setupContentAndSite(mapping);
final WebHandlerChain chain = mock(WebHandlerChain.class);
final PortalResponse response = PortalResponse.create().build();
this.request.setBaseUri("/site");
this.request.setContentPath(ContentPath.from("/site/somesite/content"));
this.handler.handle(this.request, response, chain);
verify(chain).handle(this.request, response);
verifyNoInteractions(rendererDelegate);
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class MacroProcessorScriptTest method setup.
@BeforeEach
public void setup() throws Exception {
this.macroContext = MacroContext.create().name("macroName").body("body").param("firstParam", "firstParamValue").param("secondParam", "secondParamValue").document("<h1>document</h1>").build();
final BundleContext bundleContext = Mockito.mock(BundleContext.class);
final Bundle bundle = Mockito.mock(Bundle.class);
Mockito.when(bundle.getBundleContext()).thenReturn(bundleContext);
final Application application = Mockito.mock(Application.class);
Mockito.when(application.getBundle()).thenReturn(bundle);
Mockito.when(application.getClassLoader()).thenReturn(getClass().getClassLoader());
Mockito.when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
Mockito.when(application.isStarted()).thenReturn(true);
final ApplicationService applicationService = Mockito.mock(ApplicationService.class);
Mockito.when(applicationService.getInstalledApplication(ApplicationKey.from("myapplication"))).thenReturn(application);
this.resourceService = Mockito.mock(ResourceService.class);
Mockito.when(resourceService.getResource(Mockito.any())).thenAnswer(invocation -> {
final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
final URL resourceUrl = MacroProcessorScriptTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
return new UrlResource(resourceKey, resourceUrl);
});
final ScriptAsyncService scriptAsyncService = Mockito.mock(ScriptAsyncService.class);
final ScriptRuntimeFactoryImpl runtimeFactory = new ScriptRuntimeFactoryImpl(applicationService, this.resourceService, scriptAsyncService);
final PortalScriptServiceImpl scriptService = new PortalScriptServiceImpl(runtimeFactory);
scriptService.initialize();
this.factory = new MacroProcessorFactoryImpl();
this.factory.setScriptService(scriptService);
final HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
ServletRequestHolder.setRequest(req);
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class PortalUrlServiceImpl_assetUrlTest method createUrl_withVirtualHost.
@Test
public void createUrl_withVirtualHost() {
final ResourceKey resourceKey = ResourceKey.from(ApplicationKey.from("myapplication"), "META-INF/MANIFEST.MF");
when(this.resourceService.getResource(resourceKey)).thenReturn(MockResource.empty(resourceKey, 1));
final AssetUrlParams params = new AssetUrlParams().portalRequest(this.portalRequest).path("css/my.css");
// Mocks a virtual host and the HTTP request
final VirtualHost virtualHost = mock(VirtualHost.class);
when(req.getAttribute(VirtualHost.class.getName())).thenReturn(virtualHost);
// Calls the method with a virtual mapping /main -> /
when(virtualHost.getSource()).thenReturn("/main");
when(virtualHost.getTarget()).thenReturn("/");
String url = this.service.assetUrl(params);
assertEquals("/main/site/default/draft/_/asset/myapplication:0000000000000001/css/my.css", url);
// Calls the method with a virtual mapping /main -> /site/default/draft/context
when(virtualHost.getSource()).thenReturn("/main");
when(virtualHost.getTarget()).thenReturn("/site");
url = this.service.assetUrl(params);
assertEquals("/main/default/draft/_/asset/myapplication:0000000000000001/css/my.css", url);
// Calls the method with a virtual mapping /main -> /site/default/draft/context
when(virtualHost.getSource()).thenReturn("/main");
when(virtualHost.getTarget()).thenReturn("/site/default/draft");
url = this.service.assetUrl(params);
assertEquals("/main/_/asset/myapplication:0000000000000001/css/my.css", url);
// Calls the method with a virtual mapping / -> /site/default/draft/context
when(virtualHost.getSource()).thenReturn("/");
when(virtualHost.getTarget()).thenReturn("/site/default/draft/context");
url = this.service.assetUrl(params);
assertEquals("/_/asset/myapplication:0000000000000001/css/my.css", url);
// Calls the method with a virtual mapping /main/path -> /site/default/draft/context/path
when(virtualHost.getSource()).thenReturn("/main/path");
when(virtualHost.getTarget()).thenReturn("/site/default/draft/context/path");
url = this.service.assetUrl(params);
assertEquals("/main/path/_/asset/myapplication:0000000000000001/css/my.css", url);
// Calls the method with a virtual mapping /site/default/draft/context/path -> /site/default/draft/context/path
when(virtualHost.getSource()).thenReturn("/site/default/draft/context/path");
when(virtualHost.getTarget()).thenReturn("/site/default/draft/context/path");
url = this.service.assetUrl(params);
assertEquals("/site/default/draft/context/path/_/asset/myapplication:0000000000000001/css/my.css", url);
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class PortalUrlServiceImpl_assetUrlTest method createUrl.
@Test
public void createUrl() {
final ResourceKey resourceKey = ResourceKey.from(ApplicationKey.from("myapplication"), "META-INF/MANIFEST.MF");
when(this.resourceService.getResource(resourceKey)).thenReturn(MockResource.empty(resourceKey, 1));
final AssetUrlParams params = new AssetUrlParams().portalRequest(this.portalRequest).path("css/my.css");
final String url = this.service.assetUrl(params);
assertEquals("/site/default/draft/_/asset/myapplication:0000000000000001/css/my.css", url);
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class PortalUrlServiceImpl_assetUrlTest method createUrl_withApplication.
@Test
public void createUrl_withApplication() {
final ResourceKey resourceKey = ResourceKey.from(ApplicationKey.from("otherapplication"), "META-INF/MANIFEST.MF");
when(this.resourceService.getResource(resourceKey)).thenReturn(MockResource.empty(resourceKey, 2));
final AssetUrlParams params = new AssetUrlParams().portalRequest(this.portalRequest).application("otherapplication").path("css/my.css");
final String url = this.service.assetUrl(params);
assertEquals("/site/default/draft/_/asset/otherapplication:0000000000000002/css/my.css", url);
}
Aggregations