use of com.enonic.xp.schema.content.ContentType in project xp by enonic.
the class CreateContentHandlerTest method createContentAlreadyExists.
@Test
public void createContentAlreadyExists() throws Exception {
final Exception alreadyExistException = new ContentAlreadyExistsException(ContentPath.from("/a/b/mycontent"), RepositoryId.from("some.repo"), Branch.from("draft"));
when(this.contentService.create(any(CreateContentParams.class))).thenThrow(alreadyExistException);
final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).build();
GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
when(this.contentTypeService.getByName(Mockito.eq(getContentType))).thenReturn(contentType);
runFunction("/test/CreateContentHandlerTest.js", "createContentNameAlreadyExists");
}
use of com.enonic.xp.schema.content.ContentType 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());
}
use of com.enonic.xp.schema.content.ContentType in project xp by enonic.
the class CreateContentHandlerTest method createContentWithWorkflow.
@Test
public void createContentWithWorkflow() throws Exception {
when(this.contentService.create(any(CreateContentParams.class))).thenAnswer(mock -> createContent((CreateContentParams) mock.getArguments()[0]));
final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).build();
GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
when(this.contentTypeService.getByName(Mockito.eq(getContentType))).thenReturn(contentType);
runFunction("/test/CreateContentHandlerTest.js", "createContentWithWorkflow");
}
use of com.enonic.xp.schema.content.ContentType in project xp by enonic.
the class HtmlAreaContentProcessorTest method extra_data.
@Test
public void extra_data() throws IOException {
final XDataName xDataName = XDataName.from("xDataName");
final XData xData = XData.create().name(xDataName).addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
final ContentType contentType = ContentType.create().name(contentTypeName).superType(ContentTypeName.folder()).xData(XDataNames.from(xDataName)).build();
Mockito.when(contentTypeService.getByName(GetContentTypeParams.from(ContentTypeName.site()))).thenReturn(contentType);
Mockito.when(xDataService.getByNames(XDataNames.from(xDataName))).thenReturn(XDatas.from(xData));
final PropertyTree data = new PropertyTree();
data.addProperty("htmlData", ValueFactory.newString("<img alt=\"Dictyophorus_spumans01.jpg\" data-src=\"image://image-id\"/>"));
final EditableSite editableSite = new EditableSite(Site.create().name("myContentName").type(ContentTypeName.site()).parentPath(ContentPath.ROOT).data(new PropertyTree()).extraDatas(ExtraDatas.create().add(new ExtraData(XDataName.from("xDataName"), data)).build()).build());
result.getEditor().edit(editableSite);
assertEquals(1, editableSite.processedReferences.build().getSize());
assertTrue(editableSite.processedReferences.build().contains(ContentId.from("image-id")));
}
use of com.enonic.xp.schema.content.ContentType in project xp by enonic.
the class XmlContentTypeParserTest method testI18n_formInput.
@Test
public void testI18n_formInput() throws Exception {
parse(this.parser, "-i18n.xml");
final ContentType result = this.builder.build();
final Input input = (Input) result.getForm().getFormItem("textLine");
assertEquals("translated.label", input.getLabelI18nKey());
assertEquals("translated.help-text", input.getHelpTextI18nKey());
}
Aggregations