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());
}
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());
}
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());
}
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());
}
}
}
}
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());
}
Aggregations