From 31825ef8249f0a1a52df0268612d8dbc5bd461f1 Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Sat, 30 Nov 2019 13:44:26 +0300 Subject: [PATCH] 553629 lic.base - avoid dependency from OSGi FrameworkUtil - class.getName() is used instead of a bundle symbolic name - dependency is eliminated - test suite is created Signed-off-by: elena.parovyshnaya --- .../META-INF/MANIFEST.MF | 3 +- .../passage/lic/base/LicensingResults.java | 7 +- .../lic/base/tests/LicensingResultsTest.java | 89 +++++++++++++++++++ 3 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/base/tests/LicensingResultsTest.java diff --git a/bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF index 2476c6434..ab19a27af 100644 --- a/bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF @@ -7,8 +7,7 @@ Bundle-Name: %Bundle-Name Bundle-Vendor: %Bundle-Vendor Bundle-Copyright: %Bundle-Copyright Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Require-Bundle: org.eclipse.passage.lic.api;bundle-version="0.0.0";visibility:=reexport, - org.eclipse.osgi +Require-Bundle: org.eclipse.passage.lic.api;bundle-version="0.0.0";visibility:=reexport Export-Package: org.eclipse.passage.lic.base, org.eclipse.passage.lic.base.access, org.eclipse.passage.lic.base.conditions, diff --git a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/base/LicensingResults.java b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/base/LicensingResults.java index f3c3944c5..6e23d5d72 100644 --- a/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/base/LicensingResults.java +++ b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/base/LicensingResults.java @@ -26,8 +26,6 @@ import org.eclipse.passage.lic.api.LicensingEvents; import org.eclipse.passage.lic.api.LicensingResult; -import org.osgi.framework.Bundle; -import org.osgi.framework.FrameworkUtil; /** * @@ -172,9 +170,8 @@ public static LicensingResult createWarning(String message, String source, Map source, Map attachments) { - Bundle bundle = FrameworkUtil.getBundle(source); - return new BaseLicensingResult(WARNING, message, BaseLicensingResult.CODE_NOMINAL, bundle.getSymbolicName(), - null, Collections.emptyList(), attachments); + return new BaseLicensingResult(WARNING, message, BaseLicensingResult.CODE_NOMINAL, source.getName(), null, + Collections.emptyList(), attachments); } /** diff --git a/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/base/tests/LicensingResultsTest.java b/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/base/tests/LicensingResultsTest.java new file mode 100644 index 000000000..dcf4e285b --- /dev/null +++ b/tests/org.eclipse.passage.lic.base.tests/src/org/eclipse/passage/lic/base/tests/LicensingResultsTest.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2019 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.lic.base.tests; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.eclipse.passage.lic.api.LicensingResult; +import org.eclipse.passage.lic.base.LicensingResults; +import org.junit.Test; + +/** + * {@linkplain LicensingResults} is going to be completely reworked from a + * bundle of static function to a set of classes. + * + */ +public class LicensingResultsTest { + @Test + public void testBlankOk() { + LicensingResult ok = createOk(); + assertBlankOkIsCorrect(ok); + assertMessageIsBlank(ok); + assertSourceIsNotBlank(ok); + } + + @Test + public void testInformativeOk() { + String message = "informative"; //$NON-NLS-1$ + LicensingResult ok = createOk(message); + assertBlankOkIsCorrect(ok); + assertInformativeOkIsCorrect(ok, message); + assertSourceIsNotBlank(ok); + } + + @Test + public void testSourcedOk() { + String message = "highly informative"; //$NON-NLS-1$ + String source = "the blue"; //$NON-NLS-1$ + LicensingResult ok = createOk(message, source); + assertBlankOkIsCorrect(ok); + assertInformativeOkIsCorrect(ok, message); + assertSourcedIsCorrect(ok, source); + } + + private LicensingResult createOk() { + return LicensingResults.createOK(); + } + + private LicensingResult createOk(String message) { + return LicensingResults.createOK(message); + } + + private LicensingResult createOk(String message, String source) { + return LicensingResults.createOK(message, source); + } + + private void assertBlankOkIsCorrect(LicensingResult ok) { + assertNotNull("Creation failed", ok); //$NON-NLS-1$ + assertTrue("Creation is incorrect: OK expected", ok.getSeverity() == LicensingResult.OK); //$NON-NLS-1$ + } + + private void assertInformativeOkIsCorrect(LicensingResult ok, String message) { + assertTrue("Creation is incorrect: unexpected message", message.equals(ok.getMessage())); //$NON-NLS-1$ + } + + private void assertSourcedIsCorrect(LicensingResult ok, String source) { + assertTrue("Creation is incorrect: unexpected source", source.equals(ok.getSource())); //$NON-NLS-1$ + } + + private void assertMessageIsBlank(LicensingResult result) { + assertTrue("Creation is incorrect: unexpected message", result.getMessage().length() == 0); //$NON-NLS-1$ + } + + private void assertSourceIsNotBlank(LicensingResult result) { + assertNotNull("Creation is incorrect: source is null", result.getSource()); //$NON-NLS-1$ + assertTrue("Creation is incorrect: source is blank", result.getSource().length() != 0); //$NON-NLS-1$ + } + +}