use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class FilterScriptImplTest method setup.
@BeforeEach
public void setup() throws Exception {
this.portalRequest = new PortalRequest();
this.portalResponse = PortalResponse.create().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.isStarted()).thenReturn(true);
Mockito.when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
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 = FilterScriptImplTest.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 FilterScriptFactoryImpl();
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 MappingHandlerTest method executeFilter.
@Test
public void executeFilter() throws Exception {
final ResourceKey filter = ResourceKey.from("demo:/services/test");
final ControllerMappingDescriptor mapping = ControllerMappingDescriptor.create().filter(filter).pattern(".*/content").build();
setupContentAndSite(mapping);
this.request.setBaseUri("/site");
this.request.setContentPath(ContentPath.from("/site/somesite/content"));
final WebResponse response = this.handler.handle(this.request, PortalResponse.create().build(), null);
assertEquals(HttpStatus.OK, response.getStatus());
assertNotNull(this.request.getApplicationKey());
assertNotNull(this.request.getSite());
assertNotNull(this.request.getContent());
assertEquals("/site/draft/site", this.request.getContextPath());
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class MainExecutorTest method mainJsError.
@Test
public void mainJsError() {
final ResourceKey key = ResourceKey.from("foo.bar:/main.js");
when(this.scriptService.hasScript(key)).thenReturn(true);
when(this.scriptService.executeAsync(key)).thenReturn(CompletableFuture.failedFuture(new RuntimeException()));
final Application app = mock(Application.class);
when(app.getKey()).thenReturn(ApplicationKey.from("foo.bar"));
this.executor.activated(app);
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class PortalUrlServiceImpl_assetUrlTest method createUrl_encodeChars.
@Test
public void createUrl_encodeChars() {
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 other & strange.css");
final String url = this.service.assetUrl(params);
assertEquals("/site/default/draft/_/asset/myapplication:0000000000000001/css/my%20other%20&%20strange.css", url);
}
use of com.enonic.xp.resource.ResourceKey in project xp by enonic.
the class PortalUrlServiceImpl_assetUrlTest method createUrl_absolute.
@Test
public void createUrl_absolute() {
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().type(UrlTypeConstants.ABSOLUTE).portalRequest(this.portalRequest).path("css/my.css");
when(req.getServerName()).thenReturn("localhost");
when(req.getScheme()).thenReturn("http");
when(req.getServerPort()).thenReturn(80);
final String url = this.service.assetUrl(params);
assertEquals("http://localhost/site/default/draft/_/asset/myapplication:0000000000000001/css/my.css", url);
}
Aggregations