org.eclipse.xtext.junit4.validation.AssertableDiagnostics Java Examples

The following examples show how to use org.eclipse.xtext.junit4.validation.AssertableDiagnostics. 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: SGenJavaValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see SGenJavaValidator#checkDeprecatedParameters(GeneratorEntry)
 */
@Test
public void checkDeprecatedParameters() {
	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;
		FeatureParameter featureParameter = genModel.getEntries().get(0).getFeatures().get(0).getType().getParameters().get(0);
		featureParameter.setDeprecated(true);
		AssertableDiagnostics result = tester.validate(genModel);
		result.assertAny(new MsgPredicate(String.format(DEPRECATED, featureParameter.getName())));
	}
}
 
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
/**
 *
 * @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 #4
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 #5
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 #6
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void checkNoAssignmentInGuard() {
	String scope = "internal: var myInt : integer var myBool : boolean = true";
	EObject expression = super.parseExpression("[myBool = false]", ReactionTrigger.class.getSimpleName(), scope);
	AssertableDiagnostics validationResult = tester.validate(expression);
	validationResult.assertErrorContains(STextValidator.GUARD_CONTAINS_ASSIGNMENT);
	expression = super.parseExpression("[myInt = 5]", ReactionTrigger.class.getSimpleName(), scope);
	validationResult = tester.validate(expression);
	Iterator<Diagnostic> diag = validationResult.getAllDiagnostics().iterator();
	while (diag.hasNext()) {
		Diagnostic d = diag.next();
		if (d.getMessage().equals(GUARD_EXPRESSION)) {
			assertEquals(STextValidator.GUARD_EXPRESSION, d.getMessage());
		} else {
			assertEquals(STextValidator.GUARD_CONTAINS_ASSIGNMENT, d.getMessage());
		}
	}
	expression = super.parseExpression("[myInt++ > 10]", ReactionTrigger.class.getSimpleName(), scope);
	validationResult = tester.validate(expression);
	validationResult.assertErrorContains(STextValidator.GUARD_CONTAINS_ASSIGNMENT);
}
 
Example #7
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see STextValidator#checkEventDefinition(org.yakindu.sct.model.stext.stext.EventDefinition)
 */
@Test
public void checkEventDefinition() {
	// No local declarations in interface scope
	EObject model = super.parseExpression("interface MyInterface: event Event1",
			InterfaceScope.class.getSimpleName());
	AssertableDiagnostics result = tester.validate(model);
	result.assertErrorContains(LOCAL_DECLARATIONS);
	// No in declarations in internal scope
	model = super.parseExpression("internal: in event Event1", InternalScope.class.getSimpleName());
	result = tester.validate(model);
	result.assertDiagnosticsCount(1);
	result.assertErrorContains(STextValidator.IN_OUT_DECLARATIONS);
	// No out declarations in internal scope
	model = super.parseExpression("internal: out event Event1", InternalScope.class.getSimpleName());
	result = tester.validate(model);
	result.assertDiagnosticsCount(1);
	result.assertErrorContains(IN_OUT_DECLARATIONS);
}
 
Example #8
Source File: XsemanticsValidatorTests.java    From xsemantics with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testRuleConclusionNotSubtypeBoth() throws Exception {
	AssertableDiagnostics validate = loadModelAndValidate(testFiles
			.testRuleWithConclusionNotSubtypeBoth());
	validate.assertAll(
			AssertableDiagnostics
					.error(NOT_SUBTYPE,
							"Rule conclusion type EObject "
									+ "is not subtype of JudgmentDescription declared type "
									+ "EClass"),
			AssertableDiagnostics
					.error(NOT_SUBTYPE,
							"Rule conclusion type String "
									+ "is not subtype of JudgmentDescription declared type "
									+ "EObject"));
}
 
Example #9
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 #10
Source File: SGenJavaValidatorTest.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @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;
		FeatureType type = genModel.getEntries().get(0).getFeatures().get(0).getType();
		type.setDeprecated(true);
		AssertableDiagnostics result = tester.validate(genModel);
		result.assertAny(new MsgPredicate(String.format(DEPRECATED, type.getName())));
	}
}
 
Example #11
Source File: XsemanticsValidatorTests.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected void assertDuplicateErrors(AssertableDiagnostics validate,
		String elementClassName, String duplicateName,
		String... msgFragments) {
	//System.out.println(diagnosticsToString(validate));
	String messageFragment = "Duplicate " + elementClassName + " '"
			+ duplicateName + "'";
	validate.assertAll(AssertableDiagnostics.errorMsg(messageFragment),
			AssertableDiagnostics.errorMsg(messageFragment));
	for (String msgFragment : msgFragments) {
		validate.assertAny(AssertableDiagnostics.errorMsg(msgFragment));
	}
}
 
Example #12
Source File: XsemanticsValidatorTests.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testNoRuleForJudgmentDescription() throws Exception {
	validator.setEnableWarnings(true);
	AssertableDiagnostics validate = loadModelAndValidate(testFiles
			.testJudgmentDescriptions());
	validate.assertAll(AssertableDiagnostics
			.warningMsg("No rule defined for the judgment description"));
}
 
Example #13
Source File: XsemanticsValidatorTests.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testSystemExtendsInvalidBaseSystem() throws Exception {
	AssertableDiagnostics validate = loadModelAndValidate(testFiles
			.testSystemExtendsInvalidBaseSystem());
	validate.assertAll(AssertableDiagnostics
			.error(NOT_VALID_SUPER_SYSTEM,
					"Not an Xsemantics system: TestInvalidBaseSystem"));
}
 
Example #14
Source File: XsemanticsValidatorTests.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testWrongThrowInPremises() throws Exception {
	AssertableDiagnostics validate = loadModelAndValidate(testFiles
			.testWrongThrowInPremises());
	validate.assertAll(AssertableDiagnostics.error(
			THROW_NOT_ALLOWED,
			"Throw statements are not allowed here"));
	// AssertableDiagnostics
	// .error(org.eclipse.xtext.xbase.validation.UNHANDLED_EXCEPTION,
	// "Unhandled exception"));
}
 
Example #15
Source File: XsemanticsValidatorTests.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testRuleWithBooleanExpressionsWithNoSideEffectInsideClosure()
		throws Exception {
	AssertableDiagnostics validate = loadModelAndValidate(testFiles
			.testForClosureWithExpressionWithNoSideEffect());
	assertOk(validate);
}
 
Example #16
Source File: XsemanticsValidatorTests.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
@Test
	public void testErrorNoSideEffect() throws Exception {
		AssertableDiagnostics validate = loadModelAndValidate(testFiles
				.testErrorNoSideEffect());
		assertOk(validate);
//		validate.assertAll(AssertableDiagnostics
//				.error(org.eclipse.xtext.xbase.validation.INVALID_INNER_EXPRESSION,
//						"This expression is not allowed in this context"));
	}
 
Example #17
Source File: XsemanticsValidatorTests.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testValidatorExtendsNotAbstractDeclarativeValidator()
		throws Exception {
	AssertableDiagnostics validate = loadModelAndValidate(testFiles
			.testSystemWithValidatorExtendsNotAbstractDeclarativeValidator());
	validate.assertAll(AssertableDiagnostics
			.error(NOT_VALIDATOR,
					"Not an AbstractDeclarativeValidator: EClass"));
}
 
Example #18
Source File: SGenJavaValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void checkInitialValue() {
	EObject model = parseExpression("GeneratorModel for yakindu::java { var x : boolean = 5 }",
			GeneratorModel.class.getSimpleName());
	AssertableDiagnostics result = tester.validate(model);
	result.assertAny(new MsgPredicate("Incompatible types boolean and integer."));
}
 
Example #19
Source File: XsemanticsValidatorTests.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testRulesWithExpressionInConclusionWrong() throws Exception {
	AssertableDiagnostics validate = loadModelAndValidate(testFiles
			.testRuleWithExpressionInConclusion2());
	validate.assertAll(AssertableDiagnostics.error(
			NOT_PARAMETER,
			"Must be a parameter, not an expression"));
}
 
Example #20
Source File: XsemanticsValidatorTests.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected void assertContains(AssertableDiagnostics validate, String string) {
	final String diagnosticsToString = diagnosticsToString(validate);
	if (!diagnosticsToString.contains(string)) {
		fail("diagnostics: " + diagnosticsToString
				+ "\n does not contain: " + string);
	}
}
 
Example #21
Source File: XsemanticsValidatorTests.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testDuplicateJudgmentDescriptionSymbols() throws Exception {
	AssertableDiagnostics validate = loadModelAndValidate(testFiles
			.testJudgmentDescriptionsWithDuplicateSymbols());
	String messageFragment = "Duplicate judgment symbols '|- :'";
	validate.assertAll(AssertableDiagnostics.error(
			DUPLICATE_JUDGMENT_DESCRIPTION_SYMBOLS,
			messageFragment), AssertableDiagnostics.error(
			DUPLICATE_JUDGMENT_DESCRIPTION_SYMBOLS,
			messageFragment));
}
 
Example #22
Source File: FjAbstractGeneratedValidatorTests.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected void assertOk(AssertableDiagnostics validate) {
	if (listOfDiagnostics(validate).size() != 0) {
		System.err.println(utils.diagnosticsToString(validate));
		fail("There are expected to be no diagnostics.: "
				+ utils.diagnosticsToString(validate));
	}
}
 
Example #23
Source File: SGenJavaValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see SGenJavaValidator#checkDeprecatedParameters(GeneratorEntry)
 */
@Test
public void checkEntriesExist() {
	EObject model = parseExpression("GeneratorModel for yakindu::java {}", GeneratorModel.class.getSimpleName());
	if (!(model instanceof GeneratorModel)) {
		fail("Model is of the wrong type");
	} else {
		GeneratorModel genModel = (GeneratorModel) model;
		AssertableDiagnostics result = tester.validate(genModel);
		result.assertAny(new MsgPredicate(EMPTY_SGEN));
	}
}
 
Example #24
Source File: SGenJavaValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see SGenJavaValidator#checkRequiredParameters(FeatureConfiguration)
 */
@Test
public void checkRequiredParameters() {
	EObject model = parseExpression("GeneratorModel for yakindu::java { statechart Example { feature Outlet {}}}",
			GeneratorModel.class.getSimpleName());
	AssertableDiagnostics result = tester.validate(model);
	result.assertAny(new MsgPredicate(MISSING_REQUIRED_PARAMETER));
}
 
Example #25
Source File: SGenJavaValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see SGenJavaValidator#checkRequiredFeatures(org.yakindu.sct.model.sgen.GeneratorEntry)
 */
@Test
public void checkRequiredFeatures() {
	EObject model = parseExpression("GeneratorModel for yakindu::java { statechart Example {}}",
			GeneratorModel.class.getSimpleName());
	AssertableDiagnostics result = tester.validate(model);
	result.assertAny(new MsgPredicate(MISSING_REQUIRED_FEATURE));
}
 
Example #26
Source File: SGenJavaValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see SGenJavaValidator#checkDuplicateFeatureParameter(org.yakindu.sct.model.sgen.FeatureParameterValue)
 */
@Test
public void checkDuplicateFeatureParameter() {
	EObject model = parseExpression(
			"GeneratorModel for yakindu::java { statechart Example { feature Outlet { targetFolder = true  targetFolder = true }}}",
			GeneratorModel.class.getSimpleName());
	AssertableDiagnostics result = tester.validate(model);
	result.assertAny(new MsgPredicate(DUPLICATE_PARAMETER));
}
 
Example #27
Source File: SGenJavaValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see SGenJavaValidator#checkDuplicateGeneratorEntryFeature(FeatureConfiguration)
 */
@Test
public void checkDuplicateGeneratorEntryFeature() {
	EObject model = parseExpression(
			"GeneratorModel for yakindu::java { statechart Example { feature Outlet { } feature Outlet { }}}",
			GeneratorModel.class.getSimpleName());
	AssertableDiagnostics result = tester.validate(model);
	result.assertAny(new MsgPredicate(DUPLICATE_FEATURE));
}
 
Example #28
Source File: SGenJavaValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see SGenJavaValidator#checkGeneratorExists(GeneratorModel)
 */
@Test
public void checkGeneratorExists() {
	EObject model = parseExpression("GeneratorModel for yakindu::unknown {}", GeneratorModel.class.getSimpleName());
	AssertableDiagnostics result = tester.validate(model);
	result.assertAny(new MsgPredicate(UNKOWN_GENERATOR));
}
 
Example #29
Source File: SGenJavaValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @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."));
}
 
Example #30
Source File: SGenJavaValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see SGenJavaValidator#checkContentType(org.yakindu.sct.model.sgen.GeneratorEntry)
 */
@Test
public void checkContentType() {
	EObject model = parseExpression("GeneratorModel for yakindu::java { unkownType Example {}}",
			GeneratorModel.class.getSimpleName());
	AssertableDiagnostics result = tester.validate(model);
	result.assertAny(new MsgPredicate(UNKNOWN_CONTENT_TYPE));
}