-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathFeatureSegmentModelTest.java
More file actions
58 lines (46 loc) · 1.95 KB
/
FeatureSegmentModelTest.java
File metadata and controls
58 lines (46 loc) · 1.95 KB
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
package com.flagsmith.flagengine.models;
import static org.assertj.core.api.Assertions.assertThat;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.flagsmith.MapperFactory;
import com.flagsmith.models.features.FeatureStateModel;
import org.junit.jupiter.api.Test;
public class FeatureSegmentModelTest {
@Test
public void deserializesFeatureSegmentAsIntegerForeignKey() throws JsonProcessingException {
String json = "{"
+ "\"feature\": {\"id\": 1, \"name\": \"my_feature\", \"type\": \"STANDARD\"},"
+ "\"enabled\": true,"
+ "\"feature_state_value\": \"foo\","
+ "\"feature_segment\": 321"
+ "}";
FeatureStateModel model =
MapperFactory.getMapper().readValue(json, FeatureStateModel.class);
assertThat(model.getFeatureSegment()).isNotNull();
assertThat(model.getFeatureSegment().getPriority()).isEqualTo(321);
}
@Test
public void deserializesFeatureSegmentAsEngineObject() throws JsonProcessingException {
String json = "{"
+ "\"feature\": {\"id\": 1, \"name\": \"my_feature\", \"type\": \"STANDARD\"},"
+ "\"enabled\": true,"
+ "\"feature_state_value\": \"foo\","
+ "\"feature_segment\": {\"priority\": 5}"
+ "}";
FeatureStateModel model =
MapperFactory.getMapper().readValue(json, FeatureStateModel.class);
assertThat(model.getFeatureSegment()).isNotNull();
assertThat(model.getFeatureSegment().getPriority()).isEqualTo(5);
}
@Test
public void deserializesNullFeatureSegment() throws JsonProcessingException {
String json = "{"
+ "\"feature\": {\"id\": 1, \"name\": \"my_feature\", \"type\": \"STANDARD\"},"
+ "\"enabled\": true,"
+ "\"feature_state_value\": \"foo\","
+ "\"feature_segment\": null"
+ "}";
FeatureStateModel model =
MapperFactory.getMapper().readValue(json, FeatureStateModel.class);
assertThat(model.getFeatureSegment()).isNull();
}
}