16
16
17
17
package io .apicurio .registry .noprofile .serde ;
18
18
19
- import static io .apicurio .registry .utils .tests .TestUtils .waitForSchema ;
20
- import static org .junit .jupiter .api .Assertions .assertEquals ;
21
-
22
- import java .util .HashMap ;
23
- import java .util .Map ;
24
-
25
- import io .apicurio .registry .serde .SerdeConfig ;
26
- import io .api .sample .TableNotification ;
27
- import org .apache .kafka .common .serialization .Deserializer ;
28
- import org .apache .kafka .common .serialization .Serializer ;
29
- import org .junit .jupiter .api .Assertions ;
30
- import org .junit .jupiter .api .BeforeEach ;
31
- import org .junit .jupiter .api .Test ;
32
-
33
19
import com .google .protobuf .Descriptors ;
34
20
import com .google .protobuf .DynamicMessage ;
21
+ import io .api .sample .TableNotification ;
35
22
import io .apicurio .registry .AbstractResourceTestBase ;
23
+ import io .apicurio .registry .resolver .SchemaResolverConfig ;
36
24
import io .apicurio .registry .rest .client .RegistryClient ;
37
25
import io .apicurio .registry .rest .client .RegistryClientFactory ;
38
26
import io .apicurio .registry .rest .v2 .beans .ArtifactMetaData ;
27
+ import io .apicurio .registry .serde .SerdeConfig ;
39
28
import io .apicurio .registry .serde .protobuf .ProtobufKafkaDeserializer ;
40
29
import io .apicurio .registry .serde .protobuf .ProtobufKafkaSerializer ;
41
30
import io .apicurio .registry .serde .strategy .SimpleTopicIdStrategy ;
42
31
import io .apicurio .registry .support .TestCmmn ;
43
32
import io .apicurio .registry .utils .tests .TestUtils ;
44
33
import io .quarkus .test .junit .QuarkusTest ;
34
+ import org .apache .kafka .common .serialization .Deserializer ;
35
+ import org .apache .kafka .common .serialization .Serializer ;
36
+ import org .junit .jupiter .api .Assertions ;
37
+ import org .junit .jupiter .api .BeforeEach ;
38
+ import org .junit .jupiter .api .Test ;
39
+
40
+ import java .util .HashMap ;
41
+ import java .util .Map ;
42
+
43
+ import static io .apicurio .registry .utils .tests .TestUtils .waitForSchema ;
44
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
45
45
46
46
/**
47
47
* @author Fabian Martinez
50
50
public class ProtobufSerdeTest extends AbstractResourceTestBase {
51
51
52
52
private RegistryClient restClient ;
53
- // Isolating this test in it's own groupId:
54
- // io.apicurio.registry.rest.client.exception.ArtifactAlreadyExistsException: An artifact with ID 'google/protobuf/timestamp.proto' in group 'default' already exists.
55
53
private String groupId = "protobuf-serde-test" ;
56
54
57
55
@ BeforeEach
58
56
public void createIsolatedClient () {
59
57
restClient = RegistryClientFactory .create (TestUtils .getRegistryV2ApiUrl (testPort ));
60
58
}
61
59
62
- //FIXME
63
- //test not working because of getArtifactVersionMetaDataByContent does not find the schema for somereason
64
- // @Test
65
- // public void testConfiguration() throws Exception {
66
- //
67
- // TestCmmn.UUID record = TestCmmn.UUID.newBuilder().setLsb(2).setMsb(1).build();
68
- // byte[] schema = toSchemaProto(record.getDescriptorForType().getFile()).toByteArray();
69
- //// String schema = IoUtil.toString(toSchemaProto(record));
70
- //
71
- // String groupId = TestUtils.generateGroupId();
72
- // String topic = generateArtifactId();
73
- //
74
- // createArtifact(groupId, topic, ArtifactType.PROTOBUF_FD, IoUtil.toString(schema));
75
- //
76
- // System.out.println("artifaaact " + clientV2.listArtifactsInGroup(groupId).getArtifacts().get(0).getId());
77
- //
78
- // Map<String, Object> config = new HashMap<>();
79
- // config.put(SerdeConfigKeys.REGISTRY_URL, TestUtils.getRegistryV2ApiUrl());
80
- // config.put(SerdeConfigKeys.ARTIFACT_GROUP_ID, groupId);
81
- // config.put(SerdeConfigKeys.ARTIFACT_ID_STRATEGY, new SimpleTopicIdStrategy<>());
82
- // Serializer<TestCmmn.UUID> serializer = new ProtobufKafkaSerializer<>();
83
- // serializer.configure(config, true);
84
- //
85
- // byte[] bytes = serializer.serialize(topic, record);
86
- //
87
- // Map<String, Object> deserializerConfig = new HashMap<>();
88
- // deserializerConfig.put(SerdeConfigKeys.REGISTRY_URL, TestUtils.getRegistryV2ApiUrl());
89
- // Deserializer<DynamicMessage> deserializer = new ProtobufKafkaDeserializer();
90
- // deserializer.configure(deserializerConfig, true);
91
- //
92
- // DynamicMessage deserializedRecord = deserializer.deserialize(topic, bytes);
93
- // assertProtobufEquals(record, deserializedRecord);
94
- //
95
- // config.put(SerdeConfigKeys.ARTIFACT_ID_STRATEGY, SimpleTopicIdStrategy.class);
96
- // serializer.configure(config, true);
97
- // bytes = serializer.serialize(topic, record);
98
- //
99
- // deserializer.configure(deserializerConfig, true);
100
- // deserializedRecord = deserializer.deserialize(topic, bytes);
101
- // assertProtobufEquals(record, deserializedRecord);
102
- //
103
- // config.put(SerdeConfigKeys.ARTIFACT_ID_STRATEGY, SimpleTopicIdStrategy.class.getName());
104
- // serializer.configure(config, true);
105
- // bytes = serializer.serialize(topic, record);
106
- // deserializer.configure(deserializerConfig, true);
107
- // deserializedRecord = deserializer.deserialize(topic, bytes);
108
- // assertProtobufEquals(record, deserializedRecord);
109
- //
110
- // serializer.close();
111
- // deserializer.close();
112
- // }
113
- //
114
- // private Serde.Schema toSchemaProto(Descriptors.FileDescriptor file) {
115
- // Serde.Schema.Builder b = Serde.Schema.newBuilder();
116
- // b.setFile(file.toProto());
117
- // for (Descriptors.FileDescriptor d : file.getDependencies()) {
118
- // b.addImport(toSchemaProto(d));
119
- // }
120
- // return b.build();
121
- // }
122
-
123
- @ SuppressWarnings ({ "rawtypes" , "unchecked" })
60
+ @ SuppressWarnings ({"rawtypes" , "unchecked" })
124
61
@ Test
125
62
public void testProto () throws Exception {
126
63
try (Serializer <TestCmmn .UUID > serializer = new ProtobufKafkaSerializer <>(restClient );
@@ -154,10 +91,9 @@ public void testProto() throws Exception {
154
91
}
155
92
}
156
93
157
- @ SuppressWarnings ({ "rawtypes" , "unchecked" })
94
+ @ SuppressWarnings ({"rawtypes" , "unchecked" })
158
95
@ Test
159
96
public void testProtobufSchemaWithReferences () {
160
-
161
97
try (Serializer <TableNotification > serializer = new ProtobufKafkaSerializer <>(restClient );
162
98
Deserializer <TableNotification > deserializer = new ProtobufKafkaDeserializer (restClient )) {
163
99
@@ -169,11 +105,30 @@ public void testProtobufSchemaWithReferences() {
169
105
serializer .configure (config , false );
170
106
deserializer .configure (config , false );
171
107
172
- byte [] data = serializer .serialize ("test" , TableNotification .newBuilder ().build ());
108
+ byte [] data = serializer .serialize ("test" , TableNotification .newBuilder ().build ());
173
109
deserializer .deserialize ("test" , data );
174
110
175
111
}
112
+ }
113
+
114
+ @ SuppressWarnings ({"rawtypes" , "unchecked" })
115
+ @ Test
116
+ public void testProtobufSchemaWithReferencesDereferenced () {
117
+ try (Serializer <TableNotification > serializer = new ProtobufKafkaSerializer <>(restClient );
118
+ Deserializer <TableNotification > deserializer = new ProtobufKafkaDeserializer (restClient )) {
176
119
120
+ Map <String , Object > config = new HashMap <>();
121
+ config .put (SerdeConfig .ARTIFACT_RESOLVER_STRATEGY , SimpleTopicIdStrategy .class );
122
+ config .put (SerdeConfig .AUTO_REGISTER_ARTIFACT , "true" );
123
+ config .put (SerdeConfig .EXPLICIT_ARTIFACT_GROUP_ID , groupId );
124
+ config .put (SerdeConfig .FALLBACK_ARTIFACT_GROUP_ID , groupId );
125
+ config .put (SchemaResolverConfig .DESERIALIZER_DEREFERENCE_SCHEMA , "true" );
126
+ serializer .configure (config , false );
127
+ deserializer .configure (config , false );
128
+
129
+ byte [] data = serializer .serialize ("test" , TableNotification .newBuilder ().build ());
130
+ deserializer .deserialize ("test" , data );
131
+ }
177
132
}
178
133
179
134
private void assertProtobufEquals (TestCmmn .UUID record , DynamicMessage dm ) {
0 commit comments