forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestUtilTest.java
More file actions
105 lines (94 loc) · 4.08 KB
/
RequestUtilTest.java
File metadata and controls
105 lines (94 loc) · 4.08 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2019 The Feast Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.feast;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableList;
import com.google.protobuf.TextFormat;
import feast.proto.serving.ServingAPIProto.FeatureReferenceV2;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.NullSource;
class RequestUtilTest {
private static Stream<Arguments> provideValidFeatureRefs() {
return Stream.of(
Arguments.of(
Arrays.asList("driver:driver_id"),
Arrays.asList(
FeatureReferenceV2.newBuilder()
.setFeatureViewName("driver")
.setFeatureName("driver_id")
.build())));
}
@ParameterizedTest
@MethodSource("provideValidFeatureRefs")
void createFeatureRefs_ShouldReturnFeaturesForValidFeatureRefs(
List<String> input, List<FeatureReferenceV2> expected) {
List<FeatureReferenceV2> actual = RequestUtil.createFeatureRefs(input);
// Order of the actual and expected FeatureTables do no not matter
actual.sort(Comparator.comparing(FeatureReferenceV2::getFeatureName));
expected.sort(Comparator.comparing(FeatureReferenceV2::getFeatureName));
assertEquals(expected.size(), actual.size());
for (int i = 0; i < expected.size(); i++) {
String expectedString = TextFormat.printer().printToString(expected.get(i));
String actualString = TextFormat.printer().printToString(actual.get(i));
assertEquals(expectedString, actualString);
}
}
@ParameterizedTest
@MethodSource("provideValidFeatureRefs")
void renderFeatureRef_ShouldReturnFeatureRefString(
List<String> expected, List<FeatureReferenceV2> input) {
input = input.stream().map(ref -> ref.toBuilder().build()).collect(Collectors.toList());
List<String> actual =
input.stream()
.map(ref -> String.format("%s:%s", ref.getFeatureViewName(), ref.getFeatureName()))
.collect(Collectors.toList());
assertEquals(expected.size(), actual.size());
for (int i = 0; i < expected.size(); i++) {
assertEquals(expected.get(i), actual.get(i));
}
}
private static Stream<Arguments> provideInvalidFeatureRefs() {
return Stream.of(Arguments.of(ImmutableList.of("project/feature")));
}
private static Stream<Arguments> provideMissingFeatureTableFeatureRefs() {
return Stream.of(Arguments.of(ImmutableList.of("feature")));
}
@ParameterizedTest
@MethodSource("provideInvalidFeatureRefs")
void createFeatureRefs_ShouldThrowExceptionForProjectInFeatureRefs(List<String> input) {
assertThrows(IllegalArgumentException.class, () -> RequestUtil.createFeatureRefs(input));
}
@ParameterizedTest
@MethodSource("provideMissingFeatureTableFeatureRefs")
void createFeatureRefs_ShouldThrowExceptionForMissingFeatureTableInFeatureRefs(
List<String> input) {
assertThrows(IllegalArgumentException.class, () -> RequestUtil.createFeatureRefs(input));
}
@ParameterizedTest
@NullSource
void createFeatureRefs_ShouldThrowExceptionForNullFeatureRefs(List<String> input) {
assertThrows(IllegalArgumentException.class, () -> RequestUtil.createFeatureRefs(input));
}
}