From b9dc08991e7b101248fb0b85cb14a9f134362b9d Mon Sep 17 00:00:00 2001 From: eparovyshnaya Date: Mon, 9 Nov 2020 10:19:39 +0300 Subject: [PATCH 1/2] Bug 568632 Implement feature grant acquire/release RemoteConditions now sends 'mine' command for condition mining request Signed-off-by: eparovyshnaya --- .../internal/api/conditions/ConditionAction.java | 12 ++++++------ .../hc/remote/impl/DecryptedConditions.java | 13 +++++++------ ...stParameters.java => MineRequestParameters.java} | 6 +++--- .../hc/remote/impl/RemoteConditionsRequest.java | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) rename bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/{RequestParameters.java => MineRequestParameters.java} (93%) diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/ConditionAction.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/ConditionAction.java index 6cd6cda2d..e53fc3650 100644 --- a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/ConditionAction.java +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/ConditionAction.java @@ -45,18 +45,18 @@ public String toString() { return name; } - public static final class Aquire extends ConditionAction { + public static final class Mine extends ConditionAction { - public Aquire() { - super("acquire"); //$NON-NLS-1$ + public Mine() { + super("mine"); //$NON-NLS-1$ } } - public static final class Keep extends ConditionAction { + public static final class Aquire extends ConditionAction { - public Keep() { - super("keep"); //$NON-NLS-1$ + public Aquire() { + super("acquire"); //$NON-NLS-1$ } } diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/DecryptedConditions.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/DecryptedConditions.java index 72b69305b..ff6e2215d 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/DecryptedConditions.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/DecryptedConditions.java @@ -47,7 +47,7 @@ public Collection read(byte[] raw, String contentType) throws Lic return Collections.singleton(// new BaseConditionPack(// source(), // - transport(new ContentType.Of(contentType)).read(stream)// + transport(contentType).read(stream)// )); } catch (IOException e) { throw new LicensingException(HcMessages.DecryptedConditions_reading_error, e); @@ -58,12 +58,13 @@ private String source() { return String.format("net:%s:%d", coordinates.getIp(), coordinates.getPort());//$NON-NLS-1$ } - private ConditionTransport transport(ContentType contentType) throws LicensingException { - if (!transports.get().hasService(contentType)) { - throw new LicensingException(String.format(HcMessages.DecryptedConditions_no_transport_for_content_type, - contentType.contentType())); + private ConditionTransport transport(String contentType) throws LicensingException { + ContentType type = new ContentType.Of(contentType); + if (!transports.get().hasService(type)) { + throw new LicensingException( + String.format(HcMessages.DecryptedConditions_no_transport_for_content_type, contentType)); } - return transports.get().service(contentType); + return transports.get().service(type); } } diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RequestParameters.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/MineRequestParameters.java similarity index 93% rename from bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RequestParameters.java rename to bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/MineRequestParameters.java index 7d3bdd228..b7fb8d98e 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RequestParameters.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/MineRequestParameters.java @@ -26,12 +26,12 @@ import org.eclipse.passage.lic.internal.base.conditions.mining.LicensingContentType; import org.eclipse.passage.lic.internal.net.LicensingAction; -final class RequestParameters { +final class MineRequestParameters { private final LicensedProduct product; private final FloatingLicenseAccess access; - RequestParameters(LicensedProduct product, FloatingLicenseAccess access) { + MineRequestParameters(LicensedProduct product, FloatingLicenseAccess access) { this.product = product; this.access = access; } @@ -50,7 +50,7 @@ private NamedData[] parameters() throws UnsupportedEncodingException { return new NamedData[] { // new ProductIdentifier(encode(product.identifier())), // new ProductVersion(encode(product.version())), // - new LicensingAction(new ConditionAction.Aquire()), // + new LicensingAction(new ConditionAction.Mine()), // new LicensingContentType(new ContentType.Xml()), // new LicenseUser(access.getUser()), // new ServerAuthenticationType(access.getServer()), // diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditionsRequest.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditionsRequest.java index 565f3fcab..c6dd0ae31 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditionsRequest.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditionsRequest.java @@ -54,7 +54,7 @@ public URL url() throws LicensingException { return new URL("http", //$NON-NLS-1$ corrdinates.host(), // Integer.parseInt(corrdinates.port()), // - new RequestParameters(product, access).query()); + new MineRequestParameters(product, access).query()); } catch (LicensingException // | NumberFormatException // | MalformedURLException // From 9be9d478ca90b5915a2f108de95dff6f97629f8d Mon Sep 17 00:00:00 2001 From: eparovyshnaya Date: Mon, 9 Nov 2020 10:37:42 +0300 Subject: [PATCH 2/2] Bug 568632 Implement feature grant acquire/release Fix typo in class name Rework test for better coverage. Signed-off-by: eparovyshnaya --- .../api/conditions/ConditionAction.java | 4 +-- .../internal/hc/remote/impl/LicenseUser.java | 4 +-- .../hc/tests/RemoteConditionsRequestTest.java | 31 ++++++++++++++----- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/ConditionAction.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/ConditionAction.java index e53fc3650..daa7ccb82 100644 --- a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/ConditionAction.java +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/ConditionAction.java @@ -53,9 +53,9 @@ public Mine() { } - public static final class Aquire extends ConditionAction { + public static final class Acquire extends ConditionAction { - public Aquire() { + public Acquire() { super("acquire"); //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/LicenseUser.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/LicenseUser.java index ba055c33a..8df8bd388 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/LicenseUser.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/LicenseUser.java @@ -22,9 +22,9 @@ * * FIXME: for development: #564815 */ -final class LicenseUser extends StringNamedData { +public final class LicenseUser extends StringNamedData { - protected LicenseUser(String value) { + public LicenseUser(String value) { super(value); } diff --git a/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/RemoteConditionsRequestTest.java b/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/RemoteConditionsRequestTest.java index cffc21c65..20c841e99 100644 --- a/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/RemoteConditionsRequestTest.java +++ b/tests/org.eclipse.passage.lic.hc.tests/src/org/eclipse/passage/lic/internal/hc/tests/RemoteConditionsRequestTest.java @@ -32,6 +32,7 @@ import org.eclipse.passage.lic.internal.base.ProductIdentifier; import org.eclipse.passage.lic.internal.base.ProductVersion; import org.eclipse.passage.lic.internal.base.conditions.mining.LicensingContentType; +import org.eclipse.passage.lic.internal.hc.remote.impl.LicenseUser; import org.eclipse.passage.lic.internal.hc.remote.impl.RemoteConditionsRequest; import org.eclipse.passage.lic.internal.hc.remote.impl.ServerAuthenticationExpression; import org.eclipse.passage.lic.internal.hc.remote.impl.ServerAuthenticationType; @@ -57,13 +58,29 @@ public void urlContainsAllParameters() throws IOException { assertEquals(host, url.getHost()); assertEquals(port, url.getPort()); assertNotNull(url.getQuery()); - assertTrue(url.getQuery().contains(new ProductIdentifier("any").key())); //$NON-NLS-1$ - assertTrue(url.getQuery().contains(new ProductVersion("any").key())); //$NON-NLS-1$ - assertTrue(url.getQuery().contains(new LicensingAction(new ConditionAction.Of("any")).key())); //$NON-NLS-1$ - assertTrue(url.getQuery().contains(new ServerAuthenticationExpression("any").key())); //$NON-NLS-1$ - assertTrue(url.getQuery().contains(new ServerAuthenticationType("any").key())); //$NON-NLS-1$ - assertTrue(url.getQuery().contains("user")); //$NON-NLS-1$ - assertTrue(url.getQuery().contains(new LicensingContentType(new ContentType.Of("any")).key())); //$NON-NLS-1$ + queryHas(url, new ProductIdentifier("any").key()); //$NON-NLS-1$ + queryHas(url, new ProductVersion("any").key()); //$NON-NLS-1$ + queryHas(url, // + new LicensingAction(new ConditionAction.Of("any")).key(), //$NON-NLS-1$ + new ConditionAction.Mine().name()); + queryHas(url, // + new ServerAuthenticationExpression("any").key(), //$NON-NLS-1$ + expression); + queryHas(url, // + new ServerAuthenticationType("any").key(), //$NON-NLS-1$ + environment); + queryHas(url, // + new LicenseUser(user).key(), // + user); + queryHas(url, // + new LicensingContentType(new ContentType.Of("any")).key(), //$NON-NLS-1$ + new ContentType.Xml().contentType()); + } + + private void queryHas(URL url, String... values) { + for (String value : values) { + assertTrue(url.getQuery().contains(value)); + } } private URL url() {