From 8508566da690636ab4711e2faab69d7f951314e2 Mon Sep 17 00:00:00 2001 From: Aurelien Pupier Date: Wed, 11 May 2016 11:49:33 +0200 Subject: [PATCH] FUSETOOLS-1778 - Insert valid xml respecting extension point (#16) - Use extension point and don't insert on our own the element - Generate xsd valid node - Add an integration tests - use latest Fuse Tooling Snapshot build --- .../META-INF/MANIFEST.MF | 1 + .../provider/SAPServerContribution.java | 11 +- ...apGlobalConnectionConfigurationWizard.java | 44 ++++-- .../ui/jaxb/SapConnectionConfiguration.java | 19 +++ .../sap/ui/jaxb/blueprint/BlueprintFile.java | 19 ++- .../ide/sap/ui/jaxb/spring/SpringFile.java | 21 ++- .../fusesource/ide/sap/ui/util/ModelUtil.java | 76 ---------- jboss-fuse-sap-tool-suite/pom.xml | 2 +- .../.classpath | 8 ++ .../.project | 28 ++++ .../META-INF/MANIFEST.MF | 13 ++ .../build.properties | 5 + .../infinitest.filters | 1 + .../pom.xml | 17 +++ .../SapGlobalConfigurationWizardIT.java | 135 ++++++++++++++++++ .../tests/integration/util/FuseProject.java | 68 +++++++++ .../src/main/resources/blueprintDefault.xml | 5 + .../resources/expectedSAPBlueprintNode.xml | 20 +++ .../main/resources/expectedSAPSpringNode.xml | 20 +++ .../src/main/resources/springDefault.xml | 5 + jboss-fuse-sap-tool-suite/tests/pom.xml | 3 +- 21 files changed, 418 insertions(+), 103 deletions(-) create mode 100644 jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/.classpath create mode 100644 jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/.project create mode 100644 jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/META-INF/MANIFEST.MF create mode 100644 jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/build.properties create mode 100644 jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/infinitest.filters create mode 100644 jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/pom.xml create mode 100644 jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/java/org/fusesource/ide/sap/ui/tests/integration/SapGlobalConfigurationWizardIT.java create mode 100644 jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/java/org/fusesource/ide/sap/ui/tests/integration/util/FuseProject.java create mode 100644 jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/blueprintDefault.xml create mode 100644 jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/expectedSAPBlueprintNode.xml create mode 100644 jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/expectedSAPSpringNode.xml create mode 100644 jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/springDefault.xml diff --git a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/META-INF/MANIFEST.MF b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/META-INF/MANIFEST.MF index 0153868..ef3be42 100644 --- a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/META-INF/MANIFEST.MF +++ b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/META-INF/MANIFEST.MF @@ -28,3 +28,4 @@ Bundle-ActivationPolicy: lazy Bundle-Vendor: %Bundle-Vendor Bundle-ClassPath: . Bundle-Localization: OSGI-INF/l10n/bundle +Export-Package: org.fusesource.ide.sap.ui.export;x-friends:="org.fusesource.ide.sap.ui.tests.integration" diff --git a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/editor/globalconf/provider/SAPServerContribution.java b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/editor/globalconf/provider/SAPServerContribution.java index fb30ca6..e74f8e8 100644 --- a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/editor/globalconf/provider/SAPServerContribution.java +++ b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/editor/globalconf/provider/SAPServerContribution.java @@ -28,7 +28,6 @@ import org.fusesource.ide.camel.model.service.core.catalog.Dependency; import org.fusesource.ide.camel.model.service.core.model.CamelFile; import org.fusesource.ide.sap.ui.export.SapGlobalConnectionConfigurationWizard; -import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -44,7 +43,7 @@ public class SAPServerContribution implements ICustomGlobalConfigElementContribu */ @Override public GlobalConfigurationTypeWizard createGlobalElement(CamelFile camelFile) { - return createWizard(camelFile.getDocument()); + return createWizard(camelFile); } /* @@ -52,8 +51,8 @@ public GlobalConfigurationTypeWizard createGlobalElement(CamelFile camelFile) { * @see org.fusesource.ide.camel.editor.provider.ext.ICustomGlobalConfigElementContribution#modifyGlobalElement(org.w3c.dom.Document, org.w3c.dom.Node) */ @Override - public GlobalConfigurationTypeWizard modifyGlobalElement(Document document) { - return createWizard(document); + public GlobalConfigurationTypeWizard modifyGlobalElement(CamelFile camelFile) { + return createWizard(camelFile); } /* (non-Javadoc) @@ -101,8 +100,8 @@ public List getElementDependencies() { * @param document - document edited by wizard * @return SAP Global Connection Configuration Wizard */ - private GlobalConfigurationTypeWizard createWizard(Document document) { - SapGlobalConnectionConfigurationWizard wizard = new SapGlobalConnectionConfigurationWizard(document); + private GlobalConfigurationTypeWizard createWizard(CamelFile camelFile) { + SapGlobalConnectionConfigurationWizard wizard = new SapGlobalConnectionConfigurationWizard(camelFile); IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); ISelection selection = window.getSelectionService().getSelection(); if (!(selection instanceof IStructuredSelection)) { diff --git a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/export/SapGlobalConnectionConfigurationWizard.java b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/export/SapGlobalConnectionConfigurationWizard.java index 407f205..f319b19 100644 --- a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/export/SapGlobalConnectionConfigurationWizard.java +++ b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/export/SapGlobalConnectionConfigurationWizard.java @@ -12,10 +12,12 @@ package org.fusesource.ide.sap.ui.export; import static org.fusesource.ide.sap.ui.util.ModelUtil.getSapConnectionConfigurationModelFromDocument; -import static org.fusesource.ide.sap.ui.util.ModelUtil.setSapConnectionConfigurationModelIntoDocument; import java.util.HashMap; +import javax.xml.bind.JAXBException; +import javax.xml.transform.dom.DOMResult; + import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.emf.common.command.BasicCommandStack; import org.eclipse.emf.ecore.resource.Resource; @@ -30,11 +32,13 @@ import org.fusesource.camel.component.sap.util.ComponentDestinationDataProvider; import org.fusesource.camel.component.sap.util.ComponentServerDataProvider; import org.fusesource.ide.camel.editor.provider.ext.GlobalConfigurationTypeWizard; +import org.fusesource.ide.camel.model.service.core.model.CamelFile; import org.fusesource.ide.sap.ui.Messages; import org.fusesource.ide.sap.ui.edit.command.TransactionalCommandStack; import org.fusesource.ide.sap.ui.edit.idoc.IdocItemProviderAdapterFactory; import org.fusesource.ide.sap.ui.edit.rfc.RfcItemProviderAdapterFactory; -import org.w3c.dom.Document; +import org.fusesource.ide.sap.ui.jaxb.SapConnectionConfiguration; +import org.fusesource.ide.sap.ui.jaxb.SapConnectionConfigurationBuilder; import org.w3c.dom.Element; /** @@ -61,13 +65,15 @@ public class SapGlobalConnectionConfigurationWizard extends Wizard implements IE private DataBindingContext context; private SapGlobalConnectionConfigurationPage exportPage; - private Document document; + private CamelFile camelFile; private org.fusesource.camel.component.sap.model.rfc.SapConnectionConfiguration sapConnectionConfigurationModel; + + private Element globalConfigurationElementNode; - public SapGlobalConnectionConfigurationWizard(Document document) { - this.document = document; + public SapGlobalConnectionConfigurationWizard(CamelFile camelFile) { + this.camelFile = camelFile; initializeEditingDomain(); - this.sapConnectionConfigurationModel = getSapConnectionConfigurationModelFromDocument(this.document, editingDomain); + this.sapConnectionConfigurationModel = getSapConnectionConfigurationModelFromDocument(camelFile.getDocument(), editingDomain); } @Override @@ -90,7 +96,17 @@ public void addPages() { @Override public boolean performFinish() { - setSapConnectionConfigurationModelIntoDocument(this.document, this.sapConnectionConfigurationModel); + SapConnectionConfiguration sapConnectionConfiguration = new SapConnectionConfiguration(); + SapConnectionConfigurationBuilder.populateSapConnectionConfiguration(sapConnectionConfigurationModel, sapConnectionConfiguration); + try { + DOMResult result = sapConnectionConfiguration.marshal(); + final Element beanNode = (Element) result.getNode().getFirstChild(); + final Element importedBeanNode = (Element) camelFile.getDocument().importNode(beanNode, true); + setGlobalConfigurationElementNode(importedBeanNode); + } catch (JAXBException e) { + e.printStackTrace(); + return false; + } return true; } @@ -128,12 +144,22 @@ private void unregisterDataStores() { @Override public Element getGlobalConfigurationElementNode() { - return null; + return globalConfigurationElementNode; } @Override public void setGlobalConfigurationElementNode(Element node) { - // NOOP + this.globalConfigurationElementNode = node; + } + + /** + * /!\ Public for test purpose only + * + * @param sapConnectionConfigurationModel + * the sapConnectionConfigurationModel to set + */ + public void setSapConnectionConfigurationModel(org.fusesource.camel.component.sap.model.rfc.SapConnectionConfiguration sapConnectionConfigurationModel) { + this.sapConnectionConfigurationModel = sapConnectionConfigurationModel; } } diff --git a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/jaxb/SapConnectionConfiguration.java b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/jaxb/SapConnectionConfiguration.java index 377dca8..3bf3826 100644 --- a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/jaxb/SapConnectionConfiguration.java +++ b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/jaxb/SapConnectionConfiguration.java @@ -11,11 +11,16 @@ ******************************************************************************/ package org.fusesource.ide.sap.ui.jaxb; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.PropertyException; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.transform.dom.DOMResult; @XmlRootElement(name="bean") @XmlAccessorType(XmlAccessType.FIELD) @@ -41,4 +46,18 @@ public ServerDataStore getServerDataStore() { return serverDataStore; } + public DOMResult marshal() throws JAXBException, PropertyException { + Marshaller m = prepareMarshaller(); + DOMResult result = new DOMResult(); + m.marshal(this, result); + return result; + } + + private Marshaller prepareMarshaller() throws JAXBException, PropertyException { + JAXBContext context = JAXBContext.newInstance(SapConnectionConfiguration.class); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + return m; + } + } diff --git a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/jaxb/blueprint/BlueprintFile.java b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/jaxb/blueprint/BlueprintFile.java index cf96508..db4ae5a 100644 --- a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/jaxb/blueprint/BlueprintFile.java +++ b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/jaxb/blueprint/BlueprintFile.java @@ -14,7 +14,9 @@ import java.io.OutputStream; import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; +import javax.xml.bind.PropertyException; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; @@ -37,15 +39,20 @@ public void setSapConnectionConfiguration(SapConnectionConfiguration sapConnecti this.sapConnectionConfiguration = sapConnectionConfiguration; } - public void marshal(OutputStream os) throws Exception { + public void marshal(OutputStream os) throws JAXBException, PropertyException { if (sapConnectionConfiguration != null) { - JAXBContext context = JAXBContext.newInstance(BlueprintFile.class); - Marshaller m = context.createMarshaller(); - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, - "http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"); + Marshaller m = prepareMarshaller(); m.marshal(this, os); } } + private Marshaller prepareMarshaller() throws JAXBException, PropertyException { + JAXBContext context = JAXBContext.newInstance(BlueprintFile.class); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, + "http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"); + return m; + } + } diff --git a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/jaxb/spring/SpringFile.java b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/jaxb/spring/SpringFile.java index a6bb69d..b9063e2 100644 --- a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/jaxb/spring/SpringFile.java +++ b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/jaxb/spring/SpringFile.java @@ -14,7 +14,9 @@ import java.io.OutputStream; import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; +import javax.xml.bind.PropertyException; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; @@ -40,12 +42,23 @@ public void setSapConnectionConfiguration( public void marshal(OutputStream os) throws Exception { if (sapConnectionConfiguration != null) { - JAXBContext context = JAXBContext.newInstance(SpringFile.class); - Marshaller m = context.createMarshaller(); - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"); + Marshaller m = prepareMarshaller(); m.marshal(this, os); } } + + /** + * @return + * @throws JAXBException + * @throws PropertyException + */ + private Marshaller prepareMarshaller() throws JAXBException, PropertyException { + JAXBContext context = JAXBContext.newInstance(SpringFile.class); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, + "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"); + return m; + } } diff --git a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/util/ModelUtil.java b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/util/ModelUtil.java index 000a551..4d97ddc 100644 --- a/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/util/ModelUtil.java +++ b/jboss-fuse-sap-tool-suite/plugins/org.fusesource.ide.sap.ui/src/org/fusesource/ide/sap/ui/util/ModelUtil.java @@ -146,44 +146,6 @@ public static SapConnectionConfiguration getSapConnectionConfigurationModelFromD return sapConnectionConfigurationModel; } - public static void setSapConnectionConfigurationModelIntoDocument(Document document, SapConnectionConfiguration sapConnectionConfigurationModel) { - if (document == null || sapConnectionConfigurationModel == null) { - return; - } - - - Element sapConfigurationConfig = getSapConfiguration(document); - Element destinationDataStoreConfig = getDestinationDataStore(sapConfigurationConfig); - Element serverDataStoreConfig = getServerDataStore(sapConfigurationConfig); - - DestinationDataStore destinationDataStoreModel = sapConnectionConfigurationModel.getDestinationDataStore(); - populateDestinationDataStoreModelIntoConfig(destinationDataStoreModel, destinationDataStoreConfig); - - ServerDataStore serverDataStoreModel = sapConnectionConfigurationModel.getServerDataStore(); - populateServerDataStoreModelIntoConfig(serverDataStoreModel, serverDataStoreConfig); - } - - public static void populateDestinationDataStoreModelIntoConfig(DestinationDataStore destinationDataStoreModel, Element destinationDataStoreConfig) { - if (destinationDataStoreModel == null || destinationDataStoreConfig == null) { - return; - } - - Element map = getFirstChildElementWithName(destinationDataStoreConfig, MAP_TAG); - if (map == null) { - map = destinationDataStoreConfig.getOwnerDocument().createElement(MAP_TAG); - destinationDataStoreConfig.appendChild(map); - } - - removeChildNodes(map); - for (Map.Entry entry: destinationDataStoreModel.getEntries()) { - Element entryConfig = destinationDataStoreConfig.getOwnerDocument().createElement(ENTRY_TAG); - entryConfig.setAttribute(KEY_ATTRIBUTE, entry.getKey()); - entryConfig.setAttribute(CLASS_ATTRIBUTE, DESTINATION_DATA_CLASS); - map.appendChild(entryConfig); - populateDestinationDataModelIntoConfig(entry.getValue(), entryConfig); - } - } - public static void populateDestinationDataConfigIntoModel(DestinationData destinationDataModel, Element destinationDataConfig) { if (destinationDataModel == null || destinationDataConfig == null) { return; @@ -201,43 +163,6 @@ public static void populateDestinationDataConfigIntoModel(DestinationData destin } } - public static void populateDestinationDataModelIntoConfig(DestinationData destinationDataModel, Element destinationDataConfig) { - if (destinationDataModel == null || destinationDataConfig == null) { - return; - } - - // Check if configuration entry is a reference to global bean config - String beanName = getAttributeValue(destinationDataConfig, "value-ref"); //$NON-NLS-1$ - if (beanName != null) { - destinationDataConfig = getGlobalConfigurationById(destinationDataConfig.getOwnerDocument(), beanName); - } - - Map destinationDataProperties = extractDestinationDataProperties(destinationDataModel); - - setPropertyValues(destinationDataConfig, destinationDataProperties); - } - - public static void populateServerDataStoreModelIntoConfig(ServerDataStore serverDataStoreModel, Element serverDataStoreConfig) { - if (serverDataStoreModel == null || serverDataStoreConfig == null) { - return; - } - - Element map = getFirstChildElementWithName(serverDataStoreConfig, MAP_TAG); - if (map == null) { - map = serverDataStoreConfig.getOwnerDocument().createElement(MAP_TAG); - serverDataStoreConfig.appendChild(map); - } - - removeChildNodes(map); - for (Map.Entry entry: serverDataStoreModel.getEntries()) { - Element entryConfig = serverDataStoreConfig.getOwnerDocument().createElement(ENTRY_TAG); - entryConfig.setAttribute(KEY_ATTRIBUTE, entry.getKey()); - entryConfig.setAttribute(CLASS_ATTRIBUTE, SERVER_DATA_CLASS); - map.appendChild(entryConfig); - populateServerDataModelIntoConfig(entry.getValue(), entryConfig); - } - } - public static void populateServerDataConfigIntoModel(ServerData serverDataModel, Element serverDataConfig) { if (serverDataModel == null || serverDataConfig == null) { return; @@ -607,7 +532,6 @@ public static Element getSapConfiguration(Document document) { sapConfigurationElement = document.createElement(BEAN_TAG); sapConfigurationElement.setAttribute(ID_ATTRIBUTE, SAP_CONNECTION_CONFIGURATION_ID); sapConfigurationElement.setAttribute(CLASS_ATTRIBUTE, SAP_CONNECTION_CONFIGURATION_CLASS); - document.getDocumentElement().appendChild(sapConfigurationElement); } return sapConfigurationElement; diff --git a/jboss-fuse-sap-tool-suite/pom.xml b/jboss-fuse-sap-tool-suite/pom.xml index 77ba5c0..e861e5f 100644 --- a/jboss-fuse-sap-tool-suite/pom.xml +++ b/jboss-fuse-sap-tool-suite/pom.xml @@ -28,7 +28,7 @@ scm:git:https://github.com/fusesource/fuseide.git ide ${project.version} - http://download.jboss.org/jbosstools/mars/development/updates/integration-stack/fuse-tooling/8.0.0.Beta2/all/repo/ + http://download.jboss.org/jbosstools/snapshots/builds/Fuse-Tooling/all/repo/ 2.15.1.redhat-620133 diff --git a/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/.classpath b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/.classpath new file mode 100644 index 0000000..12780ca --- /dev/null +++ b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/.project b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/.project new file mode 100644 index 0000000..63de7ad --- /dev/null +++ b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/.project @@ -0,0 +1,28 @@ + + + org.fusesource.ide.sap.ui.tests.integration + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/META-INF/MANIFEST.MF b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8f9ae94 --- /dev/null +++ b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: JBoss SAP UI Integration Tests +Bundle-SymbolicName: org.fusesource.ide.sap.ui.tests.integration +Bundle-Version: 8.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.junit;bundle-version="4.12.0", + org.assertj.core;bundle-version="2.1.0", + org.fusesource.ide.sap.ui;bundle-version="8.0.0", + org.eclipse.core.resources, + org.eclipse.core.runtime;bundle-version="3.11.1", + org.fusesource.ide.camel.model.service.core, + org.fusesource.camel.component.sap.model diff --git a/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/build.properties b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/build.properties new file mode 100644 index 0000000..65cc57d --- /dev/null +++ b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/build.properties @@ -0,0 +1,5 @@ +source.. = src/main/java/,\ + src/main/resources/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/infinitest.filters b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/infinitest.filters new file mode 100644 index 0000000..ae0fc02 --- /dev/null +++ b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/infinitest.filters @@ -0,0 +1 @@ +.*IT \ No newline at end of file diff --git a/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/pom.xml b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/pom.xml new file mode 100644 index 0000000..974f0d2 --- /dev/null +++ b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + + org.fusesource.ide.sap + tests + 8.0.0-SNAPSHOT + .. + + + org.fusesource.ide.sap.ui.tests.integration + eclipse-plugin + JBoss Fuse Tooling :: SAP :: Tests :: SAP Tool Suite UI Integration Tests + + diff --git a/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/java/org/fusesource/ide/sap/ui/tests/integration/SapGlobalConfigurationWizardIT.java b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/java/org/fusesource/ide/sap/ui/tests/integration/SapGlobalConfigurationWizardIT.java new file mode 100644 index 0000000..29b77de --- /dev/null +++ b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/java/org/fusesource/ide/sap/ui/tests/integration/SapGlobalConfigurationWizardIT.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2016 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.fusesource.ide.sap.ui.tests.integration; + + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.fusesource.camel.component.sap.model.rfc.DestinationData; +import org.fusesource.camel.component.sap.model.rfc.DestinationDataStore; +import org.fusesource.camel.component.sap.model.rfc.RfcFactory; +import org.fusesource.camel.component.sap.model.rfc.SapConnectionConfiguration; +import org.fusesource.ide.camel.model.service.core.io.CamelIOHandler; +import org.fusesource.ide.camel.model.service.core.model.CamelFile; +import org.fusesource.ide.sap.ui.export.SapGlobalConnectionConfigurationWizard; +import org.fusesource.ide.sap.ui.tests.integration.util.FuseProject; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.w3c.dom.Element; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Aurelien Pupier + * + */ +public class SapGlobalConfigurationWizardIT { + + @Rule + public FuseProject fuseProject = new FuseProject(SapGlobalConfigurationWizardIT.class.getSimpleName()); + + @Rule + public TemporaryFolder tmpFolder = new TemporaryFolder(); + + @Test + public void testGeneratesCorrectGlobalNodeForBlueprint() throws Exception { + testGeneratesGlobalNode("blueprintDefault.xml", "expectedSAPBlueprintNode.xml"); + } + + @Test + public void testGeneratesCorrectGlobalNodeForSpring() throws Exception { + testGeneratesGlobalNode("springDefault.xml", "expectedSAPSpringNode.xml"); + } + + /** + * @param initialFileName + * @param expectedNodeFileName + * @throws IOException + * @throws CoreException + * @throws TransformerException + */ + private void testGeneratesGlobalNode(final String initialFileName, final String expectedNodeFileName) throws IOException, CoreException, TransformerException { + CamelFile camelFile = getInitialCamelFile(initialFileName); + SapConnectionConfiguration sapConnectionConfigurationModel = generateSAPConfig(); + + final SapGlobalConnectionConfigurationWizard sapGlobalConnectionConfigurationWizard = new SapGlobalConnectionConfigurationWizard(camelFile); + sapGlobalConnectionConfigurationWizard.setSapConnectionConfigurationModel(sapConnectionConfigurationModel); + sapGlobalConnectionConfigurationWizard.performFinish(); + + assertThat(toString(sapGlobalConnectionConfigurationWizard.getGlobalConfigurationElementNode())).isXmlEqualToContentOf(getFile(expectedNodeFileName)); + } + + public String toString(Element element) throws TransformerException { + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer transformer = tf.newTransformer(); + StringWriter writer = new StringWriter(); + transformer.transform(new DOMSource(element), new StreamResult(writer)); + return writer.getBuffer().toString().replaceAll("\n|\r", ""); + } + + private File getFile(String fileName) { + File tmpFile = null; + try { + tmpFile = File.createTempFile(fileName, ".xml", tmpFolder.getRoot()); + Files.copy(this.getClass().getResourceAsStream("/" + fileName), tmpFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + e.printStackTrace(); + } + return tmpFile; + } + + /** + * @return + */ + private SapConnectionConfiguration generateSAPConfig() { + SapConnectionConfiguration sapConnectionConfigurationModel = RfcFactory.eINSTANCE.createSapConnectionConfiguration(); + DestinationDataStore destinationDataStore = sapConnectionConfigurationModel.getDestinationDataStore(); + DestinationData destinationDataModel = RfcFactory.eINSTANCE.createDestinationData(); + destinationDataModel.setAliasUser("myAliasUser"); + destinationDataStore.getDestinationData().add(destinationDataModel); + destinationDataStore.getEntries().put("destinationDataStoreEntry", destinationDataModel); + return sapConnectionConfigurationModel; + } + + /** + * @return + * @throws IOException + * @throws CoreException + */ + private CamelFile getInitialCamelFile(String name) throws IOException, CoreException { + InputStream inputStream = SapGlobalConfigurationWizardIT.class.getClassLoader().getResourceAsStream("/" + name); + + File baseFile = File.createTempFile("baseFile" + name, "xml"); + Files.copy(inputStream, baseFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + + inputStream = SapGlobalConfigurationWizardIT.class.getClassLoader().getResourceAsStream("/" + name); + IFile fileInProject = fuseProject.getProject().getFile(name); + fileInProject.create(inputStream, true, new NullProgressMonitor()); + + return new CamelIOHandler().loadCamelModel(fileInProject, new NullProgressMonitor()); + } + +} diff --git a/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/java/org/fusesource/ide/sap/ui/tests/integration/util/FuseProject.java b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/java/org/fusesource/ide/sap/ui/tests/integration/util/FuseProject.java new file mode 100644 index 0000000..1049124 --- /dev/null +++ b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/java/org/fusesource/ide/sap/ui/tests/integration/util/FuseProject.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2016 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.fusesource.ide.sap.ui.tests.integration.util; + +import java.io.ByteArrayInputStream; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.junit.rules.ExternalResource; + +/** + * @author Aurelien Pupier + * + */ +public class FuseProject extends ExternalResource { + + private IProject project = null; + private String projectName; + + public FuseProject(String projectName) { + this.projectName = projectName; + } + + @Override + protected void before() throws Throwable { + super.before(); + IWorkspace ws = ResourcesPlugin.getWorkspace(); + project = ws.getRoot().getProject(projectName); + if (!project.exists()) { + project.create(null); + } + if (!project.isOpen()) { + project.open(null); + } + // Create a fake pom.xml + IFile pom = project.getFile("pom.xml"); + pom.create(new ByteArrayInputStream("".getBytes()), true, new NullProgressMonitor()); + } + + @Override + protected void after() { + super.after(); + if (project != null && project.exists()) { + try { + project.delete(true, new NullProgressMonitor()); + } catch (CoreException e) { + e.printStackTrace(); + } + } + } + + public IProject getProject() { + return project; + } + +} diff --git a/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/blueprintDefault.xml b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/blueprintDefault.xml new file mode 100644 index 0000000..7b57b92 --- /dev/null +++ b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/blueprintDefault.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/expectedSAPBlueprintNode.xml b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/expectedSAPBlueprintNode.xml new file mode 100644 index 0000000..7e47b66 --- /dev/null +++ b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/expectedSAPBlueprintNode.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/expectedSAPSpringNode.xml b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/expectedSAPSpringNode.xml new file mode 100644 index 0000000..a3a8f7c --- /dev/null +++ b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/expectedSAPSpringNode.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/springDefault.xml b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/springDefault.xml new file mode 100644 index 0000000..3d3c2dc --- /dev/null +++ b/jboss-fuse-sap-tool-suite/tests/org.fusesource.ide.sap.ui.tests.integration/src/main/resources/springDefault.xml @@ -0,0 +1,5 @@ + + + + diff --git a/jboss-fuse-sap-tool-suite/tests/pom.xml b/jboss-fuse-sap-tool-suite/tests/pom.xml index 4e218a8..2ae34db 100644 --- a/jboss-fuse-sap-tool-suite/tests/pom.xml +++ b/jboss-fuse-sap-tool-suite/tests/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs 4.0.0 org.fusesource.ide - sap + sap 8.0.0-SNAPSHOT @@ -16,6 +16,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs /qa/tools/opt/jdk1.7.0_last + org.fusesource.ide.sap.ui.tests.integration