Search in sources :

Example 6 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class DescriptorKeysTest method testFrom_array.

@Test
public void testFrom_array() {
    final DescriptorKey key1 = DescriptorKey.from("app1:abc");
    final DescriptorKey key2 = DescriptorKey.from("app2:abc");
    final DescriptorKeys keys = DescriptorKeys.from(key1, key2);
    assertEquals("[app1:abc, app2:abc]", keys.toString());
}
Also used : DescriptorKey(com.enonic.xp.page.DescriptorKey) Test(org.junit.jupiter.api.Test)

Example 7 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class PageDescriptorServiceImpl method getByKey.

@Override
public PageDescriptor getByKey(final DescriptorKey key) {
    final ResourceProcessor<DescriptorKey, PageDescriptor> processor = newProcessor(key);
    final PageDescriptor descriptor = this.resourceService.processResource(processor);
    if (descriptor == null) {
        return createDefaultDescriptor(key);
    }
    return PageDescriptor.copyOf(descriptor).config(this.mixinService.inlineFormItems(descriptor.getConfig())).build();
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) DescriptorKey(com.enonic.xp.page.DescriptorKey)

Example 8 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class FlattenedPageIndexUpgraderTest method test.

private void test(final String dataFile, final String oldIndexDocumentFile, final String newIndexDocumentFile) throws Exception {
    final JsonNode pageComponents = loadJson(dataFile);
    final PropertyTree data = new JsonToPropertyTreeTranslator().translate(pageComponents);
    final List<PropertySet> components = Lists.newArrayList(data.getSets("components"));
    if (components.size() == 0) {
        throw new RuntimeException("page components is empty");
    }
    final String descriptorKeyStr = data.getString(PropertyPath.from("components.page.descriptor"));
    if (descriptorKeyStr == null) {
        throw new RuntimeException("page descriptorKey is null");
    }
    final DescriptorKey descriptorKey = DescriptorKey.from(descriptorKeyStr);
    final PatternIndexConfigDocument oldDocument = getIndexConfigDocument(oldIndexDocumentFile);
    final PatternIndexConfigDocument newDocument = new FlattenedPageIndexUpgrader(descriptorKey, components).upgrade(oldDocument);
    assertEquals(getIndexConfigDocument(newIndexDocumentFile), newDocument);
}
Also used : JsonToPropertyTreeTranslator(com.enonic.xp.json.JsonToPropertyTreeTranslator) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) DescriptorKey(com.enonic.xp.page.DescriptorKey) JsonNode(com.fasterxml.jackson.databind.JsonNode) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) FlattenedPageIndexUpgrader(com.enonic.xp.repo.impl.dump.upgrade.flattenedpage.FlattenedPageIndexUpgrader)

Example 9 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class AdminToolHandlerTest method setup.

@BeforeEach
public final void setup() throws Exception {
    this.adminToolDescriptorService = Mockito.mock(AdminToolDescriptorService.class);
    ControllerScript controllerScript = Mockito.mock(ControllerScript.class);
    this.portalResponse = PortalResponse.create().build();
    Mockito.when(controllerScript.execute(Mockito.any(PortalRequest.class))).thenReturn(this.portalResponse);
    final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
    Mockito.when(controllerScriptFactory.fromDir(Mockito.any(ResourceKey.class))).thenReturn(controllerScript);
    this.handler = new AdminToolHandler();
    this.handler.setAdminToolDescriptorService(this.adminToolDescriptorService);
    this.handler.setControllerScriptFactory(controllerScriptFactory);
    this.rawRequest = Mockito.mock(HttpServletRequest.class);
    Mockito.when(this.rawRequest.isUserInRole(Mockito.anyString())).thenReturn(true);
    this.portalRequest = new PortalRequest();
    this.portalRequest.setRawRequest(this.rawRequest);
    this.portalRequest.setMode(RenderMode.ADMIN);
    final DescriptorKey defaultDescriptorKey = AdminToolPortalHandler.DEFAULT_DESCRIPTOR_KEY;
    this.portalRequest.setBaseUri(AdminToolPortalHandler.ADMIN_TOOL_PREFIX + defaultDescriptorKey.getApplicationKey() + "/" + defaultDescriptorKey.getName());
    this.portalRequest.setApplicationKey(defaultDescriptorKey.getApplicationKey());
    this.webResponse = WebResponse.create().build();
    this.chain = Mockito.mock(WebHandlerChain.class);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) AdminToolDescriptorService(com.enonic.xp.admin.tool.AdminToolDescriptorService) DescriptorKey(com.enonic.xp.page.DescriptorKey) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) PortalRequest(com.enonic.xp.portal.PortalRequest) ResourceKey(com.enonic.xp.resource.ResourceKey) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with DescriptorKey

use of com.enonic.xp.page.DescriptorKey in project xp by enonic.

the class AdminToolHandlerTest method mockDescriptor.

private void mockDescriptor(DescriptorKey descriptorKey, boolean hasAccess) {
    AdminToolDescriptor descriptor = Mockito.mock(AdminToolDescriptor.class);
    Mockito.when(descriptor.getKey()).thenReturn(descriptorKey);
    Mockito.when(descriptor.isAccessAllowed(Mockito.any(PrincipalKeys.class))).thenReturn(hasAccess);
    Mockito.when(this.adminToolDescriptorService.getByKey(Mockito.any(DescriptorKey.class))).thenReturn(descriptor);
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) DescriptorKey(com.enonic.xp.page.DescriptorKey) AdminToolDescriptor(com.enonic.xp.admin.tool.AdminToolDescriptor)

Aggregations

DescriptorKey (com.enonic.xp.page.DescriptorKey)73 Test (org.junit.jupiter.api.Test)45 PropertyTree (com.enonic.xp.data.PropertyTree)25 PrincipalKey (com.enonic.xp.security.PrincipalKey)11 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)10 TaskId (com.enonic.xp.task.TaskId)10 Page (com.enonic.xp.page.Page)7 ScheduledJobName (com.enonic.xp.scheduler.ScheduledJobName)7 TaskDescriptor (com.enonic.xp.task.TaskDescriptor)7 Instant (java.time.Instant)7 PropertySet (com.enonic.xp.data.PropertySet)6 ServiceDescriptor (com.enonic.xp.service.ServiceDescriptor)6 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)5 CronCalendar (com.enonic.xp.scheduler.CronCalendar)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ApplicationKey (com.enonic.xp.app.ApplicationKey)4 AbstractDescriptorServiceTest (com.enonic.xp.core.impl.content.page.AbstractDescriptorServiceTest)4 DescribedTask (com.enonic.xp.impl.task.distributed.DescribedTask)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4 PortalResponse (com.enonic.xp.portal.PortalResponse)4