Search in sources :

Example 1 with Feedback

use of io.lumeer.api.model.Feedback in project engine by Lumeer.

the class FeedbackCodec method decode.

@Override
public Feedback decode(final BsonReader bsonReader, final DecoderContext decoderContext) {
    Document bson = documentCodec.decode(bsonReader, decoderContext);
    String id = bson.getObjectId(ID).toHexString();
    String userId = bson.getString(USER_ID);
    ZonedDateTime creationTime = ZonedDateTime.ofInstant(bson.getDate(CREATION_TIME).toInstant(), ZoneOffset.UTC);
    String message = bson.getString(MESSAGE);
    return new Feedback(id, userId, creationTime, message);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Feedback(io.lumeer.api.model.Feedback) Document(org.bson.Document)

Example 2 with Feedback

use of io.lumeer.api.model.Feedback in project engine by Lumeer.

the class UserFacadeIT method testCreateFeedback.

@Test
public void testCreateFeedback() {
    ZonedDateTime before = ZonedDateTime.now();
    String message = "This application is great!";
    Feedback feedback = new Feedback(message);
    Feedback returnedFeedback = userFacade.createFeedback(feedback);
    ZonedDateTime after = ZonedDateTime.now();
    assertThat(returnedFeedback).isNotNull();
    assertThat(returnedFeedback.getId()).isNotNull();
    assertThat(returnedFeedback.getUserId()).isEqualTo(userFacade.getCurrentUser().getId());
    assertThat(returnedFeedback.getCreationTime()).isAfterOrEqualTo(before.truncatedTo(ChronoUnit.MILLIS));
    assertThat(returnedFeedback.getCreationTime()).isBeforeOrEqualTo(after.truncatedTo(ChronoUnit.MILLIS));
    assertThat(returnedFeedback.getMessage()).isEqualTo(message);
    Feedback storedFeedback = feedbackDao.getFeedbackById(returnedFeedback.getId());
    assertThat(storedFeedback).isNotNull();
    assertThat(storedFeedback.getId()).isEqualTo(returnedFeedback.getId());
    assertThat(storedFeedback.getUserId()).isEqualTo(returnedFeedback.getUserId());
    assertThat(storedFeedback.getCreationTime()).isEqualTo(returnedFeedback.getCreationTime().truncatedTo(ChronoUnit.MILLIS));
    assertThat(storedFeedback.getMessage()).isEqualTo(returnedFeedback.getMessage());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Feedback(io.lumeer.api.model.Feedback) Test(org.junit.Test)

Example 3 with Feedback

use of io.lumeer.api.model.Feedback in project engine by Lumeer.

the class MongoFeedbackDaoTest method testGetFeedbackById.

@Test
public void testGetFeedbackById() {
    Feedback feedback = prepareFeedback();
    mongoFeedbackDao.databaseCollection().insertOne(feedback);
    Feedback storedFeedback = mongoFeedbackDao.getFeedbackById(feedback.getId());
    assertThat(storedFeedback).isNotNull();
    assertThat(storedFeedback.getId()).isEqualTo(feedback.getId());
    assertThat(storedFeedback.getUserId()).isEqualTo(feedback.getUserId());
    assertThat(storedFeedback.getCreationTime()).isEqualTo(feedback.getCreationTime().truncatedTo(ChronoUnit.MILLIS));
    assertThat(storedFeedback.getMessage()).isEqualTo(feedback.getMessage());
}
Also used : Feedback(io.lumeer.api.model.Feedback) Test(org.junit.Test)

Example 4 with Feedback

use of io.lumeer.api.model.Feedback in project engine by Lumeer.

the class MongoFeedbackDaoTest method testGetFeedbackByIdNotExisting.

@Test
public void testGetFeedbackByIdNotExisting() {
    Feedback storedFeedback = mongoFeedbackDao.getFeedbackById("596e3b86d412bc5a3caaa22a");
    assertThat(storedFeedback).isNull();
}
Also used : Feedback(io.lumeer.api.model.Feedback) Test(org.junit.Test)

Example 5 with Feedback

use of io.lumeer.api.model.Feedback in project engine by Lumeer.

the class MongoFeedbackDaoTest method testCreateFeedback.

@Test
public void testCreateFeedback() {
    Feedback feedback = prepareFeedback();
    Feedback returnedFeedback = mongoFeedbackDao.createFeedback(feedback);
    assertThat(returnedFeedback).isNotNull();
    String id = returnedFeedback.getId();
    assertThat(id).isNotNull().isNotEmpty();
    assertThat(ObjectId.isValid(id)).isTrue();
    Feedback storedFeedback = mongoFeedbackDao.databaseCollection().find(MongoFilters.idFilter(id)).first();
    assertThat(storedFeedback).isNotNull();
    assertThat(storedFeedback.getUserId()).isEqualTo(feedback.getUserId());
    assertThat(storedFeedback.getCreationTime()).isEqualTo(feedback.getCreationTime().truncatedTo(ChronoUnit.MILLIS));
    assertThat(storedFeedback.getMessage()).isEqualTo(feedback.getMessage());
}
Also used : Feedback(io.lumeer.api.model.Feedback) Test(org.junit.Test)

Aggregations

Feedback (io.lumeer.api.model.Feedback)5 Test (org.junit.Test)4 ZonedDateTime (java.time.ZonedDateTime)2 Document (org.bson.Document)1