Skip to content

Commit

Permalink
Merge pull request #70 from eparovyshnaya/553629
Browse files Browse the repository at this point in the history
553629	lic.base - avoid dependency from OSGi FrameworkUtil
  • Loading branch information
eparovyshnaya authored Nov 30, 2019
2 parents 7c5725b + 31825ef commit 91197fd
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 7 deletions.
3 changes: 1 addition & 2 deletions bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -172,9 +170,8 @@ public static LicensingResult createWarning(String message, String source, Map<S
* @see LicensingResult
*/
public static LicensingResult createWarning(String message, Class<?> source, Map<String, Object> 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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$
}

}

0 comments on commit 91197fd

Please sign in to comment.