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