|
1 | 1 | package io.cloudquery.internal.servers.plugin.v3; |
2 | 2 |
|
| 3 | +import static org.junit.jupiter.api.Assertions.*; |
3 | 4 | import static org.mockito.ArgumentMatchers.any; |
4 | 5 | import static org.mockito.Mockito.verify; |
5 | 6 |
|
|
9 | 10 | import io.cloudquery.messages.WriteInsert; |
10 | 11 | import io.cloudquery.messages.WriteMigrateTable; |
11 | 12 | import io.cloudquery.plugin.Plugin; |
| 13 | +import io.cloudquery.plugin.v3.GetSpecSchema; |
12 | 14 | import io.cloudquery.plugin.v3.PluginGrpc; |
13 | 15 | import io.cloudquery.plugin.v3.PluginGrpc.PluginStub; |
14 | 16 | import io.cloudquery.plugin.v3.Write; |
|
25 | 27 | import java.io.IOException; |
26 | 28 | import java.util.List; |
27 | 29 | import java.util.concurrent.CountDownLatch; |
| 30 | +import lombok.Getter; |
28 | 31 | import org.apache.arrow.vector.types.pojo.ArrowType; |
29 | 32 | import org.junit.Rule; |
30 | 33 | import org.junit.jupiter.api.BeforeEach; |
31 | 34 | import org.junit.jupiter.api.Test; |
32 | 35 | import org.junit.jupiter.api.extension.ExtendWith; |
33 | 36 | import org.mockito.Mock; |
| 37 | +import org.mockito.Mockito; |
34 | 38 | import org.mockito.junit.jupiter.MockitoExtension; |
35 | 39 |
|
36 | 40 | @ExtendWith(MockitoExtension.class) |
@@ -91,6 +95,31 @@ public void shouldSendWriteDeleteStaleMessage() throws Exception { |
91 | 95 | verify(plugin).write(any(WriteDeleteStale.class)); |
92 | 96 | } |
93 | 97 |
|
| 98 | + @Test |
| 99 | + public void shouldSendNullJSONSchema() throws Exception { |
| 100 | + NullResponseStream<GetSpecSchema.Response> responseObserver = new NullResponseStream<>(); |
| 101 | + |
| 102 | + pluginStub.getSpecSchema(GetSpecSchema.Request.getDefaultInstance(), responseObserver); |
| 103 | + responseObserver.await(); |
| 104 | + |
| 105 | + verify(plugin).getJsonSchema(); |
| 106 | + assertFalse(responseObserver.getValue().hasJsonSchema()); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void shouldSendNonNullJSONSchema() throws Exception { |
| 111 | + Mockito.doReturn("{}").when(plugin).getJsonSchema(); |
| 112 | + |
| 113 | + NullResponseStream<GetSpecSchema.Response> responseObserver = new NullResponseStream<>(); |
| 114 | + |
| 115 | + pluginStub.getSpecSchema(GetSpecSchema.Request.getDefaultInstance(), responseObserver); |
| 116 | + responseObserver.await(); |
| 117 | + |
| 118 | + verify(plugin).getJsonSchema(); |
| 119 | + assertTrue(responseObserver.getValue().hasJsonSchema()); |
| 120 | + assertEquals("{}", responseObserver.getValue().getJsonSchema()); |
| 121 | + } |
| 122 | + |
94 | 123 | private static Write.Request generateMigrateTableMessage() throws IOException { |
95 | 124 | Table table = Table.builder().name("test").build(); |
96 | 125 | return Write.Request.newBuilder() |
@@ -121,12 +150,18 @@ private Write.Request generateDeleteStaleMessage() { |
121 | 150 |
|
122 | 151 | private static class NullResponseStream<T> implements StreamObserver<T> { |
123 | 152 | private final CountDownLatch countDownLatch = new CountDownLatch(1); |
| 153 | + @Getter private T value; |
| 154 | + @Getter private Throwable error; |
124 | 155 |
|
125 | 156 | @Override |
126 | | - public void onNext(T value) {} |
| 157 | + public void onNext(T value) { |
| 158 | + this.value = value; |
| 159 | + } |
127 | 160 |
|
128 | 161 | @Override |
129 | | - public void onError(Throwable t) {} |
| 162 | + public void onError(Throwable t) { |
| 163 | + this.error = t; |
| 164 | + } |
130 | 165 |
|
131 | 166 | @Override |
132 | 167 | public void onCompleted() { |
|
0 commit comments