-
Notifications
You must be signed in to change notification settings - Fork 0
/
FFVIIAllyUpdateTest.java
71 lines (60 loc) · 3.19 KB
/
FFVIIAllyUpdateTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.bevans.kafka.connect.springboot;
import com.bevans.kafka.connect.springboot.data.ally.FFVIIAllyUpdateRepository;
import com.bevans.kafka.connect.springboot.ffvii.FFVIIAllyUpdateCreator;
import com.bevans.kafka.connect.springboot.kafka.KafkaProducer;
import org.json.JSONArray;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import static org.apache.kafka.common.utils.Utils.sleep;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatList;
import static org.junit.jupiter.api.Assertions.assertAll;
@SpringBootTest
class FFVIIAllyUpdateTest {
private final KafkaProducer kafkaProducer;
private final FFVIIAllyUpdateRepository ffviiAllyUpdateRepository;
private final FFVIIAllyUpdateCreator ffviiAllyUpdateCreator;
@Autowired
public FFVIIAllyUpdateTest(KafkaProducer kafkaProducer,
FFVIIAllyUpdateRepository ffviiAllyUpdateRepository,
FFVIIAllyUpdateCreator ffviiAllyUpdateCreator) {
this.kafkaProducer = kafkaProducer;
this.ffviiAllyUpdateRepository = ffviiAllyUpdateRepository;
this.ffviiAllyUpdateCreator = ffviiAllyUpdateCreator;
}
@Test
void shouldSendAllyUpdateAndFindInDatabase() {
// given
var avroData = ffviiAllyUpdateCreator.getAvroData();
var now = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME);
var avroRecord = this.ffviiAllyUpdateCreator.createAvroRecord(now);
var createdName = (String) avroRecord.get("name");
// when
kafkaProducer.send("ff_vii.ally_updates.v1", "key", avroRecord);
sleep(2000);
var allyUpdateFromDatabase = ffviiAllyUpdateRepository.findAllByName(createdName);
// then
assertThatList(allyUpdateFromDatabase).hasSize(1);
var allyUpdate = allyUpdateFromDatabase.get(0);
assertAll(
() -> assertThat(allyUpdate.getName()).isEqualTo(createdName),
() -> assertThat(allyUpdate.getUpdateTs()).isNotNull(),
() -> assertThat(allyUpdate.getAge()).isEqualTo(avroData.getAge()),
() -> assertThat(allyUpdate.getExp()).isEqualTo(avroData.getExp()),
() -> assertThat(allyUpdate.getHp()).isEqualTo(avroData.getHp()),
() -> assertThat(allyUpdate.getMp()).isEqualTo(avroData.getMp()),
() -> assertThat(allyUpdate.getWinLossRatio()).isEqualTo(avroData.getWinLossRatio()),
() -> assertThat(allyUpdate.getPsStoreCost()).isEqualTo(avroData.getPsStoreCost()),
() -> assertThat(allyUpdate.getWeapon()).isEqualTo(avroData.getWeapon().toString()),
() -> assertThat(allyUpdate.getMateria()).isEqualTo(getJsonStringArrayWithSpaces(avroData.getMateria()))
);
}
private String getJsonStringArrayWithSpaces(List<String> stringList) {
var jsonStringArray = new JSONArray(stringList).toString();
return jsonStringArray.replace(",", ", ");
}
}