|
| 1 | +/* |
| 2 | + * ------------------------------------------------------------------------ |
| 3 | + * |
| 4 | + * Copyright by KNIME AG, Zurich, Switzerland |
| 5 | + * Website: http://www.knime.com; Email: contact@knime.com |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License, Version 3, as |
| 9 | + * published by the Free Software Foundation. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, but |
| 12 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses>. |
| 18 | + * |
| 19 | + * Additional permission under GNU GPL version 3 section 7: |
| 20 | + * |
| 21 | + * KNIME interoperates with ECLIPSE solely via ECLIPSE's plug-in APIs. |
| 22 | + * Hence, KNIME and ECLIPSE are both independent programs and are not |
| 23 | + * derived from each other. Should, however, the interpretation of the |
| 24 | + * GNU GPL Version 3 ("License") under any applicable laws result in |
| 25 | + * KNIME and ECLIPSE being a combined program, KNIME AG herewith grants |
| 26 | + * you the additional permission to use and propagate KNIME together with |
| 27 | + * ECLIPSE with only the license terms in place for ECLIPSE applying to |
| 28 | + * ECLIPSE and the GNU GPL Version 3 applying for KNIME, provided the |
| 29 | + * license terms of ECLIPSE themselves allow for the respective use and |
| 30 | + * propagation of ECLIPSE together with KNIME. |
| 31 | + * |
| 32 | + * Additional permission relating to nodes for KNIME that extend the Node |
| 33 | + * Extension (and in particular that are based on subclasses of NodeModel, |
| 34 | + * NodeDialog, and NodeView) and that only interoperate with KNIME through |
| 35 | + * standard APIs ("Nodes"): |
| 36 | + * Nodes are deemed to be separate and independent programs and to not be |
| 37 | + * covered works. Notwithstanding anything to the contrary in the |
| 38 | + * License, the License does not apply to Nodes, you are not required to |
| 39 | + * license Nodes under the License, and you are granted a license to |
| 40 | + * prepare and propagate Nodes, in each case even if such Nodes are |
| 41 | + * propagated with or for interoperation with KNIME. The owner of a Node |
| 42 | + * may freely choose the license terms applicable to such Node, including |
| 43 | + * when such Node is propagated with or for interoperation with KNIME. |
| 44 | + * ------------------------------------------------------------------------ |
| 45 | + */ |
| 46 | +package org.knime.base.filehandling.findmimetype; |
| 47 | + |
| 48 | +import java.io.FileInputStream; |
| 49 | +import java.io.IOException; |
| 50 | + |
| 51 | +import org.knime.core.data.DataTableSpec; |
| 52 | +import org.knime.core.data.DataType; |
| 53 | +import org.knime.core.data.def.StringCell; |
| 54 | +import org.knime.core.data.uri.URIDataCell; |
| 55 | +import org.knime.core.node.InvalidSettingsException; |
| 56 | +import org.knime.core.node.NodeSettings; |
| 57 | +import org.knime.core.node.port.PortObjectSpec; |
| 58 | +import org.knime.core.webui.node.dialog.SettingsType; |
| 59 | +import org.knime.core.webui.node.dialog.defaultdialog.NodeParametersUtil; |
| 60 | +import org.knime.testing.node.dialog.DefaultNodeSettingsSnapshotTest; |
| 61 | +import org.knime.testing.node.dialog.SnapshotTestConfiguration; |
| 62 | + |
| 63 | +/** |
| 64 | + * Snapshot test for {@link FindMIMETypeNodeParameters}. |
| 65 | + */ |
| 66 | +@SuppressWarnings("restriction") |
| 67 | +final class FindMIMETypeNodeParametersTest extends DefaultNodeSettingsSnapshotTest { |
| 68 | + |
| 69 | + FindMIMETypeNodeParametersTest() { |
| 70 | + super(getConfig()); |
| 71 | + } |
| 72 | + |
| 73 | + private static SnapshotTestConfiguration getConfig() { |
| 74 | + return SnapshotTestConfiguration.builder() // |
| 75 | + .withInputPortObjectSpecs(createInputPortSpecs()) // |
| 76 | + .testJsonFormsForModel(FindMIMETypeNodeParameters.class) // |
| 77 | + .testJsonFormsWithInstance(SettingsType.MODEL, () -> readSettings()) // |
| 78 | + .testNodeSettingsStructure(() -> readSettings()) // |
| 79 | + .build(); |
| 80 | + } |
| 81 | + |
| 82 | + private static FindMIMETypeNodeParameters readSettings() { |
| 83 | + try { |
| 84 | + var path = getSnapshotPath(FindMIMETypeNodeParameters.class).getParent().resolve("node_settings") |
| 85 | + .resolve("FindMIMETypeNodeParameters.xml"); |
| 86 | + try (var fis = new FileInputStream(path.toFile())) { |
| 87 | + var nodeSettings = NodeSettings.loadFromXML(fis); |
| 88 | + return NodeParametersUtil.loadSettings(nodeSettings.getNodeSettings(SettingsType.MODEL.getConfigKey()), |
| 89 | + FindMIMETypeNodeParameters.class); |
| 90 | + } |
| 91 | + } catch (IOException | InvalidSettingsException e) { |
| 92 | + throw new IllegalStateException(e); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + private static PortObjectSpec[] createInputPortSpecs() { |
| 97 | + return new PortObjectSpec[]{createDefaultTestTableSpec()}; |
| 98 | + } |
| 99 | + |
| 100 | + private static DataTableSpec createDefaultTestTableSpec() { |
| 101 | + return new DataTableSpec( |
| 102 | + new String[]{"URI", "String_Column", "Another_URI"}, |
| 103 | + new DataType[]{ |
| 104 | + URIDataCell.TYPE, |
| 105 | + DataType.getType(StringCell.class), |
| 106 | + URIDataCell.TYPE |
| 107 | + } |
| 108 | + ); |
| 109 | + } |
| 110 | +} |
0 commit comments