Search in sources :

Example 1 with AssertableDiagnostics

use of org.eclipse.xtext.junit4.validation.AssertableDiagnostics in project statecharts by Yakindu.

the class SGenJavaValidatorTest method checkParameterValueType.

/**
 * @see SGenJavaValidator#checkParameterValueType(org.yakindu.sct.model.sgen.FeatureParameterValue)
 */
@Test
public void checkParameterValueType() {
    EObject model = parseExpression("GeneratorModel for yakindu::java { statechart Example { feature Outlet { targetFolder = true }}}", GeneratorModel.class.getSimpleName());
    AssertableDiagnostics result = tester.validate(model);
    result.assertAny(new MsgPredicate("Incompatible types string and boolean."));
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) EObject(org.eclipse.emf.ecore.EObject) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) AbstractSGenTest(org.yakindu.sct.generator.genmodel.test.util.AbstractSGenTest) Test(org.junit.Test)

Example 2 with AssertableDiagnostics

use of org.eclipse.xtext.junit4.validation.AssertableDiagnostics in project statecharts by Yakindu.

the class SGenJavaValidatorTest method checkDeprecatedFeatures.

/**
 * @see SGenJavaValidator#checkDeprecatedFeatures(GeneratorEntry)
 */
@Test
public void checkDeprecatedFeatures() {
    EObject model = parseExpression("GeneratorModel for yakindu::java { statechart Example { feature Outlet {targetFolder = \"src-gen\"  targetProject = \"TestProject\" }}}", GeneratorModel.class.getSimpleName());
    if (!(model instanceof GeneratorModel)) {
        fail("Model is of the wrong type");
    } else {
        GeneratorModel genModel = (GeneratorModel) model;
        genModel.getEntries().get(0).getFeatures().get(0).getType().setDeprecated(true);
        AssertableDiagnostics result = tester.validate(genModel);
        result.assertAny(new MsgPredicate(DEPRECATED));
    }
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) EObject(org.eclipse.emf.ecore.EObject) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) AbstractSGenTest(org.yakindu.sct.generator.genmodel.test.util.AbstractSGenTest) Test(org.junit.Test)

Example 3 with AssertableDiagnostics

use of org.eclipse.xtext.junit4.validation.AssertableDiagnostics in project statecharts by Yakindu.

the class STextJavaValidatorTest method testMixedOptionalAndVarArgsParameters.

@Test
@Ignore("Why should anyone do that anyways")
public void testMixedOptionalAndVarArgsParameters() {
    EObject model;
    String rule = Expression.class.getSimpleName();
    AssertableDiagnostics result;
    model = parseExpression("optOp4(3)", rule);
    result = tester.validate(model);
    result.assertOK();
    model = parseExpression("optOp4(3, 4)", rule);
    result = tester.validate(model);
    result.assertOK();
    model = parseExpression("optOp4(3, 4, 5, 6)", rule);
    result = tester.validate(model);
    result.assertOK();
    model = parseExpression("optOp4(3, 4, true)", rule);
    result = tester.validate(model);
    result.assertOK();
    model = parseExpression("optOp4(true)", rule);
    result = tester.validate(model);
    result.assertError(ITypeSystemInferrer.NOT_COMPATIBLE_CODE);
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) EObject(org.eclipse.emf.ecore.EObject) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with AssertableDiagnostics

use of org.eclipse.xtext.junit4.validation.AssertableDiagnostics in project statecharts by Yakindu.

the class STextJavaValidatorTest method checkAnnotations.

@Test
public void checkAnnotations() {
    String scope;
    StatechartSpecification model;
    AssertableDiagnostics validationResult;
    statechart.setName("Annotated");
    scope = "@EventDriven";
    model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    statechart.getAnnotations().addAll(model.getAnnotations());
    validationResult = tester.validate(statechart);
    validationResult.assertOK();
    scope = "@CycleBased(200)";
    model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    statechart.getAnnotations().clear();
    statechart.getAnnotations().addAll(model.getAnnotations());
    validationResult = tester.validate(statechart);
    validationResult.assertOK();
    scope = "@CycleBased(200)\n" + "@EventDriven";
    model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    statechart.getAnnotations().clear();
    statechart.getAnnotations().addAll(model.getAnnotations());
    validationResult = tester.validate(statechart);
    validationResult.assertErrorContains(CONTRADICTORY_ANNOTATIONS.split("%s")[0]);
    scope = "@ParentFirstExecution";
    model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    statechart.getAnnotations().clear();
    statechart.getAnnotations().addAll(model.getAnnotations());
    validationResult = tester.validate(statechart);
    validationResult.assertOK();
    scope = "@ChildFirstExecution";
    model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    statechart.getAnnotations().clear();
    statechart.getAnnotations().addAll(model.getAnnotations());
    validationResult = tester.validate(statechart);
    validationResult.assertOK();
    scope = "@ParentFirstExecution\n" + "@ChildFirstExecution";
    model = (StatechartSpecification) super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
    statechart.getAnnotations().clear();
    statechart.getAnnotations().addAll(model.getAnnotations());
    validationResult = tester.validate(statechart);
    validationResult.assertErrorContains(CONTRADICTORY_ANNOTATIONS.split("%s")[0]);
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) StatechartSpecification(org.yakindu.sct.model.stext.stext.StatechartSpecification) Test(org.junit.Test)

Example 5 with AssertableDiagnostics

use of org.eclipse.xtext.junit4.validation.AssertableDiagnostics in project statecharts by Yakindu.

the class STextJavaValidatorTest method checkReactionTriggerRegularEvent.

@Test
public void checkReactionTriggerRegularEvent() {
    String scope = "interface : in event e  var x : integer  var y : integer  operation op():integer";
    EObject model = super.parseExpression("e", TransitionSpecification.class.getSimpleName(), scope);
    AssertableDiagnostics validationResult = tester.validate(model);
    validationResult.assertOK();
    model = super.parseExpression("x", TransitionSpecification.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertError(TRIGGER_IS_NO_EVENT);
    model = super.parseExpression("e, x", TransitionSpecification.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertError(TRIGGER_IS_NO_EVENT);
    model = super.parseExpression("op()", TransitionSpecification.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertError(TRIGGER_IS_NO_EVENT);
    model = super.parseExpression("x, y", TransitionSpecification.class.getSimpleName(), scope);
    validationResult = tester.validate(model);
    validationResult.assertAll(errorMsg("Trigger 'x' is no event."), errorMsg("Trigger 'y' is no event."));
}
Also used : AssertableDiagnostics(org.eclipse.xtext.junit4.validation.AssertableDiagnostics) EObject(org.eclipse.emf.ecore.EObject) TransitionSpecification(org.yakindu.sct.model.stext.stext.TransitionSpecification) Test(org.junit.Test)

Aggregations

AssertableDiagnostics (org.eclipse.xtext.junit4.validation.AssertableDiagnostics)42 Test (org.junit.Test)42 EObject (org.eclipse.emf.ecore.EObject)38 AbstractSGenTest (org.yakindu.sct.generator.genmodel.test.util.AbstractSGenTest)11 GeneratorModel (org.yakindu.sct.model.sgen.GeneratorModel)11 InternalScope (org.yakindu.sct.model.stext.stext.InternalScope)7 Expression (org.yakindu.base.expressions.expressions.Expression)6 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)3 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)3 StatechartSpecification (org.yakindu.sct.model.stext.stext.StatechartSpecification)3 TransitionSpecification (org.yakindu.sct.model.stext.stext.TransitionSpecification)3 Scope (org.yakindu.sct.model.sgraph.Scope)2 ImportScope (org.yakindu.sct.model.stext.stext.ImportScope)2 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)2 Diagnostic (org.eclipse.emf.common.util.Diagnostic)1 Ignore (org.junit.Ignore)1