Search in sources :

Example 6 with WidgetDescriptor

use of com.enonic.xp.admin.widget.WidgetDescriptor in project xp by enonic.

the class WidgetDescriptorServiceTest method get_allowed_by_interfaces_as_admin.

@Test
public void get_allowed_by_interfaces_as_admin() throws Exception {
    final AuthenticationInfo authenticationInfo = AuthenticationInfo.copyOf(ContextAccessor.current().getAuthInfo()).principals(PrincipalKey.ofRole("system.admin")).build();
    final Context adminContext = ContextBuilder.from(ContextAccessor.current()).authInfo(authenticationInfo).build();
    adminContext.runWith(() -> {
        final Descriptors<WidgetDescriptor> result = this.service.getAllowedByInterfaces("com.enonic.xp.my-interface");
        assertEquals(4, result.getSize());
        assertTrue(result.contains(widgetDescriptor1));
        assertTrue(result.contains(widgetDescriptor3));
        assertTrue(result.contains(widgetDescriptor4));
        assertTrue(result.contains(widgetDescriptor5));
    });
}
Also used : Context(com.enonic.xp.context.Context) WidgetDescriptor(com.enonic.xp.admin.widget.WidgetDescriptor) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Test(org.junit.jupiter.api.Test)

Example 7 with WidgetDescriptor

use of com.enonic.xp.admin.widget.WidgetDescriptor in project xp by enonic.

the class WidgetDescriptorLoaderTest method testCreateDefault.

@Test
public void testCreateDefault() {
    final DescriptorKey key = DescriptorKey.from("myapp1:widget1");
    final WidgetDescriptor descriptor = this.loader.createDefault(key);
    assertEquals(key, descriptor.getKey());
    assertEquals("widget1", descriptor.getName());
}
Also used : DescriptorKey(com.enonic.xp.page.DescriptorKey) WidgetDescriptor(com.enonic.xp.admin.widget.WidgetDescriptor) Test(org.junit.jupiter.api.Test)

Example 8 with WidgetDescriptor

use of com.enonic.xp.admin.widget.WidgetDescriptor in project xp by enonic.

the class WidgetDescriptorLoaderTest method testLoadMax.

@Test
public void testLoadMax() {
    final DescriptorKey descriptorKey = DescriptorKey.from("myapp1:widget1");
    final ResourceKey resourceKey = this.loader.toResource(descriptorKey);
    assertEquals("myapp1:/admin/widgets/widget1/widget1.xml", resourceKey.toString());
    final Resource resource = this.resourceService.getResource(resourceKey);
    final WidgetDescriptor descriptor = this.loader.load(descriptorKey, resource);
    assertEquals("MyWidget", descriptor.getDisplayName());
    assertEquals(1, descriptor.getInterfaces().size());
    assertTrue(descriptor.getInterfaces().contains("com.enonic.xp.my-interface"));
    assertEquals(1, descriptor.getAllowedPrincipals().getSize());
    assertTrue(descriptor.getAllowedPrincipals().contains(PrincipalKey.from("role:system.user.admin")));
}
Also used : Resource(com.enonic.xp.resource.Resource) DescriptorKey(com.enonic.xp.page.DescriptorKey) WidgetDescriptor(com.enonic.xp.admin.widget.WidgetDescriptor) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 9 with WidgetDescriptor

use of com.enonic.xp.admin.widget.WidgetDescriptor in project xp by enonic.

the class XmlWidgetDescriptorParserTest method assertResult.

private void assertResult() throws Exception {
    final WidgetDescriptor result = this.builder.build();
    assertEquals("myapplication:mywidget", result.getKey().toString());
    assertEquals("mywidget", result.getName());
    assertEquals("My widget", result.getDisplayName());
    assertEquals("My widget description", result.getDescription());
    assertEquals("myapplication:mywidget", result.getKeyString());
    assertEquals("_/widgets/myapplication/mywidget", result.getUrl());
    final Set<String> interfaces = result.getInterfaces();
    assertNotNull(interfaces);
    assertEquals(2, interfaces.size());
    final Map<String, String> config = result.getConfig();
    assertNotNull(config);
    assertEquals(2, config.size());
}
Also used : WidgetDescriptor(com.enonic.xp.admin.widget.WidgetDescriptor)

Example 10 with WidgetDescriptor

use of com.enonic.xp.admin.widget.WidgetDescriptor in project xp by enonic.

the class WidgetDescriptorServiceTest method get_by_key.

@Test
public void get_by_key() throws Exception {
    final WidgetDescriptor allowedWidget = this.service.getByKey(DescriptorKey.from("app:d"));
    assertSame(allowedWidget, widgetDescriptor4);
    final WidgetDescriptor unknownWidget = this.service.getByKey(DescriptorKey.from("app:unknown"));
    assertNull(unknownWidget);
}
Also used : WidgetDescriptor(com.enonic.xp.admin.widget.WidgetDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

WidgetDescriptor (com.enonic.xp.admin.widget.WidgetDescriptor)10 Test (org.junit.jupiter.api.Test)6 DescriptorKey (com.enonic.xp.page.DescriptorKey)4 ResourceKey (com.enonic.xp.resource.ResourceKey)3 Resource (com.enonic.xp.resource.Resource)2 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)2 Context (com.enonic.xp.context.Context)1 Icon (com.enonic.xp.icon.Icon)1 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)1 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)1