-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from eclipse-passage/565011
Bug 565011 rebuild the core of condition expression evaluation
- Loading branch information
Showing
14 changed files
with
564 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...rc/org/eclipse/passage/lic/api/tests/conditions/evaluation/EmissionImplsContractTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/******************************************************************************* | ||
* 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.conditions.evaluation; | ||
|
||
import org.eclipse.passage.lic.api.tests.fakes.conditions.evaluation.FakePermission; | ||
import org.eclipse.passage.lic.api.tests.fakes.diagnostic.FakeFailureDiagnostic; | ||
import org.eclipse.passage.lic.internal.api.conditions.evaluation.Emission; | ||
|
||
@SuppressWarnings("restriction") | ||
public class EmissionImplsContractTest extends EmissionContractTest { | ||
|
||
@Override | ||
protected Emission failed() { | ||
return new Emission.Failed(new FakeFailureDiagnostic()); | ||
} | ||
|
||
@Override | ||
protected Emission successful() { | ||
return new Emission.Successful(new FakePermission()); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
.../passage/lic/api/tests/conditions/evaluation/ExpressionEvaluationServiceContractTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/******************************************************************************* | ||
* 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.conditions.evaluation; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
import org.eclipse.passage.lic.api.tests.fakes.conditions.evaluation.FakeExpressionTokenAssessmentService; | ||
import org.eclipse.passage.lic.api.tests.fakes.conditions.evaluation.FakeParsedExpression; | ||
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ExpressionEvaluationException; | ||
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ExpressionEvaluationService; | ||
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ExpressionTokenAssessmentService; | ||
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ParsedExpression; | ||
import org.junit.Test; | ||
|
||
@SuppressWarnings("restriction") | ||
public abstract class ExpressionEvaluationServiceContractTest { | ||
|
||
@Test(expected = NullPointerException.class) | ||
public final void prohibitsNullExpression() { | ||
prohibitsNullArgument(null, new FakeExpressionTokenAssessmentService()); | ||
} | ||
|
||
@Test(expected = NullPointerException.class) | ||
public final void prohibitsNullAssessor() { | ||
prohibitsNullArgument(new FakeParsedExpression(), null); | ||
} | ||
|
||
@Test(expected = ExpressionEvaluationException.class) | ||
public final void canOnlyEvaluateExpressionOfSameProtocl() throws ExpressionEvaluationException { | ||
evaluator().evaluate(new FakeParsedExpression("fake"), //$NON-NLS-1$ | ||
new FakeExpressionTokenAssessmentService()); | ||
} | ||
|
||
private void prohibitsNullArgument(ParsedExpression expression, ExpressionTokenAssessmentService assessor) { | ||
try { | ||
evaluator().evaluate(expression, assessor); | ||
} catch (ExpressionEvaluationException e) { | ||
fail("No evaluation activity is expected to be started for invalid incoming data"); //$NON-NLS-1$ | ||
} | ||
} | ||
|
||
protected abstract ExpressionEvaluationService evaluator(); | ||
} |
57 changes: 57 additions & 0 deletions
57
...pse/passage/lic/api/tests/conditions/evaluation/ExpressionParsingServiceContractTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/******************************************************************************* | ||
* 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.conditions.evaluation; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ExpressionParsingException; | ||
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ExpressionParsingService; | ||
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ParsedExpression; | ||
import org.junit.Test; | ||
|
||
@SuppressWarnings("restriction") | ||
public abstract class ExpressionParsingServiceContractTest { | ||
|
||
@Test(expected = ExpressionParsingException.class) | ||
public final void blankExpressionCausesFailure() throws ExpressionParsingException { | ||
parser().parsed("\t"); //$NON-NLS-1$ | ||
} | ||
|
||
@Test(expected = NullPointerException.class) | ||
public final void prohibitsNullExpression() throws ExpressionParsingException { | ||
parser().parsed(null); | ||
} | ||
|
||
@Test | ||
public final void producesSameProtocolResult() { | ||
ExpressionParsingService parser = parser(); | ||
try { | ||
assertEquals(parser.id(), parser.parsed(validExpression()).protocol()); | ||
} catch (ExpressionParsingException e) { | ||
fail("Is not expected to fail on valid data"); //$NON-NLS-1$ | ||
} | ||
} | ||
|
||
@Test | ||
public final void producesResultOfExpectedType() throws ExpressionParsingException { | ||
assertTrue(resultType().isInstance(parser().parsed(validExpression()))); | ||
} | ||
|
||
protected abstract ExpressionParsingService parser(); | ||
|
||
protected abstract String validExpression(); | ||
|
||
protected abstract Class<? extends ParsedExpression> resultType(); | ||
} |
40 changes: 40 additions & 0 deletions
40
...c/org/eclipse/passage/lic/api/tests/fakes/conditions/evaluation/FakeParsedExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/******************************************************************************* | ||
* 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.conditions.evaluation; | ||
|
||
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ExpressionProtocol; | ||
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ParsedExpression; | ||
|
||
@SuppressWarnings("restriction") | ||
public final class FakeParsedExpression implements ParsedExpression { | ||
|
||
private final ExpressionProtocol protocol; | ||
|
||
public FakeParsedExpression(ExpressionProtocol protocol) { | ||
this.protocol = protocol; | ||
} | ||
|
||
public FakeParsedExpression(String protocol) { | ||
this(new ExpressionProtocol.Of(protocol)); | ||
} | ||
|
||
public FakeParsedExpression() { | ||
this(new ExpressionProtocol.Default()); | ||
} | ||
|
||
@Override | ||
public ExpressionProtocol protocol() { | ||
return protocol; | ||
} | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
...lic/internal/base/tests/conditions/evaluation/AndsProtocolExpressionParseServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/******************************************************************************* | ||
* 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.tests.conditions.evaluation; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.fail; | ||
|
||
import org.eclipse.passage.lic.api.tests.conditions.evaluation.ExpressionParsingServiceContractTest; | ||
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ExpressionParsingException; | ||
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ExpressionParsingService; | ||
import org.eclipse.passage.lic.internal.api.conditions.evaluation.ParsedExpression; | ||
import org.eclipse.passage.lic.internal.base.conditions.evaluation.AndsProtocolExpressionParseService; | ||
import org.eclipse.passage.lic.internal.base.conditions.evaluation.SimpleMapExpression; | ||
import org.junit.Test; | ||
|
||
@SuppressWarnings("restriction") | ||
public final class AndsProtocolExpressionParseServiceTest extends ExpressionParsingServiceContractTest { | ||
|
||
@Test | ||
public void parsesValidData() { | ||
try { | ||
parser().parsed("a=b"); //$NON-NLS-1$ | ||
} catch (ExpressionParsingException e) { | ||
fail("Is not expected to fial on valid data"); //$NON-NLS-1$ | ||
} | ||
} | ||
|
||
@Test | ||
public void pasingIsAccurate() throws ExpressionParsingException { | ||
SimpleMapExpression parsed = (SimpleMapExpression) parser().parsed("k1=v1;k2=*;"); //$NON-NLS-1$ | ||
assertEquals("v1", parsed.expected("k1")); //$NON-NLS-1$//$NON-NLS-2$ | ||
assertEquals("*", parsed.expected("k2")); //$NON-NLS-1$//$NON-NLS-2$ | ||
} | ||
|
||
@Test(expected = ExpressionParsingException.class) | ||
public void evenSingleCorruptedSegmentFailsParsing() throws ExpressionParsingException { | ||
parser().parsed("k1=v1;k2;k3=v3"); //$NON-NLS-1$ | ||
} | ||
|
||
@Test(expected = ExpressionParsingException.class) | ||
public void valueOnlySegmentIsCorrupted() throws ExpressionParsingException { | ||
parser().parsed("k1=v1;=v2;k3=v3"); //$NON-NLS-1$ | ||
} | ||
|
||
@Test(expected = ExpressionParsingException.class) | ||
public void mediatorOnlySegmentIsCorrupted() throws ExpressionParsingException { | ||
parser().parsed("k1=v1;=;k3=v3"); //$NON-NLS-1$ | ||
} | ||
|
||
@Test | ||
public void allowsWhiteSpaces() throws ExpressionParsingException { | ||
SimpleMapExpression parsed = (SimpleMapExpression) parser().parsed("k 1=v 1"); //$NON-NLS-1$ | ||
assertEquals("v 1", parsed.expected("k 1")); //$NON-NLS-1$//$NON-NLS-2$ | ||
} | ||
|
||
@Test | ||
public void keysAndValuesAreTrimmed() throws ExpressionParsingException { | ||
SimpleMapExpression parsed = (SimpleMapExpression) parser().parsed(" k\n= v\t"); //$NON-NLS-1$ | ||
assertEquals("v", parsed.expected("k")); //$NON-NLS-1$//$NON-NLS-2$ | ||
} | ||
|
||
@Override | ||
protected ExpressionParsingService parser() { | ||
return new AndsProtocolExpressionParseService(); | ||
} | ||
|
||
@Override | ||
protected String validExpression() { | ||
return "a=b;c=*;d=1 2"; //$NON-NLS-1$ | ||
} | ||
|
||
@Override | ||
protected Class<? extends ParsedExpression> resultType() { | ||
return SimpleMapExpression.class; | ||
} | ||
|
||
} |
Oops, something went wrong.