| /***************************************************************************** |
| * Copyright (c) 2021 CEA LIST and others. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Initial API and implementation |
| * |
| *****************************************************************************/ |
| |
| package org.eclipse.papyrus.model2doc.integration.gmf.template2structure.tests; |
| |
| import static org.junit.Assert.assertTrue; |
| |
| import java.util.Collection; |
| import java.util.Collections; |
| |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.util.EcoreUtil; |
| import org.eclipse.emf.transaction.TransactionalEditingDomain; |
| import org.eclipse.papyrus.junit.utils.rules.AbstractModelFixture; |
| import org.eclipse.papyrus.junit.utils.rules.ActiveDiagram; |
| import org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture; |
| import org.eclipse.papyrus.junit.utils.rules.PluginResource; |
| import org.eclipse.papyrus.model2doc.emf.documentstructure.TextDocument; |
| import org.eclipse.papyrus.model2doc.emf.documentstructuretemplate.TextDocumentTemplate; |
| import org.junit.Assert; |
| import org.junit.Rule; |
| import org.junit.Test; |
| |
| /** |
| * Test for PapyrusGMFDiagramViewMapper |
| * |
| * WARNING expected generated files should be modified to be sure that the path is the same as in the test environment |
| */ |
| @SuppressWarnings("nls") |
| @PluginResource({ "resources/PapyrusGMFDiagramView/PapyrusGMFDiagramView.di", "resources/PapyrusGMFDiagramView/PapyrusGMFDiagramView.pdst" }) |
| @ActiveDiagram("NewClassDiagram") |
| public class PapyrusGMFDiagramViewMapperTest extends AbstractDiagramViewMapperTests { |
| |
| public static final String EXPECTED_RESOURCE_PATH = Activator.PLUGIN_ID + "/resources/PapyrusGMFDiagramView/expectedOutput/"; |
| |
| /** |
| * The editor fixture |
| */ |
| @Rule |
| public PapyrusEditorFixture fixture = new PapyrusEditorFixture(true, Collections.singletonList("pdst")); |
| |
| /** |
| * @see org.eclipse.papyrus.model2doc.emf.template2structure.tests.AbstractTemplateToStructureTests#getFixture() |
| * |
| * @return |
| */ |
| @Override |
| public AbstractModelFixture<TransactionalEditingDomain> getFixture() { |
| return fixture; |
| } |
| |
| /** |
| * Test the default PapyrusGMFDiagramView |
| */ |
| @Test |
| public void semanticContextAllDiagramsPapyrusGMFDiagramViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("semanticContextAllDiagrams"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| Assert.assertTrue("The generated object should be a TextDocument", commandResult.iterator().next() instanceof TextDocument); |
| TextDocument generatedTextDocument = (TextDocument) commandResult.iterator().next(); |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "semanticContextAllDiagrams.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one" |
| + debugDisplay("output/semanticContextAllDiagrams.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| |
| // Check generated image |
| checkGeneratedImages(generatedTextDocument, "png"); |
| } |
| |
| /** |
| * Test the default PapyrusGMFDiagramView with a custom title |
| */ |
| @Test |
| public void customTitlePapyrusGMFDiagramViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("customTitle"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "customTitle.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one" |
| + debugDisplay("output/customTitle.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| |
| // Check generated image |
| assertTrue("The result should be a TextDocument", expectedTextDocument instanceof TextDocument); |
| checkGeneratedImages((TextDocument) commandResult.iterator().next(), "png"); |
| } |
| |
| /** |
| * Test the default PapyrusGMFDiagramView with the kindId property set |
| */ |
| @Test |
| public void diagramKindIdPapyrusGMFDiagramViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("diagramKindId"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "diagramKindId.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one" |
| + debugDisplay("output/diagramKindId.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| |
| // Check generated image |
| assertTrue("The result should be a TextDocument", expectedTextDocument instanceof TextDocument); |
| checkGeneratedImages((TextDocument) commandResult.iterator().next(), "png"); |
| } |
| |
| /** |
| * Test the default PapyrusGMFDiagramView with the type property set |
| */ |
| @Test |
| public void diagramTypePapyrusGMFDiagramViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("diagramType"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "diagramType.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one" |
| + debugDisplay("output/diagramType.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| |
| // Check generated image |
| assertTrue("The result should be a TextDocument", expectedTextDocument instanceof TextDocument); |
| checkGeneratedImages((TextDocument) commandResult.iterator().next(), "png"); |
| } |
| |
| /** |
| * Test the default PapyrusGMFDiagramView with the generate property set to false |
| */ |
| @Test |
| public void doNotGeneratePapyrusGMFDiagramViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("doNotGenerate"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "doNotGenerate.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one" |
| + debugDisplay("output/doNotGenerate.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| |
| // Check generated image |
| assertTrue("The result should be a TextDocument", expectedTextDocument instanceof TextDocument); |
| checkGeneratedImages((TextDocument) commandResult.iterator().next(), "png"); |
| } |
| |
| /** |
| * Test the default PapyrusGMFDiagramView with the generateTitle property set to false |
| */ |
| @Test |
| public void doNotGenerateTitlePapyrusGMFDiagramViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("doNotGenerateTitle"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "doNotGenerateTitle.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one" |
| + debugDisplay("output/doNotGenerateTitle.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| |
| // Check generated image |
| assertTrue("The result should be a TextDocument", expectedTextDocument instanceof TextDocument); |
| checkGeneratedImages((TextDocument) commandResult.iterator().next(), "png"); |
| } |
| |
| /** |
| * Test the default PapyrusGMFDiagramView with an empty result |
| */ |
| @Test |
| public void emptyPapyrusGMFDiagramViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("empty"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "empty.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one" |
| + debugDisplay("output/empty.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| |
| // Check generated image |
| assertTrue("The result should be a TextDocument", expectedTextDocument instanceof TextDocument); |
| checkGeneratedImages((TextDocument) commandResult.iterator().next(), "png"); |
| } |
| |
| /** |
| * Test the default PapyrusGMFDiagramView with an empty result and the property generateIfEmpty set to true |
| */ |
| @Test |
| public void generateIfEmptyPapyrusGMFDiagramViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("generateIfEmpty"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "generateIfEmpty.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one" |
| + debugDisplay("output/generateIfEmpty.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| |
| // Check generated image |
| assertTrue("The result should be a TextDocument", expectedTextDocument instanceof TextDocument); |
| checkGeneratedImages((TextDocument) commandResult.iterator().next(), "png"); |
| } |
| |
| /** |
| * Test the default PapyrusGMFDiagramView with ContextFilterRule set to GRAPHICAL_CONTEXT |
| */ |
| @Test |
| public void graphicalContextAllDiagramsPapyrusGMFDiagramViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("graphicalContextAllDiagrams"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "graphicalContextAllDiagrams.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one" |
| + debugDisplay("output/graphicalContextAllDiagrams.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| |
| // Check generated image |
| assertTrue("The result should be a TextDocument", expectedTextDocument instanceof TextDocument); |
| checkGeneratedImages((TextDocument) commandResult.iterator().next(), "png"); |
| } |
| |
| /** |
| * Test the default PapyrusGMFDiagramView with ContextFilterRule set to GRAPHICAL_CONTEXT |
| */ |
| @Test |
| public void bothDiagramContextPapyrusGMFDiagramViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("bothDiagramContext"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "bothDiagramContext.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one" |
| + debugDisplay("output/bothDiagramContext.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| |
| // Check generated image |
| assertTrue("The result should be a TextDocument", expectedTextDocument instanceof TextDocument); |
| checkGeneratedImages((TextDocument) commandResult.iterator().next(), "png"); |
| } |
| |
| /** |
| * Test the default PapyrusGMFDiagramView with the imageFormat set to SVG |
| */ |
| @Test |
| public void imageFormatPapyrusGMFDiagramViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("imageFormat"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "imageFormat.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one" |
| + debugDisplay("output/imageFormat.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| |
| // Check generated image |
| assertTrue("The result should be a TextDocument", expectedTextDocument instanceof TextDocument); |
| checkGeneratedImages((TextDocument) commandResult.iterator().next(), "svg"); |
| |
| // FIXME should test the mime type |
| } |
| |
| /** |
| * Test the default PapyrusGMFDiagramView with output folder path with space and accent |
| */ |
| @Test |
| public void withSpacesInPathPapyrusGMFDiagramViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("withSpacesInPath"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "withSpacesInPath.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one" |
| + debugDisplay("output/withSpacesInPath.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| |
| // Check generated image |
| assertTrue("The result should be a TextDocument", expectedTextDocument instanceof TextDocument); |
| checkGeneratedImages((TextDocument) commandResult.iterator().next(), "png"); |
| } |
| } |