Skip to content

Commit cbf657b

Browse files
authored
Json maven deref test (#5499)
1 parent 6cfa0de commit cbf657b

File tree

9 files changed

+1762
-1
lines changed

9 files changed

+1762
-1
lines changed

app/src/test/java/io/apicurio/registry/noprofile/maven/RegistryMojoWithAutoReferencesTest.java

+59-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.apicurio.registry.maven.RegisterArtifact;
55
import io.apicurio.registry.maven.RegisterRegistryMojo;
66
import io.apicurio.registry.rest.client.models.ArtifactReference;
7+
import io.apicurio.registry.rest.client.models.HandleReferencesType;
78
import io.apicurio.registry.rest.client.models.VersionMetaData;
89
import io.apicurio.registry.rest.v3.beans.IfArtifactExists;
910
import io.apicurio.registry.types.ArtifactType;
@@ -17,6 +18,7 @@
1718
import java.io.File;
1819
import java.io.FileInputStream;
1920
import java.io.FileNotFoundException;
21+
import java.io.InputStream;
2022
import java.nio.charset.StandardCharsets;
2123
import java.util.Arrays;
2224
import java.util.Collections;
@@ -148,6 +150,62 @@ public void autoRegisterJsonSchemaWithReferences() throws Exception {
148150
validateStructure(groupId, artifactId, 3, 4, protoFiles);
149151
}
150152

153+
@Test
154+
public void autoRegisterJsonSchemaWithReferencesDeref() throws Exception {
155+
// Preparation
156+
String groupId = "autoRegisterJsonSchemaWithReferencesDeref";
157+
String artifactId = "stock";
158+
String version = "1.0.0";
159+
160+
File stockFile = new File(getClass().getResource("./stock/FLIStockAdjustment.json").getFile());
161+
162+
Set<String> jsonFiles = Arrays.stream(Objects.requireNonNull(
163+
stockFile.getParentFile().listFiles((dir, name) -> name.endsWith(JSON_SCHEMA_EXTENSION))))
164+
.map(file -> {
165+
FileInputStream fis = null;
166+
try {
167+
fis = new FileInputStream(file);
168+
} catch (FileNotFoundException e) {
169+
}
170+
return IoUtil.toString(fis).trim();
171+
}).collect(Collectors.toSet());
172+
173+
RegisterArtifact stock = new RegisterArtifact();
174+
stock.setAutoRefs(true);
175+
stock.setGroupId(groupId);
176+
stock.setArtifactId(artifactId);
177+
stock.setVersion(version);
178+
stock.setArtifactType(ArtifactType.JSON);
179+
stock.setFile(stockFile);
180+
stock.setIfExists(IfArtifactExists.FIND_OR_CREATE_VERSION);
181+
182+
registerMojo.setArtifacts(Collections.singletonList(stock));
183+
184+
// Execution
185+
registerMojo.execute();
186+
187+
// Assertions
188+
validateStructure(groupId, artifactId, 9, 6, jsonFiles);
189+
190+
final VersionMetaData artifactWithReferences = clientV3.groups().byGroupId(groupId).artifacts()
191+
.byArtifactId(artifactId).versions().byVersionExpression(version).get();
192+
InputStream contentByGlobalId = clientV3.ids().globalIds()
193+
.byGlobalId(artifactWithReferences.getGlobalId()).get(getRequestConfiguration -> {
194+
getRequestConfiguration.queryParameters.references = HandleReferencesType.DEREFERENCE;
195+
});
196+
197+
File stockFileDeref = new File(
198+
getClass().getResource("./stock/FLIStockAdjustment_deref.json").getFile());
199+
200+
FileInputStream fis = null;
201+
try {
202+
fis = new FileInputStream(stockFileDeref);
203+
} catch (FileNotFoundException e) {
204+
}
205+
206+
Assertions.assertEquals(IoUtil.toString(fis).trim(), IoUtil.toString(contentByGlobalId));
207+
}
208+
151209
private void validateStructure(String groupId, String artifactId, int expectedMainReferences,
152210
int expectedTotalArtifacts, Set<String> originalContents) throws Exception {
153211
final VersionMetaData artifactWithReferences = clientV3.groups().byGroupId(groupId).artifacts()
@@ -157,7 +215,7 @@ private void validateStructure(String groupId, String artifactId, int expectedMa
157215
.content().get().readAllBytes(), StandardCharsets.UTF_8);
158216

159217
Assertions.assertTrue(originalContents.contains(mainContent)); // The main content has been registered
160-
// as-is.
218+
// as-is.
161219

162220
final List<ArtifactReference> mainArtifactReferences = clientV3.ids().globalIds()
163221
.byGlobalId(artifactWithReferences.getGlobalId()).references().get();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"$id": "FLIBusinessUnitBaseTypes.json",
4+
"type": "object",
5+
"$defs": {
6+
"buCodeType": {
7+
"type": "string",
8+
"pattern": "(^[0-9A-Z]{3,5})|AP"
9+
},
10+
"buTypeType": {
11+
"type": "string",
12+
"pattern": "(^[A-Z]{2,3})"
13+
},
14+
"buNumber":{
15+
"type": "string",
16+
"pattern": "(^[A-Z]{2,3})"
17+
},
18+
"BusinessUnitReferenceType": {
19+
"type": "object",
20+
"required": [
21+
"BusinessUnitCode",
22+
"BusinessUnitType"
23+
],
24+
"properties": {
25+
"BusinessUnitCode": {
26+
"$ref": "#/$defs/buCodeType"
27+
},
28+
"BusinessUnitType": {
29+
"$ref": "#/$defs/buTypeType"
30+
}
31+
},
32+
"additionalProperties": false
33+
},
34+
"BusinessUnitReferenceDuplicateType": {
35+
"type": "object",
36+
"required": [
37+
"BusinessUnitCode",
38+
"BusinessUnitType"
39+
],
40+
"properties": {
41+
"BusinessUnitCode": {
42+
"$ref": "#/$defs/buCodeType"
43+
},
44+
"BusinessUnitType": {
45+
"$ref": "#/$defs/buTypeType"
46+
}
47+
},
48+
"additionalProperties": false
49+
},
50+
"BusinessUnitAddressReferenceType": {
51+
"type": "object",
52+
"required": [
53+
"BusinessUnitCode",
54+
"BusinessUnitType",
55+
"BusinessUnitSequence"
56+
],
57+
"properties": {
58+
"BusinessUnitCode": {
59+
"$ref": "#/$defs/buCodeType"
60+
},
61+
"BusinessUnitType": {
62+
"$ref": "#/$defs/buTypeType"
63+
},
64+
"BusinessUnitSequence": {
65+
"$ref": "FLIServiceTypes.json#/$defs/positiveInteger4"
66+
}
67+
},
68+
"additionalProperties": false
69+
}
70+
},
71+
"anyOf": [
72+
{
73+
"$ref": "#/$defs/BusinessUnitReferenceType"
74+
},
75+
{
76+
"$ref": "#/$defs/BusinessUnitAddressReferenceType"
77+
}
78+
]
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"$id": "FLIItemBaseTypes.json",
4+
"$defs": {
5+
"ItemReferenceType": {
6+
"type": "object",
7+
"properties": {
8+
"ItemNumber": {
9+
"type": "string",
10+
"minLength": 1,
11+
"maxLength": 15
12+
},
13+
"ItemType": {
14+
"type": "string",
15+
"enum": [
16+
"ADS",
17+
"ART",
18+
"CCI",
19+
"HM",
20+
"OAD",
21+
"SGR",
22+
"SPR"
23+
]
24+
}
25+
},
26+
"required": [
27+
"ItemNumber",
28+
"ItemType"
29+
],
30+
"additionalProperties": false
31+
},
32+
"ItemSKUType": {
33+
"type": "string",
34+
"minLength": 1,
35+
"maxLength": 20
36+
},
37+
"DWPReferenceType": {
38+
"type": "object",
39+
"properties": {
40+
"ItemReference": {
41+
"$ref": "#/$defs/ItemReferenceType"
42+
},
43+
"ItemSupplierReference": {
44+
"$ref": "FLIBusinessUnitBaseTypes.json#/$defs/BusinessUnitReferenceType"
45+
},
46+
"DWPNumber": { "type": "integer" },
47+
"DWPEdition": { "type": "integer" },
48+
"DWPFromPackagingDate": {
49+
"type": "string",
50+
"format": "date"
51+
}
52+
},
53+
"required": [
54+
"ItemReference",
55+
"ItemSupplierReference",
56+
"DWPNumber",
57+
"DWPEdition",
58+
"DWPFromPackagingDate"
59+
],
60+
"additionalProperties": false
61+
}
62+
},
63+
"anyOf": [
64+
{ "$ref": "#/$defs/ItemReferenceType" },
65+
{ "$ref": "#/$defs/DWPReferenceType" }
66+
]
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2019-09/schema",
3+
"$id": "FLIMessageHeader.json",
4+
"$defs": {
5+
"MsgHeaderType": {
6+
"type": "object",
7+
"properties": {
8+
"MsgName": {
9+
"type": "string",
10+
"minLength": 1,
11+
"maxLength": 36
12+
},
13+
"MsgVersNo": {
14+
"type": "string",
15+
"minLength": 1,
16+
"maxLength": 10
17+
},
18+
"MsgDateTime": {
19+
"type": "string",
20+
"format": "date-time",
21+
"pattern": "^(.{20})([0-9]{3})[+-]((2[0-3]|[01][0-9])[:]([0-5][0-9]))$"
22+
},
23+
"MsgReference": {
24+
"type": "string",
25+
"minLength": 1,
26+
"maxLength": 36
27+
},
28+
"SendingSystem": {
29+
"type": "string",
30+
"minLength": 1,
31+
"maxLength": 20
32+
},
33+
"SendingUnit": {
34+
"type": "object",
35+
"properties": {
36+
"BUCode": {
37+
"type": "string",
38+
"minLength": 3,
39+
"maxLength": 5
40+
},
41+
"BUType": {
42+
"type": "string",
43+
"minLength": 2,
44+
"maxLength": 3
45+
}
46+
},
47+
"required": [
48+
"BUCode",
49+
"BUType"
50+
],
51+
"additionalProperties": false
52+
},
53+
"LogicalRoutingIdentifier": {
54+
"type": "object",
55+
"properties": {
56+
"SourceCode": {
57+
"type": "string",
58+
"minLength": 1
59+
},
60+
"SourceType": {
61+
"type": "string",
62+
"minLength": 1
63+
},
64+
"SourceLookupType": {
65+
"type": "string",
66+
"minLength": 1
67+
}
68+
},
69+
"required": [
70+
"SourceCode",
71+
"SourceType"
72+
],
73+
"additionalProperties": false
74+
}
75+
},
76+
"additionalProperties": false,
77+
"required": [
78+
"MsgName",
79+
"MsgVersNo",
80+
"MsgDateTime",
81+
"MsgReference",
82+
"SendingSystem"
83+
]
84+
}
85+
},
86+
"type": "object",
87+
"properties": {
88+
"MsgHeader": {
89+
"$ref": "#/$defs/MsgHeaderType"
90+
}
91+
},
92+
"required": [
93+
"MsgHeader"
94+
],
95+
"additionalProperties": false
96+
}

0 commit comments

Comments
 (0)