Skip to content

Commit 1efd7a2

Browse files
committed
Add test of group metadata, fix issues.
1 parent 6606e19 commit 1efd7a2

File tree

8 files changed

+138
-32
lines changed

8 files changed

+138
-32
lines changed

app/src/main/java/io/apicurio/registry/rest/v3/V3ApiUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public static GroupMetaData groupDtoToGroup(GroupMetaDataDto dto) {
284284
group.setModifiedBy(dto.getModifiedBy());
285285
group.setCreatedOn(new Date(dto.getCreatedOn()));
286286
group.setModifiedOn(new Date(dto.getModifiedOn()));
287-
group.setProperties(dto.getLabels());
287+
group.setLabels(dto.getLabels());
288288
return group;
289289
}
290290

app/src/main/java/io/apicurio/registry/storage/impl/sql/AbstractSqlRegistryStorage.java

+16
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,7 @@ public List<DynamicConfigPropertyDto> getStaleConfigProperties(Instant lastRefre
20322032
public void createGroup(GroupMetaDataDto group) throws GroupAlreadyExistsException, RegistryStorageException {
20332033
try {
20342034
handles.withHandle(handle -> {
2035+
// Insert a row into the groups table
20352036
handle.createUpdate(sqlStatements.insertGroup())
20362037
.bind(0, group.getGroupId())
20372038
.bind(1, group.getDescription())
@@ -2043,6 +2044,20 @@ public void createGroup(GroupMetaDataDto group) throws GroupAlreadyExistsExcepti
20432044
.bind(6, group.getModifiedOn() == 0 ? null : new Date(group.getModifiedOn()))
20442045
.bind(7, SqlUtil.serializeLabels(group.getLabels()))
20452046
.execute();
2047+
2048+
// Insert new labels into the "group_labels" table
2049+
Map<String, String> labels = group.getLabels();
2050+
if (labels != null && !labels.isEmpty()) {
2051+
labels.forEach((k, v) -> {
2052+
String sqli = sqlStatements.insertGroupLabel();
2053+
handle.createUpdate(sqli)
2054+
.bind(0, group.getGroupId())
2055+
.bind(1, limitStr(k.toLowerCase(), 256))
2056+
.bind(2, limitStr(asLowerCase(v), 512))
2057+
.execute();
2058+
});
2059+
}
2060+
20462061
return null;
20472062
});
20482063
} catch (Exception ex) {
@@ -2104,6 +2119,7 @@ public void updateGroupMetaData(String groupId, String description, Map<String,
21042119
log.debug("Updating metadata for group {}.", groupId);
21052120

21062121
handles.withHandleNoException(handle -> {
2122+
// Update the row in the groups table
21072123
int rows = handle.createUpdate(sqlStatements.updateGroup())
21082124
.bind(0, description)
21092125
.bind(1, modifiedBy)

app/src/main/java/io/apicurio/registry/storage/impl/sql/CommonSqlStatements.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public String insertArtifactLabel() {
435435
*/
436436
@Override
437437
public String insertGroupLabel() {
438-
return "INSERT INTO group_labels (globalId, labelKey, labelValue) VALUES (?, ?, ?)";
438+
return "INSERT INTO group_labels (groupId, labelKey, labelValue) VALUES (?, ?, ?)";
439439
}
440440

441441
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package io.apicurio.registry.noprofile.rest.v3;
2+
3+
import java.util.Map;
4+
import java.util.UUID;
5+
6+
import org.junit.jupiter.api.Assertions;
7+
import org.junit.jupiter.api.Test;
8+
9+
import io.apicurio.registry.AbstractResourceTestBase;
10+
import io.apicurio.registry.rest.client.models.CreateGroupMetaData;
11+
import io.apicurio.registry.rest.client.models.EditableGroupMetaData;
12+
import io.apicurio.registry.rest.client.models.GroupMetaData;
13+
import io.apicurio.registry.rest.client.models.Labels;
14+
import io.quarkus.test.junit.QuarkusTest;
15+
16+
@QuarkusTest
17+
public class GroupMetaDataTest extends AbstractResourceTestBase {
18+
19+
@Test
20+
public void createGroupWithMetadata() throws Exception {
21+
String groupId = UUID.randomUUID().toString();
22+
Map<String, Object> labels = Map.of("label-1", "value-1", "label-2", "value-2");
23+
24+
Labels l = new Labels();
25+
l.setAdditionalData(labels);
26+
27+
CreateGroupMetaData body = new CreateGroupMetaData();
28+
body.setId(groupId);
29+
body.setDescription("My favorite test group.");
30+
body.setLabels(l);
31+
GroupMetaData gmd = clientV3.groups().post(body);
32+
33+
Assertions.assertEquals(groupId, gmd.getId());
34+
Assertions.assertEquals("My favorite test group.", gmd.getDescription());
35+
Assertions.assertEquals(labels, gmd.getLabels().getAdditionalData());
36+
}
37+
38+
@Test
39+
public void getGroupMetadata() throws Exception {
40+
String groupId = UUID.randomUUID().toString();
41+
Map<String, Object> labels = Map.of("label-1", "value-1", "label-2", "value-2");
42+
43+
Labels l = new Labels();
44+
l.setAdditionalData(labels);
45+
46+
CreateGroupMetaData body = new CreateGroupMetaData();
47+
body.setId(groupId);
48+
body.setDescription("My favorite test group.");
49+
body.setLabels(l);
50+
clientV3.groups().post(body);
51+
52+
// Now fetch the metadata
53+
GroupMetaData gmd = clientV3.groups().byGroupId(groupId).get();
54+
55+
Assertions.assertEquals(groupId, gmd.getId());
56+
Assertions.assertEquals("My favorite test group.", gmd.getDescription());
57+
Assertions.assertEquals(labels, gmd.getLabels().getAdditionalData());
58+
}
59+
60+
@Test
61+
public void updateGroupMetadata() throws Exception {
62+
String groupId = UUID.randomUUID().toString();
63+
Map<String, Object> labels1 = Map.of("label-1", "value-1", "label-2", "value-2");
64+
Map<String, Object> labels2 = Map.of("label-5", "value-5", "label-6", "value-6", "label-7", "value-7");
65+
66+
Labels l = new Labels();
67+
l.setAdditionalData(labels1);
68+
69+
CreateGroupMetaData body = new CreateGroupMetaData();
70+
body.setId(groupId);
71+
body.setDescription("My favorite test group.");
72+
body.setLabels(l);
73+
clientV3.groups().post(body);
74+
75+
EditableGroupMetaData egmd = new EditableGroupMetaData();
76+
egmd.setDescription("UPDATED DESCRIPTION");
77+
l.setAdditionalData(labels2);
78+
egmd.setLabels(l);
79+
// Update the metadata
80+
clientV3.groups().byGroupId(groupId).put(egmd);
81+
82+
// Now fetch the metadata
83+
GroupMetaData gmd = clientV3.groups().byGroupId(groupId).get();
84+
85+
Assertions.assertEquals(groupId, gmd.getId());
86+
Assertions.assertEquals("UPDATED DESCRIPTION", gmd.getDescription());
87+
Assertions.assertEquals(labels2, gmd.getLabels().getAdditionalData());
88+
}
89+
90+
}

app/src/test/java/io/apicurio/registry/rbac/RegistryClientTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void groupsCrud() throws Exception {
136136
final GroupMetaData artifactGroup = clientV3.groups().byGroupId(groupId).get();
137137
assertEquals(groupMetaData.getId(), artifactGroup.getId());
138138
assertEquals(groupMetaData.getDescription(), artifactGroup.getDescription());
139-
assertEquals(groupMetaData.getLabels().getAdditionalData(), artifactGroup.getProperties().getAdditionalData());
139+
assertEquals(groupMetaData.getLabels().getAdditionalData(), artifactGroup.getLabels().getAdditionalData());
140140

141141

142142
String group1Id = UUID.randomUUID().toString();

common/src/main/resources/META-INF/openapi.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4379,7 +4379,7 @@
43794379
"createdOn",
43804380
"modifiedBy",
43814381
"modifiedOn",
4382-
"properties"
4382+
"labels"
43834383
],
43844384
"type": "object",
43854385
"properties": {
@@ -4404,7 +4404,7 @@
44044404
"format": "date-time",
44054405
"type": "string"
44064406
},
4407-
"properties": {
4407+
"labels": {
44084408
"$ref": "#/components/schemas/Labels",
44094409
"description": ""
44104410
}

go-sdk/pkg/registryclient-v3/kiota-lock.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"descriptionHash": "A082EB30389D82AC8245967203939E539DDA246F24242BC166080749D16B8E6592DD2F8F2FD727D03E7BE82B30E9764D3763B050205E7E82F8847E24D4BB0517",
2+
"descriptionHash": "56939600DE2087832A8FA7E34BA9DAEC34B8E144309EB838A080FB5F4F2F00C5E494D8628EB8111FED284D083455132478DC840DB99CF21ABA85D9B99672DFE1",
33
"descriptionLocation": "../../v3.json",
44
"lockFileVersion": "1.0.0",
55
"kiotaVersion": "1.10.1",

go-sdk/pkg/registryclient-v3/models/group_meta_data.go

+26-26
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ type GroupMetaData struct {
1717
description *string
1818
// An ID of a single artifact group.
1919
id *string
20+
// User-defined name-value pairs. Name and value must be strings.
21+
labels Labelsable
2022
// The modifiedBy property
2123
modifiedBy *string
2224
// The modifiedOn property
2325
modifiedOn *i336074805fc853987abe6f7fe3ad97a6a6f3077a16391fec744f671a015fbd7e.Time
24-
// User-defined name-value pairs. Name and value must be strings.
25-
properties Labelsable
2626
}
2727

2828
// NewGroupMetaData instantiates a new GroupMetaData and sets the default values.
@@ -100,33 +100,33 @@ func (m *GroupMetaData) GetFieldDeserializers() map[string]func(i878a80d2330e89d
100100
}
101101
return nil
102102
}
103-
res["modifiedBy"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
104-
val, err := n.GetStringValue()
103+
res["labels"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
104+
val, err := n.GetObjectValue(CreateLabelsFromDiscriminatorValue)
105105
if err != nil {
106106
return err
107107
}
108108
if val != nil {
109-
m.SetModifiedBy(val)
109+
m.SetLabels(val.(Labelsable))
110110
}
111111
return nil
112112
}
113-
res["modifiedOn"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
114-
val, err := n.GetTimeValue()
113+
res["modifiedBy"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
114+
val, err := n.GetStringValue()
115115
if err != nil {
116116
return err
117117
}
118118
if val != nil {
119-
m.SetModifiedOn(val)
119+
m.SetModifiedBy(val)
120120
}
121121
return nil
122122
}
123-
res["properties"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
124-
val, err := n.GetObjectValue(CreateLabelsFromDiscriminatorValue)
123+
res["modifiedOn"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
124+
val, err := n.GetTimeValue()
125125
if err != nil {
126126
return err
127127
}
128128
if val != nil {
129-
m.SetProperties(val.(Labelsable))
129+
m.SetModifiedOn(val)
130130
}
131131
return nil
132132
}
@@ -138,6 +138,11 @@ func (m *GroupMetaData) GetId() *string {
138138
return m.id
139139
}
140140

141+
// GetLabels gets the labels property value. User-defined name-value pairs. Name and value must be strings.
142+
func (m *GroupMetaData) GetLabels() Labelsable {
143+
return m.labels
144+
}
145+
141146
// GetModifiedBy gets the modifiedBy property value. The modifiedBy property
142147
func (m *GroupMetaData) GetModifiedBy() *string {
143148
return m.modifiedBy
@@ -148,11 +153,6 @@ func (m *GroupMetaData) GetModifiedOn() *i336074805fc853987abe6f7fe3ad97a6a6f307
148153
return m.modifiedOn
149154
}
150155

151-
// GetProperties gets the properties property value. User-defined name-value pairs. Name and value must be strings.
152-
func (m *GroupMetaData) GetProperties() Labelsable {
153-
return m.properties
154-
}
155-
156156
// Serialize serializes information the current object
157157
func (m *GroupMetaData) Serialize(writer i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.SerializationWriter) error {
158158
{
@@ -180,19 +180,19 @@ func (m *GroupMetaData) Serialize(writer i878a80d2330e89d26896388a3f487eef27b0a0
180180
}
181181
}
182182
{
183-
err := writer.WriteStringValue("modifiedBy", m.GetModifiedBy())
183+
err := writer.WriteObjectValue("labels", m.GetLabels())
184184
if err != nil {
185185
return err
186186
}
187187
}
188188
{
189-
err := writer.WriteTimeValue("modifiedOn", m.GetModifiedOn())
189+
err := writer.WriteStringValue("modifiedBy", m.GetModifiedBy())
190190
if err != nil {
191191
return err
192192
}
193193
}
194194
{
195-
err := writer.WriteObjectValue("properties", m.GetProperties())
195+
err := writer.WriteTimeValue("modifiedOn", m.GetModifiedOn())
196196
if err != nil {
197197
return err
198198
}
@@ -231,6 +231,11 @@ func (m *GroupMetaData) SetId(value *string) {
231231
m.id = value
232232
}
233233

234+
// SetLabels sets the labels property value. User-defined name-value pairs. Name and value must be strings.
235+
func (m *GroupMetaData) SetLabels(value Labelsable) {
236+
m.labels = value
237+
}
238+
234239
// SetModifiedBy sets the modifiedBy property value. The modifiedBy property
235240
func (m *GroupMetaData) SetModifiedBy(value *string) {
236241
m.modifiedBy = value
@@ -241,11 +246,6 @@ func (m *GroupMetaData) SetModifiedOn(value *i336074805fc853987abe6f7fe3ad97a6a6
241246
m.modifiedOn = value
242247
}
243248

244-
// SetProperties sets the properties property value. User-defined name-value pairs. Name and value must be strings.
245-
func (m *GroupMetaData) SetProperties(value Labelsable) {
246-
m.properties = value
247-
}
248-
249249
// GroupMetaDataable
250250
type GroupMetaDataable interface {
251251
i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.AdditionalDataHolder
@@ -254,14 +254,14 @@ type GroupMetaDataable interface {
254254
GetCreatedOn() *i336074805fc853987abe6f7fe3ad97a6a6f3077a16391fec744f671a015fbd7e.Time
255255
GetDescription() *string
256256
GetId() *string
257+
GetLabels() Labelsable
257258
GetModifiedBy() *string
258259
GetModifiedOn() *i336074805fc853987abe6f7fe3ad97a6a6f3077a16391fec744f671a015fbd7e.Time
259-
GetProperties() Labelsable
260260
SetCreatedBy(value *string)
261261
SetCreatedOn(value *i336074805fc853987abe6f7fe3ad97a6a6f3077a16391fec744f671a015fbd7e.Time)
262262
SetDescription(value *string)
263263
SetId(value *string)
264+
SetLabels(value Labelsable)
264265
SetModifiedBy(value *string)
265266
SetModifiedOn(value *i336074805fc853987abe6f7fe3ad97a6a6f3077a16391fec744f671a015fbd7e.Time)
266-
SetProperties(value Labelsable)
267267
}

0 commit comments

Comments
 (0)