Skip to content

Commit 375ce83

Browse files
v-rudkovskiyViacheslav Rudkovskyi
andauthored
fix "Inconsistecy in the validation result object" (#47)
Co-authored-by: Viacheslav Rudkovskyi <viachaslau.rudkovski@labs64.de>
1 parent 34bcf7f commit 375ce83

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemsToValidationResultConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public ValidationResult convert(final Netlicensing source) throws ConversionExce
3838
LicenseeImpl licensee = new LicenseeImpl();
3939

4040
for (final Property property : item.getProperty()) {
41-
if (Constants.Licensee.LICENSEE_NUMBER.equals(property.getName())) {
41+
if (Constants.NUMBER.equals(property.getName()) || Constants.Licensee.LICENSEE_NUMBER.equals(
42+
property.getName())) {
4243
licensee.setNumber(property.getValue());
4344
continue;
4445
}

NetLicensingClient/src/test/java/com/labs64/netlicensing/service/LicenseeServiceTest.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,31 @@ public void testValidate() throws Exception {
174174
.get(Constants.ValidationResult.WARNING_LEVEL).getValue()));
175175
}
176176

177+
@Test
178+
public void testOfflineValidation() throws Exception {
179+
final ValidationParameters validationParameters = new ValidationParameters();
180+
validationParameters.setLicenseeName("Test Licensee");
181+
validationParameters.setProductNumber(productNumber);
182+
validationParameters.setLicenseeProperty("customProperty", "Licensee Custom Property");
183+
validationParameters.setForOfflineUse(true);
184+
final ValidationResult result = LicenseeService.validate(context, licenseeNumber, validationParameters);
185+
186+
assertEquals(licenseeNumber, result.getLicensee().getNumber());
187+
188+
final Composition validation = result.getProductModuleValidation("M001-TEST");
189+
assertNotNull(validation);
190+
assertEquals("FeatureWithTimeVolume", validation.getProperties().get(Constants.ProductModule.LICENSING_MODEL)
191+
.getValue());
192+
assertEquals("Test module", validation.getProperties().get(Constants.ProductModule.PRODUCT_MODULE_NAME)
193+
.getValue());
194+
assertTrue(Boolean.parseBoolean(validation.getProperties().get("LIST1").getProperties()
195+
.get(Constants.LicensingModel.VALID).getValue()));
196+
assertEquals(
197+
WarningLevel.GREEN,
198+
WarningLevel.parseString(validation.getProperties().get("LIST2").getProperties()
199+
.get(Constants.ValidationResult.WARNING_LEVEL).getValue()));
200+
}
201+
177202
@Test
178203
public void testTransfer() throws Exception {
179204
final String sourceLicenseeNumber = "L002-TEST";
@@ -239,7 +264,8 @@ public Response delete(final String licenseeNumber, final UriInfo uriInfo) {
239264
public Response validateLicensee(@PathParam("licenseeNumber") final String licenseeNumber,
240265
@FormParam("productNumber") final String productNumber,
241266
@FormParam("licenseeName") final String licenseeName,
242-
@FormParam("customProperty") final String licenseeCustomProperty) {
267+
@FormParam("customProperty") final String licenseeCustomProperty,
268+
@FormParam("forOfflineUse") final String forOfflineUse) {
243269

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

281+
final String validationFile = (Boolean.parseBoolean(forOfflineUse))
282+
? "netlicensing-licensee-validate-offline.xml"
283+
: "netlicensing-licensee-validate.xml";
284+
255285
final Netlicensing netlicensing = JAXBUtils.readObject(TEST_CASE_BASE
256-
+ "netlicensing-licensee-validate.xml", Netlicensing.class);
286+
+ validationFile, Netlicensing.class);
257287
return Response.ok(netlicensing).build();
258288
}
259289

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<netlicensing xmlns="http://netlicensing.labs64.com/schema/context"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://netlicensing.labs64.com/schema/context
4+
https://go.netlicensing.io/schema/context/netlicensing-context-2.1.xsd">
5+
<items>
6+
<item type="Licensee">
7+
<property name="number">L001-TEST</property>
8+
</item>
9+
<item type="ProductModuleValidation">
10+
<property name="productModuleNumber">M001-TEST</property>
11+
<property name="licensingModel">FeatureWithTimeVolume</property>
12+
<property name="productModuleName">Test module</property>
13+
<list name="LIST1">
14+
<property name="valid">true</property>
15+
<property name="expires">2014-08-06T21:30:45.574Z</property>
16+
<property name="warningLevel">GREEN</property>
17+
</list>
18+
<list name="LIST2">
19+
<property name="valid">true</property>
20+
<property name="expires">2014-08-06T21:30:45.186Z</property>
21+
<property name="warningLevel">GREEN</property>
22+
</list>
23+
</item>
24+
</items>
25+
</netlicensing>

0 commit comments

Comments
 (0)