Search in sources :

Example 11 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class XmlSiteParserTest method testSiteXmlDeserializationWithMappings.

@Test
public void testSiteXmlDeserializationWithMappings() {
    final String xml = loadTestXml("serialized-site-with-mappings.xml");
    final SiteDescriptor.Builder siteDescriptorBuilder = SiteDescriptor.create();
    ApplicationKey applicationKey = ApplicationKey.from("myapplication");
    this.parser.source(xml).currentApplication(applicationKey).siteDescriptorBuilder(siteDescriptorBuilder).parse();
    SiteDescriptor siteDescriptor = siteDescriptorBuilder.build();
    assertEquals(1, siteDescriptor.getForm().getFormItems().size());
    assertEquals(2, siteDescriptor.getXDataMappings().getSize());
    assertEquals(2, siteDescriptor.getResponseProcessors().getSize());
    assertEquals(3, siteDescriptor.getMappingDescriptors().getSize());
    final ControllerMappingDescriptor mapping1 = siteDescriptor.getMappingDescriptors().get(0);
    final ControllerMappingDescriptor mapping2 = siteDescriptor.getMappingDescriptors().get(1);
    final ControllerMappingDescriptor mapping3 = siteDescriptor.getMappingDescriptors().get(2);
    assertEquals("myapplication:/site/page/person/person.js", mapping1.getController().toString());
    assertNull(mapping1.getContentConstraint());
    assertEquals("/person/*", mapping1.getPattern().toString());
    assertEquals(10, mapping1.getOrder());
    assertEquals("myapplication:/controller1.js", mapping2.getController().toString());
    assertEquals("_path:'/*/fisk'", mapping2.getContentConstraint().toString());
    assertEquals("/.*", mapping2.getPattern().toString());
    assertEquals(50, mapping2.getOrder());
    assertEquals("myapplication:/controller2.js", mapping3.getController().toString());
    assertEquals("type:'portal:fragment'", mapping3.getContentConstraint().toString());
    assertEquals("/.*", mapping3.getPattern().toString());
    assertEquals(5, mapping3.getOrder());
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) Test(org.junit.jupiter.api.Test)

Example 12 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class XmlSiteParserTest method testSiteXmlDeserialization.

@Test
public void testSiteXmlDeserialization() {
    final String xml = loadTestXml("serialized-site.xml");
    final SiteDescriptor.Builder siteDescriptorBuilder = SiteDescriptor.create();
    ApplicationKey applicationKey = ApplicationKey.from("myapplication");
    this.parser.source(xml).currentApplication(applicationKey).siteDescriptorBuilder(siteDescriptorBuilder).parse();
    SiteDescriptor siteDescriptor = siteDescriptorBuilder.build();
    assertEquals(1, siteDescriptor.getForm().getFormItems().size());
    assertEquals(2, siteDescriptor.getXDataMappings().getSize());
    assertEquals(2, siteDescriptor.getResponseProcessors().getSize());
    assertEquals(0, siteDescriptor.getMappingDescriptors().getSize());
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) Test(org.junit.jupiter.api.Test)

Example 13 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class XmlSiteParserTest method testSiteXmlWithUtf16LeBomEncoding.

@Test
public void testSiteXmlWithUtf16LeBomEncoding() {
    final String xml = loadTestFile("utf16lebom.xml", StandardCharsets.UTF_16LE);
    final SiteDescriptor.Builder siteDescriptorBuilder = SiteDescriptor.create();
    ApplicationKey applicationKey = ApplicationKey.from("myapplication");
    this.parser.source(xml).currentApplication(applicationKey).siteDescriptorBuilder(siteDescriptorBuilder).parse();
    SiteDescriptor siteDescriptor = siteDescriptorBuilder.build();
    assertEquals(1, siteDescriptor.getForm().getFormItems().size());
    assertEquals(2, siteDescriptor.getXDataMappings().getSize());
    assertEquals(2, siteDescriptor.getResponseProcessors().getSize());
    assertEquals(0, siteDescriptor.getMappingDescriptors().getSize());
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) Test(org.junit.jupiter.api.Test)

Example 14 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class SiteConfigsValidator method validate.

@Override
public void validate(final ContentValidatorParams params, final ValidationErrors.Builder validationErrorsBuilder) {
    final SiteConfigs siteConfigs = new SiteConfigsDataSerializer().fromProperties(params.getData().getRoot()).build();
    for (final SiteConfig siteConfig : siteConfigs) {
        final ApplicationKey applicationKey = siteConfig.getApplicationKey();
        final SiteDescriptor siteDescriptor = siteService.getDescriptor(applicationKey);
        if (siteDescriptor != null) {
            OccurrenceValidator.validate(siteDescriptor.getForm(), siteConfig.getConfig().getRoot(), validationErrorsBuilder);
            try {
                InputValidator.create().form(siteDescriptor.getForm()).inputTypeResolver(InputTypes.BUILTIN).build().validate(siteConfig.getConfig());
            } catch (final Exception e) {
                validationErrorsBuilder.add(ValidationError.generalError(ValidationErrorCode.from(ApplicationKey.SYSTEM, "cms.validation.siteConfigInvalid")).args(siteConfig.getApplicationKey()).build());
            }
        }
    }
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) SiteConfigsDataSerializer(com.enonic.xp.site.SiteConfigsDataSerializer) SiteConfig(com.enonic.xp.site.SiteConfig) SiteConfigs(com.enonic.xp.site.SiteConfigs)

Example 15 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class CreateContentHandlerTest method mockCreateContent.

private void mockCreateContent() {
    when(this.contentService.create(any(CreateContentParams.class))).thenAnswer(mock -> createContent((CreateContentParams) mock.getArguments()[0]));
    final FormItemSet eSet = FormItemSet.create().name("e").addFormItem(Input.create().label("f").name("f").inputType(InputTypeName.DOUBLE).build()).addFormItem(Input.create().label("g").name("g").inputType(InputTypeName.CHECK_BOX).build()).build();
    final FormItemSet dSet = FormItemSet.create().name("d").addFormItem(eSet).build();
    final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.LONG).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.LONG).build()).addFormItem(Input.create().label("c").name("c").occurrences(0, 10).inputType(InputTypeName.TEXT_LINE).build()).addFormItem(dSet).build();
    GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
    when(this.contentTypeService.getByName(Mockito.eq(getContentType))).thenReturn(contentType);
    final PropertyTree extraData = new PropertyTree();
    extraData.addDouble("a", 1.0);
    extraData.addBoolean("b", true);
    final XData xData = XData.create().name(XDataName.from("com.enonic.myapplication:myschema")).addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.DOUBLE).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.CHECK_BOX).build()).build();
    final SiteDescriptor siteDescriptor1 = SiteDescriptor.create().form(Form.create().addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.CHECK_BOX).build()).build()).build();
    final SiteDescriptor siteDescriptor2 = SiteDescriptor.create().form(Form.create().addFormItem(Input.create().label("c").name("c").inputType(InputTypeName.LONG).build()).build()).build();
    when(this.siteService.getDescriptor(ApplicationKey.from("appKey1"))).thenReturn(siteDescriptor1);
    when(this.siteService.getDescriptor(ApplicationKey.from("appKey2"))).thenReturn(siteDescriptor2);
    when(this.xDataService.getByName(Mockito.eq(XDataName.from("com.enonic.myapplication:myschema")))).thenReturn(xData);
    when(this.mixinService.inlineFormItems(any(Form.class))).then(returnsFirstArg());
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) XData(com.enonic.xp.schema.xdata.XData) FormItemSet(com.enonic.xp.form.FormItemSet)

Aggregations

SiteDescriptor (com.enonic.xp.site.SiteDescriptor)24 Test (org.junit.jupiter.api.Test)17 ApplicationKey (com.enonic.xp.app.ApplicationKey)13 Content (com.enonic.xp.content.Content)7 ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)7 Site (com.enonic.xp.site.Site)6 SiteConfig (com.enonic.xp.site.SiteConfig)4 ControllerMappingDescriptors (com.enonic.xp.site.mapping.ControllerMappingDescriptors)3 EditableContent (com.enonic.xp.content.EditableContent)2 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 Form (com.enonic.xp.form.Form)2 ResponseProcessorDescriptor (com.enonic.xp.site.processor.ResponseProcessorDescriptor)2 ContentPath (com.enonic.xp.content.ContentPath)1 CreateContentParams (com.enonic.xp.content.CreateContentParams)1 Property (com.enonic.xp.data.Property)1 FormItemSet (com.enonic.xp.form.FormItemSet)1 ContentType (com.enonic.xp.schema.content.ContentType)1 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)1 XData (com.enonic.xp.schema.xdata.XData)1