use of com.icthh.xm.ms.entity.domain.FunctionContext in project xm-ms-entity by xm-online.
the class StartUpdateDateGenerationStrategyUnitTest method testGenerateStartDateNullCheck.
@Test
public void testGenerateStartDateNullCheck() {
checkNullParameter(() -> {
strategy.preProcessStartDate(null, null, null, null, null);
}, "entity can not be null");
checkNullParameter(() -> {
strategy.preProcessStartDate(new Object(), null, null, null, null);
}, "repository can not be null");
checkNullParameter(() -> {
strategy.preProcessStartDate(new FunctionContext(), null, repository, null, null);
}, "startDateSetter can not be null");
checkNullParameter(() -> {
strategy.preProcessStartDate(new FunctionContext(), null, repository, FunctionContext::setStartDate, null);
}, "startDateGetter can not be nul");
}
use of com.icthh.xm.ms.entity.domain.FunctionContext in project xm-ms-entity by xm-online.
the class StartUpdateDateGenerationStrategyUnitTest method testUpdateDateChanging.
@Test
public void testUpdateDateChanging() {
FunctionContext context = new FunctionContext();
assertThat(context.getStartDate()).isNull();
assertThat(context.getUpdateDate()).isNull();
strategy.preProcessStartUpdateDates(context, context.getId(), repository, FunctionContext::setStartDate, FunctionContext::getStartDate, FunctionContext::setUpdateDate);
assertThat(context.getStartDate()).isEqualTo(MOCK_START_DATE);
assertThat(context.getUpdateDate()).isEqualTo(MOCK_UPDATE_DATE);
Instant updateDate = Instant.now();
when(strategy.generateUpdateDate()).thenReturn(updateDate);
strategy.preProcessStartUpdateDates(context, context.getId(), repository, FunctionContext::setStartDate, FunctionContext::getStartDate, FunctionContext::setUpdateDate);
assertThat(context.getStartDate()).isEqualTo(MOCK_START_DATE);
assertThat(context.getUpdateDate()).isEqualTo(updateDate);
}
use of com.icthh.xm.ms.entity.domain.FunctionContext in project xm-ms-entity by xm-online.
the class StartUpdateDateGenerationStrategyUnitTest method testGenerateStartDate.
@Test
public void testGenerateStartDate() {
FunctionContext context = new FunctionContext();
assertThat(context.getStartDate()).isNull();
assertThat(context.getUpdateDate()).isNull();
strategy.preProcessStartDate(context, context.getId(), repository, FunctionContext::setStartDate, FunctionContext::getStartDate);
assertThat(context.getStartDate()).isEqualTo(MOCK_START_DATE);
assertThat(context.getUpdateDate()).isNull();
}
use of com.icthh.xm.ms.entity.domain.FunctionContext in project xm-ms-entity by xm-online.
the class StartUpdateDateGenerationStrategyUnitTest method testStartDateNotChanging.
@Test
public void testStartDateNotChanging() {
FunctionContext oldContext = new FunctionContext();
assertThat(oldContext.getStartDate()).isNull();
assertThat(oldContext.getUpdateDate()).isNull();
strategy.preProcessStartUpdateDates(oldContext, oldContext.getId(), repository, FunctionContext::setStartDate, FunctionContext::getStartDate, FunctionContext::setUpdateDate);
assertThat(oldContext.getStartDate()).isEqualTo(MOCK_START_DATE);
assertThat(oldContext.getUpdateDate()).isEqualTo(MOCK_UPDATE_DATE);
Instant updateDate = Instant.now();
when(strategy.generateUpdateDate()).thenReturn(updateDate);
when(repository.findOne(1L)).thenReturn(oldContext);
FunctionContext newContext = new FunctionContext();
// set ID to trigger findOne from repo.
newContext.setId(1L);
// try to override startDate
newContext.setStartDate(Instant.now());
strategy.preProcessStartUpdateDates(newContext, newContext.getId(), repository, FunctionContext::setStartDate, FunctionContext::getStartDate, FunctionContext::setUpdateDate);
verify(repository).findOne(1L);
System.out.println(newContext);
assertThat(newContext.getStartDate()).isEqualTo(MOCK_START_DATE);
assertThat(newContext.getUpdateDate()).isEqualTo(updateDate);
}
use of com.icthh.xm.ms.entity.domain.FunctionContext in project xm-ms-entity by xm-online.
the class DeleteEntityTest method createXmEntity.
private XmEntity createXmEntity() {
XmEntity xmEntity = new XmEntity().key(randomUUID().toString()).typeKey("TEST_DELETE");
xmEntity.name("name").functionContexts(asSet(new FunctionContext().key("1").typeKey("A").xmEntity(xmEntity), new FunctionContext().key("2").typeKey("A").xmEntity(xmEntity), new FunctionContext().key("3").typeKey("A").xmEntity(xmEntity))).attachments(asSet(new Attachment().typeKey("A").name("1"), new Attachment().typeKey("A").name("2"), new Attachment().typeKey("A").name("3"))).calendars(asSet(new Calendar().typeKey("A").name("1").events(asSet(new Event().typeKey("A").title("1"), new Event().typeKey("A").title("2"))), new Calendar().typeKey("A").name("2").events(asSet(new Event().typeKey("A").title("3"), new Event().typeKey("A").title("4"))))).locations(asSet(new Location().typeKey("A").name("1"), new Location().typeKey("A").name("2"))).ratings(asSet(new Rating().typeKey("A").votes(asSet(new Vote().message("1").value(1.1).userKey("1"), new Vote().message("2").value(2.1).userKey("2"))))).tags(asSet(new Tag().typeKey("A").name("1"), new Tag().typeKey("A").name("2"))).comments(asSet(new Comment().message("1").userKey("1"), new Comment().message("2").userKey("1")));
return xmEntity;
}
Aggregations