Search in sources :

Example 1 with ContentTypeService

use of com.enonic.xp.schema.content.ContentTypeService in project xp by enonic.

the class ContentServiceImplTest_getInvalidContent method test_invalid_content.

@Test
public void test_invalid_content() throws Exception {
    final ContentTypeService contentTypeService = Mockito.mock(ContentTypeService.class);
    this.contentService.setContentTypeService(contentTypeService);
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().superType(ContentTypeName.documentMedia()).name("myContentType").addFormItem(Input.create().label("double").name("Double").required(true).inputType(InputTypeName.DOUBLE).build()).build());
    PropertyTree data = new PropertyTree();
    final Content content = this.contentService.create(CreateContentParams.create().type(ContentTypeName.from("myContentType")).contentData(data).requireValid(false).parent(ContentPath.ROOT).displayName("my display-name").build());
    assertFalse(this.contentService.getInvalidContent(ContentIds.from(content.getId())).isEmpty());
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) Test(org.junit.jupiter.api.Test)

Example 2 with ContentTypeService

use of com.enonic.xp.schema.content.ContentTypeService in project xp by enonic.

the class SuperTypeValidatorTest method content_type_super_is_null.

@Test
public void content_type_super_is_null() {
    final ContentTypeService contentTypeService = Mockito.mock(ContentTypeService.class);
    ContentTypeSuperTypeValidator validator = ContentTypeSuperTypeValidator.create().contentTypeService(contentTypeService).build();
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(null);
    validator.validate(ContentTypeName.documentMedia(), ContentTypeName.media());
    assertNotNull(validator.getResult().getFirst().getErrorMessage());
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) Test(org.junit.jupiter.api.Test)

Example 3 with ContentTypeService

use of com.enonic.xp.schema.content.ContentTypeService in project xp by enonic.

the class SuperTypeValidatorTest method content_type_passes_validation.

@Test
public void content_type_passes_validation() {
    ContentType contentType = ContentType.create().name(ContentTypeName.documentMedia()).superType(ContentTypeName.media()).build();
    final ContentTypeService contentTypeService = Mockito.mock(ContentTypeService.class);
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(contentType);
    ContentTypeSuperTypeValidator validator = ContentTypeSuperTypeValidator.create().contentTypeService(contentTypeService).build();
    validator.validate(ContentTypeName.documentMedia(), ContentTypeName.media());
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) Test(org.junit.jupiter.api.Test)

Example 4 with ContentTypeService

use of com.enonic.xp.schema.content.ContentTypeService in project xp by enonic.

the class ContentServiceImplTest_getInvalidContent method test_valid_and_invalid_contents_return_false.

@Test
public void test_valid_and_invalid_contents_return_false() throws Exception {
    final ContentTypeService contentTypeService = Mockito.mock(ContentTypeService.class);
    this.contentService.setContentTypeService(contentTypeService);
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().superType(ContentTypeName.documentMedia()).name("myContentType").addFormItem(Input.create().label("double").name("Double").required(true).inputType(InputTypeName.DOUBLE).build()).build());
    PropertyTree data = new PropertyTree();
    final Content content = this.contentService.create(CreateContentParams.create().type(ContentTypeName.from("myContentType")).contentData(data).requireValid(false).parent(ContentPath.ROOT).displayName("my display-name").build());
    final Content content2 = this.contentService.create(CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build());
    assertFalse(this.contentService.getInvalidContent(ContentIds.from(content.getId(), content2.getId())).isEmpty());
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) Test(org.junit.jupiter.api.Test)

Example 5 with ContentTypeService

use of com.enonic.xp.schema.content.ContentTypeService in project xp by enonic.

the class ContentServiceImplTest_update method update_incorrect_content_data.

@Test
public void update_incorrect_content_data() throws Exception {
    // Mocks the content service to return our content type
    final ContentTypeService contentTypeService = Mockito.mock(ContentTypeService.class);
    this.contentService.setContentTypeService(contentTypeService);
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(createContentTypeForAllInputTypes());
    // Creates a valid content
    PropertyTree data = createPropertyTreeForAllInputTypes();
    final Content content = this.contentService.create(CreateContentParams.create().type(ContentTypeName.from("myContentType")).contentData(data).name("myContent").parent(ContentPath.ROOT).displayName("my display-name").build());
    // Updates the content with an incorrect value
    PropertyTree invalidData = new PropertyTree();
    invalidData.addLong("textLine", 1L);
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addLong("double", 1L);
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addDouble("long", 1.0d);
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addBoolean("comboBox", true);
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addString("comboBox", "value4");
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addDouble("checkbox", 1.0d);
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addDouble("tag", 1.0d);
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addDouble("contentSelector", 1.0d);
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addDouble("contentTypeFilter", 1.0d);
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addLocalDateTime("date", LocalDateTime.of(2015, 3, 13, 10, 0, 0));
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addInstant("time", Instant.now());
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addString("geoPoint", "59.9127300, 10.7460900");
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addXml("htmlArea", "<p>paragraph</p>");
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addLocalDate("localDateTime", LocalDate.of(2015, 3, 13));
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidData.addLocalDate("dateTime", LocalDate.of(2015, 3, 13));
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    PropertySet invalidSet = new PropertySet();
    invalidSet.addDouble("setString", 1.0d);
    invalidData.addSet("set", invalidSet);
    update_incorrect_content_data(content, invalidData);
    // Updates the content with an incorrect value
    invalidData = new PropertyTree();
    invalidSet = new PropertySet();
    invalidSet.addLong("setDouble", 1L);
    invalidData.addSet("set", invalidSet);
    update_incorrect_content_data(content, invalidData);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) Test(org.junit.jupiter.api.Test)

Aggregations

ContentTypeService (com.enonic.xp.schema.content.ContentTypeService)9 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)8 Test (org.junit.jupiter.api.Test)7 Content (com.enonic.xp.content.Content)6 PropertyTree (com.enonic.xp.data.PropertyTree)6 PageDescriptorService (com.enonic.xp.page.PageDescriptorService)2 LayoutDescriptorService (com.enonic.xp.region.LayoutDescriptorService)2 PartDescriptorService (com.enonic.xp.region.PartDescriptorService)2 XDataService (com.enonic.xp.schema.xdata.XDataService)2 SiteService (com.enonic.xp.site.SiteService)2 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)1 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)1 UpdateContentTranslatorParams (com.enonic.xp.content.UpdateContentTranslatorParams)1 ProcessUpdateParams (com.enonic.xp.content.processor.ProcessUpdateParams)1 ContentIndexConfigFactory (com.enonic.xp.core.impl.content.index.ContentIndexConfigFactory)1 ContentDataSerializer (com.enonic.xp.core.impl.content.serializer.ContentDataSerializer)1 PropertySet (com.enonic.xp.data.PropertySet)1 NodeEditor (com.enonic.xp.node.NodeEditor)1 NodeId (com.enonic.xp.node.NodeId)1 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)1