Search in sources :

Example 26 with Resource

use of com.enonic.xp.resource.Resource in project xp by enonic.

the class SchemaLoader method loadIcon.

private Icon loadIcon(final N name, final String mimeType, final String ext) {
    final ResourceKey resourceKey = toResourceKey(name, ext);
    final Resource resource = this.resourceService.getResource(resourceKey);
    return SchemaHelper.loadIcon(resource, mimeType);
}
Also used : Resource(com.enonic.xp.resource.Resource) ResourceKey(com.enonic.xp.resource.ResourceKey)

Example 27 with Resource

use of com.enonic.xp.resource.Resource in project xp by enonic.

the class TaskDescriptorLoaderTest method testLoad.

@Test
public void testLoad() {
    final DescriptorKey descriptorKey = DescriptorKey.from("myapp1:task1");
    final ResourceKey resourceKey = this.loader.toResource(descriptorKey);
    assertEquals("myapp1:/tasks/task1/task1.xml", resourceKey.toString());
    final Resource resource = this.resourceService.getResource(resourceKey);
    final TaskDescriptor descriptor = this.loader.load(descriptorKey, resource);
    assertEquals("MyTask", descriptor.getDescription());
    FormItem formItem = descriptor.getConfig().getFormItem("param1");
    assertEquals(" something ", formItem.toInput().getDefaultValue().getRootValue());
}
Also used : TaskDescriptor(com.enonic.xp.task.TaskDescriptor) FormItem(com.enonic.xp.form.FormItem) Resource(com.enonic.xp.resource.Resource) DescriptorKey(com.enonic.xp.page.DescriptorKey) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 28 with Resource

use of com.enonic.xp.resource.Resource in project xp by enonic.

the class ServiceHandlerTest method setup.

@BeforeEach
public final void setup() throws Exception {
    this.request = new PortalRequest();
    final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
    this.controllerScript = Mockito.mock(ControllerScript.class);
    Mockito.when(controllerScriptFactory.fromDir(Mockito.any())).thenReturn(this.controllerScript);
    final PortalResponse portalResponse = PortalResponse.create().build();
    Mockito.when(this.controllerScript.execute(Mockito.any())).thenReturn(portalResponse);
    this.resourceService = Mockito.mock(ResourceService.class);
    final Resource resourceNotFound = Mockito.mock(Resource.class);
    Mockito.when(resourceNotFound.exists()).thenReturn(false);
    final Resource resource = Mockito.mock(Resource.class);
    Mockito.when(resource.exists()).thenReturn(true);
    Mockito.when(this.resourceService.getResource(ResourceKey.from("demo:/services/test"))).thenReturn(resourceNotFound);
    this.serviceDescriptorService = Mockito.mock(ServiceDescriptorService.class);
    final DescriptorKey serviceDescriptorKey = DescriptorKey.from("demo:test");
    final ServiceDescriptor serviceDescriptor = ServiceDescriptor.create().key(serviceDescriptorKey).build();
    Mockito.when(this.serviceDescriptorService.getByKey(serviceDescriptorKey)).thenReturn(serviceDescriptor);
    this.contentService = Mockito.mock(ContentService.class);
    this.handler = new ServiceHandler();
    this.handler.setControllerScriptFactory(controllerScriptFactory);
    this.handler.setContentService(this.contentService);
    this.handler.setResourceService(this.resourceService);
    this.handler.setServiceDescriptorService(this.serviceDescriptorService);
    this.request.setMethod(HttpMethod.GET);
    this.request.setContentPath(ContentPath.from("/site/somepath/content"));
    this.request.setEndpointPath("/_/service/demo/myservice");
    this.request.setRawPath("/site/draft/site/somepath/content/_/service/demo/myservice");
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) ServiceDescriptor(com.enonic.xp.service.ServiceDescriptor) ResourceService(com.enonic.xp.resource.ResourceService) Resource(com.enonic.xp.resource.Resource) DescriptorKey(com.enonic.xp.page.DescriptorKey) ContentService(com.enonic.xp.content.ContentService) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) PortalRequest(com.enonic.xp.portal.PortalRequest) ServiceDescriptorService(com.enonic.xp.service.ServiceDescriptorService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Resource (com.enonic.xp.resource.Resource)28 ResourceKey (com.enonic.xp.resource.ResourceKey)21 Test (org.junit.jupiter.api.Test)14 PortalResponse (com.enonic.xp.portal.PortalResponse)7 ContentService (com.enonic.xp.content.ContentService)6 PortalRequest (com.enonic.xp.portal.PortalRequest)6 ResourceService (com.enonic.xp.resource.ResourceService)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 ApplicationKey (com.enonic.xp.app.ApplicationKey)5 Branch (com.enonic.xp.branch.Branch)4 ContentId (com.enonic.xp.content.ContentId)4 ContentPath (com.enonic.xp.content.ContentPath)4 PropertyTree (com.enonic.xp.data.PropertyTree)4 DescriptorKey (com.enonic.xp.page.DescriptorKey)4 RenderMode (com.enonic.xp.portal.RenderMode)4 ErrorHandlerScript (com.enonic.xp.portal.impl.error.ErrorHandlerScript)4 ErrorHandlerScriptFactory (com.enonic.xp.portal.impl.error.ErrorHandlerScriptFactory)4 MockResource (com.enonic.xp.resource.MockResource)4 RunMode (com.enonic.xp.server.RunMode)4 Site (com.enonic.xp.site.Site)4