framework();
+
+}
diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/StreamCodecsRegitryTest.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/StreamCodecsRegitryTest.java
index 812d5ee7c..7d910d18b 100644
--- a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/StreamCodecsRegitryTest.java
+++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/StreamCodecsRegitryTest.java
@@ -23,7 +23,7 @@
/**
*
* Check that {@linkplain Framework} instance in use supplies read only
- * collection of sream codecs.
+ * collection of stream codecs.
*
*
* Each {@code Framework} implementation must extend this class and satisfy all
diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/inspection/FakeRuntimeEnvironment.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/inspection/FakeRuntimeEnvironment.java
new file mode 100644
index 000000000..bded2fde6
--- /dev/null
+++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/fakes/inspection/FakeRuntimeEnvironment.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2020 ArSysOp
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * https://www.eclipse.org/legal/epl-2.0/.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * ArSysOp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.passage.lic.api.tests.fakes.inspection;
+
+import org.eclipse.passage.lic.internal.api.LicensingException;
+import org.eclipse.passage.lic.internal.api.conditions.EvaluationType;
+import org.eclipse.passage.lic.internal.api.inspection.EnvironmentProperty;
+import org.eclipse.passage.lic.internal.api.inspection.RuntimeEnvironment;
+
+@SuppressWarnings("restriction")
+public final class FakeRuntimeEnvironment implements RuntimeEnvironment {
+
+ @Override
+ public EvaluationType id() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String state() throws LicensingException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isAssuptionTrue(EnvironmentProperty property, String value) throws LicensingException {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/inspection/RuntimeEnvironmentContractTest.java b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/inspection/RuntimeEnvironmentContractTest.java
new file mode 100644
index 000000000..3196d5222
--- /dev/null
+++ b/tests/org.eclipse.passage.lic.api.tests/src/org/eclipse/passage/lic/api/tests/inspection/RuntimeEnvironmentContractTest.java
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2020 ArSysOp
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * https://www.eclipse.org/legal/epl-2.0/.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * ArSysOp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.passage.lic.api.tests.inspection;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import org.eclipse.passage.lic.internal.api.LicensingException;
+import org.eclipse.passage.lic.internal.api.conditions.EvaluationType;
+import org.eclipse.passage.lic.internal.api.inspection.EnvironmentProperty;
+import org.eclipse.passage.lic.internal.api.inspection.RuntimeEnvironment;
+import org.junit.Test;
+
+@SuppressWarnings("restriction")
+public abstract class RuntimeEnvironmentContractTest {
+ @Test
+ public void isDedicatedToProperEvaluationType() {
+ assertEquals(expectedEvaluationType(), environment().id());
+ }
+
+ @Test
+ public void inspects() {
+ try {
+ assertFalse(environment().isAssuptionTrue(property(), invalidPropertyValue()));
+ } catch (LicensingException e) {
+ fail("Is not supposed to fail on valid data"); //$NON-NLS-1$
+ }
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void doesNotInspectNullProperty() {
+ try {
+ environment().isAssuptionTrue(null, "none"); //$NON-NLS-1$
+ } catch (LicensingException e) {
+ fail("No insection activity is intended to be triggered for invalid input data"); //$NON-NLS-1$
+ }
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void doesNotInspectForNullValue() {
+ try {
+ environment().isAssuptionTrue(property(), null); // $NON-NLS-1$
+ } catch (LicensingException e) {
+ fail("No insection activity is intended to be triggered for invalid input data"); //$NON-NLS-1$
+ }
+ }
+
+ @Test
+ public void knowsSimpleRegexp() {
+ try {
+ assertTrue(environment().isAssuptionTrue(property(), "*"));//$NON-NLS-1$
+ } catch (LicensingException e) {
+ fail("Is not supposed to fail on valid data"); //$NON-NLS-1$
+ }
+ }
+
+ @Test
+ public void depictsState() {
+ try {
+ String state = environment().state();
+ assertNotNull(state);
+ assertFalse(state.trim().isEmpty());
+ } catch (LicensingException e) {
+ fail("In not intended to fail"); //$NON-NLS-1$
+ }
+ }
+
+ @Test
+ public void standsSimultaneousRequests() {
+ // given: single instance of the env and lots of requesters
+ RuntimeEnvironment environment = environment();
+ int threads = 128;
+ CountDownLatch readySteadyGo = new CountDownLatch(1);
+ CountDownLatch done = new CountDownLatch(threads);
+ List demands = IntStream.range(0, threads) //
+ .mapToObj(no -> new InspectionDemand(environment, readySteadyGo, done))//
+ .collect(Collectors.toList());
+
+ // when: run all of the requesters simultaneously (latched by readySteadyGo)
+ Executor executor = Executors.newFixedThreadPool(threads);
+ demands.stream().forEach(executor::execute);
+ try {
+ Thread.sleep(2000); // let'em all start and hold waiting for each other
+ readySteadyGo.countDown(); // and now trigger'em all to ddos the env
+ done.await(); // and just wait until each of'em finish
+ } catch (InterruptedException e) {
+ fail("Test has been interrupted"); //$NON-NLS-1$
+ }
+
+ // then: all of'em succeed
+ assertTrue(demands.stream().allMatch(InspectionDemand::result));
+ }
+
+ private final class InspectionDemand implements Runnable {
+ private final CountDownLatch altogether;
+ private final CountDownLatch done;
+ private final RuntimeEnvironment env;
+ private boolean result = false;
+
+ InspectionDemand(RuntimeEnvironment env, CountDownLatch altogether, CountDownLatch done) {
+ this.env = env;
+ this.altogether = altogether;
+ this.done = done;
+ }
+
+ @Override
+ public void run() {
+ try {
+ altogether.await(); // wait for a common signal to start simultaneously
+ ask();
+ done.countDown(); // report you are done
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ private void ask() {
+ try {
+ result = !env.isAssuptionTrue(property(), invalidPropertyValue());
+ } catch (Exception e) {
+ result = false;
+ }
+ }
+
+ boolean result() {
+ return result;
+ }
+ }
+
+ protected abstract RuntimeEnvironment environment();
+
+ protected abstract EvaluationType expectedEvaluationType();
+
+ protected abstract String invalidPropertyValue();
+
+ protected abstract EnvironmentProperty property();
+
+}
diff --git a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/requirements/SabotagedFramework.java b/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/requirements/SabotagedFramework.java
index 265f7b4e1..c037795c4 100644
--- a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/requirements/SabotagedFramework.java
+++ b/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/internal/base/tests/requirements/SabotagedFramework.java
@@ -17,12 +17,13 @@
import org.eclipse.passage.lic.internal.api.AccessCycleConfiguration;
import org.eclipse.passage.lic.internal.api.Framework;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
-import org.eclipse.passage.lic.internal.api.conditions.evaluation.PermissionEmittersRegistry;
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ExpressionEvaluatorsRegistry;
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ExpressionPasringRegistry;
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ExpressionTokenAssessorsRegistry;
+import org.eclipse.passage.lic.internal.api.conditions.evaluation.PermissionEmittersRegistry;
import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionTransportRegistry;
import org.eclipse.passage.lic.internal.api.conditions.mining.MinedConditionsRegistry;
+import org.eclipse.passage.lic.internal.api.inspection.RuntimeEnvironmentRegistry;
import org.eclipse.passage.lic.internal.api.io.KeyKeeperRegistry;
import org.eclipse.passage.lic.internal.api.io.StreamCodecRegistry;
import org.eclipse.passage.lic.internal.api.registry.Registry;
@@ -98,6 +99,11 @@ public ExpressionTokenAssessorsRegistry expressionAssessors() {
return () -> noService();
}
+ @Override
+ public RuntimeEnvironmentRegistry environments() {
+ return () -> noService();
+ }
+
}
}
diff --git a/tests/org.eclipse.passage.lic.oshi.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.passage.lic.oshi.tests/META-INF/MANIFEST.MF
index 45f7336fd..6ef77b0cf 100644
--- a/tests/org.eclipse.passage.lic.oshi.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.passage.lic.oshi.tests/META-INF/MANIFEST.MF
@@ -14,4 +14,5 @@ Require-Bundle: org.junit;bundle-version="4.12.0",
org.eclipse.osgi.services;bundle-version="0.0.0",
org.eclipse.passage.lic.api;bundle-version="0.0.0",
org.eclipse.passage.lic.base;bundle-version="0.0.0",
- org.eclipse.passage.lic.oshi;bundle-version="0.0.0"
+ org.eclipse.passage.lic.oshi;bundle-version="0.0.0",
+ org.eclipse.passage.lic.api.tests
diff --git a/tests/org.eclipse.passage.lic.oshi.tests/src/org/eclipse/passage/lic/oshi/tests/tobemoved/HardwareEnvironmentTest.java b/tests/org.eclipse.passage.lic.oshi.tests/src/org/eclipse/passage/lic/oshi/tests/tobemoved/HardwareEnvironmentTest.java
index 5f04a9ab2..c55fb5338 100644
--- a/tests/org.eclipse.passage.lic.oshi.tests/src/org/eclipse/passage/lic/oshi/tests/tobemoved/HardwareEnvironmentTest.java
+++ b/tests/org.eclipse.passage.lic.oshi.tests/src/org/eclipse/passage/lic/oshi/tests/tobemoved/HardwareEnvironmentTest.java
@@ -12,131 +12,34 @@
*******************************************************************************/
package org.eclipse.passage.lic.oshi.tests.tobemoved;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-
-import org.eclipse.passage.lic.internal.api.LicensingException;
+import org.eclipse.passage.lic.api.tests.inspection.RuntimeEnvironmentContractTest;
import org.eclipse.passage.lic.internal.api.conditions.EvaluationType;
-import org.eclipse.passage.lic.internal.base.inspection.hardware.Disk;
+import org.eclipse.passage.lic.internal.api.inspection.RuntimeEnvironment;
import org.eclipse.passage.lic.internal.base.inspection.hardware.OS;
+import org.eclipse.passage.lic.internal.base.inspection.hardware.OS.Family;
import org.eclipse.passage.lic.internal.oshi.tobemoved.HardwareEnvironment;
-import org.junit.Test;
@SuppressWarnings("restriction")
-public final class HardwareEnvironmentTest {
-
- @Test
- public void isDedicatedToHardware() {
- assertEquals(new EvaluationType.Hardware(), new HardwareEnvironment().id());
- }
-
- @Test
- public void inspects() {
- try {
- assertFalse(new HardwareEnvironment().isAssuptionTrue(//
- new OS.Family(), //
- "not-existing-operating-system")); //$NON-NLS-1$
- } catch (LicensingException e) {
- fail("Is not supposed to fail on valid data"); //$NON-NLS-1$
- }
- }
-
- @Test(expected = NullPointerException.class)
- public void doesNotInspectNullProperty() {
- try {
- new HardwareEnvironment().isAssuptionTrue(null, "none"); //$NON-NLS-1$
- } catch (LicensingException e) {
- fail("No insection activity is intended to be triggered for invalid input data"); //$NON-NLS-1$
- }
- }
+public final class HardwareEnvironmentTest extends RuntimeEnvironmentContractTest {
- @Test(expected = NullPointerException.class)
- public void doesNotInspectForNullValue() {
- try {
- new HardwareEnvironment().isAssuptionTrue(new OS.Family(), null); // $NON-NLS-1$
- } catch (LicensingException e) {
- fail("No insection activity is intended to be triggered for invalid input data"); //$NON-NLS-1$
- }
+ @Override
+ protected RuntimeEnvironment environment() {
+ return new HardwareEnvironment();
}
- @Test
- public void knowsSimpleRegexp() {
- try {
- assertTrue(new HardwareEnvironment().isAssuptionTrue(new OS.Family(), "*"));//$NON-NLS-1$
- } catch (LicensingException e) {
- fail("Is not supposed to fail on valid data"); //$NON-NLS-1$
- }
+ @Override
+ protected EvaluationType expectedEvaluationType() {
+ return new EvaluationType.Hardware();
}
- @Test
- public void standsSimultaneousRequests() {
- // given: single instance of the env and lots of requesters
- HardwareEnvironment hardware = new HardwareEnvironment();
- int threads = 128;
- CountDownLatch readySteadyGo = new CountDownLatch(1);
- CountDownLatch done = new CountDownLatch(threads);
- List demands = IntStream.range(0, threads) //
- .mapToObj(no -> new InspectionDemand(hardware, readySteadyGo, done, no))//
- .collect(Collectors.toList());
-
- // when: run all of the requesters simultaneously (latched by readySteadyGo)
- Executor executor = Executors.newFixedThreadPool(threads);
- demands.stream().forEach(executor::execute);
- try {
- Thread.sleep(2000); // let'em all start and hold waiting for each other
- readySteadyGo.countDown(); // and now trigger'em all to ddos the env
- done.await(); // and just wait until each of'em finish
- } catch (InterruptedException e) {
- fail("Test has been interrupted"); //$NON-NLS-1$
- }
-
- // then: all of'em succeed
- assertTrue(demands.stream().allMatch(InspectionDemand::result));
+ @Override
+ protected String invalidPropertyValue() {
+ return "not-existing-operating-system"; //$NON-NLS-1$
}
- private static final class InspectionDemand implements Runnable {
- private final CountDownLatch altogether;
- private final CountDownLatch done;
- private final HardwareEnvironment env;
- private boolean result = false;
-
- InspectionDemand(HardwareEnvironment env, CountDownLatch altogether, CountDownLatch done, int no) {
- this.env = env;
- this.altogether = altogether;
- this.done = done;
- }
-
- @Override
- public void run() {
- try {
- altogether.await(); // wait for a common signal to start simultaneously
- ask();
- done.countDown(); // report you are done
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- }
- }
-
- private void ask() {
- try {
- result = !env.isAssuptionTrue(new Disk.Serial(), "not-existing-disk-serial"); //$NON-NLS-1$
- } catch (Exception e) {
- result = false;
- }
- }
-
- boolean result() {
- return result;
- }
+ @Override
+ protected Family property() {
+ return new OS.Family();
}
}
diff --git a/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/registries/SealedRuntimeEnvironmentRegistryTest.java b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/registries/SealedRuntimeEnvironmentRegistryTest.java
new file mode 100644
index 000000000..1f86dfab3
--- /dev/null
+++ b/tests/org.eclipse.passage.seal.demo.tests/src/org/eclipse/passage/seal/demo/tests/registries/SealedRuntimeEnvironmentRegistryTest.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2020 ArSysOp
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * https://www.eclipse.org/legal/epl-2.0/.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * ArSysOp - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.passage.seal.demo.tests.registries;
+
+import java.util.Optional;
+
+import org.eclipse.passage.lic.api.tests.RuntimeEnvironmentRegitryTest;
+import org.eclipse.passage.lic.internal.api.Framework;
+import org.eclipse.passage.seal.internal.demo.DemoFrameworkSupplier;
+
+@SuppressWarnings("restriction")
+public final class SealedRuntimeEnvironmentRegistryTest extends RuntimeEnvironmentRegitryTest {
+
+ @Override
+ protected Optional framework() {
+ return new DemoFrameworkSupplier().get();
+ }
+
+}