Java Code Examples for org.eclipse.xtext.junit4.validation.AssertableDiagnostics#assertError()

The following examples show how to use org.eclipse.xtext.junit4.validation.AssertableDiagnostics#assertError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 *
 * @see STextValidator#checkReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger)
 */
@Test
public void checkReactionTrigger() {
	// ENTRY, EXIT not allowed in transitions
	String scope = "internal : event a : integer var myVar : integer";
	EObject model = super.parseExpression("entry / myVar = 5", TransitionSpecification.class.getSimpleName(),
			scope);
	AssertableDiagnostics validationResult = tester.validate(model);
	validationResult.assertError(ENTRY_EXIT_TRIGGER_NOT_ALLOWED);
	
	model = super.parseExpression("exit / myVar = 5", TransitionSpecification.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertError(ENTRY_EXIT_TRIGGER_NOT_ALLOWED);
	
	model = super.parseExpression("oncycle / myVar = 5", TransitionSpecification.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	
	model = super.parseExpression("always / myVar = 5", TransitionSpecification.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
}
 
Example 2
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@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."));
	
}
 
Example 3
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void checkValueOfNoEvent() {
	String decl = "interface: in event e1:integer var x:integer operation op():integer interface i: in event e2:integer var y:integer";
	
	EObject model = super.parseExpression("valueof(e1)", Expression.class.getSimpleName(), decl);
	AssertableDiagnostics result = tester.validate(model);
	result.assertOK();
	
	model = super.parseExpression("valueof(i.e2)", Expression.class.getSimpleName(), decl);
	result = tester.validate(model);
	result.assertOK();
	
	model = super.parseExpression("valueof(x)", Expression.class.getSimpleName(), decl);
	result = tester.validate(model);
	result.assertError(VALUE_OF_REQUIRES_EVENT);
	
	model = super.parseExpression("valueof(i.y)", Expression.class.getSimpleName(), decl);
	result = tester.validate(model);
	result.assertError(VALUE_OF_REQUIRES_EVENT);
	
	model = super.parseExpression("valueof(op())", Expression.class.getSimpleName(), decl);
	result = tester.validate(model);
	result.assertError(VALUE_OF_REQUIRES_EVENT);
	
}
 
Example 4
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testOptionalParameter() {
	EObject model;
	String rule = Expression.class.getSimpleName();
	AssertableDiagnostics result;
	
	model = parseExpression("optOp1()", rule);
	result = tester.validate(model);
	result.assertOK();
	
	model = parseExpression("optOp1(3)", rule);
	result = tester.validate(model);
	result.assertOK();
	
	model = parseExpression("optOp1(true)", rule);
	result = tester.validate(model);
	result.assertError(ITypeSystemInferrer.NOT_COMPATIBLE_CODE);
}
 
Example 5
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testMixedOptionalParameters() {
	EObject model;
	String rule = Expression.class.getSimpleName();
	AssertableDiagnostics result;
	
	model = parseExpression("optOp3(3)", rule);
	result = tester.validate(model);
	result.assertOK();
	
	model = parseExpression("optOp3(3, 4)", rule);
	result = tester.validate(model);
	result.assertOK();
	
	model = parseExpression("optOp3(3, 4, true)", rule);
	result = tester.validate(model);
	result.assertError(ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE);
	
	model = parseExpression("optOp3()", rule);
	result = tester.validate(model);
	result.assertError(ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE);
	
	model = parseExpression("optOp3(3, true)", rule);
	result = tester.validate(model);
	result.assertError(ITypeSystemInferrer.NOT_COMPATIBLE_CODE);
}
 
Example 6
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void checkOperationNamedParameters() {
	String scope = "internal: operation myOperation(param1 : integer, param2 : boolean)";
	EObject model = super.parseExpression(scope, InternalScope.class.getSimpleName());
	AssertableDiagnostics validationResult = tester.validate(model);
	validationResult.assertOK();
	
	model = super.parseExpression("myOperation(5, true)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("myOperation(5, param2 = true)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("myOperation(param1 = 5, true)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("myOperation(param1 = 5, param2 = true)", Expression.class.getSimpleName(),
			scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("myOperation(param2 = true, param1 = 5)", Expression.class.getSimpleName(),
			scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	
	model = super.parseExpression("myOperation(param2 = true)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertError(ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE);
	
	model = super.parseExpression("myOperation(param1 = 5)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertError(ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE);
	
}
 
Example 7
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see STextValidator#checkAnnotationArguments(org.yakindu.sct.model.stext.stext.AnnotationDefinition)
 */
@Test
public void checkAnnotationArguments() {
	String scope = "@CycleBased";
	EObject model = super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
	AssertableDiagnostics validationResult = tester.validate(model);
	validationResult.assertError(STextValidator.ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE);
	;
	
	scope = "@EventDriven";
	model = super.parseExpression(scope, StatechartSpecification.class.getSimpleName());
	validationResult = tester.validate(model);
	validationResult.assertOK();
}
 
Example 8
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void checkPostFixOperatorOnlyOnVariables() {
	EObject model = super.parseExpression("ABC.intVar++", Expression.class.getSimpleName(), interfaceScope());
	AssertableDiagnostics validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("intVar++", Expression.class.getSimpleName(), internalScope());
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("5++", Expression.class.getSimpleName(), interfaceScope());
	validationResult = tester.validate(model);
	validationResult.assertError(ExpressionsValidator.POSTFIX_ONLY_ON_VARIABLES_CODE);
}
 
Example 9
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see STextValidator#checkReactionEffectActions(org.yakindu.sct.model.stext.stext.ReactionEffect)
 */
@Test
public void checkReactionEffectActions() {
	String s1 = "internal : var a : integer event e operation o () : void";
	String s2 = "interface if : var a : integer in event e operation o()";
	
	EObject model = super.parseExpression("a", ReactionEffect.class.getSimpleName(), s1);
	AssertableDiagnostics result = tester.validate(model);
	result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
	
	model = super.parseExpression("1+3", ReactionEffect.class.getSimpleName(), s1);
	result = tester.validate(model);
	result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
	
	model = super.parseExpression("valueof(e)", ReactionEffect.class.getSimpleName(), s1);
	result = tester.validate(model);
	result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
	
	model = super.parseExpression("o()", ReactionEffect.class.getSimpleName(), s1);
	result = tester.validate(model);
	result.assertOK();
	
	model = super.parseExpression("if.a", ReactionEffect.class.getSimpleName(), s2);
	result = tester.validate(model);
	result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
	
	model = super.parseExpression("valueof(if.e)", ReactionEffect.class.getSimpleName(), s2);
	result = tester.validate(model);
	result.assertError(FEATURE_CALL_HAS_NO_EFFECT);
	
	model = super.parseExpression("if.o", ReactionEffect.class.getSimpleName(), s2);
	result = tester.validate(model);
	result.assertOK();
	
}
 
Example 10
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testMultipleOptionalParameters() {
	EObject model;
	String rule = Expression.class.getSimpleName();
	AssertableDiagnostics result;
	
	model = parseExpression("optOp2()", rule);
	result = tester.validate(model);
	result.assertOK();
	
	model = parseExpression("optOp2(3)", rule);
	result = tester.validate(model);
	result.assertOK();
	
	model = parseExpression("optOp2(3, 4)", rule);
	result = tester.validate(model);
	result.assertOK();
	
	model = parseExpression("optOp2(true)", rule);
	result = tester.validate(model);
	result.assertError(ITypeSystemInferrer.NOT_COMPATIBLE_CODE);
	
	model = parseExpression("optOp2(true, 3, 4)", rule);
	result = tester.validate(model);
	result.assertAll(errorCode(ITypeSystemInferrer.NOT_COMPATIBLE_CODE),
			errorCode(ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE));
}
 
Example 11
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@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);
}
 
Example 12
Source File: StateValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * A regular state must have a name.
 */
@Test
public void stateWithoutName() {
	State state = createState();
	state.setName(null);
	AssertableDiagnostics result = tester.validate(state);
	result.assertError(STATE_NAME_REQUIRED_CODE);
}
 
Example 13
Source File: StateValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * A states name must not be empty.
 */
@Test
public void nameIsNotEmpty() {
	State state = createState();
	state.setName("");
	AssertableDiagnostics result = tester.validate(state);
	result.assertError(STATE_NAME_REQUIRED_CODE);
}
 
Example 14
Source File: StateValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * A state name with just white spaces is not valid.
 */
@Test
public void stateWithWhitespaceName() {
	State state = createState();
	state.setName(" 	");
	AssertableDiagnostics result = tester.validate(state);
	result.assertError(STATE_NAME_REQUIRED_CODE);
}
 
Example 15
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see STextValidator#checkVarArgParameterIsLast(Operation)
 */
@Test
public void checkVarArgParameterIsLast() {
	String scope = "internal: operation myOperation(param1... : integer)"
			+ "operation myOperation2(param0 : string, param1 ... : integer)";
	EObject model = super.parseExpression(scope, InternalScope.class.getSimpleName());
	AssertableDiagnostics validationResult = tester.validate(model);
	validationResult.assertOK();
	
	model = super.parseExpression("myOperation()", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("myOperation(5)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("myOperation(5,5,5)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("myOperation2('')", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("myOperation2('',5)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	model = super.parseExpression("myOperation2('',5,5,5)", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertOK();
	
	model = super.parseExpression("myOperation2('','')", Expression.class.getSimpleName(), scope);
	validationResult = tester.validate(model);
	validationResult.assertErrorContains("Incompatible types string and integer.");
	
	scope = "internal: operation myOperation(param1... : integer, param2...: integer)";
	model = super.parseExpression(scope, InternalScope.class.getSimpleName());
	validationResult = tester.validate(model);
	validationResult.assertError(ERROR_VAR_ARGS_LAST_CODE);
	
	scope = "internal: operation myOperation2(param1 ... : integer, param0 : string)";
	model = super.parseExpression(scope, InternalScope.class.getSimpleName());
	validationResult = tester.validate(model);
	validationResult.assertError(ERROR_VAR_ARGS_LAST_CODE);
	
}
 
Example 16
Source File: RegionValidatorTest.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void regionCantBeEnteredUsingShallowHistory() {
	Statechart statechart = loadStatechart("RegionCantBeEnteredUsingShallowHistory.sct");
	AssertableDiagnostics result = tester.validate(statechart);
	result.assertError(REGION_REQUIRES_DEFAULT_ENTRY_IF_ENTERED_BY_SHALLOW_HISTORY_CODE);
}