| /***************************************************************************** |
| * 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 java.io.File; |
| import java.net.URL; |
| |
| import org.eclipse.core.resources.IContainer; |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.resources.IResource; |
| import org.eclipse.core.resources.ResourcesPlugin; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.NullProgressMonitor; |
| import org.eclipse.emf.common.util.TreeIterator; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.osgi.util.NLS; |
| import org.eclipse.papyrus.model2doc.emf.documentstructure.Image; |
| import org.eclipse.papyrus.model2doc.emf.documentstructure.TextDocument; |
| import org.eclipse.papyrus.model2doc.emf.template2structure.tests.AbstractTemplateToStructureTests; |
| import org.junit.Assert; |
| |
| /** |
| * |
| */ |
| @SuppressWarnings("nls") |
| public abstract class AbstractDiagramViewMapperTests extends AbstractTemplateToStructureTests { |
| |
| /** |
| * @param generatedTextDocument |
| */ |
| protected void checkGeneratedImages(TextDocument generatedTextDocument, String expectedFileExtension) { |
| final String projectToRefresh = generatedTextDocument.getDocumentGeneratorConfiguration().createDocumentOutputAccessor().getProjectName(); |
| if (projectToRefresh != null && !projectToRefresh.isEmpty()) { |
| final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectToRefresh); |
| try { |
| project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); |
| } catch (CoreException e) { |
| Assert.fail("Can not refresh project"); |
| } |
| } else { |
| Assert.fail("The project does not exist"); |
| } |
| |
| TreeIterator<EObject> treeIter = generatedTextDocument.eAllContents(); |
| while (treeIter.hasNext()) { |
| EObject eObject = treeIter.next(); |
| if (eObject instanceof Image) { |
| Image image = (Image) eObject; |
| URL url = image.getFileAccessor().createInputFileURL(); |
| String myPath = image.getFileAccessor().urlToPathString(url, true); |
| File file3 = new File(myPath); |
| Assert.assertTrue(NLS.bind("The generated image {0} should exist", myPath), file3.exists()); |
| } |
| } |
| } |
| |
| private static void displayRes(IResource resource, String prefix) { |
| if (resource instanceof IContainer) { |
| IContainer folder = (IContainer) resource; |
| System.out.println(prefix + "folder name: " + folder.getName()); |
| try { |
| for (int i = 0; i < folder.members().length; i++) { |
| displayRes(folder.members()[i], prefix + "*"); |
| } |
| } catch (CoreException e) { |
| Activator.log.error(e); |
| } |
| } else if (resource instanceof IFile) { |
| System.out.println(prefix + "file name: " + ((IFile) resource).getName()); |
| } |
| } |
| |
| } |