Search in sources :

Example 16 with QuizEntity

use of easytests.core.entities.QuizEntity in project easy-tests by malinink.

the class QuizzesMapperTest method testDelete.

@Test
public void testDelete() throws Exception {
    QuizEntity quiz = this.quizzesMapper.find(1);
    Assert.assertNotNull(quiz);
    this.quizzesMapper.delete(quiz);
    quiz = this.quizzesMapper.find(1);
    Assert.assertNull(quiz);
}
Also used : QuizEntity(easytests.core.entities.QuizEntity) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with QuizEntity

use of easytests.core.entities.QuizEntity in project easy-tests by malinink.

the class QuizzesMapperTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    final Integer id = 2;
    final String inviteCode = "updated";
    final LocalDateTime testStartedAt = LocalDateTime.of(2017, 5, 18, 12, 1, 0);
    final LocalDateTime testFinishedAt = LocalDateTime.of(2017, 5, 18, 13, 0, 0);
    final boolean testCodeExpired = false;
    QuizEntity quiz = this.quizzesMapper.find(id);
    Assert.assertNotEquals(inviteCode, quiz.getInviteCode());
    quiz = Mockito.mock(QuizEntity.class);
    Mockito.when(quiz.getId()).thenReturn(id);
    Mockito.when(quiz.getInviteCode()).thenReturn(inviteCode);
    Mockito.when(quiz.getStartedAt()).thenReturn(testStartedAt);
    Mockito.when(quiz.getFinishedAt()).thenReturn(testFinishedAt);
    Mockito.when(quiz.getCodeExpired()).thenReturn(testCodeExpired);
    this.quizzesMapper.update(quiz);
    final QuizEntity readQuiz = quizzesMapper.find(id);
    Assert.assertEquals(inviteCode, readQuiz.getInviteCode());
    Assert.assertEquals(testStartedAt, readQuiz.getStartedAt());
    Assert.assertEquals(testFinishedAt, readQuiz.getFinishedAt());
    Assert.assertEquals(testCodeExpired, readQuiz.getCodeExpired());
}
Also used : LocalDateTime(java.time.LocalDateTime) QuizEntity(easytests.core.entities.QuizEntity) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with QuizEntity

use of easytests.core.entities.QuizEntity in project easy-tests by malinink.

the class QuizzesMapperTest method testInsert.

@Test
public void testInsert() throws Exception {
    final Integer id = this.quizzesMapper.findAll().size() + 1;
    final Integer testIssueId = 1;
    final String testInviteCode = "test";
    final LocalDateTime testStartedAt = LocalDateTime.of(2017, 5, 18, 12, 1, 0);
    final LocalDateTime testFinishedAt = LocalDateTime.of(2017, 5, 18, 13, 0, 0);
    final boolean testCodeExpired = false;
    final QuizEntity testQuiz = Mockito.mock(QuizEntity.class);
    Mockito.when(testQuiz.getId()).thenReturn(id);
    Mockito.when(testQuiz.getInviteCode()).thenReturn(testInviteCode);
    Mockito.when(testQuiz.getIssueId()).thenReturn(testIssueId);
    Mockito.when(testQuiz.getStartedAt()).thenReturn(testStartedAt);
    Mockito.when(testQuiz.getFinishedAt()).thenReturn(testFinishedAt);
    Mockito.when(testQuiz.getCodeExpired()).thenReturn(testCodeExpired);
    quizzesMapper.insert(testQuiz);
    verify(testQuiz, times(1)).setId(id);
    final QuizEntity readQuiz = quizzesMapper.find(testQuiz.getId());
    Assert.assertNotNull(readQuiz);
    Assert.assertEquals(testIssueId, readQuiz.getIssueId());
    Assert.assertEquals(testInviteCode, readQuiz.getInviteCode());
    Assert.assertEquals(testStartedAt, readQuiz.getStartedAt());
    Assert.assertEquals(testFinishedAt, readQuiz.getFinishedAt());
    Assert.assertEquals(testCodeExpired, readQuiz.getCodeExpired());
}
Also used : LocalDateTime(java.time.LocalDateTime) QuizEntity(easytests.core.entities.QuizEntity) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with QuizEntity

use of easytests.core.entities.QuizEntity in project easy-tests by malinink.

the class QuizzesService method delete.

@Override
public void delete(QuizModelInterface quizModel) {
    final QuizEntity quizEntity = this.map(quizModel);
    if (quizEntity.getId() == null) {
        throw new DeleteUnidentifiedModelException();
    }
    this.quizzesMapper.delete(quizEntity);
}
Also used : QuizEntity(easytests.core.entities.QuizEntity) DeleteUnidentifiedModelException(easytests.core.services.exceptions.DeleteUnidentifiedModelException)

Example 20 with QuizEntity

use of easytests.core.entities.QuizEntity in project easy-tests by malinink.

the class QuizzesServiceTest method testFindAllWithOptions.

@Test
public void testFindAllWithOptions() throws Exception {
    final List<QuizEntity> quizzesEntities = this.getQuizzesEntities();
    final List<QuizModelInterface> quizzesModels = this.getIssuesModels();
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    given(this.quizzesMapper.findAll()).willReturn(quizzesEntities);
    given(quizzesOptions.withRelations(Mockito.anyList())).willReturn(quizzesModels);
    final List<QuizModelInterface> foundedQuizzesModels = this.quizzesService.findAll(quizzesOptions);
    verify(quizzesOptions).withRelations(foundedQuizzesModels);
    Assert.assertEquals(quizzesModels, foundedQuizzesModels);
}
Also used : QuizEntity(easytests.core.entities.QuizEntity) QuizModelInterface(easytests.core.models.QuizModelInterface) QuizzesOptionsInterface(easytests.core.options.QuizzesOptionsInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

QuizEntity (easytests.core.entities.QuizEntity)22 Test (org.junit.Test)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 QuizModelInterface (easytests.core.models.QuizModelInterface)7 ArrayList (java.util.ArrayList)4 IssueModelInterface (easytests.core.models.IssueModelInterface)3 QuizzesOptionsInterface (easytests.core.options.QuizzesOptionsInterface)3 LocalDateTime (java.time.LocalDateTime)3 IssueModelEmpty (easytests.core.models.empty.IssueModelEmpty)1 ModelsListEmpty (easytests.core.models.empty.ModelsListEmpty)1 TesteeModelEmpty (easytests.core.models.empty.TesteeModelEmpty)1 DeleteUnidentifiedModelException (easytests.core.services.exceptions.DeleteUnidentifiedModelException)1