Search in sources :

Example 11 with FunctionContext

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");
}
Also used : FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext) Test(org.junit.Test)

Example 12 with FunctionContext

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);
}
Also used : Instant(java.time.Instant) FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext) Test(org.junit.Test)

Example 13 with FunctionContext

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();
}
Also used : FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext) Test(org.junit.Test)

Example 14 with FunctionContext

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);
}
Also used : Instant(java.time.Instant) FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext) Test(org.junit.Test)

Example 15 with FunctionContext

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;
}
Also used : Comment(com.icthh.xm.ms.entity.domain.Comment) Vote(com.icthh.xm.ms.entity.domain.Vote) Calendar(com.icthh.xm.ms.entity.domain.Calendar) Rating(com.icthh.xm.ms.entity.domain.Rating) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Event(com.icthh.xm.ms.entity.domain.Event) Attachment(com.icthh.xm.ms.entity.domain.Attachment) Tag(com.icthh.xm.ms.entity.domain.Tag) FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext) Location(com.icthh.xm.ms.entity.domain.Location)

Aggregations

FunctionContext (com.icthh.xm.ms.entity.domain.FunctionContext)17 Test (org.junit.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Transactional (org.springframework.transaction.annotation.Transactional)6 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)3 Instant (java.time.Instant)2 Timed (com.codahale.metrics.annotation.Timed)1 Attachment (com.icthh.xm.ms.entity.domain.Attachment)1 Calendar (com.icthh.xm.ms.entity.domain.Calendar)1 Comment (com.icthh.xm.ms.entity.domain.Comment)1 Event (com.icthh.xm.ms.entity.domain.Event)1 Location (com.icthh.xm.ms.entity.domain.Location)1 Rating (com.icthh.xm.ms.entity.domain.Rating)1 Tag (com.icthh.xm.ms.entity.domain.Tag)1 Vote (com.icthh.xm.ms.entity.domain.Vote)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1