Skip to content

Commit 6614c88

Browse files
committed
Add unit test for UIServiceController
1 parent 2075b42 commit 6614c88

2 files changed

Lines changed: 178 additions & 0 deletions

File tree

core/src/main/java/feast/core/model/FeatureInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import feast.specs.FeatureSpecProto.FeatureSpec;
2626
import feast.types.ValueProto.ValueType;
2727
import lombok.AllArgsConstructor;
28+
import lombok.Builder;
2829
import lombok.Getter;
2930
import lombok.Setter;
3031

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
package feast.core.http;
2+
3+
import feast.core.UIServiceProto;
4+
import feast.core.UIServiceProto.UIServiceTypes.EntityDetail;
5+
import feast.core.UIServiceProto.UIServiceTypes.FeatureDetail;
6+
import feast.core.UIServiceProto.UIServiceTypes.FeatureGroupDetail;
7+
import feast.core.UIServiceProto.UIServiceTypes.StorageDetail;
8+
import feast.core.model.EntityInfo;
9+
import feast.core.model.FeatureGroupInfo;
10+
import feast.core.model.FeatureInfo;
11+
import feast.core.model.StorageInfo;
12+
import feast.core.service.JobManagementService;
13+
import feast.core.service.SpecService;
14+
import feast.specs.FeatureSpecProto;
15+
import org.junit.Before;
16+
import org.junit.Test;
17+
18+
import java.util.Collections;
19+
20+
import static feast.specs.FeatureSpecProto.*;
21+
import static org.junit.Assert.assertEquals;
22+
import static org.mockito.Mockito.mock;
23+
import static org.mockito.Mockito.when;
24+
25+
public class UiServiceControllerTest {
26+
private UiServiceController goodUiServiceController;
27+
private UiServiceController badUiServiceController;
28+
29+
@Before
30+
public void setUp() throws Exception {
31+
FeatureInfo mockFeatureInfo = mock(FeatureInfo.class);
32+
when(mockFeatureInfo.getFeatureDetail()).thenReturn(FeatureDetail.getDefaultInstance());
33+
when(mockFeatureInfo.getFeatureSpec()).thenReturn(FeatureSpec.getDefaultInstance());
34+
when(mockFeatureInfo.resolve()).thenReturn(mockFeatureInfo);
35+
36+
EntityInfo mockEntityInfo = mock(EntityInfo.class);
37+
when(mockEntityInfo.getEntityDetail()).thenReturn(EntityDetail.getDefaultInstance());
38+
39+
FeatureGroupInfo mockFeatureGroupInfo = mock(FeatureGroupInfo.class);
40+
when(mockFeatureGroupInfo.getFeatureGroupDetail())
41+
.thenReturn(FeatureGroupDetail.getDefaultInstance());
42+
43+
StorageInfo mockStorageInfo = mock(StorageInfo.class);
44+
when(mockStorageInfo.getStorageDetail()).thenReturn(StorageDetail.getDefaultInstance());
45+
46+
SpecService goodMockSpecService = mock(SpecService.class);
47+
when(goodMockSpecService.listFeatures()).thenReturn(Collections.singletonList(mockFeatureInfo));
48+
when(goodMockSpecService.getFeatures(Collections.singletonList("1")))
49+
.thenReturn(Collections.singletonList(mockFeatureInfo));
50+
when(goodMockSpecService.listFeatureGroups())
51+
.thenReturn(Collections.singletonList(mockFeatureGroupInfo));
52+
when(goodMockSpecService.getFeatureGroups(Collections.singletonList("1")))
53+
.thenReturn(Collections.singletonList(mockFeatureGroupInfo));
54+
when(goodMockSpecService.listEntities()).thenReturn(Collections.singletonList(mockEntityInfo));
55+
when(goodMockSpecService.getEntities(Collections.singletonList("1")))
56+
.thenReturn(Collections.singletonList(mockEntityInfo));
57+
when(goodMockSpecService.listStorage()).thenReturn(Collections.singletonList(mockStorageInfo));
58+
when(goodMockSpecService.getStorage(Collections.singletonList("1")))
59+
.thenReturn(Collections.singletonList(mockStorageInfo));
60+
61+
JobManagementService goodMockJobMangementService = mock(JobManagementService.class);
62+
63+
goodUiServiceController =
64+
new UiServiceController(goodMockSpecService, goodMockJobMangementService);
65+
66+
SpecService badMockSpecService = mock(SpecService.class);
67+
when(badMockSpecService.listFeatures()).thenReturn(null);
68+
when(badMockSpecService.getFeatures(Collections.singletonList("1"))).thenReturn(null);
69+
when(badMockSpecService.listFeatureGroups()).thenReturn(null);
70+
when(badMockSpecService.getFeatureGroups(Collections.singletonList("1"))).thenReturn(null);
71+
when(badMockSpecService.listEntities()).thenReturn(null);
72+
when(badMockSpecService.getEntities(Collections.singletonList("1"))).thenReturn(null);
73+
when(badMockSpecService.listStorage()).thenReturn(null);
74+
when(badMockSpecService.getStorage(Collections.singletonList("1"))).thenReturn(null);
75+
76+
JobManagementService badMockJobMangementService = mock(JobManagementService.class);
77+
78+
badUiServiceController =
79+
new UiServiceController(badMockSpecService, badMockJobMangementService);
80+
}
81+
82+
@Test
83+
public void listFeatures() {
84+
FeatureDetail expected = FeatureDetail.getDefaultInstance();
85+
FeatureDetail actual = goodUiServiceController.listFeatures().getFeaturesList().get(0);
86+
assertEquals(expected, actual);
87+
}
88+
89+
@Test(expected = Exception.class)
90+
public void listFeaturesWithExecption() {
91+
badUiServiceController.listFeatures();
92+
}
93+
94+
@Test
95+
public void getFeature() {
96+
FeatureDetail expected = FeatureDetail.getDefaultInstance();
97+
FeatureDetail actual = goodUiServiceController.getFeature("1").getFeature();
98+
assertEquals(expected, actual);
99+
}
100+
101+
@Test(expected = Exception.class)
102+
public void getFeatureWithException() {
103+
badUiServiceController.getFeature("1");
104+
}
105+
106+
@Test
107+
public void listFeatureGroups() {
108+
FeatureGroupDetail expected = FeatureGroupDetail.getDefaultInstance();
109+
FeatureGroupDetail actual = goodUiServiceController.listFeatureGroups().getFeatureGroups(0);
110+
assertEquals(expected, actual);
111+
}
112+
113+
@Test(expected = Exception.class)
114+
public void listFeatureGroupsWithException() {
115+
badUiServiceController.listFeatureGroups();
116+
}
117+
118+
@Test
119+
public void getFeatureGroup() {
120+
FeatureGroupDetail expected = FeatureGroupDetail.getDefaultInstance();
121+
FeatureGroupDetail actual = goodUiServiceController.getFeatureGroup("1").getFeatureGroup();
122+
assertEquals(expected, actual);
123+
}
124+
125+
@Test(expected = Exception.class)
126+
public void getFeatureGroupWithException() {
127+
badUiServiceController.getFeatureGroup("1");
128+
}
129+
130+
@Test
131+
public void listEntities() {
132+
EntityDetail expected = EntityDetail.getDefaultInstance();
133+
EntityDetail actual = goodUiServiceController.listEntities().getEntitiesList().get(0);
134+
assertEquals(expected, actual);
135+
}
136+
137+
@Test(expected = Exception.class)
138+
public void listEntitiesWithException() {
139+
badUiServiceController.listEntities();
140+
}
141+
142+
@Test
143+
public void getEntity() {
144+
EntityDetail expected = EntityDetail.getDefaultInstance();
145+
EntityDetail actual = goodUiServiceController.getEntity("1").getEntity();
146+
assertEquals(expected, actual);
147+
}
148+
149+
@Test(expected = Exception.class)
150+
public void getEntityWithException() {
151+
badUiServiceController.getEntity("1");
152+
}
153+
154+
@Test
155+
public void listStorage() {
156+
StorageDetail expected = StorageDetail.getDefaultInstance();
157+
StorageDetail actual = goodUiServiceController.listStorage().getStorage(0);
158+
assertEquals(expected, actual);
159+
}
160+
161+
@Test(expected = Exception.class)
162+
public void listStorageWithException() {
163+
badUiServiceController.listStorage();
164+
}
165+
166+
@Test
167+
public void getStorage() {
168+
StorageDetail expected = StorageDetail.getDefaultInstance();
169+
StorageDetail actual = goodUiServiceController.getStorage("1").getStorage();
170+
assertEquals(expected, actual);
171+
}
172+
173+
@Test(expected = Exception.class)
174+
public void getStorageWithException() {
175+
badUiServiceController.getStorage("1");
176+
}
177+
}

0 commit comments

Comments
 (0)