Search in sources :

Example 1 with SimplePropertyResolver

use of net.n2oapp.framework.config.test.SimplePropertyResolver in project n2o-framework by i-novus-llc.

the class AccessHeaderAT method testAdminAccess.

@Test
public void testAdminAccess() {
    Map<String, Object> user = new HashMap<>();
    user.put("username", "Admin");
    user.put("roles", Collections.singleton("admin"));
    user.put("permissions", Collections.singleton("edit"));
    setUserInfo(user);
    ((SimplePropertyResolver) builder.getEnvironment().getSystemProperties()).setProperty("n2o.access.schema.id", "schema");
    builder.getEnvironment().getContextProcessor().set("username", user.get("username"));
    SimplePage page = open(SimplePage.class);
    page.shouldExists();
    page.header().brandNameShouldBe("Шапка");
    page.widget(FormWidget.class).shouldExists();
    page.breadcrumb().titleShouldHaveText("Главная страница");
    page.header().nav().shouldHaveSize(3);
    AnchorMenuItem menuItem0 = page.header().nav().anchor(0);
    menuItem0.labelShouldHave("Доступно всем");
    menuItem0.urlShouldHave(getBaseUrl() + "/#/menu1");
    menuItem0.click();
    page.breadcrumb().titleShouldHaveText("Страница доступная всем");
    AnchorMenuItem menuItem1 = page.header().nav().anchor(1);
    menuItem1.labelShouldHave("Требуется роль admin");
    menuItem1.urlShouldHave(getBaseUrl() + "/#/menu2");
    menuItem1.click();
    page.breadcrumb().titleShouldHaveText("Страница доступная с ролью admin");
    AnchorMenuItem menuItem2 = page.header().nav().anchor(2);
    menuItem2.labelShouldHave("Требуется право edit");
    menuItem2.urlShouldHave(getBaseUrl() + "/#/menu3");
    menuItem2.click();
    page.breadcrumb().titleShouldHaveText("Страница доступная с правом edit");
    page.header().extra().shouldHaveSize(1);
    AnchorMenuItem extraLink = page.header().extra().item(0, AnchorMenuItem.class);
    extraLink.labelShouldHave("Admin");
    extraLink.click();
    page.breadcrumb().titleShouldHaveText("Главная страница");
}
Also used : FormWidget(net.n2oapp.framework.autotest.api.component.widget.FormWidget) HashMap(java.util.HashMap) AnchorMenuItem(net.n2oapp.framework.autotest.api.component.header.AnchorMenuItem) SimplePage(net.n2oapp.framework.autotest.api.component.page.SimplePage) SimplePropertyResolver(net.n2oapp.framework.config.test.SimplePropertyResolver) Test(org.junit.jupiter.api.Test)

Example 2 with SimplePropertyResolver

use of net.n2oapp.framework.config.test.SimplePropertyResolver in project n2o-framework by i-novus-llc.

the class AccessHeaderAT method testAnonymousAccess.

@Test
public void testAnonymousAccess() {
    setUserInfo(null);
    ((SimplePropertyResolver) builder.getEnvironment().getSystemProperties()).setProperty("n2o.access.schema.id", "schema");
    SimplePage page = open(SimplePage.class);
    page.shouldExists();
    page.header().brandNameShouldBe("Шапка");
    page.widget(FormWidget.class).shouldExists();
    page.breadcrumb().titleShouldHaveText("Главная страница");
    page.header().nav().shouldHaveSize(2);
    AnchorMenuItem menuItem0 = page.header().nav().anchor(0);
    menuItem0.labelShouldHave("Доступно всем");
    menuItem0.urlShouldHave(getBaseUrl() + "/#/menu1");
    menuItem0.click();
    page.breadcrumb().titleShouldHaveText("Страница доступная всем");
    AnchorMenuItem menuItem3 = page.header().nav().anchor(1);
    menuItem3.labelShouldHave("Только анонимам");
    menuItem3.urlShouldHave(getBaseUrl() + "/#/menu4");
    menuItem3.click();
    page.breadcrumb().titleShouldHaveText("Страница доступная только анонимам");
}
Also used : FormWidget(net.n2oapp.framework.autotest.api.component.widget.FormWidget) AnchorMenuItem(net.n2oapp.framework.autotest.api.component.header.AnchorMenuItem) SimplePage(net.n2oapp.framework.autotest.api.component.page.SimplePage) SimplePropertyResolver(net.n2oapp.framework.config.test.SimplePropertyResolver) Test(org.junit.jupiter.api.Test)

Example 3 with SimplePropertyResolver

use of net.n2oapp.framework.config.test.SimplePropertyResolver in project n2o-framework by i-novus-llc.

the class ApplicationAccessTransformerTest method testHeaderSidebarTransformV2permitAll.

@Test
public void testHeaderSidebarTransformV2permitAll() {
    ((SimplePropertyResolver) builder.getEnvironment().getSystemProperties()).setProperty("n2o.access.schema.id", "testHeaderV2permitAll");
    ReadCompileTerminalPipeline pipeline = compile("net/n2oapp/framework/access/metadata/schema/testHeaderV2permitAll.access.xml", "net/n2oapp/framework/access/metadata/transform/testApplicationAccessTransformer.application.xml");
    Application application = (Application) ((ReadCompileTerminalPipeline) pipeline.transform()).get(new ApplicationContext("testApplicationAccessTransformer"));
    checkPermitAll(((Security) application.getHeader().getMenu().getItems().get(0).getProperties().get(SECURITY_PROP_NAME)).getSecurityMap());
    checkPermitAll(((Security) application.getSidebar().getMenu().getItems().get(0).getProperties().get(SECURITY_PROP_NAME)).getSecurityMap());
}
Also used : ApplicationContext(net.n2oapp.framework.config.metadata.compile.context.ApplicationContext) ReadCompileTerminalPipeline(net.n2oapp.framework.api.metadata.pipeline.ReadCompileTerminalPipeline) Application(net.n2oapp.framework.api.metadata.application.Application) SimplePropertyResolver(net.n2oapp.framework.config.test.SimplePropertyResolver) Test(org.junit.Test)

Example 4 with SimplePropertyResolver

use of net.n2oapp.framework.config.test.SimplePropertyResolver in project n2o-framework by i-novus-llc.

the class ApplicationAccessTransformerTest method testHeaderSidebarTransformV2Auth.

@Test
public void testHeaderSidebarTransformV2Auth() {
    ((SimplePropertyResolver) builder.getEnvironment().getSystemProperties()).setProperty("n2o.access.schema.id", "testHeaderV2auth");
    ReadCompileTerminalPipeline pipeline = compile("net/n2oapp/framework/access/metadata/schema/testHeaderV2auth.access.xml", "net/n2oapp/framework/access/metadata/transform/testApplicationAccessTransformer.application.xml");
    Application application = (Application) ((ReadCompileTerminalPipeline) pipeline.transform()).get(new ApplicationContext("testApplicationAccessTransformer"));
    checkAuth(((Security) application.getHeader().getMenu().getItems().get(0).getProperties().get(SECURITY_PROP_NAME)).getSecurityMap());
    checkAuth(((Security) application.getSidebar().getMenu().getItems().get(0).getProperties().get(SECURITY_PROP_NAME)).getSecurityMap());
}
Also used : ApplicationContext(net.n2oapp.framework.config.metadata.compile.context.ApplicationContext) ReadCompileTerminalPipeline(net.n2oapp.framework.api.metadata.pipeline.ReadCompileTerminalPipeline) Application(net.n2oapp.framework.api.metadata.application.Application) SimplePropertyResolver(net.n2oapp.framework.config.test.SimplePropertyResolver) Test(org.junit.Test)

Example 5 with SimplePropertyResolver

use of net.n2oapp.framework.config.test.SimplePropertyResolver in project n2o-framework by i-novus-llc.

the class ApplicationAccessTransformerTest method testHeaderSidebarTransformV2Anonym.

@Test
public void testHeaderSidebarTransformV2Anonym() {
    ((SimplePropertyResolver) builder.getEnvironment().getSystemProperties()).setProperty("n2o.access.schema.id", "testHeaderV2anonym");
    ReadCompileTerminalPipeline pipeline = compile("net/n2oapp/framework/access/metadata/schema/testHeaderV2anonym.access.xml", "net/n2oapp/framework/access/metadata/transform/testApplicationAccessTransformer.application.xml");
    Application application = (Application) ((ReadCompileTerminalPipeline) pipeline.transform()).get(new ApplicationContext("testApplicationAccessTransformer"));
    checkAnonym(((Security) application.getHeader().getMenu().getItems().get(0).getProperties().get(SECURITY_PROP_NAME)).getSecurityMap());
    checkAnonym(((Security) application.getSidebar().getMenu().getItems().get(0).getProperties().get(SECURITY_PROP_NAME)).getSecurityMap());
}
Also used : ApplicationContext(net.n2oapp.framework.config.metadata.compile.context.ApplicationContext) ReadCompileTerminalPipeline(net.n2oapp.framework.api.metadata.pipeline.ReadCompileTerminalPipeline) Application(net.n2oapp.framework.api.metadata.application.Application) SimplePropertyResolver(net.n2oapp.framework.config.test.SimplePropertyResolver) Test(org.junit.Test)

Aggregations

SimplePropertyResolver (net.n2oapp.framework.config.test.SimplePropertyResolver)39 Test (org.junit.Test)30 Security (net.n2oapp.framework.access.metadata.Security)22 ReadCompileTerminalPipeline (net.n2oapp.framework.api.metadata.pipeline.ReadCompileTerminalPipeline)20 PageContext (net.n2oapp.framework.config.metadata.compile.context.PageContext)17 StandardPage (net.n2oapp.framework.api.metadata.meta.page.StandardPage)16 N2oEnvironment (net.n2oapp.framework.config.compile.pipeline.N2oEnvironment)6 Before (org.junit.Before)6 Application (net.n2oapp.framework.api.metadata.application.Application)5 N2oApplicationBuilder (net.n2oapp.framework.config.N2oApplicationBuilder)5 ApplicationContext (net.n2oapp.framework.config.metadata.compile.context.ApplicationContext)5 ReaderFactoryByMap (net.n2oapp.framework.config.selective.reader.ReaderFactoryByMap)5 Properties (java.util.Properties)4 AbstractButton (net.n2oapp.framework.api.metadata.meta.widget.toolbar.AbstractButton)4 MessageSourceAccessor (org.springframework.context.support.MessageSourceAccessor)4 ResourceBundleMessageSource (org.springframework.context.support.ResourceBundleMessageSource)4 PersisterFactoryByMap (net.n2oapp.framework.config.selective.persister.PersisterFactoryByMap)3 OverrideProperties (net.n2oapp.properties.OverrideProperties)3 HashMap (java.util.HashMap)2 SecurityFilters (net.n2oapp.framework.access.metadata.SecurityFilters)2