<commit_before>package tools.vitruv.dsls.reactions.tests.simpleChangesTests

import allElementTypes.Root
import org.eclipse.emf.common.util.ECollections
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import static tools.vitruv.dsls.reactions.tests.simpleChangesTests.SimpleChangesTestsExecutionMonitor.ChangeType.*

import static org.hamcrest.MatcherAssert.assertThat
import static tools.vitruv.dsls.reactions.tests.ExecutionMonitor.observedExecutions
import static tools.vitruv.testutils.metamodels.AllElementTypesCreators.newNonRoot
import static tools.vitruv.testutils.metamodels.AllElementTypesCreators.newNonRootObjectContainerHelper
import static tools.vitruv.testutils.metamodels.AllElementTypesCreators.newRoot
import static tools.vitruv.testutils.matchers.ModelMatchers.containsModelOf
import static org.hamcrest.CoreMatchers.is
import static tools.vitruv.testutils.matchers.ModelMatchers.exists
import static tools.vitruv.testutils.matchers.ModelMatchers.doesNotExist
import org.junit.jupiter.api.Disabled
import static extension tools.vitruv.testutils.domains.DomainModelCreators.allElementTypes
import tools.vitruv.dsls.reactions.tests.ReactionsExecutionTest
import tools.vitruv.dsls.reactions.tests.TestReactionsCompiler
import static extension tools.vitruv.testutils.matchers.CorrespondenceMatchers.hasNoCorrespondences

class SimpleChangesTests extends ReactionsExecutionTest {
	static val SOURCE_MODEL = 'SimpleChangeSource'.allElementTypes
	static val TARGET_MODEL = "SimpleChangeTarget".allElementTypes
	static val FURTHER_SOURCE_MODEL = 'FurtherSource'.allElementTypes
	static val FURTHER_TARGET_MODEL = 'FurtherTarget'.allElementTypes

	String[] nonContainmentNonRootIds = #["NonRootHelper0", "NonRootHelper1", "NonRootHelper2"]

	override protected createCompiler(TestReactionsCompiler.Factory factory) {
		factory.createCompiler [
			reactions = #["/tools/vitruv/dsls/reactions/tests/AllElementTypesRedundancy.reactions"]
			changePropagationSegments = #["simpleChangesTests"]
		]
	}

	@BeforeEach
	def createRoot() {
		resourceAt(SOURCE_MODEL).recordAndPropagate [
			contents += newRoot => [
				id = 'EachTestModelSource'
				nonRootObjectContainerHelper = newNonRootObjectContainerHelper => [
					id = 'NonRootObjectContainer'
					nonRootObjectsContainment += nonContainmentNonRootIds.map [ nonRootId |
						newNonRoot => [id = nonRootId]
					]
				]
			]
		]

		assertThat(resourceAt(TARGET_MODEL), containsModelOf(resourceAt(SOURCE_MODEL)))

		executionMonitor.reset()
	}

	private static def getExecutionMonitor() {
		SimpleChangesTestsExecutionMonitor.instance
	}

	private def nonRootWithId(Root rootObject, String searchId) {
		rootObject.nonRootObjectContainerHelper.nonRootObjectsContainment.findFirst [
			it.id == searchId
		]
	}

	@Test
	@Disabled("Unset does not produce any change event at the moment") // TODO HK (Change MM)
	def void testUnsetSingleValuedEAttribute() {
		Root.from(SOURCE_MODEL).recordAndPropagate [
			singleValuedEAttribute = null
		]

		assertThat(executionMonitor, observedExecutions(UnsetEAttribute))
		assertThat(resourceAt(TARGET_MODEL), containsModelOf(resourceAt(SOURCE_MODEL)))
	}

	@Test
	@Disabled
	def void testUnsetSingleValuedNonContainmentEReference() {
		Root.from(SOURCE_MODEL).recordAndPropagate [
			singleValuedNonContainmentEReference = nonRootWithId(nonContainmentNonRootIds.get(1))
		]
		executionMonitor.reset()
		Root.from(SOURCE_MODEL).recordAndPropagate [
			singleValuedNonContainmentEReference = null
		]

		assertThat(executionMonitor, observedExecutions(UnsetNonContainmentEReference))
		assertThat(resourceAt(TARGET_MODEL), containsModelOf(resourceAt(SOURCE_MODEL)))
	}

	@Test
	def void testUpdateSingleValuedEAttribute() {
		Root.from(SOURCE_MODEL).recordAndPropagate [
			singleValuedEAttribute = -1
		]

		assertThat(executionMonitor, observedExecutions(UpdateSingleValuedEAttribute))
		assertThat(resourceAt(TARGET_MODEL), containsModelOf(resourceAt(SOURCE_MODEL)))
	}

	@Test
	def void testUpdateSingleValuedPrimitiveTypeEAttribute() {
		Root.from(SOURCE_MODEL).recordAndPropagate [
			singleValuedPrimitiveTypeEAttribute = -1
		]

		assertThat(executionMonitor, observedExecutions(UpdateSingleValuedPrimitveTypeEAttribute))
		assertThat(resourceAt(TARGET_MODEL), containsModelOf(resourceAt(SOURCE_MODEL)))
	}

	@Test
	def void testCreateSingleValuedContainmentEReference() {
		Root.from(SOURCE_MODEL).recordAndPropagate [
			singleValuedContainmentEReference = null
		]
		executionMonitor.reset()
		Root.from(SOURCE_MODEL).recordAndPropagate [
			singleValuedContainmentEReference = newNonRoot => [id = "singleValuedContainmentNonRootTest"]
		]

		assertThat(executionMonitor, observedExecutions(CreateEObject, CreateNonRootEObjectSingle))<commit_msg>remove unnecessary propagation from reactions tests<commit_after>package tools.vitruv.dsls.reactions.tests.simpleChangesTests

import allElementTypes.Root
import org.eclipse.emf.common.util.ECollections
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import static tools.vitruv.dsls.reactions.tests.simpleChangesTests.SimpleChangesTestsExecutionMonitor.ChangeType.*

import static org.hamcrest.MatcherAssert.assertThat
import static tools.vitruv.dsls.reactions.tests.ExecutionMonitor.observedExecutions
import static tools.vitruv.testutils.metamodels.AllElementTypesCreators.newNonRoot
import static tools.vitruv.testutils.metamodels.AllElementTypesCreators.newNonRootObjectContainerHelper
import static tools.vitruv.testutils.metamodels.AllElementTypesCreators.newRoot
import static tools.vitruv.testutils.matchers.ModelMatchers.containsModelOf
import static org.hamcrest.CoreMatchers.is
import static tools.vitruv.testutils.matchers.ModelMatchers.exists
import static tools.vitruv.testutils.matchers.ModelMatchers.doesNotExist
import org.junit.jupiter.api.Disabled
import static extension tools.vitruv.testutils.domains.DomainModelCreators.allElementTypes
import tools.vitruv.dsls.reactions.tests.ReactionsExecutionTest
import tools.vitruv.dsls.reactions.tests.TestReactionsCompiler
import static extension tools.vitruv.testutils.matchers.CorrespondenceMatchers.hasNoCorrespondences

class SimpleChangesTests extends ReactionsExecutionTest {
	static val SOURCE_MODEL = 'SimpleChangeSource'.allElementTypes
	static val TARGET_MODEL = "SimpleChangeTarget".allElementTypes
	static val FURTHER_SOURCE_MODEL = 'FurtherSource'.allElementTypes
	static val FURTHER_TARGET_MODEL = 'FurtherTarget'.allElementTypes

	String[] nonContainmentNonRootIds = #["NonRootHelper0", "NonRootHelper1", "NonRootHelper2"]

	override protected createCompiler(TestReactionsCompiler.Factory factory) {
		factory.createCompiler [
			reactions = #["/tools/vitruv/dsls/reactions/tests/AllElementTypesRedundancy.reactions"]
			changePropagationSegments = #["simpleChangesTests"]
		]
	}

	@BeforeEach
	def createRoot() {
		resourceAt(SOURCE_MODEL).recordAndPropagate [
			contents += newRoot => [
				id = 'EachTestModelSource'
				nonRootObjectContainerHelper = newNonRootObjectContainerHelper => [
					id = 'NonRootObjectContainer'
					nonRootObjectsContainment += nonContainmentNonRootIds.map [ nonRootId |
						newNonRoot => [id = nonRootId]
					]
				]
			]
		]

		assertThat(resourceAt(TARGET_MODEL), containsModelOf(resourceAt(SOURCE_MODEL)))

		executionMonitor.reset()
	}

	private static def getExecutionMonitor() {
		SimpleChangesTestsExecutionMonitor.instance
	}

	private def nonRootWithId(Root rootObject, String searchId) {
		rootObject.nonRootObjectContainerHelper.nonRootObjectsContainment.findFirst [
			it.id == searchId
		]
	}

	@Test
	@Disabled("Unset does not produce any change event at the moment") // TODO HK (Change MM)
	def void testUnsetSingleValuedEAttribute() {
		Root.from(SOURCE_MODEL).recordAndPropagate [
			singleValuedEAttribute = null
		]

		assertThat(executionMonitor, observedExecutions(UnsetEAttribute))
		assertThat(resourceAt(TARGET_MODEL), containsModelOf(resourceAt(SOURCE_MODEL)))
	}

	@Test
	@Disabled
	def void testUnsetSingleValuedNonContainmentEReference() {
		Root.from(SOURCE_MODEL).recordAndPropagate [
			singleValuedNonContainmentEReference = nonRootWithId(nonContainmentNonRootIds.get(1))
		]
		executionMonitor.reset()
		Root.from(SOURCE_MODEL).recordAndPropagate [
			singleValuedNonContainmentEReference = null
		]

		assertThat(executionMonitor, observedExecutions(UnsetNonContainmentEReference))
		assertThat(resourceAt(TARGET_MODEL), containsModelOf(resourceAt(SOURCE_MODEL)))
	}

	@Test
	def void testUpdateSingleValuedEAttribute() {
		Root.from(SOURCE_MODEL).recordAndPropagate [
			singleValuedEAttribute = -1
		]

		assertThat(executionMonitor, observedExecutions(UpdateSingleValuedEAttribute))
		assertThat(resourceAt(TARGET_MODEL), containsModelOf(resourceAt(SOURCE_MODEL)))
	}

	@Test
	def void testUpdateSingleValuedPrimitiveTypeEAttribute() {
		Root.from(SOURCE_MODEL).recordAndPropagate [
			singleValuedPrimitiveTypeEAttribute = -1
		]

		assertThat(executionMonitor, observedExecutions(UpdateSingleValuedPrimitveTypeEAttribute))
		assertThat(resourceAt(TARGET_MODEL), containsModelOf(resourceAt(SOURCE_MODEL)))
	}

	@Test
	def void testCreateSingleValuedContainmentEReference() {
		Root.from(SOURCE_MODEL).recordAndPropagate [
			singleValuedContainmentEReference = newNonRoot => [id = "singleValuedContainmentNonRootTest"]
		]

		assertThat(executionMonitor, observedExecutions(CreateEObject, CreateNonRootEObjectSingle))
{'fraction_non_alphanumeric': 0.08083579569438581, 'fraction_numerical': 0.001266357112705783, 'mean_word_length': 7.051826677994902, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '146886', 'n_tokens_mistral': 3117, 'n_tokens_neox': 2853, 'n_words': 404}