Skip to content

Commit

Permalink
Json maven deref test
Browse files Browse the repository at this point in the history
  • Loading branch information
carlesarnal committed Nov 12, 2024
1 parent 417dde2 commit 35d558c
Show file tree
Hide file tree
Showing 9 changed files with 1,755 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,58 @@ public void autoRegisterJsonSchemaWithReferences() throws Exception {
validateStructure(groupId, artifactId, 3, 4, protoFiles);
}

@Test
public void autoRegisterJsonSchemaWithReferencesDeref()
throws MojoExecutionException, MojoFailureException {
// Preparation
String groupId = "autoRegisterJsonSchemaWithReferencesDeref";
String artifactId = "stock";

File stockFile = new File(getClass().getResource("./stock/FLIStockAdjustment.json").getFile());

Set<String> jsonFiles = Arrays.stream(Objects.requireNonNull(
stockFile.getParentFile().listFiles((dir, name) -> name.endsWith(JSON_SCHEMA_EXTENSION))))
.map(file -> {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
}
return IoUtil.toString(fis).trim();
}).collect(Collectors.toSet());

RegisterArtifact stock = new RegisterArtifact();
stock.setAutoRefs(true);
stock.setGroupId(groupId);
stock.setArtifactId(artifactId);
stock.setType(ArtifactType.JSON);
stock.setFile(stockFile);
stock.setIfExists(IfExists.RETURN_OR_UPDATE);

registerMojo.setArtifacts(Collections.singletonList(stock));

// Execution
registerMojo.execute();

// Assertions
validateStructure(groupId, artifactId, 9, 6, jsonFiles);

final ArtifactMetaData artifactWithReferences = clientV2.getArtifactMetaData(groupId, artifactId);
InputStream contentByGlobalId = clientV2.getContentByGlobalId(artifactWithReferences.getGlobalId(),
false, true);

File stockFileDeref = new File(
getClass().getResource("./stock/FLIStockAdjustment_deref.json").getFile());

FileInputStream fis = null;
try {
fis = new FileInputStream(stockFileDeref);
} catch (FileNotFoundException e) {
}

Assertions.assertEquals(IoUtil.toString(fis).trim(), IoUtil.toString(contentByGlobalId));
}

private void validateStructure(String groupId, String artifactId, int expectedMainReferences,
int expectedTotalArtifacts, Set<String> originalContents) throws Exception {
final VersionMetaData artifactWithReferences = clientV3.groups().byGroupId(groupId).artifacts()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "FLIBusinessUnitBaseTypes.json",
"type": "object",
"$defs": {
"buCodeType": {
"type": "string",
"pattern": "(^[0-9A-Z]{3,5})|AP"
},
"buTypeType": {
"type": "string",
"pattern": "(^[A-Z]{2,3})"
},
"buNumber":{
"type": "string",
"pattern": "(^[A-Z]{2,3})"
},
"BusinessUnitReferenceType": {
"type": "object",
"required": [
"BusinessUnitCode",
"BusinessUnitType"
],
"properties": {
"BusinessUnitCode": {
"$ref": "#/$defs/buCodeType"
},
"BusinessUnitType": {
"$ref": "#/$defs/buTypeType"
}
},
"additionalProperties": false
},
"BusinessUnitReferenceDuplicateType": {
"type": "object",
"required": [
"BusinessUnitCode",
"BusinessUnitType"
],
"properties": {
"BusinessUnitCode": {
"$ref": "#/$defs/buCodeType"
},
"BusinessUnitType": {
"$ref": "#/$defs/buTypeType"
}
},
"additionalProperties": false
},
"BusinessUnitAddressReferenceType": {
"type": "object",
"required": [
"BusinessUnitCode",
"BusinessUnitType",
"BusinessUnitSequence"
],
"properties": {
"BusinessUnitCode": {
"$ref": "#/$defs/buCodeType"
},
"BusinessUnitType": {
"$ref": "#/$defs/buTypeType"
},
"BusinessUnitSequence": {
"$ref": "FLIServiceTypes.json#/$defs/positiveInteger4"
}
},
"additionalProperties": false
}
},
"anyOf": [
{
"$ref": "#/$defs/BusinessUnitReferenceType"
},
{
"$ref": "#/$defs/BusinessUnitAddressReferenceType"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "FLIItemBaseTypes.json",
"$defs": {
"ItemReferenceType": {
"type": "object",
"properties": {
"ItemNumber": {
"type": "string",
"minLength": 1,
"maxLength": 15
},
"ItemType": {
"type": "string",
"enum": [
"ADS",
"ART",
"CCI",
"HM",
"OAD",
"SGR",
"SPR"
]
}
},
"required": [
"ItemNumber",
"ItemType"
],
"additionalProperties": false
},
"ItemSKUType": {
"type": "string",
"minLength": 1,
"maxLength": 20
},
"DWPReferenceType": {
"type": "object",
"properties": {
"ItemReference": {
"$ref": "#/$defs/ItemReferenceType"
},
"ItemSupplierReference": {
"$ref": "FLIBusinessUnitBaseTypes.json#/$defs/BusinessUnitReferenceType"
},
"DWPNumber": { "type": "integer" },
"DWPEdition": { "type": "integer" },
"DWPFromPackagingDate": {
"type": "string",
"format": "date"
}
},
"required": [
"ItemReference",
"ItemSupplierReference",
"DWPNumber",
"DWPEdition",
"DWPFromPackagingDate"
],
"additionalProperties": false
}
},
"anyOf": [
{ "$ref": "#/$defs/ItemReferenceType" },
{ "$ref": "#/$defs/DWPReferenceType" }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "FLIMessageHeader.json",
"$defs": {
"MsgHeaderType": {
"type": "object",
"properties": {
"MsgName": {
"type": "string",
"minLength": 1,
"maxLength": 36
},
"MsgVersNo": {
"type": "string",
"minLength": 1,
"maxLength": 10
},
"MsgDateTime": {
"type": "string",
"format": "date-time",
"pattern": "^(.{20})([0-9]{3})[+-]((2[0-3]|[01][0-9])[:]([0-5][0-9]))$"
},
"MsgReference": {
"type": "string",
"minLength": 1,
"maxLength": 36
},
"SendingSystem": {
"type": "string",
"minLength": 1,
"maxLength": 20
},
"SendingUnit": {
"type": "object",
"properties": {
"BUCode": {
"type": "string",
"minLength": 3,
"maxLength": 5
},
"BUType": {
"type": "string",
"minLength": 2,
"maxLength": 3
}
},
"required": [
"BUCode",
"BUType"
],
"additionalProperties": false
},
"LogicalRoutingIdentifier": {
"type": "object",
"properties": {
"SourceCode": {
"type": "string",
"minLength": 1
},
"SourceType": {
"type": "string",
"minLength": 1
},
"SourceLookupType": {
"type": "string",
"minLength": 1
}
},
"required": [
"SourceCode",
"SourceType"
],
"additionalProperties": false
}
},
"additionalProperties": false,
"required": [
"MsgName",
"MsgVersNo",
"MsgDateTime",
"MsgReference",
"SendingSystem"
]
}
},
"type": "object",
"properties": {
"MsgHeader": {
"$ref": "#/$defs/MsgHeaderType"
}
},
"required": [
"MsgHeader"
],
"additionalProperties": false
}
Loading

0 comments on commit 35d558c

Please sign in to comment.