<commit_before>/************************************************************************
 * Copyright © 2007-2016 - General Electric Company, All Rights Reserved
 *
 * Project: SADL
 *
 * Description: The Semantic Application Design Language (SADL) is a
 * language for building semantic models and expressing rules that
 * capture additional domain knowledge. The SADL-IDE (integrated
 * development environment) is a set of Eclipse plug-ins that
 * support the editing and testing of semantic models using the
 * SADL language.
 *
 * This software is distributed "AS-IS" without ANY WARRANTIES
 * and licensed under the Eclipse Public License - v 1.0
 * which is available at http://www.eclipse.org/org/documents/epl-v10.php
 *
 ***********************************************************************/
package com.ge.research.sadl.tests.validation

import com.ge.research.sadl.sADL.SADLPackage
import com.ge.research.sadl.sADL.SadlModel
import com.ge.research.sadl.scoping.TestScopeProvider
import com.ge.research.sadl.tests.SADLNoopModelProcessorsInjectorProvider
import com.ge.research.sadl.validation.SADLValidator
import com.google.inject.Inject
import org.eclipse.xtext.resource.XtextResource
import org.eclipse.xtext.resource.XtextResourceSet
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.eclipse.xtext.testing.validation.ValidationTestHelper
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(XtextRunner)
@InjectWith(SADLNoopModelProcessorsInjectorProvider)
class ValidationTest {
	
	@Test def void testDuplicateAlias() {
		'''
			uri "http://my/uri" alias foo.
		'''.sadl
		'''
		    uri "http://other/uri" alias foo.
		'''.sadl => [
			validationTestHelper.assertError(it, SADLPackage.Literals.SADL_MODEL, SADLValidator.INVALID_MODEL_ALIAS)
		]
	}
	
	@Test def void testDuplicateSimpleFileName() {
		val uri = '''
			uri "http://my/uri1" alias foo.
		'''.sadl.URI
		parseHelper.parse('''
		    uri "http://my/uri2" alias bar.
		''', uri.trimSegments(1).appendSegment("subpath").appendSegment(uri.lastSegment), currentResourceSet) => [
			validationTestHelper.assertError(it, SADLPackage.Literals.SADL_MODEL, SADLValidator.INVALID_MODEL_FILENAME)
		]
	}
	
	@Test def void testLinkingAmbiguousElements() {
		'''
			uri "http://sadl.org/NS1.sadl" alias ns1.
			
			Car is a class.
		'''.sadl
		'''
			uri "http://sadl.org/NS2.sadl" alias ns2.
			
			Car is a class.
		'''.sadl
		val model = '''
			uri "http://sadl.org/NS3.sadl" alias ns3.
			
			import "http://sadl.org/NS1.sadl".
			import "http://sadl.org/NS2.sadl".
			
			MyCar is a Car.
			
		'''.sadl
		TestScopeProvider.registerResource(model, true)
		val issues = validationTestHelper.validate(model)
		Assert.assertEquals("Ambiguously imported name 'Car' from 'http://sadl.org/NS2.sadl', 'http://sadl.org/NS1.sadl'. Please use an alias or choose different names.", issues.head.message)
	}
	
	@Test def void testLinkingAmbiguousElementsIndirect() {
		'''
			uri "http://sadl.org/NS1.sadl" alias ns1.
			
			Car is a class.
		'''.sadl
		'''
			uri "http://sadl.org/NS2.sadl" alias ns2.
			
			Car is a class.
		'''.sadl
		'''
			uri "http://sadl.org/NS3.sadl" alias ns3.
			
			import "http://sadl.org/NS1.sadl".
			import "http://sadl.org/NS2.sadl".
						
		'''.sadl
		val model = '''
			uri "http://sadl.org/NS4.sadl" alias ns4.
			
			import "http://sadl.org/NS3.sadl".
			MyCar is a Car.
		'''.sadl
		TestScopeProvider.registerResource(model, true)
		val issues = validationTestHelper.validate(model)
		Assert.assertEquals("Ambiguously imported name 'Car' from 'http://sadl.org/NS2.sadl', 'http://sadl.org/NS1.sadl'. Please use an alias or choose different names.", issues.head.message)
	}
	
	@Test def void testLinkingAmbiguousElementsBigger() {
		'''
			uri "http://assert/Properties" alias Properties.
			//import "http://sadl.org/sadlimplicitmodel".
			reference_class is a type of annotation.
			reference_property is a type of annotation.
			reference_range is a type of annotation.
			reference_instance is a type of annotation.
			//impliedProperty is a type of annotation.
			INTERFACE_DEFINITION is a class.
			  functional_max describes INTERFACE_DEFINITION with values of type decimal.
			  functional_min describes INTERFACE_DEFINITION with values of type decimal.
			  physical_max describes INTERFACE_DEFINITION with values of type decimal.
			  physical_min describes INTERFACE_DEFINITION with values of type decimal.
			  tolerance describes INTERFACE_DEFINITION with values of type decimal.
			  resolution describes INTERFACE_DEFINITION with values of type decimal.
			  physical_mapping describes INTERFACE_DEFINITION with values of type PHYSICAL_MAPPING.
			  PHYSICAL_MAPPING is a class.
			    physical_value describes PHYSICAL_MAPPING with values of type decimal.
			
			
			//====================================================
			//All user defined Object Properties are recorded below.
			//====================================================
			<commit_msg>Updated wording for expected error message in Validation Tests.<commit_after>/************************************************************************
 * Copyright © 2007-2016 - General Electric Company, All Rights Reserved
 *
 * Project: SADL
 *
 * Description: The Semantic Application Design Language (SADL) is a
 * language for building semantic models and expressing rules that
 * capture additional domain knowledge. The SADL-IDE (integrated
 * development environment) is a set of Eclipse plug-ins that
 * support the editing and testing of semantic models using the
 * SADL language.
 *
 * This software is distributed "AS-IS" without ANY WARRANTIES
 * and licensed under the Eclipse Public License - v 1.0
 * which is available at http://www.eclipse.org/org/documents/epl-v10.php
 *
 ***********************************************************************/
package com.ge.research.sadl.tests.validation

import com.ge.research.sadl.sADL.SADLPackage
import com.ge.research.sadl.sADL.SadlModel
import com.ge.research.sadl.scoping.TestScopeProvider
import com.ge.research.sadl.tests.SADLNoopModelProcessorsInjectorProvider
import com.ge.research.sadl.validation.SADLValidator
import com.google.inject.Inject
import org.eclipse.xtext.resource.XtextResource
import org.eclipse.xtext.resource.XtextResourceSet
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.eclipse.xtext.testing.validation.ValidationTestHelper
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(XtextRunner)
@InjectWith(SADLNoopModelProcessorsInjectorProvider)
class ValidationTest {
	
	@Test def void testDuplicateAlias() {
		'''
			uri "http://my/uri" alias foo.
		'''.sadl
		'''
		    uri "http://other/uri" alias foo.
		'''.sadl => [
			validationTestHelper.assertError(it, SADLPackage.Literals.SADL_MODEL, SADLValidator.INVALID_MODEL_ALIAS)
		]
	}
	
	@Test def void testDuplicateSimpleFileName() {
		val uri = '''
			uri "http://my/uri1" alias foo.
		'''.sadl.URI
		parseHelper.parse('''
		    uri "http://my/uri2" alias bar.
		''', uri.trimSegments(1).appendSegment("subpath").appendSegment(uri.lastSegment), currentResourceSet) => [
			validationTestHelper.assertError(it, SADLPackage.Literals.SADL_MODEL, SADLValidator.INVALID_MODEL_FILENAME)
		]
	}
	
	@Test def void testLinkingAmbiguousElements() {
		'''
			uri "http://sadl.org/NS1.sadl" alias ns1.
			
			Car is a class.
		'''.sadl
		'''
			uri "http://sadl.org/NS2.sadl" alias ns2.
			
			Car is a class.
		'''.sadl
		val model = '''
			uri "http://sadl.org/NS3.sadl" alias ns3.
			
			import "http://sadl.org/NS1.sadl".
			import "http://sadl.org/NS2.sadl".
			
			MyCar is a Car.
			
		'''.sadl
		TestScopeProvider.registerResource(model, true)
		val issues = validationTestHelper.validate(model)
		Assert.assertEquals("Ambiguously imported name 'Car' from 'http://sadl.org/NS2.sadl', 'http://sadl.org/NS1.sadl'. Please use a prefix to disambiguate name.", issues.head.message)
	}
	
	@Test def void testLinkingAmbiguousElementsIndirect() {
		'''
			uri "http://sadl.org/NS1.sadl" alias ns1.
			
			Car is a class.
		'''.sadl
		'''
			uri "http://sadl.org/NS2.sadl" alias ns2.
			
			Car is a class.
		'''.sadl
		'''
			uri "http://sadl.org/NS3.sadl" alias ns3.
			
			import "http://sadl.org/NS1.sadl".
			import "http://sadl.org/NS2.sadl".
						
		'''.sadl
		val model = '''
			uri "http://sadl.org/NS4.sadl" alias ns4.
			
			import "http://sadl.org/NS3.sadl".
			MyCar is a Car.
		'''.sadl
		TestScopeProvider.registerResource(model, true)
		val issues = validationTestHelper.validate(model)
		Assert.assertEquals("Ambiguously imported name 'Car' from 'http://sadl.org/NS2.sadl', 'http://sadl.org/NS1.sadl'. Please use a prefix to disambiguate name.", issues.head.message)
	}
	
	@Test def void testLinkingAmbiguousElementsBigger() {
		'''
			uri "http://assert/Properties" alias Properties.
			//import "http://sadl.org/sadlimplicitmodel".
			reference_class is a type of annotation.
			reference_property is a type of annotation.
			reference_range is a type of annotation.
			reference_instance is a type of annotation.
			//impliedProperty is a type of annotation.
			INTERFACE_DEFINITION is a class.
			  functional_max describes INTERFACE_DEFINITION with values of type decimal.
			  functional_min describes INTERFACE_DEFINITION with values of type decimal.
			  physical_max describes INTERFACE_DEFINITION with values of type decimal.
			  physical_min describes INTERFACE_DEFINITION with values of type decimal.
			  tolerance describes INTERFACE_DEFINITION with values of type decimal.
			  resolution describes INTERFACE_DEFINITION with values of type decimal.
			  physical_mapping describes INTERFACE_DEFINITION with values of type PHYSICAL_MAPPING.
			  PHYSICAL_MAPPING is a class.
			    physical_value describes PHYSICAL_MAPPING with values of type decimal.
			
			
			//====================================================
			//All user defined Object Properties are recorded below.
			//====================================================
			
{'fraction_non_alphanumeric': 0.15126953125, 'fraction_numerical': 0.007421875, 'mean_word_length': 3.933044315992293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6967341', 'n_tokens_mistral': 3675, 'n_tokens_neox': 3187, 'n_words': 800}