Skip to content

Commit

Permalink
fix "Inconsistecy in the validation result object" (#47)
Browse files Browse the repository at this point in the history
Co-authored-by: Viacheslav Rudkovskyi <viachaslau.rudkovski@labs64.de>
  • Loading branch information
v-rudkovskiy and Viacheslav Rudkovskyi authored Feb 23, 2024
1 parent 34bcf7f commit 375ce83
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public ValidationResult convert(final Netlicensing source) throws ConversionExce
LicenseeImpl licensee = new LicenseeImpl();

for (final Property property : item.getProperty()) {
if (Constants.Licensee.LICENSEE_NUMBER.equals(property.getName())) {
if (Constants.NUMBER.equals(property.getName()) || Constants.Licensee.LICENSEE_NUMBER.equals(
property.getName())) {
licensee.setNumber(property.getValue());
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,31 @@ public void testValidate() throws Exception {
.get(Constants.ValidationResult.WARNING_LEVEL).getValue()));
}

@Test
public void testOfflineValidation() throws Exception {
final ValidationParameters validationParameters = new ValidationParameters();
validationParameters.setLicenseeName("Test Licensee");
validationParameters.setProductNumber(productNumber);
validationParameters.setLicenseeProperty("customProperty", "Licensee Custom Property");
validationParameters.setForOfflineUse(true);
final ValidationResult result = LicenseeService.validate(context, licenseeNumber, validationParameters);

assertEquals(licenseeNumber, result.getLicensee().getNumber());

final Composition validation = result.getProductModuleValidation("M001-TEST");
assertNotNull(validation);
assertEquals("FeatureWithTimeVolume", validation.getProperties().get(Constants.ProductModule.LICENSING_MODEL)
.getValue());
assertEquals("Test module", validation.getProperties().get(Constants.ProductModule.PRODUCT_MODULE_NAME)
.getValue());
assertTrue(Boolean.parseBoolean(validation.getProperties().get("LIST1").getProperties()
.get(Constants.LicensingModel.VALID).getValue()));
assertEquals(
WarningLevel.GREEN,
WarningLevel.parseString(validation.getProperties().get("LIST2").getProperties()
.get(Constants.ValidationResult.WARNING_LEVEL).getValue()));
}

@Test
public void testTransfer() throws Exception {
final String sourceLicenseeNumber = "L002-TEST";
Expand Down Expand Up @@ -239,7 +264,8 @@ public Response delete(final String licenseeNumber, final UriInfo uriInfo) {
public Response validateLicensee(@PathParam("licenseeNumber") final String licenseeNumber,
@FormParam("productNumber") final String productNumber,
@FormParam("licenseeName") final String licenseeName,
@FormParam("customProperty") final String licenseeCustomProperty) {
@FormParam("customProperty") final String licenseeCustomProperty,
@FormParam("forOfflineUse") final String forOfflineUse) {

if (!productNumber.equals(productNumber)) {
return unexpectedValueErrorResponse("productNumber");
Expand All @@ -252,8 +278,12 @@ public Response validateLicensee(@PathParam("licenseeNumber") final String licen
return unexpectedValueErrorResponse("customProperty");
}

final String validationFile = (Boolean.parseBoolean(forOfflineUse))
? "netlicensing-licensee-validate-offline.xml"
: "netlicensing-licensee-validate.xml";

final Netlicensing netlicensing = JAXBUtils.readObject(TEST_CASE_BASE
+ "netlicensing-licensee-validate.xml", Netlicensing.class);
+ validationFile, Netlicensing.class);
return Response.ok(netlicensing).build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<netlicensing xmlns="http://netlicensing.labs64.com/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://netlicensing.labs64.com/schema/context
https://go.netlicensing.io/schema/context/netlicensing-context-2.1.xsd">
<items>
<item type="Licensee">
<property name="number">L001-TEST</property>
</item>
<item type="ProductModuleValidation">
<property name="productModuleNumber">M001-TEST</property>
<property name="licensingModel">FeatureWithTimeVolume</property>
<property name="productModuleName">Test module</property>
<list name="LIST1">
<property name="valid">true</property>
<property name="expires">2014-08-06T21:30:45.574Z</property>
<property name="warningLevel">GREEN</property>
</list>
<list name="LIST2">
<property name="valid">true</property>
<property name="expires">2014-08-06T21:30:45.186Z</property>
<property name="warningLevel">GREEN</property>
</list>
</item>
</items>
</netlicensing>

0 comments on commit 375ce83

Please sign in to comment.