Skip to content

Commit

Permalink
Bug 572650 - upgrade licenses domain model
Browse files Browse the repository at this point in the history
- evolve test coverage for license grants reading

Signed-off-by: eparovyshnaya <[email protected]>
  • Loading branch information
eparovyshnaya committed May 16, 2021
1 parent 8660db9 commit 05647e3
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.passage.lic.internal.licenses.model.migration.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -108,9 +109,12 @@ private PersonalLicensePack pack(String path) throws IOException {
return pack;
}

private void loadedTwoGrants(String path) throws IOException {
private void loadedTwoGrants(String path) throws IOException, ParseException {
PersonalLicensePack pack = pack(path);
assertEquals("3251ddf1-bd2c-48e4-993a-26fbf7eb3a42", pack.getLicense().getIdentifier()); //$NON-NLS-1$
String identifier = pack.getLicense().getIdentifier();
assertEquals("3251ddf1-bd2c-48e4-993a-26fbf7eb3a42", identifier); //$NON-NLS-1$
assertEquals(getLicensingDateFormat().parse("2020-12-02T16:30:50.176+0300"), //$NON-NLS-1$
pack.getLicense().getIssueDate());
assertEquals(issueDate().getTime(), pack.getLicense().getIssueDate().getTime()); // $NON-NLS-1$
assertEquals("anti-human-magic.product", pack.getLicense().getProduct().getIdentifier()); //$NON-NLS-1$
assertEquals("0.2.1", pack.getLicense().getProduct().getVersion()); //$NON-NLS-1$
Expand All @@ -120,6 +124,32 @@ private void loadedTwoGrants(String path) throws IOException {

EList<LicenseGrant> grants = pack.getGrants();
assertEquals(2, grants.size());

assertGrant(grant(identifier, grants, 0), "prince-to-frog", "0.1.0"); //$NON-NLS-1$//$NON-NLS-2$
assertGrant(grant(identifier, grants, 1), "anti-human-magic.product", "0.2.1"); //$NON-NLS-1$//$NON-NLS-2$
}

private LicenseGrant grant(String pack, EList<LicenseGrant> grants, int no) {
String id = String.format("%s#%d", pack, no); //$NON-NLS-1$
for (LicenseGrant grant : grants) {
if (id.equals(grant.getIdentifier())) {
return grant;
}
}
fail(String.format("There is no grant with id %s", id)); //$NON-NLS-1$
return null;// unreachable
}

private void assertGrant(LicenseGrant grant, String feature, String version) throws ParseException {
assertEquals(feature, grant.getFeatureIdentifier());
assertEquals(version, grant.getMatchVersion());
assertEquals(null, grant.getMatchRule());
assertEquals("hardware", grant.getConditionType()); //$NON-NLS-1$
assertEquals("os.family=*", grant.getConditionExpression()); //$NON-NLS-1$
assertEquals(getLicensingDateFormat().parse("2020-12-02T00:00:00.000+0300"), //$NON-NLS-1$
grant.getValidFrom());
assertEquals(getLicensingDateFormat().parse("2021-12-02T00:00:00.000+0300"), //$NON-NLS-1$
grant.getValidUntil());
}

private final Date issueDate() {
Expand All @@ -129,4 +159,5 @@ private final Date issueDate() {
ZoneId.ofOffset("", ZoneOffset.ofHours(3))) //$NON-NLS-1$
.toInstant());
}

}

0 comments on commit 05647e3

Please sign in to comment.