| /***************************************************************************** |
| * 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.emf.template2structure.tests; |
| |
| import java.util.Collection; |
| |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.util.EcoreUtil; |
| import org.eclipse.papyrus.junit.utils.rules.PluginResource; |
| import org.eclipse.papyrus.model2doc.emf.documentstructuretemplate.TextDocumentTemplate; |
| import org.junit.Assert; |
| import org.junit.Test; |
| |
| /** |
| * The goal of this class is to test TreeListViewMapper |
| */ |
| @SuppressWarnings("nls") |
| @PluginResource("resources/TreeListView/TreeListView.pdst") |
| public class TreeListViewMapperTest extends AbstractTemplateToStructureTests { |
| |
| public static final String EXPECTED_RESOURCE_PATH = PLUGIN_EXPECTED_RESOURCE_PATH + "TreeListView/expectedOutput/"; |
| |
| /** |
| * Test the default TreeListView |
| */ |
| @Test |
| public void defaultTreeListViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("default"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "default.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/default.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default TreeListView with a custom title |
| */ |
| @Test |
| public void customTitleTreeListViewMapperTest() { |
| 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, the generated file is: " |
| + debugDisplay("output/customTitle.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default TreeListView with the generate property set to false |
| */ |
| @Test |
| public void doNotGenerateTreeListViewMapperTest() { |
| 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, the generated file is: " |
| + debugDisplay("output/doNotGenerate.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default TreeListView with the generateTitle property set to false |
| */ |
| @Test |
| public void doNotGenerateTitleTreeListViewMapperTest() { |
| 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, the generated file is: " |
| + debugDisplay("output/doNotGenerateTitle.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default TreeListView with the generateIfEmpty property set to true |
| */ |
| @Test |
| public void generateIfEmptyTreeListViewMapperTest() { |
| 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, the generated file is: " |
| + debugDisplay("output/generateIfEmpty.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default TreeListView with a False Expression |
| */ |
| @Test |
| public void withExpressionTreeListViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("withExpression"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "withExpression.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/withExpression.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default TreeListView with a eAttributeListItem whose customItemLabel is set |
| */ |
| @Test |
| public void eAttributeListItemCustomItemLabelTreeListViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("eAttributeListItemCustomItemLabel"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "eAttributeListItemCustomItemLabel.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/eAttributeListItemCustomItemLabel.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default TreeListView with a eAttributeListItem whose generate property is set to false |
| */ |
| @Test |
| public void eAttributeListItemDoNotGenerateTreeListViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("eAttributeListItemDoNotGenerate"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "eAttributeListItemDoNotGenerate.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/eAttributeListItemDoNotGenerate.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default TreeListView with a eAttributeListItem whose generate property is set to false |
| */ |
| @Test |
| public void eAttributeListItemEmptyTreeListViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("eAttributeListItemEmpty"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "eAttributeListItemEmpty.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/eAttributeListItemEmpty.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default TreeListView with a eClassListItem whose customItemLabel is set |
| */ |
| @Test |
| public void eClassListItemCustomItemLabelTreeListViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("eClassListItemCustomItemLabel"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "eClassListItemCustomItemLabel.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/eClassListItemCustomItemLabel.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default TreeListView with a eClassListItem whose generate property is set to false |
| */ |
| @Test |
| public void eClassListItemDoNotGenerateTreeListViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("eClassListItemDoNotGenerate"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "eClassListItemDoNotGenerate.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/eClassListItemDoNotGenerate.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default TreeListView with a eClassListItem whose filterRule property is set to KindOf |
| */ |
| @Test |
| public void eClassListItemKindOfTreeListViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("eClassListItemKindOf"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "eClassListItemKindOf.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/eClassListItemKindOf.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default TreeListView with a eReferenceListItem whose customItemLabel is set |
| */ |
| @Test |
| public void eReferenceListItemCustomItemLabelTreeListViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("eReferenceListItemCustomItemLabel"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "eReferenceListItemCustomItemLabel.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/eReferenceListItemCustomItemLabel.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| /** |
| * Test the default TreeListView with a eReferenceListItem whose generate property is set to false |
| */ |
| @Test |
| public void eReferenceListItemDoNotGenerateTreeListViewMapperTest() { |
| TextDocumentTemplate textDocumentTemplate = getTextDocumentTemplate("eReferenceListItemDoNotGenerate"); |
| Collection<?> commandResult = generateDocumentStructure(textDocumentTemplate); |
| |
| // Test the generated file is the same as the expected one |
| EObject expectedTextDocument = loadExpectedDocumentStructureResource(EXPECTED_RESOURCE_PATH + "eReferenceListItemDoNotGenerate.pds"); |
| Assert.assertTrue("The generated DocumentStructure does not match with the expected one, the generated file is: " |
| + debugDisplay("output/eReferenceListItemDoNotGenerate.pds"), |
| EcoreUtil.equals(expectedTextDocument, (EObject) commandResult.iterator().next())); |
| } |
| |
| } |