Skip to content

Commit

Permalink
Bug 569359 Passage interface test coverage
Browse files Browse the repository at this point in the history
Wider access movements explanations.

Signed-off-by: eparovyshnaya <elena.parovyshnaya@gmail.com>
  • Loading branch information
eparovyshnaya committed Dec 2, 2020
1 parent 4f1459d commit 766a285
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
Expand Up @@ -15,8 +15,13 @@
import org.eclipse.passage.lic.internal.api.Framework;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.access.GrantLockAttempt;
import org.eclipse.passage.lic.internal.api.diagnostic.Diagnostic;
import org.eclipse.passage.lic.internal.api.diagnostic.Trouble;
import org.eclipse.passage.lic.internal.api.restrictions.ExaminationCertificate;
import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult;
import org.eclipse.passage.lic.internal.base.diagnostic.BaseDiagnostic;
import org.eclipse.passage.lic.internal.base.diagnostic.SumOfDiagnostics;
import org.eclipse.passage.lic.internal.base.diagnostic.code.NoRequirements;
import org.eclipse.passage.lic.internal.base.restrictions.CertificateIsRestrictive;

/**
Expand All @@ -43,6 +48,9 @@ public ServiceInvocationResult<GrantLockAttempt> acquire(String feature) {
if (new CertificateIsRestrictive().test(certificate.data())) {
return failOnAccess(certificate);
}
if (empty(certificate.data().get())) {
return unknownFeature(feature, certificate.diagnostic());
}
return new Lock(framework).lock(certificate.data().get());
}

Expand All @@ -59,4 +67,15 @@ private ServiceInvocationResult<GrantLockAttempt> failOnAccess(
return new BaseServiceInvocationResult<>(assessment.diagnostic());
}

private ServiceInvocationResult<GrantLockAttempt> unknownFeature(String feature, Diagnostic diagnostic) {
return new BaseServiceInvocationResult<>(//
new SumOfDiagnostics().apply(//
diagnostic, //
new BaseDiagnostic(new Trouble(new NoRequirements(), feature))//
));
}

private boolean empty(ExaminationCertificate certificate) {
return certificate.restrictions().isEmpty() && certificate.satisfied().isEmpty();
}
}
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.passage.lic.internal.base.diagnostic.BaseDiagnostic;
import org.eclipse.passage.lic.internal.base.diagnostic.code.NoServicesOfType;
import org.eclipse.passage.lic.internal.base.diagnostic.code.ServiceFailedOnMorsel;
import org.eclipse.passage.lic.internal.base.diagnostic.code.TentativeAccess;
import org.eclipse.passage.lic.internal.base.i18n.AccessCycleMessages;
import org.eclipse.passage.lic.internal.base.restrictions.CertificateIsRestrictive;

Expand Down Expand Up @@ -154,7 +155,7 @@ private Diagnostic tentativeReport(ExaminationCertificate certificate) {
}

private Trouble explained(Restriction restriction) {
return new Trouble(new ServiceFailedOnMorsel(), //
return new Trouble(new TentativeAccess(), //
String.format(//
AccessCycleMessages.getString("Lock.temp_access"), //$NON-NLS-1$
feature(restriction)));
Expand Down
Expand Up @@ -18,7 +18,7 @@
public final class NoRequirements extends TroubleCode {

public NoRequirements() {
super(151, DiagnosticCodeMessages.getString("NoRequirements.explanation_feature")); //$NON-NLS-1$
super(151, DiagnosticCodeMessages.getString("NoRequirements.explanation")); //$NON-NLS-1$
}

}
@@ -0,0 +1,24 @@
/*******************************************************************************
* 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.internal.base.diagnostic.code;

import org.eclipse.passage.lic.internal.api.diagnostic.TroubleCode;
import org.eclipse.passage.lic.internal.base.i18n.DiagnosticCodeMessages;

public final class TentativeAccess extends TroubleCode {

public TentativeAccess() {
super(408, DiagnosticCodeMessages.getString("TentativeAccess.explanation")); //$NON-NLS-1$
}

}
Expand Up @@ -16,9 +16,9 @@
* finish operation because of IO error, connection troubles or other outer
* obstacle.</li>
* <li>110 - several implementations of Framework has been found. Critical.</li>
* <li>151 - no requirements defined for a feature on in product as a whole. In
* the worst case it is a sign of an error in licensing demands
* declaration.</li>
* <li>151 - no requirements defined for a feature on in product as a whole -
* the feature is unknown to Passage. In the worst case it is a sign of an error
* in licensing demands declaration.</li>
* </ul>
* </li>
* <li>2xx - reserved</li>
Expand All @@ -42,8 +42,14 @@
* access file, etc)</li>
* <li>407 - absence of an expected attendant license package file (floating
* license access file, etc)</li>
* <li>408 - a feature is not covered by a license (there is no licensing
* conditions found for it), but has not-critical restriction level (for
* instance @{code info}, {@code warning}) and thus can be used without
* license.</li>
* </ul>
* </li>
* <li>5xx - reserved</li>
* <li>6xx - floating server response codes</li>
* </ul>
*/
package org.eclipse.passage.lic.internal.base.diagnostic.code;
Expand Up @@ -25,3 +25,4 @@ ServiceFailedOnMorsel.explanation=Service failed to evaluate a morsel
ServiceFailedOnInfrastructureDenial.explanation=Service failed severely due to an invoked service denial.
InvalidLicenseAttendantFile.license_expired=Invalid content of a license attendant file
AbsentLicenseAttendantFile.license_expired=Expected license attendant file is not found
TentativeAccess.explanation=Feature is not covered by a license, but in the same it's usage is not severely restricted; thus tentative access can be granted.

0 comments on commit 766a285

Please sign in to comment.