| /***************************************************************************** |
| * 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.uml.template2structure.tests; |
| |
| import java.util.Collection; |
| |
| 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.ModelSetFixture; |
| import org.eclipse.papyrus.junit.utils.rules.PluginResource; |
| import org.eclipse.papyrus.model2doc.emf.documentstructure.Paragraph; |
| import org.eclipse.papyrus.model2doc.emf.documentstructuretemplate.TextDocumentTemplate; |
| import org.eclipse.papyrus.model2doc.emf.template2structure.tests.AbstractTemplateToStructureTests; |
| import org.junit.Assert; |
| import org.junit.Rule; |
| import org.junit.Test; |
| |
| /** |
| * This class tests the mapping between {@link CommentAsParagraph} and {@link Paragraph} |
| */ |
| @SuppressWarnings("nls") |
| @PluginResource("resources/CommentAsParagraph/CommentAsParagraph.pdst") |
| public class CommentAsParagraphMapperTest extends AbstractTemplateToStructureTests { |
| |
| public static final String EXPECTED_RESOURCE_PATH = Activator.PLUGIN_ID + "/resources/CommentAsParagraph/expectedOutput/"; |
| |
| /** |
| * The editor fixture |
| */ |
| @Rule |
| public AbstractModelFixture<TransactionalEditingDomain> fixture = new ModelSetFixture(); |
| |
| /** |
| * @see org.eclipse.papyrus.model2doc.emf.template2structure.tests.AbstractTemplateToStructureTests#getFixture() |
| * |
| * @return |
| */ |
| @Override |
| public AbstractModelFixture<TransactionalEditingDomain> getFixture() { |
| return fixture; |
| } |
| |
| /** |
| * Test the default CommentAsParagraph |
| */ |
| @Test |
| public void defaultCommentAsParagraphMapperTest() { |
| String testName = "default"; |
| String testFile = testName + ".pds"; |
| |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate(testName); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + testFile); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/" + testFile), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default CommentAsParagraph with commentChoice set to ALL_OWNED_ELEMENT |
| */ |
| @Test |
| public void commentChoiceCommentAsParagraphMapperTest() { |
| String testName = "commentChoice"; |
| String testFile = testName + ".pds"; |
| |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate(testName); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + testFile); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/" + testFile), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default CommentAsParagraph with a customTitle |
| */ |
| @Test |
| public void customTitleCommentAsParagraphMapperTest() { |
| String testName = "customTitle"; |
| String testFile = testName + ".pds"; |
| |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate(testName); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + testFile); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/" + testFile), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default CommentAsParagraph with generate feature set to false |
| */ |
| @Test |
| public void doNotGenerateCommentAsParagraphMapperTest() { |
| String testName = "doNotGenerate"; |
| String testFile = testName + ".pds"; |
| |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate(testName); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + testFile); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/" + testFile), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default CommentAsParagraph with generateTitle feature set to false |
| */ |
| @Test |
| public void doNotGenerateTitleCommentAsParagraphMapperTest() { |
| String testName = "doNotGenerateTitle"; |
| String testFile = testName + ".pds"; |
| |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate(testName); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + testFile); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/" + testFile), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default CommentAsParagraph with nothing to find |
| */ |
| @Test |
| public void emptyCommentAsParagraphMapperTest() { |
| String testName = "empty"; |
| String testFile = testName + ".pds"; |
| |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate(testName); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + testFile); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/" + testFile), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default CommentAsParagraph with generateIfEmpty feature set to true |
| */ |
| @Test |
| public void generateIfEmptyCommentAsParagraphMapperTest() { |
| String testName = "generateIfEmpty"; |
| String testFile = testName + ".pds"; |
| |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate(testName); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + testFile); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/" + testFile), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default CommentAsParagraph with an expression set to False |
| */ |
| @Test |
| public void withExpressionCommentAsParagraphMapperTest() { |
| String testName = "withExpression"; |
| String testFile = testName + ".pds"; |
| |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate(testName); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + testFile); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/" + testFile), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| } |