<commit_before>//=====================================================================
// Licensed under the Apache License, Version 2.0 (the "License"); you may not 
// use this file except in compliance with the License.  You may obtain a copy 
// of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the 
// License for the specific language governing permissions and limitations under
// the License.
//=====================================================================
package org.xtuml.bp.ui.canvas.test;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.gef.editparts.ZoomManager;
import org.eclipse.gef.tools.AbstractTool;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.PlatformUI;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.xtuml.bp.core.Association_c;
import org.xtuml.bp.core.CorePlugin;
import org.xtuml.bp.core.ModelClass_c;
import org.xtuml.bp.core.Ooaofooa;
import org.xtuml.bp.core.Package_c;
import org.xtuml.bp.core.PackageableElement_c;
import org.xtuml.bp.core.common.BridgePointPreferencesStore;
import org.xtuml.bp.core.common.ClassQueryInterface_c;
import org.xtuml.bp.core.common.Transaction;
import org.xtuml.bp.core.common.TransactionException;
import org.xtuml.bp.core.common.TransactionManager;
import org.xtuml.bp.core.ui.Selection;
import org.xtuml.bp.test.common.BaseTest;
import org.xtuml.bp.test.common.OrderedRunner;
import org.xtuml.bp.test.common.UITestingUtilities;
import org.xtuml.bp.ui.canvas.GraphicalElement_c;
import org.xtuml.bp.ui.canvas.Model_c;
import org.xtuml.bp.ui.canvas.Shape_c;
import org.xtuml.bp.ui.graphics.editor.GraphicalEditor;
import org.xtuml.bp.ui.graphics.editor.ModelEditor;
import org.xtuml.bp.utilities.ui.CanvasUtilities;

@RunWith(OrderedRunner.class)
public class CanvasCopyPasteTests extends CanvasTest {
	
	private String testModelName = "CopyPasteTestModel";
	private static boolean initialized;
	private String test_id;
	public static boolean generateResults = false;

	public CanvasCopyPasteTests() {
		super(null, null);	
	}

	@Before
	public void setUp() throws Exception {
		super.setUp();
		if(!initialized) {
			Ooaofooa.setPersistEnabled(true);
			loadProject(testModelName);
			initialized = true;
		}
	}
	@Test
	public void testCopyPackageToSystem() {
		test_id = "1";
		Package_c domain = Package_c.getOneEP_PKGOnR1401(m_sys);
		assertNotNull(domain);
		CanvasUtilities.openCanvasEditor(domain);
		GraphicalEditor ce = ((ModelEditor) PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage().getActiveEditor())
				.getGraphicalEditor();
		Package_c dtPackage = Package_c.getOneEP_PKGOnR1405(m_sys, new ClassQueryInterface_c() {
		
			public boolean evaluate(Object candidate) {
				return ((Package_c)candidate).getName().equals("DT Package");
			}
		
		});
		assertNotNull(dtPackage);
		addElementToSelection(true, dtPackage);
		copySelection(ce);
		addElementToSelection(true, m_sys);
		CanvasUtilities.openCanvasEditor(m_sys);
		ce = ((ModelEditor) PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage().getActiveEditor())
				.getGraphicalEditor();
		UITestingUtilities.pasteClipboardContents(UITestingUtilities.getClearPoint(ce), ce);
		validateOrGenerateResults(ce, generateResults);
		Package_c newDtPackage = Package_c.getOneEP_PKGOnR1405(m_sys, new ClassQueryInterface_c() {
		
			public boolean evaluate(Object candidate) {
				return ((Package_c)candidate).getName().equals("DT Package");
			}
		
		});
		// test that datatypes of package are copied correctly
		assertNotNull("Package was not created along with paste.", newDtPackage);
		addElementToSelection(true, newDtPackage);
		CanvasUtilities.openCanvasEditor(newDtPackage);
		ce = ((ModelEditor) PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage().getActiveEditor())
				.getGraphicalEditor();
		test_id = "2";
		validateOrGenerateResults(ce, generateResults);
	}
	
	@Test
	public void testCopySSWithNonSimpleAssociations() {
		test_id = "3";
	    Package_c subsystem = Package_c.PackageInstance(modelRoot, new ClassQueryInterface_c() {<commit_msg>job #10341 - manually select a clear spot on the canvas to paste.  The previous code ended up pasting _inside_ what should have been the sibling package of our pasted element.<commit_after>//=====================================================================
// Licensed under the Apache License, Version 2.0 (the "License"); you may not 
// use this file except in compliance with the License.  You may obtain a copy 
// of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the 
// License for the specific language governing permissions and limitations under
// the License.
//=====================================================================
package org.xtuml.bp.ui.canvas.test;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.gef.editparts.ZoomManager;
import org.eclipse.gef.tools.AbstractTool;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.PlatformUI;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.xtuml.bp.core.Association_c;
import org.xtuml.bp.core.CorePlugin;
import org.xtuml.bp.core.ModelClass_c;
import org.xtuml.bp.core.Ooaofooa;
import org.xtuml.bp.core.Package_c;
import org.xtuml.bp.core.PackageableElement_c;
import org.xtuml.bp.core.common.BridgePointPreferencesStore;
import org.xtuml.bp.core.common.ClassQueryInterface_c;
import org.xtuml.bp.core.common.Transaction;
import org.xtuml.bp.core.common.TransactionException;
import org.xtuml.bp.core.common.TransactionManager;
import org.xtuml.bp.core.ui.Selection;
import org.xtuml.bp.test.common.BaseTest;
import org.xtuml.bp.test.common.OrderedRunner;
import org.xtuml.bp.test.common.UITestingUtilities;
import org.xtuml.bp.ui.canvas.GraphicalElement_c;
import org.xtuml.bp.ui.canvas.Model_c;
import org.xtuml.bp.ui.canvas.Shape_c;
import org.xtuml.bp.ui.graphics.editor.GraphicalEditor;
import org.xtuml.bp.ui.graphics.editor.ModelEditor;
import org.xtuml.bp.utilities.ui.CanvasUtilities;

@RunWith(OrderedRunner.class)
public class CanvasCopyPasteTests extends CanvasTest {
	
	private String testModelName = "CopyPasteTestModel";
	private static boolean initialized;
	private String test_id;
	public static boolean generateResults = false;

	public CanvasCopyPasteTests() {
		super(null, null);	
	}

	@Before
	public void setUp() throws Exception {
		super.setUp();
		if(!initialized) {
			Ooaofooa.setPersistEnabled(true);
			loadProject(testModelName);
			initialized = true;
		}
	}
	@Test
	public void testCopyPackageToSystem() {
		test_id = "1";
		Package_c domain = Package_c.getOneEP_PKGOnR1401(m_sys);
		assertNotNull(domain);
		CanvasUtilities.openCanvasEditor(domain);
		GraphicalEditor ce = ((ModelEditor) PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage().getActiveEditor())
				.getGraphicalEditor();
		Package_c dtPackage = Package_c.getOneEP_PKGOnR1405(m_sys, new ClassQueryInterface_c() {
		
			public boolean evaluate(Object candidate) {
				return ((Package_c)candidate).getName().equals("DT Package");
			}
		
		});
		assertNotNull(dtPackage);
		addElementToSelection(true, dtPackage);
		copySelection(ce);
		addElementToSelection(true, m_sys);
		CanvasUtilities.openCanvasEditor(m_sys);
		ce = ((ModelEditor) PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage().getActiveEditor())
				.getGraphicalEditor();
		UITestingUtilities.pasteClipboardContents(new Point(400,100), ce);
		validateOrGenerateResults(ce, generateResults);
		Package_c newDtPackage = Package_c.getOneEP_PKGOnR1405(m_sys, new ClassQueryInterface_c() {
		
			public boolean evaluate(Object candidate) {
				return ((Package_c)candidate).getName().equals("DT Package");
			}
		
		});
		// test that datatypes of package are copied correctly
		assertNotNull("Package was not created along with paste.", newDtPackage);
		addElementToSelection(true, newDtPackage);
		CanvasUtilities.openCanvasEditor(newDtPackage);
		ce = ((ModelEditor) PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getActivePage().getActiveEditor())
				.getGraphicalEditor();
		test_id = "2";
		validateOrGenerateResults(ce, generateResults);
	}
	
	@Test
	public void testCopySSWithNonSimpleAssociations() {
		test_id = "3";
	    Package_c subsystem = Package_c.PackageInstance(modelRoot, new ClassQueryInterface_c() {
{'fraction_non_alphanumeric': 0.13612917694550347, 'fraction_numerical': 0.005494505494505495, 'mean_word_length': 5.339019189765459, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5221757', 'n_tokens_mistral': 2943, 'n_tokens_neox': 2736, 'n_words': 576}