From 843f2bff08c189bfd1990c947d1bc227ae386632 Mon Sep 17 00:00:00 2001 From: Jeff MAURY Date: Tue, 24 Jan 2017 11:33:24 +0100 Subject: [PATCH] [JBIDE-23724] - Integration tests: move webservices integration tests to jbosstools/webservice repo Signed-off-by: Jeff MAURY --- .../feature.xml | 1 + .../org.jboss.tools.ws.ui.bot.test/.gitignore | 6 + .../META-INF/MANIFEST.MF | 64 +++ .../org.jboss.tools.ws.ui.bot.test/README.md | 61 +++ .../build.properties | 5 + .../launcher/EAPCompAllTests.launch | 43 ++ .../launcher/WSAllBotTests.launch | 50 ++ itests/org.jboss.tools.ws.ui.bot.test/pom.xml | 163 +++++++ .../multiconfig/as7.swtbot.test.properties | 1 + .../multiconfig/eap5.swtbot.test.properties | 1 + .../properties/swtbot.properties | 4 + .../resources/.gitignore | 1 + .../resources/config/WildFly.xml | 17 + .../resources/jbossws/AreaService.wsdl | 44 ++ .../resources/jbossws/AreaWS.java.ws | 13 + .../resources/jbossws/ClassA.java.ws | 14 + .../resources/jbossws/ClassB.wsdl | 45 ++ .../resources/jbossws/Echo.java.ws | 16 + .../resources/jbossws/Person.java.ws | 32 ++ .../resources/jbossws/clientsample.java.ws | 31 ++ .../resources/jbossws/index.jsp.ws | 35 ++ .../resources/jbossws/message_soap12_out.xml | 12 + .../resources/jbossws/message_soap_out.xml | 11 + .../restful/AdvancedRestfulWS.java.ws | 43 ++ .../resources/restful/BasicRestfulWS.java.ws | 32 ++ .../resources/restful/DefaultValue.java.ws | 16 + .../resources/restful/EmptyRestfulWS.java.ws | 9 + .../resources/restful/MatrixParam.java.ws | 16 + .../resources/restful/QueryOneParam.java.ws | 15 + .../resources/restful/QueryTwoParam.java.ws | 16 + .../resources/restful/SimpleRestWS.java.ws | 17 + .../resources/wsdl/imported.wsdl | 23 + .../resources/wsdl/original.wsdl | 89 ++++ .../resources/wsdl/schema.xsd | 31 ++ .../src/log4j.xml | 65 +++ .../jboss/tools/ws/ui/bot/test/Activator.java | 43 ++ .../tools/ws/ui/bot/test/RESTWSBotTests.java | 67 +++ .../tools/ws/ui/bot/test/SOAPWSBotTests.java | 32 ++ .../tools/ws/ui/bot/test/SmokeSuite.java | 18 + .../ws/ui/bot/test/SocketWSBotTests.java | 23 + .../tools/ws/ui/bot/test/WSTestBase.java | 197 ++++++++ .../annotation/AnnotationPropertiesTest.java | 212 +++++++++ .../HTTPMethodAnnotationQuickFixTest.java | 97 ++++ .../ws/ui/bot/test/cxf/CxfWsClientTest.java | 73 +++ .../ws/ui/bot/test/facet/JAXRSFacetTest.java | 135 ++++++ .../JAXRSToolingIntegrationTest.java | 160 +++++++ .../SOAPWSToolingIntegrationTest.java | 109 +++++ .../preferences/JBossWSPreferencesTest.java | 195 ++++++++ .../test/rest/AsYouTypeValidationTest.java | 93 ++++ .../test/rest/CreateJAXRSApplicationTest.java | 306 ++++++++++++ .../test/rest/CreateJAXRSResourceTest.java | 238 ++++++++++ .../rest/FiltersInterceptorsSupportTest.java | 120 +++++ .../NameBindingAnnotationSupportTest.java | 102 ++++ .../PreMatchingAnnotationSupportTest.java | 48 ++ .../ws/ui/bot/test/rest/RESTfulHelper.java | 86 ++++ .../ws/ui/bot/test/rest/RESTfulTestBase.java | 325 +++++++++++++ .../rest/ValidatingRelatedRSElementsTest.java | 45 ++ .../completion/RESTfulCompletionTest.java | 134 ++++++ .../rest/explorer/RESTfulExplorerTest.java | 177 +++++++ .../rest/explorer/RESTfulSupportTest.java | 57 +++ .../param/BeanParamAnnotationSupportTest.java | 256 +++++++++++ .../DefaultValueAnnotationSupportTest.java | 82 ++++ .../MatrixParamAnnotationSupportTest.java | 109 +++++ .../rest/param/ParamConverterSupportTest.java | 93 ++++ .../param/PathParamAnnotationSupportTest.java | 197 ++++++++ .../QueryParamAnnotationSupportTest.java | 134 ++++++ .../validation/ApplicationValidationTest.java | 118 +++++ .../rest/validation/JaxRsValidatorTest.java | 64 +++ .../validation/RESTfulValidationTest.java | 83 ++++ .../test/sample/SampleSoapServicesTest.java | 123 +++++ .../ws/ui/bot/test/soap/SOAPTestBase.java | 118 +++++ .../uiutils/JavaBuildPathPropertiesPage.java | 41 ++ .../ui/bot/test/uiutils/PropertiesDialog.java | 64 +++ .../test/uiutils/RunConfigurationsDialog.java | 56 +++ .../bot/test/uiutils/RunOnServerDialog.java | 64 +++ .../TargetedRuntimesPropertiesPage.java | 51 ++ .../tools/ws/ui/bot/test/utils/Asserts.java | 16 + .../ui/bot/test/utils/DeploymentHelper.java | 135 ++++++ .../ws/ui/bot/test/utils/ProjectHelper.java | 272 +++++++++++ .../ws/ui/bot/test/utils/ResourceHelper.java | 122 +++++ .../ui/bot/test/utils/ServersViewHelper.java | 187 ++++++++ .../test/utils/WebServiceClientHelper.java | 177 +++++++ .../bot/test/webservice/BottomUpWSTest.java | 115 +++++ .../ui/bot/test/webservice/TopDownWSTest.java | 195 ++++++++ .../test/webservice/WebServiceRuntime.java | 23 + .../test/webservice/WebServiceTestBase.java | 196 ++++++++ .../test/webservice/eap/EAPCompAllTests.java | 29 ++ .../test/webservice/eap/EAPFromJavaTest.java | 176 +++++++ .../test/webservice/eap/EAPFromWSDLTest.java | 247 ++++++++++ .../bot/test/websocket/StubMethodsHelper.java | 217 +++++++++ .../bot/test/websocket/StubMethodsTest.java | 122 +++++ .../ws/ui/bot/test/wsclient/WSClient.java | 76 +++ .../test/wsclient/WSClientTestTemplate.java | 199 ++++++++ .../ws/ui/bot/test/wsclient/WsClientTest.java | 29 ++ .../WSTesterPromptValuesSupportTest.java | 210 +++++++++ .../ws/ui/bot/test/wstester/WsTesterTest.java | 435 ++++++++++++++++++ .../test/wstester/XmlJsonFormattingTest.java | 131 ++++++ itests/pom.xml | 40 ++ pom.xml | 1 + 99 files changed, 9137 insertions(+) create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/.gitignore create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/META-INF/MANIFEST.MF create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/README.md create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/build.properties create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/launcher/EAPCompAllTests.launch create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/launcher/WSAllBotTests.launch create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/pom.xml create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/properties/multiconfig/as7.swtbot.test.properties create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/properties/multiconfig/eap5.swtbot.test.properties create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/properties/swtbot.properties create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/.gitignore create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/config/WildFly.xml create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/AreaService.wsdl create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/AreaWS.java.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/ClassA.java.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/ClassB.wsdl create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/Echo.java.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/Person.java.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/clientsample.java.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/index.jsp.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/message_soap12_out.xml create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/message_soap_out.xml create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/restful/AdvancedRestfulWS.java.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/restful/BasicRestfulWS.java.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/restful/DefaultValue.java.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/restful/EmptyRestfulWS.java.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/restful/MatrixParam.java.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/restful/QueryOneParam.java.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/restful/QueryTwoParam.java.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/restful/SimpleRestWS.java.ws create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/wsdl/imported.wsdl create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/wsdl/original.wsdl create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/resources/wsdl/schema.xsd create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/log4j.xml create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/Activator.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/RESTWSBotTests.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SOAPWSBotTests.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SmokeSuite.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SocketWSBotTests.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/WSTestBase.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/annotation/AnnotationPropertiesTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/annotation/HTTPMethodAnnotationQuickFixTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/cxf/CxfWsClientTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/facet/JAXRSFacetTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/integration/JAXRSToolingIntegrationTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/integration/SOAPWSToolingIntegrationTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/preferences/JBossWSPreferencesTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/AsYouTypeValidationTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/CreateJAXRSApplicationTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/CreateJAXRSResourceTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/FiltersInterceptorsSupportTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/NameBindingAnnotationSupportTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/PreMatchingAnnotationSupportTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/RESTfulHelper.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/RESTfulTestBase.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/ValidatingRelatedRSElementsTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/completion/RESTfulCompletionTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/explorer/RESTfulExplorerTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/explorer/RESTfulSupportTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/BeanParamAnnotationSupportTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/DefaultValueAnnotationSupportTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/MatrixParamAnnotationSupportTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/ParamConverterSupportTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/PathParamAnnotationSupportTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/QueryParamAnnotationSupportTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/validation/ApplicationValidationTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/validation/JaxRsValidatorTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/validation/RESTfulValidationTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/sample/SampleSoapServicesTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/soap/SOAPTestBase.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/JavaBuildPathPropertiesPage.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/PropertiesDialog.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/RunConfigurationsDialog.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/RunOnServerDialog.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/TargetedRuntimesPropertiesPage.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/Asserts.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/DeploymentHelper.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/ProjectHelper.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/ResourceHelper.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/ServersViewHelper.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/WebServiceClientHelper.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/BottomUpWSTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/TopDownWSTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/WebServiceRuntime.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/WebServiceTestBase.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/eap/EAPCompAllTests.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/eap/EAPFromJavaTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/eap/EAPFromWSDLTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/websocket/StubMethodsHelper.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/websocket/StubMethodsTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wsclient/WSClient.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wsclient/WSClientTestTemplate.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wsclient/WsClientTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wstester/WSTesterPromptValuesSupportTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wstester/WsTesterTest.java create mode 100644 itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wstester/XmlJsonFormattingTest.java create mode 100644 itests/pom.xml diff --git a/features/org.jboss.tools.ws.test.feature/feature.xml b/features/org.jboss.tools.ws.test.feature/feature.xml index 1995453ce..f363abbfe 100644 --- a/features/org.jboss.tools.ws.test.feature/feature.xml +++ b/features/org.jboss.tools.ws.test.feature/feature.xml @@ -28,6 +28,7 @@ + diff --git a/itests/org.jboss.tools.ws.ui.bot.test/.gitignore b/itests/org.jboss.tools.ws.ui.bot.test/.gitignore new file mode 100644 index 000000000..1473c30f7 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/.gitignore @@ -0,0 +1,6 @@ +screenshots/ +target/ +bin/ +/.classpath +/.project +.settings/ \ No newline at end of file diff --git a/itests/org.jboss.tools.ws.ui.bot.test/META-INF/MANIFEST.MF b/itests/org.jboss.tools.ws.ui.bot.test/META-INF/MANIFEST.MF new file mode 100644 index 000000000..5dea6bd11 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/META-INF/MANIFEST.MF @@ -0,0 +1,64 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Webservices UI Bot Tests +Bundle-SymbolicName: org.jboss.tools.ws.ui.bot.test +Bundle-Version: 1.9.3.qualifier +Bundle-Activator: org.jboss.tools.ws.ui.bot.test.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.apache.log4j;bundle-version="1.2.13", + org.jboss.reddeer.go;bundle-version="[1.2.0,2.0.0)", + org.jboss.tools.ws.reddeer;bundle-version="1.9.3", + org.eclipse.jdt.ui, + org.eclipse.ui.ide;bundle-version="3.5.1", + org.eclipse.ui.forms;bundle-version="3.4.1", + org.junit;bundle-version="4.5.0", + org.eclipse.core.resources, + org.jboss.tools.ws.ui;bundle-version="1.1.0", + org.eclipse.wst.common.project.facet.core, + org.hamcrest.core;bundle-version="1.3.0", + org.eclipse.jst.ws.jaxws.ui, + org.eclipse.jst.ws.cxf.ui;bundle-version="1.0.200", + org.hamcrest.core;bundle-version="1.3.0", + org.jboss.tools.common.reddeer, + org.eclipse.wst.server.ui, + org.jboss.ide.eclipse.as.ui, + org.eclipse.jst.servlet.ui, + org.eclipse.jst.ws.creation.ui, + org.eclipse.jst.ws.uddiregistry, + org.jboss.tools.ws.creation.ui, + org.eclipse.wst.wsdl.ui, + org.eclipse.jst.ws.axis.creation.ui, + org.eclipse.jst.ws.cxf.creation.ui, + org.eclipse.jst.ws.jaxrs.ui, + org.jboss.tools.ws.jaxrs.ui, + org.eclipse.wst.jsdt.web.ui, + org.jboss.ide.eclipse.as.ui, + org.jboss.ide.eclipse.as.classpath.ui +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Eclipse-RegisterBuddy: org.apache.log4j +Bundle-ClassPath: . +Export-Package: org.jboss.tools.ws.ui.bot.test; + uses:="org.eclipse.ui.plugin, + org.eclipse.swtbot.eclipse.finder, + javax.xml.namespace, + junit.framework, + org.eclipse.core.resources, + org.jboss.tools.ui.bot.ext, + org.osgi.framework, + org.jboss.tools.ws.ui.bot.test.uiutils.wizards", + org.jboss.tools.ws.ui.bot.test.webservice.eap +Eclipse-BundleShape: jar +Bundle-Localization: plugin +Bundle-Vendor: JBoss by Red Hat +Import-Package: org.jboss.ide.eclipse.as.reddeer.server.requirement, + org.jboss.reddeer.junit.requirement.inject, + org.jboss.reddeer.junit.runner, + org.jboss.reddeer.requirements.openperspective, + org.jboss.reddeer.requirements.server, + org.jboss.tools.common.reddeer.requirements, + org.jboss.tools.ws.reddeer.ui.dialogs, + org.jboss.tools.ws.reddeer.ui.preferences, + org.jboss.tools.ws.reddeer.ui.tester.views, + org.apache.commons.lang diff --git a/itests/org.jboss.tools.ws.ui.bot.test/README.md b/itests/org.jboss.tools.ws.ui.bot.test/README.md new file mode 100644 index 000000000..22587804f --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/README.md @@ -0,0 +1,61 @@ +# JBoss Tools WebServices UI Bot Tests +### Using ** Maven ** + + 1. get jbosstools-integration-tests ``` $ git clone https://github.com/jbosstools/jbosstools-integration-tests.git ``` + + 2. run (all required plugins, files and also the server will be downloaded) ``` $ mvn clean verify -Dswtbot.test.skip=false``` + + +### Tests execution from ** Eclipse ** + + +0. Get prerequisites: + - JBoss server: WildFly, JBoss AS 7 or JBoss EAP 6 - setup RedDeer xml config file (see https://github.com/jboss-reddeer/reddeer/wiki/Write-complex-requirement-with-own-schema) e.g. WildFly config file +``` + + + + + + + + + /path/to/wildfly + + + +``` + + - projects used to test some features: download from maven repo + JBoss Tools Experiments/org/jboss/tools/ws/tests/org.jboss.tools.ws.ui.bot.test.resources.projects + https://repository.jboss.org/nexus/index.html#view-repositories;jbosstools-experiments~browseindex + - Apache CXF 2.x - create ws.properties file in directory {project_location}/properties with property ``` apache-cxf-2.x={apache-cxf-2.x-path} ``` + +1. Download tests and required plugins: + - get jbosstools-integration-tests ``` $ git clone https://github.com/jbosstools/jbosstools-integration-tests.git ``` + - get Red Deer ``` $ git clone https://github.com/jboss-reddeer/reddeer ``` + +2. ** Now run eclipse in a new workspace (e.g. ~/jbds_test_workspace_ws) ** + +3. Import projects (File > Import... > Existing Projects into workspace) + - import WebServices tests - jbosstools-integration-tests/tests/org.jboss.tools.ws.ui.bot.test + - import plugins org.jboss.tools.ws.reddeer and org.jboss.ide.eclipse.as.reddeer + from directory jbosstools-integration-tests/plugins/ + - import all Red Deer plugins from directory reddeer/plugins/ + + +4. Install RedDeer + - in eclipse open Install dialog (Help > Install New Software...) and install everything from + http://download.jboss.org/jbosstools/builds/staging/RedDeer_master/all/repo/ + (see https://github.com/jboss-reddeer/reddeer/wiki/Installation) + +5. Run with VM arguments: + - to set server configuration```-Drd.config=/path/to/wildfly.xml``` + - to close Usage reporting dialog ```-Dusage_reporting_enabled=false``` + +6. Enjoy testing :) diff --git a/itests/org.jboss.tools.ws.ui.bot.test/build.properties b/itests/org.jboss.tools.ws.ui.bot.test/build.properties new file mode 100644 index 000000000..990eb12b0 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + resources/,\ + . diff --git a/itests/org.jboss.tools.ws.ui.bot.test/launcher/EAPCompAllTests.launch b/itests/org.jboss.tools.ws.ui.bot.test/launcher/EAPCompAllTests.launch new file mode 100644 index 000000000..5a5376419 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/launcher/EAPCompAllTests.launch @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/itests/org.jboss.tools.ws.ui.bot.test/launcher/WSAllBotTests.launch b/itests/org.jboss.tools.ws.ui.bot.test/launcher/WSAllBotTests.launch new file mode 100644 index 000000000..8723ba306 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/launcher/WSAllBotTests.launch @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/itests/org.jboss.tools.ws.ui.bot.test/pom.xml b/itests/org.jboss.tools.ws.ui.bot.test/pom.xml new file mode 100644 index 000000000..0e33440ee --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/pom.xml @@ -0,0 +1,163 @@ + + + + 4.0.0 + + org.jboss.tools.ws + itests + 1.9.3-SNAPSHOT + + org.jboss.tools.ws.itests + org.jboss.tools.ws.ui.bot.test + eclipse-test-plugin + + ${project.build.outputDirectory}/config + ${project.build.directory}/requirements + ${requirementsDirectory}/wildfly-10.0.0.Final + + ${requirementsDirectory}/apache-cxf-2.x + ${apache-cxf-2.x.dir}/apache-cxf-3.1.1/ + http://archive.apache.org/dist/cxf/3.1.1/apache-cxf-3.1.1.zip + 142d0261de8012e6eafd780587313681 + + ${integrationTestsSystemProperties} -Dws.scope=${ws.scope} -Dapache-cxf-2.x=${apache-cxf-2.x} -Drd.config=${rd.config} -Djbosstools.test.jboss-wildfly-10.home=${jbosstools.test.jboss-wildfly-10.home} -Dreddeer.close.shells=false + 10800 + + + + + jax-ws + + + ws.scope + SOAP + + + + + + + com.googlecode.maven-download-plugin + download-maven-plugin + + + install-apache-cxf-2.x + pre-integration-test + + wget + + + ${apache-cxf-2.x.url} + true + ${apache-cxf-2.x.md5} + ${apache-cxf-2.x.dir} + ${skipITests} + + + + + + + + + check-pr + + + + org.eclipse.tycho + target-platform-configuration + + + + + p2-installable-unit + org.jboss.tools.ws.feature.feature.group + 0.0.0 + + + p2-installable-unit + org.jboss.tools.ws.jaxrs.feature.feature.group + 0.0.0 + + + + + + + + + + + + + jbosstools-experiments + https://repository.jboss.org/nexus/content/repositories/jbosstools-experiments/ + + + + + + resources + + config/* + + true + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack-projects + pre-integration-test + + unpack + + + ${skipITests} + + + org.jboss.tools.ws.tests + org.jboss.tools.ws.ui.bot.test.resources.projects + 4.2.0 + zip + + + ${basedir}/resources/ + + + + unpack-server + pre-integration-test + + unpack + + + ${skipITests} + + + org.wildfly + wildfly-dist + 10.0.0.Final + zip + + + + + + + + org.eclipse.tycho + tycho-surefire-plugin + + org.jboss.tools.ws.ui.bot.test + org.jboss.tools.ws.ui.bot.test.${ws.scope}WSBotTests + + + + + diff --git a/itests/org.jboss.tools.ws.ui.bot.test/properties/multiconfig/as7.swtbot.test.properties b/itests/org.jboss.tools.ws.ui.bot.test/properties/multiconfig/as7.swtbot.test.properties new file mode 100644 index 000000000..5edb872a3 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/properties/multiconfig/as7.swtbot.test.properties @@ -0,0 +1 @@ +SERVER=AS,7.0,default,/home/jjankovi/Dokumenty/Red_Hat_Stuff/Runtimes/jboss-as-7.0.1.Final diff --git a/itests/org.jboss.tools.ws.ui.bot.test/properties/multiconfig/eap5.swtbot.test.properties b/itests/org.jboss.tools.ws.ui.bot.test/properties/multiconfig/eap5.swtbot.test.properties new file mode 100644 index 000000000..19149b969 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/properties/multiconfig/eap5.swtbot.test.properties @@ -0,0 +1 @@ +SERVER=EAP,5.1,default,/home/jjankovi/Dokumenty/Red_Hat_Stuff/Runtimes/jboss-eap-5.1/jboss-as diff --git a/itests/org.jboss.tools.ws.ui.bot.test/properties/swtbot.properties b/itests/org.jboss.tools.ws.ui.bot.test/properties/swtbot.properties new file mode 100644 index 000000000..ca1191536 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/properties/swtbot.properties @@ -0,0 +1,4 @@ +#SERVER=AS,6.0,default,../../../requirements/target/jboss-6.0.0.Final +#SERVER=AS,7.0,default,../../../requirements/target/jboss-as-web-7.0.2.Final +#SERVER=AS,7.1,default,target/requirements/jboss-as-7.1.1.Final +SERVER=WILDFLY,8.1,default,target/requirements/wildfly-8.1.0.Final diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/.gitignore b/itests/org.jboss.tools.ws.ui.bot.test/resources/.gitignore new file mode 100644 index 000000000..83a372078 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/.gitignore @@ -0,0 +1 @@ +/projects/ diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/config/WildFly.xml b/itests/org.jboss.tools.ws.ui.bot.test/resources/config/WildFly.xml new file mode 100644 index 000000000..963c5855b --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/config/WildFly.xml @@ -0,0 +1,17 @@ + + + + + + + + + ${jbosstools.test.jboss-wildfly-10.home} + + + \ No newline at end of file diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/AreaService.wsdl b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/AreaService.wsdl new file mode 100644 index 000000000..7846bdef3 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/AreaService.wsdl @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/AreaWS.java.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/AreaWS.java.ws new file mode 100644 index 000000000..a721c60e9 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/AreaWS.java.ws @@ -0,0 +1,13 @@ +package org.jboss.ws.impl; + +import javax.jws.WebService; +import org.jboss.ws.AreaService; +import org.jboss.ws.Dimensions; + +@WebService(serviceName = "AreaService", + endpointInterface = "org.jboss.ws.AreaService") +public class AreaServiceImpl implements AreaService { + public float calculateRectArea(Dimensions parameters) { + return parameters.getHeight() * parameters.getWidth(); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/ClassA.java.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/ClassA.java.ws new file mode 100644 index 000000000..e84ac166f --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/ClassA.java.ws @@ -0,0 +1,14 @@ +package {0}; + +import javax.jws.WebMethod; +import javax.jws.WebService; + +@WebService() +public class {1} '{' + + @WebMethod() + public String method() '{' + System.out.println({1}.class.getName() + " Service: method() was called"); + return "{0}.{1}"; + '}' +'}' diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/ClassB.wsdl b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/ClassB.wsdl new file mode 100644 index 000000000..252b64976 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/ClassB.wsdl @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/Echo.java.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/Echo.java.ws new file mode 100644 index 000000000..b95fc8545 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/Echo.java.ws @@ -0,0 +1,16 @@ +package {0}; + +import javax.jws.WebService; +import test.Person; + +@WebService +public class {1} '{' + + public Person echo(Person p) '{' + return p; + '}' + + public Person test() '{' + return new Person(); + '}' +'}' diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/Person.java.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/Person.java.ws new file mode 100644 index 000000000..7bc9c34c8 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/Person.java.ws @@ -0,0 +1,32 @@ +package test; + +public class Person { + + private String login; + private int age; + + public Person() { + this("BartSimpson", 12); + } + + public Person(String login, int age) { + this.login = login; + this.age = age; + } + + public String getLogin() { + return login; + } + + public void setLogin(String login) { + this.login = login; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/clientsample.java.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/clientsample.java.ws new file mode 100644 index 000000000..578495d66 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/clientsample.java.ws @@ -0,0 +1,31 @@ +package org.jboss.wsclient.clientsample; + +import org.jboss.wsclient.*; + +public class ClientSample { + + public static void main(String[] args) { + System.out.println("***********************"); + System.out.println("Create Web Service Client..."); + AreaService_Service service1 = new AreaService_Service(); + System.out.println("Create Web Service..."); + AreaService port1 = service1.getAreaServiceImplPort(); + Dimensions d1 = new Dimensions(); + d1.setHeight(5); + d1.setWidth(7.5f); + System.out.println("Call Web Service Operation..."); + System.out.println( + "Server said: " + port1.calculateRectArea(d1)); + + System.out.println("Create Web Service..."); + AreaService port2 = service1.getAreaServiceImplPort(); + Dimensions d2 = new Dimensions(); + d2.setHeight(362.1f); + d2.setWidth(9.7f); + System.out.println("Call Web Service Operation..."); + System.out.println( + "Server said: " + port2.calculateRectArea(d2)); + System.out.println("***********************"); + System.out.println("Call Over!"); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/index.jsp.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/index.jsp.ws new file mode 100644 index 000000000..90f75848a --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/index.jsp.ws @@ -0,0 +1,35 @@ +<%@page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@page import="test.ws.EchoService"%> +<%@page import="test.ws.Echo"%> +<%@page import="test.ws.Person"%> + + + + Web service client... + + +

operation "test()": + <%=personToString(getPort().test())%>

+

operation "echo(Person("Homer", 44)": + <%=personToString(getPort().echo(getHomer()))%>

+ + + +<%! + private Echo getPort() { + EchoService service1 = new EchoService(); + return service1.getEchoPort(); + } + + private String personToString(Person p) { + return p.getLogin() + "(age: " + p.getAge() + ")"; + } + + private Person getHomer() { + Person homer = new Person(); + homer.setLogin("Homer"); + homer.setAge(44); + return homer; + } +%> diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/message_soap12_out.xml b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/message_soap12_out.xml new file mode 100644 index 000000000..3fc595a94 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/message_soap12_out.xml @@ -0,0 +1,12 @@ + + + + + Mark + 1 + 1 + + + diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/message_soap_out.xml b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/message_soap_out.xml new file mode 100644 index 000000000..667754cb2 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/jbossws/message_soap_out.xml @@ -0,0 +1,11 @@ + + + + + Mark + 1 + 1 + + + diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/AdvancedRestfulWS.java.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/AdvancedRestfulWS.java.ws new file mode 100644 index 000000000..10e41f244 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/AdvancedRestfulWS.java.ws @@ -0,0 +1,43 @@ +package {0}; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + + +@Path("/rest") +public class {1} '{' + + @GET + @Path("/'{'id'}'") + @Produces("text/plain") + public String getMessage(@PathParam("id") int id) '{' + return null; + '}' + + @DELETE + @Path("/delete/'{'id'}'") + public void deleteMesage(@PathParam("id") int id) '{' + //do nothing + '}' + + @PUT + @Path("/put/'{'id'}'") + @Consumes("text/plain") + public void addMessage(@PathParam("id") int id) '{' + //do nothing + '}' + + @POST + @Path("/post/'{'id'}'") + @Consumes("text/plain") + @Produces("text/plain") + public String editMessage(@PathParam("id") int id) '{' + return null; + '}' +'}' diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/BasicRestfulWS.java.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/BasicRestfulWS.java.ws new file mode 100644 index 000000000..6d0089eed --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/BasicRestfulWS.java.ws @@ -0,0 +1,32 @@ +package {0}; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; + + +@Path("/rest") +public class {1} '{' + + @GET + public String getMessage() '{' + return null; + '}' + + @DELETE + public void deleteMesage() '{' + //do nothing + '}' + + @PUT + public void addMessage() '{' + //do nothing + '}' + + @POST + public String editMessage() '{' + return null; + '}' +'}' diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/DefaultValue.java.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/DefaultValue.java.ws new file mode 100644 index 000000000..959b43871 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/DefaultValue.java.ws @@ -0,0 +1,16 @@ +package {0}; + +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +@Path("/rest") +public class {1} '{' + + @GET + public void method(@QueryParam("{2}") @DefaultValue("{3}") {4} parameter) '{' + + '}' + +'}' diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/EmptyRestfulWS.java.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/EmptyRestfulWS.java.ws new file mode 100644 index 000000000..b9ddd09fb --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/EmptyRestfulWS.java.ws @@ -0,0 +1,9 @@ +package {0}; + +import javax.ws.rs.Path; + + +@Path("/rest") +public class {1} '{' + +'}' diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/MatrixParam.java.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/MatrixParam.java.ws new file mode 100644 index 000000000..e75ac1cab --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/MatrixParam.java.ws @@ -0,0 +1,16 @@ +package {0}; + +import javax.ws.rs.GET; +import javax.ws.rs.MatrixParam; +import javax.ws.rs.Path; + +@Path("/rest") +public class {1} '{' + + @GET + public void getBooks(@MatrixParam("{2}") {3} param1, + @MatrixParam("{4}") {5} param2) '{' + + '}' + +'}' diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/QueryOneParam.java.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/QueryOneParam.java.ws new file mode 100644 index 000000000..806a43f4d --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/QueryOneParam.java.ws @@ -0,0 +1,15 @@ +package {0}; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +@Path("/rest") +public class {1} '{' + + @GET + public void method(@QueryParam("{2}") {3} parameter) '{' + + '}' + +'}' diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/QueryTwoParam.java.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/QueryTwoParam.java.ws new file mode 100644 index 000000000..4d7b89db2 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/QueryTwoParam.java.ws @@ -0,0 +1,16 @@ +package {0}; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +@Path("/rest") +public class {1} '{' + + @GET + public void method(@QueryParam("{2}") {3} parameter1, + @QueryParam("{4}") {5} parameter2) '{' + + '}' + +'}' diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/SimpleRestWS.java.ws b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/SimpleRestWS.java.ws new file mode 100644 index 000000000..dc9dd839b --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/restful/SimpleRestWS.java.ws @@ -0,0 +1,17 @@ +package {0}; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + + +@Path("/rest") +public class {1} '{' + + @GET + @Path("{2}") + public String getMessage(@PathParam("{3}") int id) '{' + return null; + '}' + +'}' diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/wsdl/imported.wsdl b/itests/org.jboss.tools.ws.ui.bot.test/resources/wsdl/imported.wsdl new file mode 100644 index 000000000..415245070 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/wsdl/imported.wsdl @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/wsdl/original.wsdl b/itests/org.jboss.tools.ws.ui.bot.test/resources/wsdl/original.wsdl new file mode 100644 index 000000000..a0c4470cc --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/wsdl/original.wsdl @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/itests/org.jboss.tools.ws.ui.bot.test/resources/wsdl/schema.xsd b/itests/org.jboss.tools.ws.ui.bot.test/resources/wsdl/schema.xsd new file mode 100644 index 000000000..a62bd9b78 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/resources/wsdl/schema.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/log4j.xml b/itests/org.jboss.tools.ws.ui.bot.test/src/log4j.xml new file mode 100644 index 000000000..df8353954 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/log4j.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/Activator.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/Activator.java new file mode 100644 index 000000000..4b37e73d4 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/Activator.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2010 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.jboss.tools.ws.ui.bot.test; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + private static BundleContext context; + + // The plug-in ID + public static final String PLUGIN_ID = "org.jboss.tools.ws.ui.bot.test"; + + static BundleContext getContext() { + return context; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext bundleContext) throws Exception { + Activator.context = bundleContext; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext bundleContext) throws Exception { + Activator.context = null; + } + +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/RESTWSBotTests.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/RESTWSBotTests.java new file mode 100644 index 000000000..c7f2d2a88 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/RESTWSBotTests.java @@ -0,0 +1,67 @@ +package org.jboss.tools.ws.ui.bot.test; + +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.tools.ws.ui.bot.test.annotation.AnnotationPropertiesTest; +import org.jboss.tools.ws.ui.bot.test.annotation.HTTPMethodAnnotationQuickFixTest; +import org.jboss.tools.ws.ui.bot.test.facet.JAXRSFacetTest; +import org.jboss.tools.ws.ui.bot.test.integration.JAXRSToolingIntegrationTest; +import org.jboss.tools.ws.ui.bot.test.preferences.JBossWSPreferencesTest; +import org.jboss.tools.ws.ui.bot.test.rest.AsYouTypeValidationTest; +import org.jboss.tools.ws.ui.bot.test.rest.CreateJAXRSApplicationTest; +import org.jboss.tools.ws.ui.bot.test.rest.CreateJAXRSResourceTest; +import org.jboss.tools.ws.ui.bot.test.rest.FiltersInterceptorsSupportTest; +import org.jboss.tools.ws.ui.bot.test.rest.NameBindingAnnotationSupportTest; +import org.jboss.tools.ws.ui.bot.test.rest.PreMatchingAnnotationSupportTest; +import org.jboss.tools.ws.ui.bot.test.rest.ValidatingRelatedRSElementsTest; +import org.jboss.tools.ws.ui.bot.test.rest.completion.RESTfulCompletionTest; +import org.jboss.tools.ws.ui.bot.test.rest.explorer.RESTfulExplorerTest; +import org.jboss.tools.ws.ui.bot.test.rest.explorer.RESTfulSupportTest; +import org.jboss.tools.ws.ui.bot.test.rest.param.BeanParamAnnotationSupportTest; +import org.jboss.tools.ws.ui.bot.test.rest.param.DefaultValueAnnotationSupportTest; +import org.jboss.tools.ws.ui.bot.test.rest.param.MatrixParamAnnotationSupportTest; +import org.jboss.tools.ws.ui.bot.test.rest.param.ParamConverterSupportTest; +import org.jboss.tools.ws.ui.bot.test.rest.param.PathParamAnnotationSupportTest; +import org.jboss.tools.ws.ui.bot.test.rest.param.QueryParamAnnotationSupportTest; +import org.jboss.tools.ws.ui.bot.test.rest.validation.ApplicationValidationTest; +import org.jboss.tools.ws.ui.bot.test.rest.validation.JaxRsValidatorTest; +import org.jboss.tools.ws.ui.bot.test.rest.validation.RESTfulValidationTest; +import org.jboss.tools.ws.ui.bot.test.wstester.WSTesterPromptValuesSupportTest; +import org.jboss.tools.ws.ui.bot.test.wstester.XmlJsonFormattingTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(RedDeerSuite.class) +@SuiteClasses({ + JBossWSPreferencesTest.class, + JAXRSFacetTest.class, + CreateJAXRSApplicationTest.class, + CreateJAXRSResourceTest.class, + AnnotationPropertiesTest.class, + RESTfulSupportTest.class, + RESTfulExplorerTest.class, + PathParamAnnotationSupportTest.class, + QueryParamAnnotationSupportTest.class, + MatrixParamAnnotationSupportTest.class, + DefaultValueAnnotationSupportTest.class, + + //Automatic project build gets stuck, build projects manually + BeanParamAnnotationSupportTest.class, + RESTfulValidationTest.class, + HTTPMethodAnnotationQuickFixTest.class, + FiltersInterceptorsSupportTest.class, + NameBindingAnnotationSupportTest.class, + ValidatingRelatedRSElementsTest.class, + ApplicationValidationTest.class, + JaxRsValidatorTest.class, + ParamConverterSupportTest.class, + PreMatchingAnnotationSupportTest.class, + + RESTfulCompletionTest.class, + AsYouTypeValidationTest.class, + WSTesterPromptValuesSupportTest.class, + XmlJsonFormattingTest.class, + JAXRSToolingIntegrationTest.class, +}) +public class RESTWSBotTests { + +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SOAPWSBotTests.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SOAPWSBotTests.java new file mode 100644 index 000000000..6b1f1a3a9 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SOAPWSBotTests.java @@ -0,0 +1,32 @@ +package org.jboss.tools.ws.ui.bot.test; + +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.tools.ws.ui.bot.test.cxf.CxfWsClientTest; +import org.jboss.tools.ws.ui.bot.test.integration.SOAPWSToolingIntegrationTest; +import org.jboss.tools.ws.ui.bot.test.sample.SampleSoapServicesTest; +import org.jboss.tools.ws.ui.bot.test.webservice.BottomUpWSTest; +import org.jboss.tools.ws.ui.bot.test.webservice.TopDownWSTest; +import org.jboss.tools.ws.ui.bot.test.wsclient.WsClientTest; +import org.jboss.tools.ws.ui.bot.test.wstester.WsTesterTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; + +/** + * Complete test suite for SOAP web services + * + * @author Jan Richter + * + */ +@RunWith(RedDeerSuite.class) +@SuiteClasses({ + SampleSoapServicesTest.class, + SOAPWSToolingIntegrationTest.class, + BottomUpWSTest.class, + TopDownWSTest.class, + WsClientTest.class, + WsTesterTest.class, + CxfWsClientTest.class +}) +public class SOAPWSBotTests { + +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SmokeSuite.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SmokeSuite.java new file mode 100644 index 000000000..2d057a643 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SmokeSuite.java @@ -0,0 +1,18 @@ +package org.jboss.tools.ws.ui.bot.test; + +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.tools.ws.ui.bot.test.preferences.JBossWSPreferencesTest; +import org.jboss.tools.ws.ui.bot.test.rest.explorer.RESTfulSupportTest; +import org.jboss.tools.ws.ui.bot.test.sample.SampleSoapServicesTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; + +@SuiteClasses({ + SampleSoapServicesTest.class, + JBossWSPreferencesTest.class, + RESTfulSupportTest.class, +}) +@RunWith(RedDeerSuite.class) +public class SmokeSuite { + +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SocketWSBotTests.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SocketWSBotTests.java new file mode 100644 index 000000000..b315df4dd --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SocketWSBotTests.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2017 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 + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.ws.ui.bot.test; + +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.tools.ws.ui.bot.test.websocket.StubMethodsTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(RedDeerSuite.class) +@SuiteClasses({ + StubMethodsTest.class, +}) +public class SocketWSBotTests { +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/WSTestBase.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/WSTestBase.java new file mode 100644 index 000000000..f0db700e5 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/WSTestBase.java @@ -0,0 +1,197 @@ +/******************************************************************************* + * Copyright (c) 2010-2011 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.jboss.tools.ws.ui.bot.test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; +import java.util.logging.Logger; + +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.common.wait.AbstractWait; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.core.matcher.WithTextMatcher; +import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; +import org.jboss.reddeer.eclipse.ui.console.ConsoleView; +import org.jboss.reddeer.eclipse.ui.perspectives.JavaEEPerspective; +import org.jboss.reddeer.eclipse.ui.wizards.datatransfer.ExternalProjectImportWizardDialog; +import org.jboss.reddeer.eclipse.ui.wizards.datatransfer.WizardProjectsImportPage; +import org.jboss.reddeer.junit.requirement.inject.InjectRequirement; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.openperspective.OpenPerspectiveRequirement.OpenPerspective; +import org.jboss.reddeer.swt.impl.button.PushButton; +import org.jboss.reddeer.swt.impl.button.RadioButton; +import org.jboss.reddeer.swt.impl.ctab.DefaultCTabItem; +import org.jboss.reddeer.swt.impl.menu.ShellMenu; +import org.jboss.reddeer.swt.impl.shell.DefaultShell; +import org.jboss.reddeer.workbench.impl.shell.WorkbenchShell; +import org.jboss.tools.common.reddeer.label.IDELabel; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ServersViewHelper; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.runner.RunWith; + +/** + * Basic test base for all web service bot tests + * + * @author jjankovi + * + */ +@RunWith(RedDeerSuite.class) +@OpenPerspective(JavaEEPerspective.class) +@JBossServer() +public class WSTestBase { + + @InjectRequirement + private static ServerRequirement serverReq; + + private String wsProjectName = null; + + protected static final Logger LOGGER = Logger.getLogger(WSTestBase.class + .getName()); + + protected final String LINE_SEPARATOR = System + .getProperty("line.separator"); + + @Before + public void setup() { + if (getEarProjectName() != null && !ProjectHelper.projectExists(getEarProjectName())) { + ProjectHelper.createEARProject(getEarProjectName()); + if (!ProjectHelper.projectExists(getWsProjectName())) { + ProjectHelper.createProjectForEAR(getWsProjectName(), + getEarProjectName()); + } + } + if (!ProjectHelper.projectExists(getWsProjectName())) { + ProjectHelper.createProject(getWsProjectName()); + } + } + + @After + public void cleanup() { + ConsoleView consoleView = new ConsoleView(); + if (consoleView.isOpened()) { + consoleView.clearConsole(); + } + } + + @AfterClass + public static void deleteAll() { + deleteAllProjectsFromServer(); + deleteAllProjects(); + } + + protected static String getConfiguredRuntimeName() { + return serverReq.getRuntimeNameLabelText(serverReq.getConfig()); + } + + protected static String getConfiguredServerName() { + return serverReq.getServerNameLabelText(serverReq.getConfig()); + } + + protected static String getConfiguredServerType() { + return serverReq.getConfig().getServerFamily().getLabel(); + } + + protected static String getConfiguredServerVersion() { + return serverReq.getConfig().getServerFamily().getVersion(); + } + + protected boolean projectExists(String name) { + ProjectExplorer projectExplorer = new ProjectExplorer(); + projectExplorer.open(); + return projectExplorer.containsProject(name); + } + + protected static void deleteAllProjects() { + ProjectHelper.deleteAllProjects(); + } + + protected static void deleteAllProjectsFromServer() { + ServersViewHelper.removeAllProjectsFromServer(getConfiguredServerName()); + } + + protected void openJavaFile(String projectName, String pkgName, String javaFileName) { + new ProjectExplorer().getProject(projectName) + .getProjectItem("Java Resources", "src", pkgName, javaFileName).open(); + } + + protected String getWsProjectName() { + return wsProjectName; + } + + protected void setWsProjectName(String wsProjectName) { + this.wsProjectName = wsProjectName; + } + + protected String getEarProjectName() { + return null; + } + + protected String getWsPackage() { + return null; + } + + protected String getWsName() { + return null; + } + + protected void assertWebServiceTesterIsActive() { + assertTrue("Web Service Tester view should be active", + new DefaultCTabItem(new WorkbenchShell(), + new WithTextMatcher(IDELabel.View.WEB_SERVICE_TESTER)).isEnabled()); + } + + protected static void importWSTestProject(String projectName) { + try { + importProject(new File("resources/projects/" + projectName).getCanonicalPath()); + } catch(IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + ProjectHelper.addConfiguredRuntimeIntoProject(projectName, getConfiguredRuntimeName()); + ProjectHelper.setProjectJRE(projectName); + cleanAllProjects(); + AbstractWait.sleep(TimePeriod.getCustom(2)); + } + + private static void importProject(String projectLocation) { + ExternalProjectImportWizardDialog importDialog = new ExternalProjectImportWizardDialog(); + importDialog.open(); + WizardProjectsImportPage importPage = new WizardProjectsImportPage(); + importPage.setRootDirectory(projectLocation); + assertFalse("There is no project to import", importPage.getProjects().isEmpty()); + importPage.selectAllProjects(); + importPage.copyProjectsIntoWorkspace(true); + importDialog.finish(); + } + + /** + * Cleans All Projects + */ + protected static void cleanAllProjects() { + new WaitWhile(new JobIsRunning()); + new ShellMenu(IDELabel.Menu.PROJECT, "Clean...").select(); + new DefaultShell("Clean"); + new RadioButton("Clean all projects").click(); + new PushButton(IDELabel.Button.OK).click(); + new WaitWhile(new JobIsRunning(), TimePeriod.LONG, false); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/annotation/AnnotationPropertiesTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/annotation/AnnotationPropertiesTest.java new file mode 100644 index 000000000..fd7584388 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/annotation/AnnotationPropertiesTest.java @@ -0,0 +1,212 @@ +/******************************************************************************* + * Copyright (c) 2010-2011 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.jboss.tools.ws.ui.bot.test.annotation; + +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.List; + +import org.hamcrest.core.Is; +import org.hamcrest.core.IsNot; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.swt.api.TreeItem; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebService; +import org.jboss.tools.ws.reddeer.ui.views.AnnotationPropertiesView; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.Asserts; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Checks behaviour of AnnotationProperties view and its + * impact on JAX-RS explorer + * + * @author jjankovi + * + * Also improve tests (mainly testAbsenceOfAnnotation() and testPresenceOfAnnotation()) + * + */ +@RunWith(RedDeerSuite.class) +public class AnnotationPropertiesTest extends RESTfulTestBase { + + @Override + public String getWsProjectName() { + return "restAdvanced"; + } + + @Override + public void setup() { + importWSTestProject(getWsProjectName()); + openJavaFile(getWsProjectName(), getWsPackage(), getWsName() + ".java"); + } + + /** + * 1 there are no incorrectly checked annotations + * 2 there are no incorrectly unchecked annotations + * + * @author Radoslav Rabara + */ + @Test + public void testAbsenceOfAnnotation() { + /** check params of annotation is synchronized **/ + navigateInActiveEditor(13, 0); + + AnnotationPropertiesView annotationsView = new AnnotationPropertiesView(); + annotationsView.open(); + + List allAnnotations = annotationsView.getAllAnnotations(); + List deactiveAnnotations = annotationsView.getAllDeactiveAnnotation(); + + assertThat(deactiveAnnotations.size(), Is.is(allAnnotations.size()-1)); + + for(TreeItem item : deactiveAnnotations) { + assertThat("Path annotation isn't deactivated", item.getText(), IsNot.not("javax.ws.rs.Path")); + } + } + + /** + * 1 there are correctly checked annotations + * 2 there are correctly unchecked annotations + */ + @Test + public void testPresenceOfAnnotation() { + /** check params of annotation is synchronized **/ + navigateInActiveEditor(13, 0); + + AnnotationPropertiesView annotationsView = new AnnotationPropertiesView(); + annotationsView.open(); + + List activeAnnotations = annotationsView.getAllActiveAnnotation(); + + assertThat("Only one annotation should be active but following annotations are active:\n" + + Arrays.toString(activeAnnotations.toArray()), activeAnnotations.size(), Is.is(1)); + assertThat("Path annotation should be active but active is " + activeAnnotations.get(0).getText(), + activeAnnotations.get(0).getText(), Is.is("javax.ws.rs.Path")); + } + + /** + * 1 check equality of param values + * 2 changing param values is mirrored to class + */ + @Test + public void testAnnotationParamValues() { + /** check params of annotation is synchronized **/ + navigateInActiveEditor(13, 0); + + AnnotationPropertiesView annotationView = new AnnotationPropertiesView(); + annotationView.open(); + + TreeItem pathAnnotation = annotationView.getAnnotation("javax.ws.rs.Path"); + List values = annotationView.getAnnotationValues(pathAnnotation); + + assertThat(values.size(), Is.is(1)); + + assertThat(values.get(0).getCell(1), Is.is("\"/rest\"")); + + /** edit parameter values and check if it is still synchronized **/ + String parameter = values.get(0).getText(); + annotationView.changeAnnotationParamValue(pathAnnotation, parameter, "/edit"); + activeEditorContains("@Path(\"/edit\")"); + activeEditorDoesntContain("@Path(\"/rest\")"); + } + + /** + * 1 activating annotation through view is mirrored to class + */ + @Test + public void testAnnotationActivating() { + navigateInActiveEditor(13, 0); + + AnnotationPropertiesView annotationsView = new AnnotationPropertiesView(); + annotationsView.open(); + annotationsView.activateAnnotation(annotationsView.getAnnotation("javax.ws.rs.Encoded")); + + activeEditorContains("@Encoded"); + } + + /** + * 1 deactivating annotation through view is mirrored to class + */ + @Test + public void testAnnotationDeactivating() { + navigateInActiveEditor(13, 0); + + AnnotationPropertiesView annotationsView = new AnnotationPropertiesView(); + annotationsView.open(); + annotationsView.deactivateAnnotation(annotationsView.getAnnotation("javax.ws.rs.Path")); + + activeEditorDoesntContain("@Path(\"/rest\")"); + } + + @Test + public void testJaxRSSupport() { + /** edit JAX-RS annotation value **/ + navigateInActiveEditor(13, 0); + + AnnotationPropertiesView annotationsView = new AnnotationPropertiesView(); + annotationsView.open(); + + TreeItem pathAnnotation = annotationsView.getAnnotation("javax.ws.rs.Path"); + + annotationsView.changeAnnotationParamValue( + pathAnnotation, + annotationsView.getAnnotationValues(pathAnnotation).get(0).getText(), + "/edit"); + new WaitUntil(new RestServicePathsHaveUpdated(getWsProjectName()), TimePeriod.getCustom(2), false); + + for (RESTfulWebService service : restfulServicesForProject(getWsProjectName())) { + String path = service.getPath(); + Asserts.assertNotContain(path, "rest"); + Asserts.assertContain(path, "edit"); + } + + /** delete JAX-RS annotation **/ + navigateInActiveEditor(16, 0); + + annotationsView.open(); + + TreeItem getAnnotation = annotationsView.getAnnotation("javax.ws.rs.GET"); + + annotationsView.deactivateAnnotation(getAnnotation); + + // It gets some time till it's shown in explorer + new WaitUntil(new RestServicePathsHaveUpdated(getWsProjectName()), TimePeriod.getCustom(2), false); + + assertThat("RESTful services", restfulServicesForProject(getWsProjectName()).size(), Is.is(3)); + } + + private void navigateInActiveEditor(int line, int column) { + TextEditor editor = new TextEditor(); + editor.setCursorPosition(line, column); + } + + private void activeEditorDoesntContain(String value) { + activeValueIsContainedInActiveEditor(value, false); + } + + private void activeEditorContains(String value) { + activeValueIsContainedInActiveEditor(value, true); + } + + private void activeValueIsContainedInActiveEditor( + String value, boolean shouldContain) { + String text = new TextEditor().getText(); + assertTrue("Editor should " + (shouldContain?"":"not ") + + "contain \""+ value +"\" but the content is:\n" + text, + text.contains(value) == shouldContain); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/annotation/HTTPMethodAnnotationQuickFixTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/annotation/HTTPMethodAnnotationQuickFixTest.java new file mode 100644 index 000000000..afb449629 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/annotation/HTTPMethodAnnotationQuickFixTest.java @@ -0,0 +1,97 @@ +package org.jboss.tools.ws.ui.bot.test.annotation; + +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.common.wait.AbstractWait; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.eclipse.ui.perspectives.JavaEEPerspective; +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView.ProblemType; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.autobuilding.AutoBuildingRequirement.AutoBuilding; +import org.jboss.reddeer.requirements.openperspective.OpenPerspectiveRequirement.OpenPerspective; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * + * @author jjankovi + * + */ +@RunWith(RedDeerSuite.class) +@JBossServer(state=ServerReqState.STOPPED) +@OpenPerspective(JavaEEPerspective.class) +@AutoBuilding(value = false, cleanup = true) +public class HTTPMethodAnnotationQuickFixTest extends RESTfulTestBase { + + @Override + public void setup() { + + } + + @Override + public void cleanup() { + deleteAllProjects(); + } + + @Test + public void testHTTPMethodWithoutParameters() { + /* import the project */ + String projectName = "httpAnnot1"; + importWSTestProject(projectName); + + /* assert that there is one Java problem */ + assertCountOfProblemsExists(ProblemType.ERROR, projectName, null, null, 1); + + /* open MyAnnot.java */ + openMyAnnotJavaFile(projectName); + TextEditor editor = setCursorPositionToLineInTextEditor("@HttpMethod"); + + /* check that there are quick fixes for both required annotations */ + editor.openQuickFixContentAssistant().chooseProposal( + "Add missing attributes"); + new TextEditor().save(); + ProjectHelper.cleanAllProjects(); + + + /* assert that there is one JAX-RS errors - empty value */ + assertCountOfProblemsExists(ProblemType.ERROR, projectName, null, JAX_RS_PROBLEM, 1); + } + + @Test + public void testTargetRetentionQuickFixes() { + /* import the project */ + String projectName = "httpAnnot2"; + importWSTestProject(projectName); + + /* assert that there are two JAX-RS errors */ + assertCountOfProblemsExists(ProblemType.ERROR, projectName, null, JAX_RS_PROBLEM, 2); + + /* open MyAnnot.java */ + openMyAnnotJavaFile(projectName); + TextEditor editor = setCursorPositionToLineInTextEditor("MyAnnot"); + + /* check that there are quick fixes for both required annotations */ + AbstractWait.sleep(TimePeriod.NORMAL); + editor.openQuickFixContentAssistant().chooseProposal( + "Add @Target annotation on type 'MyAnnot'"); + AbstractWait.sleep(TimePeriod.getCustom(1));//makes a delay between applying quickfixes + + /* there is need to wait a while until validation starts to work */ + editor.openQuickFixContentAssistant().chooseProposal( + "Add @Retention annotation on type 'MyAnnot'"); + + /* save edited file */ + new TextEditor().save(); + ProjectHelper.cleanAllProjects(); + + /* assert that there are no JAX-RS errors */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, null, JAX_RS_PROBLEM, 0); + } + + private void openMyAnnotJavaFile(String projectName) { + openJavaFile(projectName, "test", "MyAnnot.java"); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/cxf/CxfWsClientTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/cxf/CxfWsClientTest.java new file mode 100644 index 000000000..7a9aa15d2 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/cxf/CxfWsClientTest.java @@ -0,0 +1,73 @@ +package org.jboss.tools.ws.ui.bot.test.cxf; + +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.workbench.ui.dialogs.WorkbenchPreferenceDialog; +import org.jboss.tools.ws.reddeer.ui.preferences.WsCxf2xPreferencePage; +import org.jboss.tools.ws.ui.bot.test.webservice.WebServiceRuntime; +import org.jboss.tools.ws.ui.bot.test.wsclient.WSClientTestTemplate; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; + +/** + * Test Web Service Client with CXF Service Runtime, tests inherited from + * {@link WSClientTestTemplate} + * + * @author Radoslav Rabara + * + */ +@RunWith(RedDeerSuite.class) +public class CxfWsClientTest extends WSClientTestTemplate { + + private static final String CXF_HOME_LOCATION; + + static { + CXF_HOME_LOCATION = System.getProperty("apache-cxf-2.x"); + } + + public CxfWsClientTest() { + super(WebServiceRuntime.APACHE_CXF2); + } + + @Override + protected String getWsProjectName() { + return "cxfclient"; + } + + @Override + protected String getWsPackage() { + return "cxfclient." + getLevel().toString().toLowerCase(); + } + + @Override + protected String getEarProjectName() { + return "cxfclientEAR"; + } + + @Override + protected String getSampleClientFileName() { + return "ICalculator_ICalculator_Client.java"; + } + + @BeforeClass + public static void setupCxfRuntime() { + WsCxf2xPreferencePage cxfPreferencePage = new WsCxf2xPreferencePage(); + new WorkbenchPreferenceDialog().open(); + new WorkbenchPreferenceDialog().select(cxfPreferencePage); + cxfPreferencePage.add(CXF_HOME_LOCATION); + cxfPreferencePage.select(CXF_HOME_LOCATION); + new WorkbenchPreferenceDialog().ok(); + } + + @AfterClass + public static void removeCxfRuntime() { + WsCxf2xPreferencePage cxfPreferencePage = new WsCxf2xPreferencePage(); + new WorkbenchPreferenceDialog().open(); + new WorkbenchPreferenceDialog().select(cxfPreferencePage); + cxfPreferencePage.remove(CXF_HOME_LOCATION); + } + + /* + * All tests are inherited from WSClientTestTemplate + */ +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/facet/JAXRSFacetTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/facet/JAXRSFacetTest.java new file mode 100644 index 000000000..d158c7a5e --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/facet/JAXRSFacetTest.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2010-2013 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.jboss.tools.ws.ui.bot.test.facet; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertTrue; + +import org.hamcrest.core.Is; +import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.swt.api.Button; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.core.condition.ShellWithTextIsActive; +import org.jboss.reddeer.swt.impl.button.PushButton; +import org.jboss.reddeer.swt.impl.combo.LabeledCombo; +import org.jboss.reddeer.swt.impl.menu.ContextMenu; +import org.jboss.reddeer.swt.impl.shell.DefaultShell; +import org.jboss.reddeer.swt.impl.tree.DefaultTree; +import org.jboss.reddeer.swt.impl.tree.DefaultTreeItem; +import org.jboss.reddeer.common.wait.AbstractWait; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.uiforms.impl.hyperlink.DefaultHyperlink; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebServicesNode; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Test if adding JAX-RS facet into project causes enabling + * jboss tools JAX-RS tooling + * + * @author jjankovi + * + */ +@RunWith(RedDeerSuite.class) +public class JAXRSFacetTest extends RESTfulTestBase { + + private static String wsProjectName = "jaxrsFacet"; + + private static final String PROJECT_PROPERTIES = "Properties for " + wsProjectName; + + @Override + protected String getWsProjectName() { + return wsProjectName; + } + + @Override + public void cleanup() { + + } + + @Test + public void testJAXRSFacet() { + setJAXRSFacet(); + checkJAXRSTooling(); + } + + private void setJAXRSFacet() { + invokePropertiesForProject(); + setJAXRSFacetOnProject(); + confirmProjectProperties(); + } + + private void checkJAXRSTooling() { + RESTfulWebServicesNode restWebServicesNode = new RESTfulWebServicesNode(wsProjectName); + new WaitWhile(new JobIsRunning(), TimePeriod.LONG); + assertThat("Different count of rest services was expected", + restWebServicesNode.getWebServices().size(), Is.is(1)); + } + + private void invokePropertiesForProject() { + ProjectExplorer projectExplorer = new ProjectExplorer(); + projectExplorer.open(); + + projectExplorer.getProject(getWsProjectName()).select(); + new ContextMenu("Properties").select(); + + new DefaultShell(PROJECT_PROPERTIES); + } + + private void setJAXRSFacetOnProject() { + new DefaultTreeItem("Project Facets").select(); + + new DefaultTreeItem(new DefaultTree(1), "JAX-RS (REST Web Services)").setChecked(true); + assertTrue("OK Button should be enabled.", getOkButton().isEnabled()); + + handleAdditionalConfiguration(); + } + + private void confirmProjectProperties() { + new DefaultShell(PROJECT_PROPERTIES); + + Button okButton = getOkButton(); + assertTrue("OK Button should be enabled.", okButton.isEnabled()); + okButton.click(); + + new WaitWhile(new JobIsRunning(), TimePeriod.getCustom(20), false); + + new WaitWhile(new ShellWithTextIsActive(PROJECT_PROPERTIES)); + } + + private void handleAdditionalConfiguration() { + new DefaultHyperlink().activate(); + + new DefaultShell("Modify Faceted Project"); + new LabeledCombo("Type:").setSelection("Pure JEE6 Implementation"); + + Button okButton = getOkButton(); + assertTrue("OK Button should be enabled.", okButton.isEnabled()); + okButton.click(); + + new WaitWhile(new ShellWithTextIsActive("Modify Faceted Project")); + + /** workaround **/ + new DefaultHyperlink().activate(); + new DefaultShell("Modify Faceted Project"); + getOkButton().click(); + + new WaitWhile(new ShellWithTextIsActive("Modify Faceted Project")); + /** end of workaround **/ + } + + private Button getOkButton() { + return new PushButton("OK"); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/integration/JAXRSToolingIntegrationTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/integration/JAXRSToolingIntegrationTest.java new file mode 100644 index 000000000..4c48e9739 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/integration/JAXRSToolingIntegrationTest.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * Copyright (c) 2010-2012 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.jboss.tools.ws.ui.bot.test.integration; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.eclipse.ui.perspectives.JavaEEPerspective; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.openperspective.OpenPerspectiveRequirement.OpenPerspective; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebServicesNode; +import org.jboss.tools.ws.reddeer.ui.tester.views.WsTesterView; +import org.jboss.tools.ws.reddeer.ui.tester.views.WsTesterView.RequestType; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ServersViewHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * + * @author jjankovi + * + */ +@RunWith(RedDeerSuite.class) +@JBossServer(state=ServerReqState.RUNNING, cleanup=false) +@OpenPerspective(JavaEEPerspective.class) +public class JAXRSToolingIntegrationTest extends RESTfulTestBase { + + private static String projectName = "integration1"; + private String localhostUrl = "http://localhost:8080/"; + private String serviceUrl = localhostUrl + projectName + "/rest/"; + private WsTesterView wsTesterView; + + @Override + public void setup() { + if (!projectExists(getWsProjectName())) { + importWSTestProject(getWsProjectName()); + } + ServersViewHelper.runProjectOnServer(getWsProjectName()); + ServersViewHelper.waitForDeployment(getWsProjectName(), getConfiguredServerName()); + wsTesterView = new WsTesterView(); + wsTesterView.open(); + } + + @Override + public void cleanup() { + /* minimize web service tester */ + wsTesterView.close(); + ServersViewHelper.removeAllProjectsFromServer(getConfiguredServerName()); + } + + @Override + protected String getWsProjectName() { + return projectName; + } + + @Test + public void testGetMethod() { + /* get JAX-RS REST Web Services */ + restWebServicesNode = new RESTfulWebServicesNode(projectName); + + /* run on server - web service tester should be shown */ + runRestServiceOnServer("GET"); + assertWebServiceTesterIsActive(); + wsTesterView.open(); + + /* test generated url and response after invoking */ + assertEquals(serviceUrl + "get", wsTesterView.getServiceURL()); + + invokeMethodInWSTester(wsTesterView, RequestType.GET); + assertEquals("GET method", wsTesterView.getResponseBody()); + assertEquals("[HTTP/1.1 200 OK]", wsTesterView.getResponseHeaders()[0]); + } + + @Test + public void testPostMethod() { + /* get JAX-RS REST Web Services */ + restWebServicesNode = new RESTfulWebServicesNode(projectName); + + /* run on server - web service tester should be shown */ + runRestServiceOnServer("POST"); + assertWebServiceTesterIsActive(); + wsTesterView.open();//workaround for RedDeer that won't allow to close view until it the open() method was called + + /* test generated url and response after invoking */ + assertEquals(serviceUrl + "post", wsTesterView.getServiceURL()); + + invokeMethodInWSTester(wsTesterView, RequestType.POST); + assertEquals("POST method", wsTesterView.getResponseBody()); + assertEquals("[HTTP/1.1 200 OK]", wsTesterView.getResponseHeaders()[0]); + } + + @Test + public void testPutMethod() { + /* get JAX-RS REST Web Services */ + restWebServicesNode = new RESTfulWebServicesNode(projectName); + + /* run on server - web service tester should be shown */ + runRestServiceOnServer("PUT"); + assertWebServiceTesterIsActive(); + wsTesterView.open(); + + /* test generated url and response after invoking */ + assertEquals(serviceUrl + "put", wsTesterView.getServiceURL()); + + invokeMethodInWSTester(wsTesterView, RequestType.PUT); + assertEquals("PUT method", wsTesterView.getResponseBody()); + assertEquals("[HTTP/1.1 200 OK]", wsTesterView.getResponseHeaders()[0]); + } + + @Test + public void testDeleteMethod() { + /* get JAX-RS REST Web Services */ + restWebServicesNode = new RESTfulWebServicesNode(projectName); + + /* run on server - web service tester should be shown */ + runRestServiceOnServer("DELETE"); + assertWebServiceTesterIsActive(); + wsTesterView.open(); + + /* test generated url and response after invoking */ + assertEquals(serviceUrl + "delete", wsTesterView.getServiceURL()); + + invokeMethodInWSTester(wsTesterView, RequestType.DELETE); + assertEquals("DELETE method", wsTesterView.getResponseBody()); + assertEquals("[HTTP/1.1 200 OK]", wsTesterView.getResponseHeaders()[0]); + } + + @Test + public void testUnavailableServiceMethod() { + /* get JAX-RS REST Web Services */ + restWebServicesNode = new RESTfulWebServicesNode(projectName); + + /* run on server - web service tester should be shown */ + runRestServiceOnServer(restWebServicesNode.getWebServiceByMethod("GET").get(0)); + assertWebServiceTesterIsActive(); + wsTesterView.open(); + + /* test generated url and response after invoking */ + assertEquals(serviceUrl + "get", wsTesterView.getServiceURL()); + + invokeMethodInWSTester(wsTesterView, RequestType.POST); + wsTesterView.activate(); + assertFalse(wsTesterView.getResponseBody().equals("GET method")); + + assertTrue("There is no header", wsTesterView.getResponseHeaders().length > 0); + assertEquals("[HTTP/1.1 405 Method Not Allowed]", wsTesterView.getResponseHeaders()[0]); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/integration/SOAPWSToolingIntegrationTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/integration/SOAPWSToolingIntegrationTest.java new file mode 100644 index 000000000..6a637d7ca --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/integration/SOAPWSToolingIntegrationTest.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2010-2012 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.jboss.tools.ws.ui.bot.test.integration; + +import static org.junit.Assert.assertTrue; + +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.eclipse.core.resources.Project; +import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.autobuilding.AutoBuildingRequirement.AutoBuilding; +import org.jboss.reddeer.swt.impl.menu.ContextMenu; +import org.jboss.tools.ws.reddeer.swt.condition.WsTesterNotEmptyResponseText; +import org.jboss.tools.ws.reddeer.ui.tester.views.WsTesterView; +import org.jboss.tools.ws.reddeer.ui.tester.views.WsTesterView.RequestType; +import org.jboss.tools.ws.ui.bot.test.soap.SOAPTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ServersViewHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Class for testing SOAP integration in Web Service Tester + * + * @author jjankovi + * + */ +@RunWith(RedDeerSuite.class) +@AutoBuilding(value = false, cleanup = true) +public class SOAPWSToolingIntegrationTest extends SOAPTestBase { + + private final String request = " " + LINE_SEPARATOR + + " " + LINE_SEPARATOR + " " + + LINE_SEPARATOR + "" + LINE_SEPARATOR + " " + LINE_SEPARATOR + + "" + LINE_SEPARATOR + + "User" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + + LINE_SEPARATOR + ""; + + @Override + public void setup() { + if (!ProjectHelper.projectExists(getWsProjectName())) { + ProjectHelper.importWSTestProject(getWsProjectName(), getConfiguredRuntimeName()); + ProjectHelper.cleanAllProjects(); + ServersViewHelper.runProjectOnServer(getWsProjectName()); + ServersViewHelper.waitForDeployment(getWsProjectName(), getConfiguredServerName()); + } + } + + @Override + protected String getWsProjectName() { + return "integration2"; + } + + /** + * Fails due to JBDS-3907 + * + * @see https://issues.jboss.org/browse/JBDS-3907 + */ + @Test + public void testSimpleIntegration() { + WsTesterView wsTesterView = openWSDLFileInWSTester(); + testWSDLInWSTester(wsTesterView); + } + + private WsTesterView openWSDLFileInWSTester() { + ProjectExplorer projectExplorer = new ProjectExplorer(); + projectExplorer.activate(); + Project project = projectExplorer.getProject(getWsProjectName()); + project.refresh(); + project.getProjectItem("wsdl", "HelloWorldService.wsdl").select(); + new ContextMenu("Web Services", "Test in JBoss Web Service Tester").select(); + + WsTesterView tester = new WsTesterView(); + tester.open(); + return tester; + } + + private void testWSDLInWSTester(WsTesterView wsTesterView) { + wsTesterView.setRequestType(RequestType.JAX_WS); + wsTesterView.invokeGetFromWSDL().ok(); + new WaitWhile(new JobIsRunning()); + wsTesterView.open(); + wsTesterView.setRequestBody(request); + wsTesterView.invoke(); + wsTesterView.open(); + new WaitUntil(new WsTesterNotEmptyResponseText()); + String rsp = wsTesterView.getResponseBody(); + assertTrue(rsp.trim().length() > 0); + assertTrue(rsp, rsp.contains("Hello User!")); + } + + @Override + protected String getEarProjectName() { + return null; + } + +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/preferences/JBossWSPreferencesTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/preferences/JBossWSPreferencesTest.java new file mode 100644 index 000000000..52d31fac4 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/preferences/JBossWSPreferencesTest.java @@ -0,0 +1,195 @@ +/******************************************************************************* + * Copyright (c) 2010-2013 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.jboss.tools.ws.ui.bot.test.preferences; + +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.hamcrest.core.Is; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.workbench.ui.dialogs.WorkbenchPreferenceDialog; +import org.jboss.reddeer.junit.requirement.inject.InjectRequirement; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.server.IServerFamily; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.reddeer.core.condition.ShellWithTextIsActive; +import org.jboss.reddeer.swt.impl.button.PushButton; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.tools.ws.reddeer.ui.preferences.JBossWSRuntimeItem; +import org.jboss.tools.ws.reddeer.ui.preferences.JBossWSRuntimeListFieldEditor; +import org.jboss.tools.ws.reddeer.ui.preferences.JBossWSRuntimePreferencePage; +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * JBossWS Preference Page is tested with following approaches: + * 1. try to automatically generate all relevant information + * about jbossws from configured runtime + * 2. try to edit jbossws information and test it is reflected in page + * 3. try to remove jbossws from list + * + * @author jjankovi + * @author Radoslav Rabara + */ +@RunWith(RedDeerSuite.class) +@JBossServer(state=ServerReqState.PRESENT) +public class JBossWSPreferencesTest { + + @InjectRequirement + private ServerRequirement serverReq; + + private static JBossWSRuntimePreferencePage jbossWSRuntimePreferencePage; + private JBossWSRuntimeListFieldEditor jbossWsRuntimeDialog; + + private static final String NEW_JBOSS_WS_RUNTIME_DIALOG_TITLE = "New JBossWS Runtime"; + private static final String EDIT_JBOSS_WS_RUNTIME_DIALOG_TITLE = "Edit JBossWS Runtime"; + + private String runtimeName; + private String runtimeVersion; + private String runtimePath; + + private String runtimeEditedName = "modifiedRuntimeName"; + + @BeforeClass + public static void preparePrerequisites() { + jbossWSRuntimePreferencePage = new JBossWSRuntimePreferencePage(); + new WorkbenchPreferenceDialog().open(); + new WorkbenchPreferenceDialog().select(jbossWSRuntimePreferencePage); + } + + @After + public void cleanUpWorkspace() { + new WorkbenchPreferenceDialog().cancel(); + } + + @Test + public void testJBossWSPreferencePage() { + testJBossWSGenerating(); + testJBossWSRuntimeEdition(); + testJBossWSRuntimeDeletion(); + } + + private void testJBossWSGenerating() { + jbossWSRuntimePreferencePage.add(); + jbossWsRuntimeDialog = new JBossWSRuntimeListFieldEditor(false); + + setRuntimeHomeFolderAccordingToRuntime(); + assertRuntimeProperlyConfiguredInDialog(); + assertRuntimeConfiguredAccordingToRuntime(); + } + + private void testJBossWSRuntimeEdition() { + jbossWSRuntimePreferencePage.select(0); + jbossWSRuntimePreferencePage.edit(); + + jbossWsRuntimeDialog = new JBossWSRuntimeListFieldEditor(true); + + jbossWsRuntimeDialog.setName(runtimeEditedName); + jbossWsRuntimeDialog.finish(); + + new WaitWhile(new ShellWithTextIsActive(EDIT_JBOSS_WS_RUNTIME_DIALOG_TITLE)); + + assertRuntimeName(runtimeEditedName); + } + + private void testJBossWSRuntimeDeletion() { + jbossWSRuntimePreferencePage.select(0); + jbossWSRuntimePreferencePage.remove(); + + new WaitUntil(new ShellWithTextIsActive("Confirm Runtime Delete")); + new PushButton("OK").click(); + new WaitWhile(new ShellWithTextIsActive("Confirm Runtime Delete")); + + assertThat(jbossWSRuntimePreferencePage.getAllJBossWSRuntimes().size(), + Is.is(0)); + } + + private void setRuntimeHomeFolderAccordingToRuntime() { + jbossWsRuntimeDialog.setHomeFolder(serverReq.getConfig().getRuntime()); + + runtimeName = jbossWsRuntimeDialog.getName(); + runtimeVersion = jbossWsRuntimeDialog.getVersion(); + runtimePath = jbossWsRuntimeDialog.getHomeFolder(); + } + + private void assertRuntimeProperlyConfiguredInDialog() { + assertTrue("JBoss WS Runtime name was not automatically generated", + jbossWsRuntimeDialog.getName() != null && + !jbossWsRuntimeDialog.getName().isEmpty()); + + assertThat(jbossWsRuntimeDialog.getRuntimeImplementation(), + Is.is("JBoss Web Services - Stack CXF Runtime Client")); + + String runtimeVersion = jbossWsRuntimeDialog.getRuntimeVersion(); + + String expectedVersion; + IServerFamily serverFamily = serverReq.getConfig().getServerFamily(); + switch(serverFamily.getLabel()) { + case "WildFly": + if ("10.x".equals(serverFamily.getVersion())) { + expectedVersion = "5.1.3.Final"; + } else { + expectedVersion = "5.0.0.Final"; + } + break; + case "JBoss Enterprise Application Platform": + expectedVersion = "4.2.3.Final-redhat-1"; + break; + case "JBoss AS": + expectedVersion = "4.0.2.GA"; + break; + default: + fail("Server was not recognized"); + expectedVersion = ""; + } + assertTrue("Unknown runtime version: " + runtimeVersion, + Is.is(expectedVersion).matches(runtimeVersion)); + } + + private void assertRuntimeConfiguredAccordingToRuntime() { + jbossWsRuntimeDialog.finish(); + + new WaitWhile(new ShellWithTextIsActive( + NEW_JBOSS_WS_RUNTIME_DIALOG_TITLE)); + + assertThat(jbossWSRuntimePreferencePage. + getAllJBossWSRuntimes().size(), Is.is(1)); + + JBossWSRuntimeItem item = jbossWSRuntimePreferencePage. + getAllJBossWSRuntimes().iterator().next(); + assertRuntimeName(item, runtimeName); + assertRuntimeVersion(item, runtimeVersion); + assertRuntimePath(item, runtimePath); + + } + + private void assertRuntimeName(String expectedName) { + assertRuntimeName(jbossWSRuntimePreferencePage.getAllJBossWSRuntimes().get(0), + expectedName); + } + + private void assertRuntimeName(JBossWSRuntimeItem item, String expectedName) { + assertThat(item.getName(), Is.is(expectedName)); + } + + private void assertRuntimeVersion(JBossWSRuntimeItem item, String expectedVersion) { + assertThat(item.getVersion(), Is.is(expectedVersion)); + } + + private void assertRuntimePath(JBossWSRuntimeItem item, String expectedPath) { + assertThat(item.getPath(), Is.is(expectedPath)); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/AsYouTypeValidationTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/AsYouTypeValidationTest.java new file mode 100644 index 000000000..3e25fea46 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/AsYouTypeValidationTest.java @@ -0,0 +1,93 @@ +package org.jboss.tools.ws.ui.bot.test.rest; + +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.util.List; + +import org.hamcrest.core.Is; +import org.hamcrest.core.IsNot; +import org.hamcrest.core.StringContains; +import org.jboss.reddeer.common.wait.AbstractWait; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.core.exception.CoreLayerException; +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView.ProblemType; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.swt.keyboard.Keyboard; +import org.jboss.reddeer.swt.keyboard.KeyboardFactory; +import org.jboss.reddeer.workbench.impl.editor.Marker; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.ws.reddeer.editor.ExtendedTextEditor; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Testing as-you-type validation. + * + * @author Radoslav Rabara + * + * @see http://tools.jboss.org/documentation/whatsnew/jbosstools/4.2.0.Beta3.html#as-you-type-validation + * @since 4.2.0.Beta3 + */ +@RunWith(RedDeerSuite.class) +public class AsYouTypeValidationTest extends RESTfulTestBase { + + @After + public void cleanup() { + //save the modified file + try { + new TextEditor().save(); + } catch(CoreLayerException e) { + + } + //delete the project + super.cleanup(); + } + + @Override + protected String getWsProjectName() { + return "restAsYouTypeValidation"; + } + + @Test + public void invalidPathParamTest() { + /* assert there is no error */ + assertCountOfProblemsExists(ProblemType.ERROR, getWsProjectName(), null, null, 0); + + /* change pathparam's value to be invalid */ + openJavaFile(getWsProjectName(), "org.rest.test", "RestService.java"); + ExtendedTextEditor textEditor = new ExtendedTextEditor(); + int lineNumber = textEditor.getLineNum(StringContains.containsString("}")) -1; + textEditor.selectLine(lineNumber); + Keyboard keyboard = KeyboardFactory.getKeyboard(); + keyboard.type("\t@Path(\"{id}\")\n\tpublic void test(@PathParam(\"test\") Integer test){\n");//enclosing } will be added automatically by editor + AbstractWait.sleep(TimePeriod.getCustom(2)); + + /* error shows */ + List markers = textEditor.getMarkers(); + assertThat("Number of markers in editor", markers.size(), IsNot.not(Is.is(0))); + assertExpectedErrorIsPresent(markers); + } + + private void assertExpectedErrorIsPresent(List markers) { + final String EXPECTED_ERROR = "@PathParam value 'test' does not match any @Path annotation template parameters of the java method 'test' and its enclosing java type 'org.rest.test.RestService'."; + for(Marker m : markers) { + if(m.getText().equals(EXPECTED_ERROR)) { + return; + } + } + fail("Error marked with text '" + EXPECTED_ERROR + "' was not found.\n" + getMarkersText(markers)); + } + + private String getMarkersText(List markers) { + StringBuilder text = new StringBuilder(); + for(int i=0;i0) { + text.append(", "); + } + text.append(markers.get(i).getText()); + } + return text.toString(); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/CreateJAXRSApplicationTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/CreateJAXRSApplicationTest.java new file mode 100644 index 000000000..171a1442f --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/CreateJAXRSApplicationTest.java @@ -0,0 +1,306 @@ +package org.jboss.tools.ws.ui.bot.test.rest; + +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.Arrays; +import java.util.List; + +import org.hamcrest.core.Is; +import org.hamcrest.core.IsNot; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.common.exception.RedDeerException; +import org.jboss.reddeer.eclipse.core.resources.Project; +import org.jboss.reddeer.eclipse.core.resources.ProjectItem; +import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.reddeer.swt.impl.menu.ContextMenu; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.ws.reddeer.ui.wizards.jaxrs.JAXRSApplicationWizard; +import org.jboss.tools.ws.reddeer.ui.wizards.jaxrs.JAXRSApplicationWizardPage; +import org.jboss.tools.ws.reddeer.ui.wizards.jaxrs.JAXRSApplicationWizardPage.DeploymentDescriptorWizardPart; +import org.jboss.tools.ws.reddeer.ui.wizards.jaxrs.JAXRSApplicationWizardPage.SubclassOfApplicationWizardPart; +import org.jboss.tools.ws.ui.bot.test.WSTestBase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Tests operates on JAX-RS Application wizard + * + * @author Radoslav Rabara + */ +@RunWith(RedDeerSuite.class) +@JBossServer(state=ServerReqState.PRESENT) +public class CreateJAXRSApplicationTest extends WSTestBase { + + protected final JAXRSApplicationWizard wizard = new JAXRSApplicationWizard(); + protected final JAXRSApplicationWizardPage page = new JAXRSApplicationWizardPage(); + + private final String[] webXmlPath = {"WebContent", "WEB-INF", "web.xml"}; + + private final String PROJECT_SRC_FOLDER_PATH = getWsProjectName() + "/src"; + private final String PACKAGE_NAME = "org.rest.test"; + private final String FILE_NAME = "RestApp"; + private final String APPLICATION_PATH = "/app/path"; + + private final String ERROR_SOURCE_FOLDER_NAME_IS_EMPTY = " Source folder name is empty."; + + private static final String LINE_SEPARATOR = System.getProperty("line.separator", "\n"); + + @Override + protected String getWsProjectName() { + return "JAXRSApplicationTestProject"; + } + + @Before + public void setup() { + super.setup(); + wizard.open(); + } + + @After + public void cleanup() { + try {//close the wizard if it's present + wizard.cancel(); + } catch(RedDeerException e) { + + } + super.cleanup(); + deleteAllProjects(); + } + + @Test + public void createSubclassOfApplicationTest() { + /* select "Subclass of javax.ws.rs.core.Application" option */ + SubclassOfApplicationWizardPart wp = page.useSubclassOfApplication(); + + /* set fields */ + wp.setSourceFolder(PROJECT_SRC_FOLDER_PATH); + wp.setPackage(PACKAGE_NAME); + wp.setName(FILE_NAME); + wp.setApplicationPath(APPLICATION_PATH); + + /* create JAX-RS Activator */ + wizard.finish(); + + /* get source folder */ + ProjectItem srcProjectItem = getProject().getProjectItem("Java Resources", "src"); + + /* source folder contains the specified package */ + List srcChildren = srcProjectItem.getChildren(); + if(PACKAGE_NAME != null) { + assertContains(srcChildren, PACKAGE_NAME, + "Src folder doesn't contain package \"" + PACKAGE_NAME + "\" but it contains " + + Arrays.toString(srcChildren.toArray())); + } + assertTrue("Src folder should contain just 1 package but it contains " + + Arrays.toString(srcChildren.toArray()), srcChildren.size() == 1); + + /* package have to contain the specified class = activator */ + ProjectItem pkgProjectItem = srcChildren.get(0); + List pkgChildren = pkgProjectItem.getChildren(); + assertContains(pkgChildren, FILE_NAME + ".java", + "Package doesn't contain file \"" + PACKAGE_NAME + ".java\" but it contains " + + Arrays.toString(srcChildren.toArray())); + assertTrue("Package should contain just 1 file but it contains " + + Arrays.toString(srcChildren.toArray()), pkgChildren.size() == 1); + + /* the class contains @ApplicationPath and that it extends Application */ + ProjectItem sourceFile = pkgChildren.get(0); + sourceFile.open(); + TextEditor editor = new TextEditor(); + String generatedText = editor.getText(); + editor.close(); + generatedText.contains("@ApplicationPath(\"" + APPLICATION_PATH + "\")"); + generatedText.contains("extends Application"); + generatedText.contains("import javax.ws.rs.ApplicationPath;"); + generatedText.contains("import javax.ws.rs.core.Application;"); + + /* there is a web.xml*/ + assertTrue("Project does not contains " + Arrays.toString(webXmlPath), getProject().containsItem(webXmlPath)); + } + + @Test + public void createSubclassOfApplicationWithCommentsTest() { + /* select "Subclass of javax.ws.rs.core.Application" option */ + SubclassOfApplicationWizardPart wp = page.useSubclassOfApplication(); + + /* set fields */ + wp.setSourceFolder(PROJECT_SRC_FOLDER_PATH); + wp.setPackage(PACKAGE_NAME); + wp.setName(FILE_NAME); + wp.setApplicationPath(APPLICATION_PATH); + + /* generate comments */ + wp.setGenerateComments(true); + + /* create JAX-RS Activator */ + wizard.finish(); + + /* get generated class */ + ProjectItem generatedClass = getProject().getProjectItem("Java Resources", "src") + .getChildren().get(0).getChildren().get(0); + + /* the class contains @ApplicationPath and that it extends Application */ + generatedClass.open(); + TextEditor editor = new TextEditor(); + String generatedText = editor.getText(); + editor.close(); + generatedText.contains("/**"); + generatedText.contains("*/"); + generatedText.contains("@ApplicationPath(\"" + APPLICATION_PATH + "\")"); + generatedText.contains("extends Application"); + generatedText.contains("import javax.ws.rs.ApplicationPath;"); + generatedText.contains("import javax.ws.rs.core.Application;"); + } + + @Test + public void useDefinitionInTheWebDeploymentDescriptorTest() { + /* select "Defined in the web deployment descriptor" option */ + DeploymentDescriptorWizardPart wp = page.useDeploymentDescriptor(); + + /* create JAX-RS Activator */ + wp.setApplicationPath("/app/path"); + wizard.finish(); + + assertThatWebXmlContainsRequiredText(); + } + + @Test + public void setSourceFolderTest() { + String NON_EXISTING_PROJECT_NAME = "NON_EXISTING_PROJECT"; + + /* select "Subclass of javax.ws.rs.core.Application" option */ + SubclassOfApplicationWizardPart wp = page.useSubclassOfApplication(); + + /* button, which is used to browse source folder, is always enabled */ + assertThat("Browse source folder should be always enabled", + wp.isBrowseSourceFolderEnabled(), Is.is(true)); + + /* error is showed when the source folder is empty */ + wp.setSourceFolder(""); + assertThat(page.getWizardPageInfoText(), + Is.is(ERROR_SOURCE_FOLDER_NAME_IS_EMPTY)); + assertThat("Browse package button should be disabled when source folder is not set", + wp.isBrowsePackageEnabled(), Is.is(false)); + + /* error is showed when the source folder doesn't exist */ + wp.setSourceFolder(NON_EXISTING_PROJECT_NAME); + assertThat(page.getWizardPageInfoText(), Is.is(" Folder '" + NON_EXISTING_PROJECT_NAME + + "' does not exist.")); + + /* error disappear when the source folder is set */ + wp.setSourceFolder(PROJECT_SRC_FOLDER_PATH); + assertThat(page.getWizardPageInfoText(), IsNot.not(Is.is(ERROR_SOURCE_FOLDER_NAME_IS_EMPTY))); + assertThat( "Browse package button should be enabled when source folder is set", + wp.isBrowsePackageEnabled(), Is.is(true)); + } + + @Test + public void setNameTest() { + final String ERROR_TYPE_NAME_IS_EMPTY = " Type name is empty."; + + /* select "Subclass of javax.ws.rs.core.Application" option */ + SubclassOfApplicationWizardPart wp = page.useSubclassOfApplication(); + wp.setSourceFolder(PROJECT_SRC_FOLDER_PATH); + + /* error is showed when name is empty */ + wp.setName(""); + assertThat(page.getWizardPageInfoText(), Is.is(ERROR_TYPE_NAME_IS_EMPTY)); + } + + @Test + public void setPackageTest() { + final String WARNING_USE_OF_DEFAULT_PACKAGE_IS_DISCOURAGED = " The use of the default package is discouraged."; + final String ERROR_PACKAGE_NAME_CANNOT_START_OR_END_WITH_A_DOT = " Package name is not valid. A package name cannot start or end with a dot"; + + /* select "Subclass of javax.ws.rs.core.Application" option */ + SubclassOfApplicationWizardPart wp = page.useSubclassOfApplication(); + + /* set source folder and file name */ + wp.setSourceFolder(PROJECT_SRC_FOLDER_PATH); + wp.setName(FILE_NAME); + + /* warning is showed when the package name is empty */ + wp.setPackage(""); + assertThat(page.getWizardPageInfoText(), + Is.is(WARNING_USE_OF_DEFAULT_PACKAGE_IS_DISCOURAGED)); + + /* warning disappear when the package name is set */ + wp.setPackage(PACKAGE_NAME); + assertThat(page.getWizardPageInfoText(), + IsNot.not(Is.is(WARNING_USE_OF_DEFAULT_PACKAGE_IS_DISCOURAGED))); + + /* package name cannot end with a dot */ + wp.setPackage(PACKAGE_NAME + "."); + assertThat(page.getWizardPageInfoText(), + Is.is(ERROR_PACKAGE_NAME_CANNOT_START_OR_END_WITH_A_DOT)); + wp.setPackage(PACKAGE_NAME); + assertThat(page.getWizardPageInfoText(), + IsNot.not(Is.is(ERROR_PACKAGE_NAME_CANNOT_START_OR_END_WITH_A_DOT))); + + /* package name cannot start with a dot */ + wp.setPackage("." + PACKAGE_NAME); + assertThat(page.getWizardPageInfoText(), + Is.is(ERROR_PACKAGE_NAME_CANNOT_START_OR_END_WITH_A_DOT)); + } + + private void assertContains(List list, String name, String errorMessage) { + for(ProjectItem pi : list) { + if(pi.getName().equals(name)) { + return; + } + } + fail(errorMessage); + } + + private void assertThatWebXmlContainsRequiredText() { + final String WEB_XML_TEXT = "" + LINE_SEPARATOR + + "" + LINE_SEPARATOR + + " " + getWsProjectName() + "" + LINE_SEPARATOR + + " " + LINE_SEPARATOR + + " index.html" + LINE_SEPARATOR + + " index.htm" + LINE_SEPARATOR + + " index.jsp" + LINE_SEPARATOR + + " default.html" + LINE_SEPARATOR + + " default.htm" + LINE_SEPARATOR + + " default.jsp" + LINE_SEPARATOR + + " " + LINE_SEPARATOR + + " " + LINE_SEPARATOR + + " javax.ws.rs.core.Application" + LINE_SEPARATOR + + " /app/path" + LINE_SEPARATOR + + " " + LINE_SEPARATOR + + ""; + + assertThat(getWebXmlContent(), Is.is(WEB_XML_TEXT)); + } + + private String getWebXmlContent() { + String text; + + Project project = new ProjectExplorer().getProject(getWsProjectName()); + assertTrue("web.xml was not generated.\n" + Arrays.toString(webXmlPath) + " is missing", + project.containsItem(webXmlPath)); + ProjectItem webXml = project.getProjectItem(webXmlPath); + + webXml.select(); + new ContextMenu("Open With", "Text Editor").select();; + + TextEditor editor = new TextEditor(); + editor.activate(); + text = editor.getText(); + editor.close(); + + return text; + } + + private Project getProject() { + return new ProjectExplorer().getProject(getWsProjectName()); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/CreateJAXRSResourceTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/CreateJAXRSResourceTest.java new file mode 100644 index 000000000..8e3a0a0bc --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/CreateJAXRSResourceTest.java @@ -0,0 +1,238 @@ +package org.jboss.tools.ws.ui.bot.test.rest; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.List; + +import org.hamcrest.core.Is; +import org.hamcrest.core.IsNot; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.core.exception.CoreLayerException; +import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView.ProblemType; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.reddeer.swt.impl.button.PushButton; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebService; +import org.jboss.tools.ws.reddeer.ui.wizards.jaxrs.JAXRSApplicationWizardPage; +import org.jboss.tools.ws.reddeer.ui.wizards.jaxrs.JAXRSResourceCreateApplicationWizardPage; +import org.jboss.tools.ws.reddeer.ui.wizards.jaxrs.JAXRSResourceCreateResourceWizardPage; +import org.jboss.tools.ws.reddeer.ui.wizards.jaxrs.JAXRSResourceWizard; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Tests operates on JAX-RS Resource wizard + * + * @author Radoslav Rabara + */ +@RunWith(RedDeerSuite.class) +@JBossServer(state=ServerReqState.PRESENT) +public class CreateJAXRSResourceTest extends RESTfulTestBase { + + private final String PACKAGE_NAME = "org.rest.test"; + private final String FILE_NAME = "RestService"; + private final String RESOURCE_PATH = "/customer"; + private final String TARGET_ENTITY = PACKAGE_NAME + ".Customer"; + private final String APPLICATION_FILE_NAME = "App"; + private final String APPLICATION_PATH = "/rest"; + + private final JAXRSResourceWizard wizard = new JAXRSResourceWizard(); + + @Before + public void setup() { + super.setup(); + wizard.open(); + } + + @After + public void cleanup() { + //close the wizard if it's present + try { + wizard.cancel(); + } catch(CoreLayerException e) { + } + + super.cleanup(); + } + + @Override + protected String getWsProjectName() { + return "resource"; + } + + @Test + public void createResourceWithEntityAndMethodsAndCommentsTest() { + /* set wizard to create JAX-RS resource with entity and all methods */ + JAXRSResourceCreateResourceWizardPage firstPage = new JAXRSResourceCreateResourceWizardPage(); + firstPage.setPackage(PACKAGE_NAME); + firstPage.setTargetEntity(TARGET_ENTITY); + firstPage.setName(FILE_NAME); + firstPage.setResourcePath(RESOURCE_PATH); + firstPage.setCreate(true); + firstPage.setUpdate(true); + firstPage.setDeleteById(true); + firstPage.setFindById(true); + firstPage.setListAll(true); + firstPage.setGenerateComments(true); + wizard.next(); + + /* set wizard to create also JAX-RS Application */ + JAXRSResourceCreateApplicationWizardPage secondPage = new JAXRSResourceCreateApplicationWizardPage(); + JAXRSResourceCreateApplicationWizardPage.SubclassOfApplicationWizardPart wp = secondPage.useSubclassOfApplication(); + wp.setPackage(PACKAGE_NAME); + wp.setName(APPLICATION_FILE_NAME); + wp.setApplicationPath(APPLICATION_PATH); + wizard.finish(); + + /* there should be no error */ + assertCountOfProblemsExists(ProblemType.ERROR, 0); + + /* JAX-RS Resource was created */ + assertTrue("JAX-RS Application was not created", new ProjectExplorer().getProject(getWsProjectName()) + .containsItem("Java Resources", "src", PACKAGE_NAME, FILE_NAME + ".java") == true); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(getWsProjectName()); + + /* created methods should be displayed in JAX-RS Explorer */ + assertCountOfRESTServices(restServices, 5); + assertThatAllRestServicesArePresent(restServices); + + /* JAX-RS Application class was also created*/ + assertTrue("JAX-RS Application was not created", new ProjectExplorer().getProject(getWsProjectName()) + .containsItem("Java Resources", "src", PACKAGE_NAME, APPLICATION_FILE_NAME + ".java")); + } + + /** + * Resolved - JBIDE-17457 + * (JAX-RS Resource Wizard has inconsistent validation of target entity) + * + * @see https://issues.jboss.org/browse/JBIDE-17457 + */ + @Test + public void testSetTargetEntity() { + final String NON_EXISTING_TARGET_ENTITY = "NON_EXISTING_TARGET_ENTITY"; + final String ERROR_TARGET_CLASS_NOT_EXISTS = " Target Class does not exist in project's classpath"; + JAXRSResourceCreateResourceWizardPage firstPage = new JAXRSResourceCreateResourceWizardPage(); + + /* set name to dismiss "type name is empty" error */ + firstPage.setName(FILE_NAME); + + firstPage.setTargetEntity(NON_EXISTING_TARGET_ENTITY); + assertThat(firstPage.getWizardPageInfoText(), Is.is(ERROR_TARGET_CLASS_NOT_EXISTS)); + + firstPage.setTargetEntity(""); + assertThat("JBIDE-17457", firstPage.getWizardPageInfoText(), IsNot.not(Is.is(ERROR_TARGET_CLASS_NOT_EXISTS))); + + firstPage.setTargetEntity(TARGET_ENTITY); + assertThat(firstPage.getWizardPageInfoText(), IsNot.not(Is.is(ERROR_TARGET_CLASS_NOT_EXISTS))); + + assertThat(new PushButton("Next >").isEnabled(), Is.is(true)); + } + + /** + * Resolved - JBIDE-17457 + * (JAX-RS Resource Wizard has inconsistent validation of target entity) + * + * @see https://issues.jboss.org/browse/JBIDE-17457 + */ + @Test + public void testWithoutTargetEntityCantUseMethods() { + JAXRSResourceCreateResourceWizardPage firstPage = new JAXRSResourceCreateResourceWizardPage(); + + assertTrue("Dialog shouldn't allow to create methods when the target entity is not set", + !firstPage.areAvailableJAXRSResourceMethodEnabled()); + + firstPage.setTargetEntity(""); + assertTrue("Dialog shouldn't allow to create methods when the target entity is not set", + !firstPage.areAvailableJAXRSResourceMethodEnabled()); + + firstPage.setTargetEntity(TARGET_ENTITY); + assertTrue("Dialog have to allow to create methods when the target entity is set", + firstPage.areAvailableJAXRSResourceMethodEnabled()); + + firstPage.setName(FILE_NAME); + + assertThat(new PushButton("Next >").isEnabled(), Is.is(true)); + } + + @Test + public void createResourceWithoutTargetEntity() { + /* set wizard to create JAX-RS resource with entity and all methods */ + JAXRSResourceCreateResourceWizardPage firstPage = new JAXRSResourceCreateResourceWizardPage(); + firstPage.setPackage(PACKAGE_NAME); + firstPage.setName(FILE_NAME); + firstPage.setResourcePath(RESOURCE_PATH); + wizard.next(); + + /* set wizard to create also JAX-RS Application */ + JAXRSResourceCreateApplicationWizardPage secondPage = new JAXRSResourceCreateApplicationWizardPage(); + JAXRSApplicationWizardPage.SubclassOfApplicationWizardPart wp = secondPage.useSubclassOfApplication(); + wp.setPackage(PACKAGE_NAME); + wp.setName(APPLICATION_FILE_NAME); + wp.setApplicationPath(APPLICATION_PATH); + wizard.finish(); + + /* there should be no error */ + assertCountOfProblemsExists(ProblemType.ERROR, 0); + + /* JAX-RS Resource was created */ + assertTrue("JAX-RS Application was not created", new ProjectExplorer().getProject(getWsProjectName()) + .containsItem("Java Resources", "src", PACKAGE_NAME, FILE_NAME + ".java") == true); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(getWsProjectName()); + + /* created methods should be displayed in JAX-RS Explorer */ + assertCountOfRESTServices(restServices, 0); + + /* JAX-RS Application class was also created*/ + assertTrue("JAX-RS Application was not created", new ProjectExplorer().getProject(getWsProjectName()) + .containsItem("Java Resources", "src", PACKAGE_NAME, APPLICATION_FILE_NAME + ".java") == true); + } + + private void assertThatAllRestServicesArePresent(List restServices) { + final String idPathURITemplate = "/{id:[0-9][0-9]*}"; + final String mediaTypes = "application/xml,application/json"; + final String PATH_PREFIX = APPLICATION_PATH + RESOURCE_PATH; + for (RESTfulWebService restService : restServices) { + final String serviceName = restService.getMethod(); + if(serviceName.equals("POST")) { + assertEquals("Path of POST operation ", restService.getPath(), PATH_PREFIX); + assertEquals("Consumes info of POST operation ", restService.getConsumingContentType(), mediaTypes); + assertEquals("Produces info of POST operation ", restService.getProducingContentType(), mediaTypes); + continue; + } + if(serviceName.equals("GET")) { + if(restService.getPath().equals(PATH_PREFIX + idPathURITemplate)) { + assertEquals("Consumes info of GET operation ", restService.getConsumingContentType(), mediaTypes); + assertEquals("Produces info of GET operation ", restService.getProducingContentType(), mediaTypes); + continue; + } + assertEquals("Path of GET operation ", restService.getPath(), PATH_PREFIX + "?start={Integer}&max={Integer}"); + assertEquals("Consumes info of GET operation ", restService.getConsumingContentType(), mediaTypes); + assertEquals("Produces info of GET operation ", restService.getProducingContentType(), mediaTypes); + continue; + } + if(serviceName.equals("PUT")) { + assertEquals("Path of PUT operation ", restService.getPath(), PATH_PREFIX + idPathURITemplate); + assertEquals("Consumes info of PUT operation ", restService.getConsumingContentType(), mediaTypes); + assertEquals("Produces info of PUT operation ", restService.getProducingContentType(), mediaTypes); + continue; + } + if(serviceName.equals("DELETE")) { + assertEquals("Path of DELETE operation ", restService.getPath(), PATH_PREFIX + idPathURITemplate); + assertEquals("Consumes info of DELETE operation ", restService.getConsumingContentType(), mediaTypes); + assertEquals("Produces info of DELETE operation ", restService.getProducingContentType(), mediaTypes); + continue; + } + fail("Not expected rest service: " + serviceName); + } + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/FiltersInterceptorsSupportTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/FiltersInterceptorsSupportTest.java new file mode 100644 index 000000000..88a9f7108 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/FiltersInterceptorsSupportTest.java @@ -0,0 +1,120 @@ +package org.jboss.tools.ws.ui.bot.test.rest; + +import static org.junit.Assert.assertThat; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.hamcrest.core.Is; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerReqType; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.eclipse.condition.ExactNumberOfProblemsExists; +import org.jboss.reddeer.eclipse.condition.ProblemExists; +import org.jboss.reddeer.eclipse.ui.problems.Problem; +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView; +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView.ProblemType; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.autobuilding.AutoBuildingRequirement.AutoBuilding; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.tools.ws.reddeer.editor.ExtendedTextEditor; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Testing support for custom Name-Binding annotation + * + * Run with J2EE7+ server + * + * @author Radoslav Rabara + * + * @see http://tools.jboss.org/documentation/whatsnew/jbosstools/4.2.0.Beta1.html#webservices + * @since JBT 4.2.0.Beta1 + */ +@RunWith(RedDeerSuite.class) +@JBossServer(state=ServerReqState.PRESENT, type=ServerReqType.WILDFLY) +@AutoBuilding(value = false, cleanup = true) +public class FiltersInterceptorsSupportTest extends RESTfulTestBase { + + @Override + public void setup() { + // no setup required + } + + @Test + public void requestFilterSupportTest() { + filterSupportTest("filter1"); + } + + @Test + public void responseFilterSupportTest() { + filterSupportTest("filter2"); + } + + @Test + public void readInterceptorSupportTest() { + interceptorSupportTest("interceptor1"); + } + + @Test + public void writeInterceptorSupportTest() { + interceptorSupportTest("interceptor2"); + } + + @Test + public void filterInterceptorDefinedAsInnerClassesSupportTest() { + String projectName = "filterinterceptor1"; + importAndCheckErrors(projectName); + ProjectHelper.cleanAllProjects(); + assertCountOfValidationProblemsExists(ProblemType.WARNING, projectName, null, null, 4); + } + + private void filterSupportTest(String projectName) { + importAndCheckErrors(projectName); + providerValidationWarning(projectName, "Filter"); + } + + private void interceptorSupportTest(String projectName) { + importAndCheckErrors(projectName); + providerValidationWarning(projectName, "Interceptor"); + } + + private void providerValidationWarning(String projectName, String className) { + ProjectHelper.cleanAllProjects(); + /* wait for JAX-RS validator */ + new WaitUntil(new ProblemExists(ProblemType.ANY), + TimePeriod.NORMAL, false); + + // there should be "No JAX-RS Activator is defined for the project." warning + List warningsBefore = new ProblemsView().getProblems(ProblemType.WARNING); + List warningsBeforeStrings = new ArrayList(); + for (Problem warning: warningsBefore) { + warningsBeforeStrings.add(warning.toString()); + } + + //remove @Provider annotation + openJavaFile(projectName, "org.rest.test", className + ".java"); + new ExtendedTextEditor().removeLine("@Provider"); + + //remove unused import + new ExtendedTextEditor().removeLine("import javax.ws.rs.ext.Provider;"); + new ExtendedTextEditor().save(); + ProjectHelper.cleanAllProjects(); + + /* wait for JAX-RS validator */ + new WaitUntil(new ExactNumberOfProblemsExists(ProblemType.WARNING, + warningsBefore.size()+1), TimePeriod.NORMAL, false); + + //one more warning Description "The @Provider annotation is missing on this java type." + List warningsAfter = new ProblemsView().getProblems(ProblemType.WARNING); + assertThat("Expected one more warnings.\nBefore: " + + Arrays.toString(warningsBeforeStrings.toArray()) + "\nAfter: " + + Arrays.toString(warningsAfter.toArray()), warningsAfter.size() - warningsBefore.size(), Is.is(1)); + + /* there should be no error */ + assertCountOfProblemsExists(ProblemType.ERROR, projectName, null, null, 0); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/NameBindingAnnotationSupportTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/NameBindingAnnotationSupportTest.java new file mode 100644 index 000000000..74677ceb1 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/NameBindingAnnotationSupportTest.java @@ -0,0 +1,102 @@ +package org.jboss.tools.ws.ui.bot.test.rest; + +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerReqType; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView.ProblemType; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.autobuilding.AutoBuildingRequirement.AutoBuilding; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.common.reddeer.requirements.JavaFoldingRequirement.JavaFolding; +import org.jboss.tools.ws.reddeer.editor.ExtendedTextEditor; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Testing support for custom Name Binding annotation

+ * + * Run with J2EE7+ server + * + * @author Radoslav Rabara + * + * @see http://tools.jboss.org/documentation/whatsnew/jbosstools/4.2.0.Beta1.html#webservices + * @since JBT 4.2.0.Beta1 + */ +@RunWith(RedDeerSuite.class) +@JBossServer(state=ServerReqState.PRESENT, type=ServerReqType.WILDFLY) +@AutoBuilding(value = false, cleanup = true) +@JavaFolding(false) +public class NameBindingAnnotationSupportTest extends RESTfulTestBase { + + @Override + public void setup() { + // no setup required + } + + @Test + public void definingNameBindingAnnotationWithoutTargetAndRetentionTest() { + /* import the project */ + String projectName = "namebinding1"; + importAndCheckErrors(projectName); + + openJavaFile(projectName, "org.rest.test", "Authorized.java"); + + /* remove @Target and @Retention annotations*/ + ExtendedTextEditor textEditor = new ExtendedTextEditor(); + textEditor.removeLine("@Target({ElementType.METHOD, ElementType.TYPE})"); + textEditor.removeLine("@Retention(RetentionPolicy.RUNTIME)"); + ProjectHelper.cleanAllProjects(); + + /* there should be 2 errors complaining about missing deleted annotations */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, null, null, 2); + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, "Retention", null, 1); + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, "Target", null, 1); + assertCountOfProblemsExists(ProblemType.ERROR, projectName, null, null, 2); + + /* prepare editor */ + openAuthorizedJavaFile(projectName); + TextEditor editor = setCursorPositionToTextInTextEditor("Authorized"); + + /* check that there are quick fixes for both required annotations */ + editor.openQuickFixContentAssistant().chooseProposal("Add @Retention annotation on type 'Authorized'"); + new TextEditor().save(); + ProjectHelper.cleanAllProjects(); + + /* one error should disappear as a result of using a quickfix */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, null, null, 1); + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, "Retention", null, 0); + + /* apply the second quixk fix */ + editor.activate(); + editor.openQuickFixContentAssistant().chooseProposal("Add @Target annotation on type 'Authorized'"); + new TextEditor().save(); + ProjectHelper.cleanAllProjects(); + + /* both quickfixes were used which means that there should be no error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, null, null, 0); + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, "Retention", null, 0); + + } + + @Test + public void usingNameBindingAnnotationWithoutFilterOrInterceptor() { + /* import the project */ + String projectName = "namebinding2"; + importWSTestProject(projectName); + + /* remove the filter */ + new ProjectExplorer().getProject(projectName) + .getProjectItem("Java Resources", "src", "org.rest.test", "Filter.java").delete(); + ProjectHelper.cleanAllProjects(); + + /* there should be an error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, null, null, 1); + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, "no JAX-RS filter or interceptor", null, 1); + } + + private void openAuthorizedJavaFile(String projectName) { + openJavaFile(projectName, "org.rest.test", "Authorized.java"); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/PreMatchingAnnotationSupportTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/PreMatchingAnnotationSupportTest.java new file mode 100644 index 000000000..0d667d145 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/PreMatchingAnnotationSupportTest.java @@ -0,0 +1,48 @@ +package org.jboss.tools.ws.ui.bot.test.rest; + +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerReqType; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView.ProblemType; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.autobuilding.AutoBuildingRequirement.AutoBuilding; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Testing support for {@link javax.ws.rs.container.PreMatching} + * + * Run with J2EE7+ server + * + * @author Radoslav Rabara + * + * @see http://tools.jboss.org/documentation/whatsnew/jbosstools/4.2.0.Beta1.html#webservices + * @since JBT 4.2.0.Beta1 + */ +@RunWith(RedDeerSuite.class) +@JBossServer(state=ServerReqState.PRESENT, type=ServerReqType.WILDFLY) +@AutoBuilding(value = false, cleanup = true) +public class PreMatchingAnnotationSupportTest extends RESTfulTestBase { + + @Override + public void setup() { + // no setup required + } + + @Test + public void useOnContainerRequestFilterTest() { + importAndCheckErrors("prematching1"); + } + + @Test + public void useOnNotSupportedTypeTest() { + String projectName = "prematching2"; + importWSTestProject(projectName); + ProjectHelper.cleanAllProjects(); + + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, null, null, 1); + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, + "@PreMatching annotation is only allowed on subclasses of javax.ws.rs.container.ContainerRequestFilter", null, 1); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/RESTfulHelper.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/RESTfulHelper.java new file mode 100644 index 000000000..ab269cb35 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/RESTfulHelper.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2010-2012 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.jboss.tools.ws.ui.bot.test.rest; + +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.core.condition.ShellWithTextIsAvailable; +import org.jboss.reddeer.eclipse.core.resources.Project; +import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; +import org.jboss.reddeer.swt.api.Menu; +import org.jboss.reddeer.swt.impl.button.PushButton; +import org.jboss.reddeer.swt.impl.menu.ContextMenu; +import org.jboss.reddeer.swt.impl.shell.DefaultShell; +import org.jboss.reddeer.workbench.ui.dialogs.WorkbenchPreferenceDialog; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulLabel; +import org.jboss.tools.ws.reddeer.ui.preferences.JAXRSValidatorPreferencePage; + +public class RESTfulHelper { + + public void enableRESTValidation() { + modifyRESTValidation(true); + } + + public void disableRESTValidation() { + modifyRESTValidation(false); + } + + public void modifyRESTValidation(boolean enableRestSupport) { + WorkbenchPreferenceDialog dialog = new WorkbenchPreferenceDialog(); + dialog.open(); + JAXRSValidatorPreferencePage page = new JAXRSValidatorPreferencePage(); + dialog.select(page); + + page.setEnableValidation(enableRestSupport); + + page.apply(); + + new WaitUntil(new ShellWithTextIsAvailable("Validator Settings Changed"), TimePeriod.SHORT, false); + if(new ShellWithTextIsAvailable("Validator Settings Changed").test()) { + new DefaultShell("Validator Settings Changed"); + new PushButton("Yes").click(); + new WaitWhile(new ShellWithTextIsAvailable("Validator Settings Changed"), TimePeriod.NORMAL); + } + + dialog.ok(); + + new WaitUntil(new JobIsRunning(), TimePeriod.NORMAL, false); + new WaitWhile(new JobIsRunning(), TimePeriod.getCustom(20), false); + } + + public void addRestSupport(String wsProjectName) { + configureRestSupport(wsProjectName, true); + } + + public void removeRestSupport(String wsProjectName) { + configureRestSupport(wsProjectName, false); + } + + public boolean isRestSupportEnabled(String wsProjectName) { + Project project = new ProjectExplorer().getProject(wsProjectName); + return project.containsItem(RESTfulLabel.REST_WS_NODE) + || project.containsItem(RESTfulLabel.REST_WS_BUILD_NODE); + } + + private void configureRestSupport(String wsProjectName, + boolean enableRestSupport) { + new ProjectExplorer().getProject(wsProjectName).select(); + + Menu menu = new ContextMenu("Configure", + enableRestSupport ? RESTfulLabel.ADD_REST_SUPPORT : RESTfulLabel.REMOVE_REST_SUPPORT); + menu.select(); + + new WaitUntil(new JobIsRunning(), TimePeriod.NORMAL, false); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/RESTfulTestBase.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/RESTfulTestBase.java new file mode 100644 index 000000000..c7121c8f7 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/RESTfulTestBase.java @@ -0,0 +1,325 @@ +/******************************************************************************* + * Copyright (c) 2010-2013 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.jboss.tools.ws.ui.bot.test.rest; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.hamcrest.core.Is; +import org.hamcrest.core.StringContains; +import org.hamcrest.core.StringStartsWith; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.common.condition.AbstractWaitCondition; +import org.jboss.reddeer.common.exception.WaitTimeoutExpiredException; +import org.jboss.reddeer.common.matcher.RegexMatcher; +import org.jboss.reddeer.common.wait.AbstractWait; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.core.condition.ShellWithTextIsAvailable; +import org.jboss.reddeer.core.matcher.WithTextMatchers; +import org.jboss.reddeer.eclipse.condition.ExactNumberOfProblemsExists; +import org.jboss.reddeer.eclipse.condition.ProblemExists; +import org.jboss.reddeer.eclipse.core.resources.Project; +import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; +import org.jboss.reddeer.eclipse.ui.perspectives.JavaEEPerspective; +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView.ProblemType; +import org.jboss.reddeer.eclipse.ui.problems.matcher.AbstractProblemMatcher; +import org.jboss.reddeer.eclipse.ui.problems.matcher.ProblemsDescriptionMatcher; +import org.jboss.reddeer.eclipse.ui.problems.matcher.ProblemsPathMatcher; +import org.jboss.reddeer.eclipse.ui.problems.matcher.ProblemsTypeMatcher; +import org.jboss.reddeer.requirements.openperspective.OpenPerspectiveRequirement.OpenPerspective; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.reddeer.swt.api.Menu; +import org.jboss.reddeer.swt.impl.menu.ContextMenu; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.ws.reddeer.editor.ExtendedTextEditor; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebService; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebServicesNode; +import org.jboss.tools.ws.reddeer.ui.tester.views.WsTesterView; +import org.jboss.tools.ws.ui.bot.test.WSTestBase; +import org.jboss.tools.ws.ui.bot.test.uiutils.RunOnServerDialog; +import org.jboss.tools.ws.ui.bot.test.utils.ResourceHelper; +import org.junit.Assert; + +/** + * Test base for bot tests using RESTFul support + * + * @author jjankovi + * + */ +@JBossServer(state=ServerReqState.STOPPED, cleanup=false) +@OpenPerspective(JavaEEPerspective.class) +public class RESTfulTestBase extends WSTestBase { + + public static final String PATH_PARAM_VALID_ERROR = "@PathParam value"; + public static final String JAX_RS_PROBLEM = "JAX-RS Problem"; + + protected final static RESTfulHelper restfulHelper = new RESTfulHelper(); + + protected RESTfulWebServicesNode restWebServicesNode = null; + + protected final String SIMPLE_REST_WS_RESOURCE = "SimpleRestWS.java.ws"; + + private final TimePeriod WAIT_FOR_PROBLEMS_FALSE_POSItIVE_TIMEOUT = TimePeriod.getCustom(2); + private final TimePeriod WAIT_FOR_PROBLEMS_FALSE_NEGATIVE_TIMEOUT = TimePeriod.getCustom(5); + + protected String getWsPackage() { + return "org.rest.test"; + } + + protected String getWsName() { + return "RestService"; + } + + @Override + public void setup() { + if (!projectExists(getWsProjectName())) { + importWSTestProject(getWsProjectName()); + } + } + + @Override + public void cleanup() { + deleteAllProjects(); + } + + protected void importAndCheckErrors(String projectName) { + importWSTestProject(projectName); + + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, null, null, 0); + assertCountOfProblemsExists(ProblemType.ERROR, null, null, null, 0); + } + + private AbstractProblemMatcher[] getProblemMatchers(String description, String project, String type) { + List matcherList = new ArrayList(); + if (description != null) { + matcherList.add(new ProblemsDescriptionMatcher(StringContains.containsString(description))); + } + if (project != null) { + matcherList. add(new ProblemsPathMatcher(StringStartsWith.startsWith("/" + project))); + } + if (type != null) { + matcherList.add(new ProblemsTypeMatcher(Is.is(type))); + } + AbstractProblemMatcher[] matchers = new AbstractProblemMatcher[matcherList.size()]; + return matchers = matcherList.toArray(matchers); + } + + public void assertCountOfProblemsExists(ProblemType problemType, String projectName, + String description, String type, int count) { + AbstractProblemMatcher[] matchers = getProblemMatchers(description, projectName, type); + try { + new WaitUntil(new ExactNumberOfProblemsExists(problemType, count, matchers)); + } catch (WaitTimeoutExpiredException ex) { + Assert.fail("There is not " + count + " number of problems matching specified matchers existing."); + } + } + + public void assertCountOfProblemsExists(ProblemType problemType, int count) { + assertCountOfProblemsExists(problemType, null, null, null, count); + } + + public void assertCountOfValidationProblemsExists(ProblemType problemType, String projectName, + String description, String type, int count) { + AbstractProblemMatcher[] matchers = getProblemMatchers(description, projectName, type); + + if(count == 0 && !new ProblemExists(ProblemType.ANY).test()) {//prevent from false positive result when we do not expect errors and there is no error + new WaitWhile(new ExactNumberOfProblemsExists(ProblemType.ERROR, count, matchers), + WAIT_FOR_PROBLEMS_FALSE_POSItIVE_TIMEOUT, false); + } else {//prevent from false negative result + new WaitUntil(new ExactNumberOfProblemsExists(ProblemType.ERROR, count, matchers), + WAIT_FOR_PROBLEMS_FALSE_NEGATIVE_TIMEOUT, false); + } + + try { + new WaitUntil(new ExactNumberOfProblemsExists(problemType, count, matchers)); + } catch (WaitTimeoutExpiredException ex) { + Assert.fail("There is not " + count + " number of problems matching specified matchers existing."); + } + } + + protected void assertCountOfRESTServices(List restServices, + int expectedCount) { + assertTrue(restServices.size() + " RESTful services" + + " was found instead of " + expectedCount, + restServices.size() == expectedCount); + } + + protected void assertAllRESTServicesInExplorer(List restServices) { + assertTrue("All RESTful services (GET, DELETE, POST, PUT) " + + "should be present but they are not\nThere are " + + Arrays.toString(restServices.toArray()), + allRestServicesArePresent(restServices)); + } + + protected void assertNotAllRESTServicesInExplorer(List restServices) { + assertFalse("All RESTful services (GET, DELETE, POST, PUT) " + + "shouldnt be present but they are" + + Arrays.toString(restServices.toArray()), + allRestServicesArePresent(restServices)); + } + + protected void assertExpectedPathOfService(String message, + RESTfulWebService service, String expectedPath) { + assertEquals(message + "Failure when comparing paths\n", expectedPath, + service.getPath()); + } + + protected void assertExpectedPathOfService(RESTfulWebService service, + String expectedPath) { + assertExpectedPathOfService("", service, expectedPath); + } + + protected List restfulServicesForProject(String projectName) { + restWebServicesNode = new RESTfulWebServicesNode(projectName); + return restWebServicesNode.getWebServices(); + } + + protected void invokeMethodInWSTester(WsTesterView wsTesterView, WsTesterView.RequestType type) { + wsTesterView.setRequestType(type); + wsTesterView.invoke(); + } + + protected void copyRestfulResource(String resourceFile, Object... param) { + String streamPath = "/resources/restful/" + resourceFile; + InputStream stream = this.getClass().getResourceAsStream(streamPath); + ResourceHelper.copyResourceToClassWithSave( + stream, true, param); + AbstractWait.sleep(TimePeriod.getCustom(2)); + } + + private boolean allRestServicesArePresent(List restServices) { + String[] allRestMethods = {"GET", "POST", "POST", "DELETE"}; + for (String restMethod : allRestMethods) { + if(!restServiceIsPresent(restServices, restMethod)) { + return false; + } + } + return true; + } + + private boolean restServiceIsPresent(List restServices, String restMethod) { + for (RESTfulWebService restService : restServices) { + if (restService.getMethod().equals(restMethod)) { + return true; + } + } + return false; + } + + protected void runRestServiceOnServer(String restWebServiceMethod) { + runRestServiceOnServer(restWebServicesNode.getWebServiceByMethod(restWebServiceMethod).get(0)); + } + + protected void runRestServiceOnServer(RESTfulWebService restWebService) { + runRestServiceOnServer(restWebService, getConfiguredServerName()); + } + + protected void runRestServiceOnServer(RESTfulWebService restWebService, String serverName) { + restWebService.select(); + + Menu menu = new ContextMenu( + new WithTextMatchers(new RegexMatcher(".*Run.*"), + new RegexMatcher(".*Run on Server.*")).getMatchers()); + menu.select(); + + RunOnServerDialog dialog = new RunOnServerDialog(); + String dialogTitle = dialog.getText(); + dialog.chooseExistingServer(); + dialog.selectServer(serverName); + dialog.finish(); + + new WaitWhile(new ShellWithTextIsAvailable(dialogTitle), TimePeriod.getCustom(20)); + new WaitWhile(new JobIsRunning(), TimePeriod.getCustom(20)); + } + + protected void prepareSimpleRestService(String pathArgument, String pathParamArgument) { + prepareRestService(getWsProjectName(), SIMPLE_REST_WS_RESOURCE, + pathArgument, pathParamArgument); + } + + protected void prepareRestService(String projectName, String resourceFileName, + Object... param) { + openJavaFile(projectName, "org.rest.test", "RestService.java"); + Object[] newParam = new Object[2 + (param != null ? param.length : 0)]; + newParam[0] = "org.rest.test"; + newParam[1] = "RestService"; + for(int i=2;i previousState = new HashSet<>(); + + public RestServicePathsHaveUpdated(String projectName) { + this.projectName = projectName; + for (RESTfulWebService service : restfulServicesForProject(projectName)) { + previousState.add(service.getPath()); + } + } + + @Override + public boolean test() { + Set currentState = new HashSet<>(); + for (RESTfulWebService service : restfulServicesForProject(projectName)) { + currentState.add(service.getPath()); + } + + return !currentState.equals(previousState); + } + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/ValidatingRelatedRSElementsTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/ValidatingRelatedRSElementsTest.java new file mode 100644 index 000000000..9edcb377d --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/ValidatingRelatedRSElementsTest.java @@ -0,0 +1,45 @@ +package org.jboss.tools.ws.ui.bot.test.rest; + +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView.ProblemType; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.autobuilding.AutoBuildingRequirement.AutoBuilding; +import org.jboss.tools.ws.reddeer.editor.ExtendedTextEditor; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Testing validation of related JAX-RS elements. + * + * @author Radoslav Rabara + * + * @see http://tools.jboss.org/documentation/whatsnew/jbosstools/4.2.0.Beta3.html#validating-related-jax-rs-elements + * @since 4.2.0.Beta3 + */ +@RunWith(RedDeerSuite.class) +@AutoBuilding(value = false, cleanup = true) +public class ValidatingRelatedRSElementsTest extends RESTfulTestBase { + + @Override + protected String getWsProjectName() { + return "restRelatedValidation"; + } + + @Test + public void validParameterTest() { + ProjectHelper.cleanAllProjects(); + /* assert there is invalid parameter error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, getWsProjectName(), null, null, 1); + assertCountOfValidationProblemsExists(ProblemType.ERROR, getWsProjectName(), + "The type 'org.rest.test.CarFromString' is not valid for this parameter.", null, 1); + + /* fix the error */ + openJavaFile(getWsProjectName(), "org.rest.test", "CarFromString.java"); + ExtendedTextEditor textEditor = new ExtendedTextEditor(); + textEditor.replace("Car fromString(", "CarFromString fromString("); + ProjectHelper.cleanAllProjects(); + + /* error disappeared */ + assertCountOfProblemsExists(ProblemType.ERROR, getWsProjectName(), null, null, 0); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/completion/RESTfulCompletionTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/completion/RESTfulCompletionTest.java new file mode 100644 index 000000000..728804ca8 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/completion/RESTfulCompletionTest.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2010-2011 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.jboss.tools.ws.ui.bot.test.rest.completion; + +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.List; + +import org.hamcrest.core.StringContains; +import org.jboss.reddeer.jface.text.contentassist.ContentAssistant; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.common.wait.AbstractWait; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.ws.reddeer.editor.ExtendedTextEditor; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Test operates on JAX-RS completion + * @author jjankovi + * + */ +@RunWith(RedDeerSuite.class) +public class RESTfulCompletionTest extends RESTfulTestBase{ + + private static final String GET_METHOD_PATH = "/{userId}"; + private static final String CORRECT_PATH_PARAM = "userId"; + private static final String INCORRECT_PATH_PARAM = "someId"; + private static final String PATH_PARAM_NAVIGATION = "@PathParam("; + private static final List EXP_NON_EMPTY_COMPLETION_RESULT = + Arrays.asList("userId - JAX-RS Mapping"); + private static final List EXP_EMPTY_COMPLETION_RESULT = + Arrays.asList("No Default Proposals"); + + @Override + protected String getWsProjectName() { + return "restEmpty"; + } + + @Test + public void testWithEmptyPrefix() { + prepareSimpleRestService(GET_METHOD_PATH, ""); + + testContentAssistantProposal(PATH_PARAM_NAVIGATION.length() + 1, + EXP_NON_EMPTY_COMPLETION_RESULT); + } + + @Test + public void testWithValidPrefixAtTheEnd() { + prepareSimpleRestService(GET_METHOD_PATH, CORRECT_PATH_PARAM); + + testContentAssistantProposal(PATH_PARAM_NAVIGATION.length() + + CORRECT_PATH_PARAM.length() + 1, + EXP_NON_EMPTY_COMPLETION_RESULT); + + } + + @Test + public void testWithValidPrefixInTheBeginning() { + prepareSimpleRestService(GET_METHOD_PATH, CORRECT_PATH_PARAM); + + testContentAssistantProposal(PATH_PARAM_NAVIGATION.length() + 1, + EXP_NON_EMPTY_COMPLETION_RESULT); + } + + @Test + public void testWithInvalidPrefixAtTheEnd() { + prepareSimpleRestService(GET_METHOD_PATH, INCORRECT_PATH_PARAM); + + testContentAssistantProposal(PATH_PARAM_NAVIGATION.length() + + INCORRECT_PATH_PARAM.length() + 1, + EXP_EMPTY_COMPLETION_RESULT); + + } + + @Test + public void testWithInvalidPrefixInTheBeginning() { + prepareSimpleRestService(GET_METHOD_PATH, INCORRECT_PATH_PARAM); + + testContentAssistantProposal(PATH_PARAM_NAVIGATION.length() + 1, + EXP_NON_EMPTY_COMPLETION_RESULT); + } + + @Test + public void testWithAllInvalidParamSelection() { + prepareSimpleRestService(GET_METHOD_PATH, INCORRECT_PATH_PARAM); + + testContentAssistantProposal(INCORRECT_PATH_PARAM, EXP_NON_EMPTY_COMPLETION_RESULT); + } + + private void testContentAssistantProposal(String textToSelect, + List expected) { + TextEditor editor = new TextEditor(getWsName() + ".java"); + editor.selectText(INCORRECT_PATH_PARAM); + + assertContentAssistantProposal(editor, expected); + } + + private void testContentAssistantProposal(int position, + List expected) { + ExtendedTextEditor editor = new ExtendedTextEditor(getWsName() + ".java"); + int line = editor.getLineNum(StringContains.containsString(PATH_PARAM_NAVIGATION)); + int column = editor.getTextAtLine(line).indexOf(PATH_PARAM_NAVIGATION); + editor.setCursorPosition(line, column + position); + + assertContentAssistantProposal(editor, expected); + } + + private void assertContentAssistantProposal(TextEditor editor, List expected) { + AbstractWait.sleep(TimePeriod.SHORT); + + ContentAssistant assistant = editor.openContentAssistant(); + List proposals = assistant.getProposals(); + assistant.close(); + + assertTrue("Content assist should contain " + + Arrays.toString(expected.toArray()) + + "\nbut there are " + + Arrays.toString(proposals.toArray()), + proposals.containsAll(expected)); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/explorer/RESTfulExplorerTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/explorer/RESTfulExplorerTest.java new file mode 100644 index 000000000..2964d0cd1 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/explorer/RESTfulExplorerTest.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * Copyright (c) 2007-2011 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 + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.ws.ui.bot.test.rest.explorer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.List; + +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebService; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Test operates on exploring RESTFul services in RESTful explorer + * + * @author jjankovi + */ +@RunWith(RedDeerSuite.class) +public class RESTfulExplorerTest extends RESTfulTestBase { + + private static final String REST_BASIC_PROJECT_NAME = "restBasic"; + private static final String REST_ADVANCED_PROJECET_NAME = "restAdvanced"; + + @Override + public void setup() { + + } + + @Test + public void testAddingSimpleRESTMethods() { + final String projectName = REST_BASIC_PROJECT_NAME; + + /* import project */ + importWSTestProject(projectName); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(projectName); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 4); + assertAllRESTServicesInExplorer(restServices); + assertPathOfAllRESTWebServices(restServices, "/rest"); + } + + @Test + public void testAddingAdvancedRESTMethods() { + final String projectName = REST_ADVANCED_PROJECET_NAME; + + /* import project */ + importWSTestProject(projectName); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(projectName); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 4); + assertAllRESTServicesInExplorer(restServices); + testAdvancedRESTServices(restServices); + } + + @Test + public void testEditingSimpleRESTMethods() { + final String projectName = REST_BASIC_PROJECT_NAME; + + /* import project */ + importWSTestProject(projectName); + + /* replace @DELETE annotation to @GET annotation */ + replaceInRestService(projectName, "@DELETE", "@GET"); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(projectName); + + /* test JAX-RS REST explorer */ + assertNotAllRESTServicesInExplorer(restServices); + assertAbsenceOfRESTWebService(restServices, "DELETE"); + } + + @Test + public void testEditingAdvancedRESTMethods() { + final String projectName = REST_ADVANCED_PROJECET_NAME; + + /* import project */ + importWSTestProject(projectName); + + /* edit @DELETE annotation */ + replaceInRestService(projectName, "/delete/{id}", "delete/edited//{id}"); + replaceInRestService(projectName, "@DELETE", "@DELETE" + LINE_SEPARATOR + + "@Produces(\"text/plain\")"); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(projectName); + + /* test JAX-RS REST explorer */ + testEditedDeleteRestWebResource(restServices); + } + + @Test + public void testDeletingRESTMethods() { + final String projectName = REST_BASIC_PROJECT_NAME; + + /* prepare project*/ + importWSTestProject(projectName); + prepareRestService(projectName, "EmptyRestfulWS.java.ws"); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(projectName); + + /* none of REST web services found */ + assertCountOfRESTServices(restServices, 0); + } + + private void testEditedDeleteRestWebResource(List restServices) { + for (RESTfulWebService restService : restServices) { + if (restService.getMethod().equals("DELETE")) { + assertEquals("Path of DELETE operation ", "/rest/delete/edited/{id:int}", restService.getPath()); + assertEquals("Produces info of DELETE operation ", "text/plain", restService.getProducingContentType()); + } + } + } + + private void testAdvancedRESTServices(List restServices) { + for (RESTfulWebService restService : restServices) { + if (restService.getMethod().equals("GET")) { + assertTrue("Path of GET operation ", restService.getPath().equals("/rest/{id:int}")); + assertTrue("Consumes info of GET operation ", restService.getConsumingContentType().equals("*/*")); + assertTrue("Produces info of GET operation ", restService.getProducingContentType().equals("text/plain")); + } + if (restService.getMethod().equals("PUT")) { + assertTrue("Path of PUT operation ", restService.getPath().equals("/rest/put/{id:int}")); + assertTrue("Consumes info of PUT operation ", restService.getConsumingContentType().equals("text/plain")); + assertTrue("Produces info of PUT operation ", restService.getProducingContentType().equals("*/*")); + } + if (restService.getMethod().equals("POST")) { + assertTrue("Path of POST operation ", restService.getPath().equals("/rest/post/{id:int}")); + assertTrue("Consumes info of POST operation ", restService.getConsumingContentType().equals("text/plain")); + assertTrue("Produces info of POST operation ", restService.getProducingContentType().equals("text/plain")); + } + if (restService.getMethod().equals("DELETE")) { + assertEquals("Path of DELETE operation ", restService.getPath(), "/rest/delete/{id:int}"); + assertEquals("Consumes info of DELETE operation ", restService.getConsumingContentType(), "*/*"); + assertEquals("Produces info of DELETE operation ", restService.getProducingContentType(), "*/*"); + } + } + } + + protected void assertPathOfAllRESTWebServices(List restServices, + String path) { + for (RESTfulWebService restService : restServices) { + assertTrue("RESTful Web Service \"" + restService.getMethod() + + "\" has been set wrong path", + restService.getPath().equals(path)); + } + } + + protected void assertAbsenceOfRESTWebService(List restServices, + String restWebServiceMethod) { + for (RESTfulWebService restService : restServices) { + if (restService.getMethod().equals(restWebServiceMethod)) { + fail("There should not be " + restWebServiceMethod + "RESTful services"); + } + } + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/explorer/RESTfulSupportTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/explorer/RESTfulSupportTest.java new file mode 100644 index 000000000..0678a6ac8 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/explorer/RESTfulSupportTest.java @@ -0,0 +1,57 @@ +package org.jboss.tools.ws.ui.bot.test.rest.explorer; + +import static org.junit.Assert.assertNotNull; + +import org.jboss.reddeer.jface.exception.JFaceLayerException; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebServicesNode; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Test checks if context menu 'Add RESTful Support' works properly + * + * @author jjankovi + * @author Radoslav Rabara + * + * @see https://issues.jboss.org/browse/JBIDE-16329 + */ +@RunWith(RedDeerSuite.class) +public class RESTfulSupportTest extends RESTfulTestBase { + + protected String getWsProjectName() { + return "RestExplorerTest"; + } + + @Override + public void setup() { + + } + + @Test + public void testJaxRsExplorerSupport() { + /* create dynamic web project */ + ProjectHelper.createProject(getWsProjectName()); + + /* add RESTful support into project */ + restfulHelper.addRestSupport(getWsProjectName()); + + /* test if RESTful explorer is not missing */ + assertRestFullSupport(getWsProjectName()); + } + + protected void assertRestFullSupport(String projectName) { + RESTfulWebServicesNode webServicesNode = null; + String missingRESTExplorerMessage = "JAX-RS REST Web Services explorer is missing in " + + "project \"" + projectName + "\""; + try { + webServicesNode = new RESTfulWebServicesNode(projectName); + } catch (JFaceLayerException e) { + Assert.fail(missingRESTExplorerMessage + "\nThrown exception: " + e.getMessage()); + } + assertNotNull(missingRESTExplorerMessage, webServicesNode); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/BeanParamAnnotationSupportTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/BeanParamAnnotationSupportTest.java new file mode 100644 index 000000000..478858742 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/BeanParamAnnotationSupportTest.java @@ -0,0 +1,256 @@ +package org.jboss.tools.ws.ui.bot.test.rest.param; + +import java.util.List; + +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerReqType; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView.ProblemType; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.autobuilding.AutoBuildingRequirement.AutoBuilding; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.tools.ws.reddeer.editor.ExtendedTextEditor; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebService; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * + * Testing support for JAX-RS ParamConverterProvider + * + * Run with J2EE7+ server + * + * @author Radoslav Rabara + * @since JBT 4.2.0 Beta3 + * @see https://issues.jboss.org/browse/JBIDE-16825 + */ +@RunWith(RedDeerSuite.class) +@JBossServer(state=ServerReqState.PRESENT, type=ServerReqType.WILDFLY) +@AutoBuilding(value = false, cleanup = true) +public class BeanParamAnnotationSupportTest extends RESTfulTestBase { + + + // Projects containing RestService with method with {@link BeanParam} + // bound to class Car, which contains field annotated with {@link @PathParam} + private final String PROJECT1_NAME = "bean1"; + private final String PROJECT2_NAME = "bean2"; + private final String PROJECT3_NAME = "bean3"; + private final String PROJECT4_NAME = "bean4"; + private final String PROJECT5_NAME = "bean5"; + private final String PROJECT6_NAME = "bean6"; + + private final String pathParam1 = "id"; + private final String pathType1 = "Integer"; + private final String queryParam1 = "author"; + private final String queryType1 = "String"; + private final String matrixParam1 = "country"; + private final String matrixType1 = "Long"; + + @Override + public void setup() { + + } + + @Test + public void testBeanClassWithPathParamField() { + final String pathAnnotation = "@Path(\"{" + pathParam1 + "}\")"; + final String pathParameterNotBoundToAnyFieldWarning = "The @Path template parameter 'id' is not bound to any field, property or method parameter annotated with @PathParam(\"id\")."; + final String pathParamNotBoundToPathParameterError = "@PathParam value 'id' does not match any @Path annotation template parameters in 'org.rest.test.RestService'."; + final String pathParameterNotBoundToPathParamError = "@PathParam value 'id' in associated Parameter Aggregator 'org.rest.test.BeanClass' does not match any @Path annotation template parameters of the java method 'post' and its enclosing java type 'org.rest.test.RestService'."; + + /* prepare project */ + importWSTestProject(PROJECT1_NAME); + + /* there is no error */ + assertCountOfProblemsExists(ProblemType.ERROR, PROJECT1_NAME, null, null, 0); + assertCountOfValidationProblemsExists(ProblemType.WARNING, PROJECT1_NAME, pathParameterNotBoundToAnyFieldWarning, null, 0); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(PROJECT1_NAME); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest/{" + pathParam1 + ":" + pathType1 + "}"); + + /* open RestService class */ + openJavaFile(PROJECT1_NAME, "org.rest.test", "RestService.java"); + ExtendedTextEditor editor = new ExtendedTextEditor(); + + /* remove @Path annotation from RestService and assert there are two errors (one in RestService and one in BeanClass */ + editor.removeLine(pathAnnotation); + ProjectHelper.cleanAllProjects(); + new WaitUntil(new RestServicePathsHaveUpdated(PROJECT1_NAME), TimePeriod.getCustom(3), false); + + assertCountOfProblemsExists(ProblemType.ERROR, PROJECT1_NAME, pathParamNotBoundToPathParameterError, null, 1); + assertCountOfProblemsExists(ProblemType.ERROR, PROJECT1_NAME, pathParameterNotBoundToPathParamError, null, 1); + assertCountOfProblemsExists(ProblemType.ERROR, PROJECT1_NAME, null, null, 2); + + /* add @Path annotation into RestService and assert that errors disappear */ + editor.insertBeforeLine(pathAnnotation, "public void post("); + ProjectHelper.cleanAllProjects(); + assertCountOfValidationProblemsExists(ProblemType.ERROR, PROJECT1_NAME, null, null, 0); + + /* open BeanClass class */ + openBeanClass(PROJECT1_NAME); + editor = new ExtendedTextEditor(); + + /* remove @PathParam from BeanClass and assert that there is an warning */ + editor.removeLine("@PathParam"); + ProjectHelper.cleanAllProjects(); + assertCountOfValidationProblemsExists(ProblemType.WARNING, PROJECT1_NAME, pathParameterNotBoundToAnyFieldWarning, null, 1); + } + + @Test + public void testBeanClassWithQueryParamField() { + final String defaultValue = "defVal"; + + /* prepare project */ + importWSTestProject(PROJECT2_NAME); + + /* there is no error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, PROJECT2_NAME, null, null, 0); + + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(PROJECT2_NAME); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest?" + queryParam1 + "={" + queryType1 + "}"); + + /* open BeanClass class */ + openBeanClass(PROJECT2_NAME); + ExtendedTextEditor editor = new ExtendedTextEditor(); + + /* remove @QueryParam from BeanClass and assert that endpoint URI was updated */ + editor.removeLine("@QueryParam"); + ProjectHelper.cleanAllProjects(); + + refreshRestServices(PROJECT2_NAME); + new WaitUntil(new RestServicePathsHaveUpdated(PROJECT2_NAME), TimePeriod.getCustom(3), false); + + restServices = restfulServicesForProject(PROJECT2_NAME); + assertExpectedPathOfService("unstable ", restServices.get(0), "/rest"); + + /* add @QueryParam and @DefaultValue into BeanClass and assert that endpoint URI was updated */ + editor.insertBeforeLine("@QueryParam(\"" + queryParam1 + "\")", queryType1); + editor.insertBeforeLine("import javax.ws.rs.DefaultValue;", "import javax.ws.rs.QueryParam;"); + editor.insertBeforeLine("@DefaultValue(\"" + defaultValue + "\")", queryType1); + ProjectHelper.cleanAllProjects(); + new WaitUntil(new RestServicePathsHaveUpdated(PROJECT2_NAME), TimePeriod.SHORT, false); + + restServices = restfulServicesForProject(PROJECT2_NAME); + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest?" + queryParam1 + "={" + queryType1 + ":\"" + defaultValue + "\"}"); + } + + @Test + public void testBeanClassWithMatrixParamField() { + final String defaultValue = "1"; + + /* prepare project */ + importWSTestProject(PROJECT3_NAME); + + /* there is no error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, PROJECT3_NAME, null, null, 0); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(PROJECT3_NAME); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest;" + matrixParam1 + "={" + matrixType1 + "}"); + + new WaitWhile(new JobIsRunning(), TimePeriod.LONG); + + /* open BeanClass class */ + openBeanClass(PROJECT3_NAME); + ExtendedTextEditor editor = new ExtendedTextEditor(); + + /* remove @MatrixParam from BeanClass and assert that endpoint URI was updated */ + editor.removeLine("@MatrixParam"); + ProjectHelper.cleanAllProjects(); + + refreshRestServices(PROJECT3_NAME); + new WaitUntil(new RestServicePathsHaveUpdated(PROJECT3_NAME), TimePeriod.getCustom(3), false); + + restServices = restfulServicesForProject(PROJECT3_NAME); + + assertExpectedPathOfService("unstable ", restServices.get(0), "/rest"); + + /* add @MatrixParam and @DefaultValue into BeanClass and assert that endpoint URI was updated */ + editor.insertBeforeLine("@MatrixParam(\"" + matrixParam1 + "\")", matrixType1); + editor.insertBeforeLine("import javax.ws.rs.DefaultValue;", "import javax.ws.rs.MatrixParam;"); + editor.insertBeforeLine("@DefaultValue(\"" + defaultValue + "\")", matrixType1); + ProjectHelper.cleanAllProjects(); + new WaitUntil(new RestServicePathsHaveUpdated(PROJECT3_NAME), TimePeriod.SHORT, false); + + restServices = restfulServicesForProject(PROJECT3_NAME); + assertExpectedPathOfService(restServices.get(0), + "/rest;" + matrixParam1 + "={" + matrixType1 + ":\"" + defaultValue + "\"}");//unstable + } + + @Test + public void testBeanClassWithPathParamMethod() { + /* prepare project */ + importWSTestProject(PROJECT4_NAME); + + /* there is no error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, PROJECT4_NAME, null, null, 0); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(PROJECT4_NAME); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest/{" + pathParam1 + ":" + pathType1 + "}"); + } + + @Test + public void testBeanClassWithQueryParamMethod() { + /* prepare project */ + importWSTestProject(PROJECT5_NAME); + + /* there is no error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, PROJECT5_NAME, null, null, 0); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(PROJECT5_NAME); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest?" + queryParam1 + "={" + queryType1 + "}"); + } + + @Test + public void testBeanClassWithMatrixParamMethod() { + /* prepare project */ + importWSTestProject(PROJECT6_NAME); + + /* there is no error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, PROJECT6_NAME, null, null, 0); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(PROJECT6_NAME); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest;" + matrixParam1 + "={" + matrixType1 + "}"); + } + + private void openBeanClass(String projectName) { + openJavaFile(projectName, "org.rest.test", "BeanClass.java"); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/DefaultValueAnnotationSupportTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/DefaultValueAnnotationSupportTest.java new file mode 100644 index 000000000..149fb3efc --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/DefaultValueAnnotationSupportTest.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2007-2012 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 + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.ws.ui.bot.test.rest.param; + +import java.util.List; + +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebService; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.junit.ComparisonFailure; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(RedDeerSuite.class) +public class DefaultValueAnnotationSupportTest extends RESTfulTestBase { + + private String paramName = "param"; + private String defaultValue = "abc"; + private String paramType = "String"; + + @Override + public void setup() { + + } + + @Test + public void testQueryParamDefaultValue() { + /* prepare project */ + importWSTestProject("default1"); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject("default1"); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest?" + paramName + "={" + paramType + ":\"" + defaultValue + "\"}"); + } + + @Test + public void testMatrixParamDefaultValue() { + /* prepare project */ + importWSTestProject("default2"); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject("default2"); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest;" + paramName + "={" + paramType + ":\"" + defaultValue + "\"}"); + } + + /** + * Fails due to JBIDE-12027 + * + * @see https://issues.jboss.org/browse/JBIDE-12027 + */ + @Test(expected=ComparisonFailure.class) + public void testPathParamDefaultValue() { + /* prepare project */ + importWSTestProject("default3"); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject("default3"); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService("JBIDE-12027: ", restServices.get(0), + "/rest/{" + paramName +":" + paramType + ":" + defaultValue + "}"); + } + +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/MatrixParamAnnotationSupportTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/MatrixParamAnnotationSupportTest.java new file mode 100644 index 000000000..56fcc7d64 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/MatrixParamAnnotationSupportTest.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2007-2012 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 + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.ws.ui.bot.test.rest.param; + +import java.util.List; + +import javax.ws.rs.MatrixParam; + +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebService; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * {@link MatrixParam} annotation support test

+ * + * @author jjankovi + * @author Radoslav Rabara + */ +@RunWith(RedDeerSuite.class) +public class MatrixParamAnnotationSupportTest extends RESTfulTestBase { + + private final String projectName = "matrix1"; + private final String project2Name = "matrix2"; + + private final String matrixParam1 = "author"; + private final String matrixParam2 = "country"; + private final String matrixParamNew = "library"; + private final String matrixParamType1 = "String"; + private final String matrixParamType2 = "Integer"; + private final String matrixParamTypeNew = "Long"; + + @Override + protected String getWsProjectName() { + return projectName; + } + + @Test + public void testMatrixParamSupport() { + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(projectName); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest;" + matrixParam1 + "={" + matrixParamType1 + "};" + + matrixParam2 + "={" + matrixParamType2 + "}"); + } + + @Test + public void testMatrixParamFieldSupport() { + /* prepare project */ + importWSTestProject(project2Name); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(project2Name); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest;" + matrixParam1 + "={" + matrixParamType1 + "};" + + matrixParam2 + "={" + matrixParamType2 + "}"); + } + + @Test + public void testEditingMatrixParam() { + /* prepare project */ + replaceInRestService(matrixParam1, matrixParamNew); + new WaitUntil(new RestServicePathsHaveUpdated(projectName), TimePeriod.getCustom(2), false); + refreshRestServices(projectName); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(projectName); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest;" + matrixParamNew + "={" + matrixParamType1 + "};" + + matrixParam2 + "={" + matrixParamType2 + "}"); + } + + @Test + public void testEditingTypeOfMatrixParam() { + /* prepare project */ + replaceInRestService(matrixParamType1, matrixParamTypeNew); + new WaitUntil(new RestServicePathsHaveUpdated(projectName), TimePeriod.getCustom(2), false); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(projectName); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest;" + matrixParam1 + "={" + matrixParamTypeNew + "};" + + matrixParam2 + "={" + matrixParamType2 + "}"); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/ParamConverterSupportTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/ParamConverterSupportTest.java new file mode 100644 index 000000000..db43b6bcc --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/ParamConverterSupportTest.java @@ -0,0 +1,93 @@ +package org.jboss.tools.ws.ui.bot.test.rest.param; + +import javax.ws.rs.PathParam; + +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerReqType; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.eclipse.jdt.ui.NewJavaClassWizardDialog; +import org.jboss.reddeer.eclipse.jdt.ui.NewJavaClassWizardPage; +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView.ProblemType; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.autobuilding.AutoBuildingRequirement.AutoBuilding; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * + * Testing support for JAX-RS ParamConverterProvider + * + * Run with J2EE7+ server + * + * @author Radoslav Rabara + * @since JBT 4.2.0 Beta3 + * @see https://issues.jboss.org/browse/JBIDE-16763 + */ +@RunWith(RedDeerSuite.class) +@JBossServer(state=ServerReqState.PRESENT, type=ServerReqType.WILDFLY) +@AutoBuilding(value = false, cleanup = true) +public class ParamConverterSupportTest extends RESTfulTestBase { + + /** + * Project contains RestService with @POST method with {@link PathParam} + * bound to class Car + */ + final String PROJECT1_NAME = "paramConverter"; + + @Override + public void setup() { + + } + + @Test + public void testParamConverterSupport() { + /* prepare project */ + importWSTestProject(PROJECT1_NAME); + ProjectHelper.cleanAllProjects(); + + /* assert that type Car is not valid for the parameter */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, PROJECT1_NAME, null, null, 1); + assertCountOfValidationProblemsExists(ProblemType.ERROR, PROJECT1_NAME, + "The type 'org.rest.test.Car' is not valid for this parameter. " + + "See JAX-RS 2.0 Specification (section 3.2) for more information. ", null, 1); + + /* create class implementing ParamConverterProvider */ + createParamConverter(); + ProjectHelper.cleanAllProjects(); + + /* there is no error anymore */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, PROJECT1_NAME, null, null, 0); + } + + private void createParamConverter() { + NewJavaClassWizardDialog newJavaClassDialog = new NewJavaClassWizardDialog(); + newJavaClassDialog.open(); + NewJavaClassWizardPage newJavaClassPage = new NewJavaClassWizardPage(); + newJavaClassPage.setPackage("org.rest.test"); + newJavaClassPage.setName("Converter"); + newJavaClassDialog.finish(); + + TextEditor editor = new TextEditor(); + editor.activate(); + editor.setText(PARAM_CONVERTER_PROVIDER_CLASS_TEXT); + editor.save(); + } + + private final String PARAM_CONVERTER_PROVIDER_CLASS_TEXT = + "package org.rest.test;\n" + + "import java.lang.annotation.Annotation;\n" + + "import java.lang.reflect.Type;\n\n" + + "import javax.ws.rs.ext.ParamConverter;\n" + + "import javax.ws.rs.ext.Provider;\n" + + "import javax.ws.rs.ext.ParamConverterProvider;\n\n" + + + "@Provider\n" + + "public class Converter implements ParamConverterProvider {\n" + + " @Override\n public ParamConverter getConverter(Class arg0, Type arg1, Annotation[] arg2) {\n" + + " return null;\n" + + " }\n" + + "}\n"; +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/PathParamAnnotationSupportTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/PathParamAnnotationSupportTest.java new file mode 100644 index 000000000..7fc426bca --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/PathParamAnnotationSupportTest.java @@ -0,0 +1,197 @@ +/******************************************************************************* + * Copyright (c) 2007-2014 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 + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.ws.ui.bot.test.rest.param; + +import java.util.List; + +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.tools.ws.reddeer.editor.ExtendedTextEditor; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebService; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * {@link PathParam} annotation support test

+ * + * @author Radoslav Rabara + */ +@RunWith(RedDeerSuite.class) +public class PathParamAnnotationSupportTest extends RESTfulTestBase { + + /** + * Project contains method with {@link PathParam}s bound to method's {@link Path}'s parameters + */ + private final static String projectPath1 = "path1"; + /** + * Project contains field with {@link PathParam} bound to method's {@link Path}'s parameter + */ + private final static String projectPath2 = "path2";//uses field annotated with @PathParam + /** + * Project contains field with {@link PathParam} bound to class's {@link Path}'s parameter + */ + private final static String projectPath3 = "path3";//uses field annotated with @PathParam + + private final String pathParam1 = "author"; + private final String pathParam2 = "country"; + private final String pathType1 = "String"; + private final String pathType2 = "Integer"; + + private final String pathParam1New = "newParam1"; + private final String pathType1New = "Long"; + + @Override + public void setup() { + + } + + @Test + public void testPathParamSupport() { + /* prepare project */ + importWSTestProject(projectPath1); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(projectPath1); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest/{" + pathParam1 + ":" + pathType1 + "}" + + "/{" + pathParam2 + ":" + pathType2 + "}"); + } + + @Test + public void testPathParamFieldSupport() { + /* prepare project */ + importWSTestProject(projectPath2); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(projectPath2); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest/{" + pathParam1 + ":" + pathType1 + "}"); + + /* prepare project */ + importWSTestProject(projectPath3); + new WaitUntil(new RestServicePathsHaveUpdated(projectPath3), TimePeriod.getCustom(2), false); + + /* get RESTful services from JAX-RS REST explorer for the project */ + restServices = restfulServicesForProject(projectPath3); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService("JBIDE-17663: ", restServices.get(0), + "/rest/{" + pathParam2 + ":" + pathType1 + "}"); + } + + @Test + public void testAdvancedPathParamFieldSupport() { + final String newPathParam = "year"; + final String newPathType = "Integer"; + /* prepare project */ + importWSTestProject(projectPath2); + + /* open RestService.java */ + openRestService(projectPath2); + + /* add new path param to @Path annotation */ + ExtendedTextEditor editor = new ExtendedTextEditor(); + editor.activate(); + editor.replaceLine("@Path(\"{author}\"", " @Path(\"{author}/{" + newPathParam + "}\")"); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(projectPath2); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest/{" + pathParam1 + ":" + pathType1 + "}/{" + + newPathParam + ":.*}"); + + /* add new @PathParam */ + editor.activate(); + editor.insertBeforeLine(" @PathParam(\"" + newPathParam + "\")\n " + + newPathType + " year;", "@PathParam(\"author\")"); + + /* get RESTful services from JAX-RS REST explorer for the project */ + new WaitUntil(new RestServicePathsHaveUpdated(projectPath2), TimePeriod.getCustom(2), false); + restServices = restfulServicesForProject(projectPath2); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService("JBIDE-17663: ", restServices.get(0), + "/rest/{" + pathParam1 + ":" + pathType1 + "}/{" + + newPathParam + ":" + newPathType + "}"); + } + + @Test + public void testEditingPathParam() { + /* prepare project */ + importWSTestProject(projectPath1); + + /* open RestService.java */ + openRestService(projectPath1); + + /* replace path param's value */ + ExtendedTextEditor editor = new ExtendedTextEditor(); + editor.activate(); + editor.replace(pathParam1, pathParam1New); + refreshRestServices(projectPath1); + + new WaitUntil(new RestServicePathsHaveUpdated(projectPath1), TimePeriod.getCustom(2), false); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(projectPath1); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest/{" + pathParam1New + ":" + pathType1 + "}" + + "/{" + pathParam2 + ":" + pathType2 + "}"); + } + + @Test + public void testEditingTypeOfPathParam() { + /* prepare project */ + importWSTestProject(projectPath1); + + /* open RestService.java */ + openRestService(projectPath1); + + /* replace path param's type */ + ExtendedTextEditor editor = new ExtendedTextEditor(); + editor.activate(); + editor.replace(pathType1, pathType1New); + + new WaitUntil(new RestServicePathsHaveUpdated(projectPath1), TimePeriod.getCustom(2), false); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(projectPath1); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest/{" + pathParam1 + ":" + pathType1New + "}" + + "/{" + pathParam2 + ":" + pathType2 + "}"); + } + + private void openRestService(String projectName) { + openJavaFile(projectName, "org.rest.test", "RestService.java"); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/QueryParamAnnotationSupportTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/QueryParamAnnotationSupportTest.java new file mode 100644 index 000000000..1c0dfdb14 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/param/QueryParamAnnotationSupportTest.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2007-2012 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 + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.ws.ui.bot.test.rest.param; + +import java.util.List; + +import javax.ws.rs.QueryParam; + +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebService; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * {@link QueryParam} annotation support test

+ * + * @author jjankovi + * @author Radoslav Rabara + */ +@RunWith(RedDeerSuite.class) +public class QueryParamAnnotationSupportTest extends RESTfulTestBase { + + private final String QUERY_TWO_PARAM_RESOURCE = "QueryTwoParam.java.ws"; + + private final String project1Name = "query1"; + private final String project2Name = "query2"; + private final String project3Name = "query3"; + + private final String queryParam1 = "param1"; + private final String queryParam2 = "param2"; + private final String queryParam1New = "newParam1"; + private final String queryType1 = "String"; + private final String queryType2 = "Integer"; + private final String queryTypeNew = "Long"; + + @Override + public void setup() { + + } + + @Test + public void testQueryParamSupport() { + /* prepare project */ + importWSTestProject(project1Name); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(project1Name); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest?" + queryParam1 + "={" + queryType1 + "}"); + + /* prepare project*/ + importWSTestProject(project2Name); + + /* get RESTful services from JAX-RS REST explorer for the project */ + restServices = restfulServicesForProject(project2Name); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest?" + queryParam1 + "={" + queryType1 + "}&" + + queryParam2 + "={" + queryType1 + "}"); + } + + @Test + public void testMatrixParamFieldSupport() { + /* prepare project */ + importWSTestProject(project3Name); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(project3Name); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest?" + queryParam1 + "={" + queryType1 + "}&" + + queryParam2 + "={" + queryType2 + "}"); + } + + @Test + public void testEditingQueryParam() { + /* prepare project */ + importWSTestProject(project2Name); + + /* replace param1 to newParam1 */ + replaceInRestService(project2Name, queryParam1, queryParam1New); + refreshRestServices(project2Name); + new WaitUntil(new RestServicePathsHaveUpdated(project2Name), TimePeriod.getCustom(2), false); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(project2Name); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest?" + queryParam1New + "={" + queryType1 + "}&" + + queryParam2 + "={" + queryType1 + "}"); + } + + @Test + public void testEditingTypeOfQueryParam() { + final String query2ProjectName = "query2"; + + /* prepare project and class */ + importWSTestProject(query2ProjectName); + prepareRestService(query2ProjectName, QUERY_TWO_PARAM_RESOURCE, + queryParam1, queryType1, queryParam2, queryType2); + replaceInRestService(query2ProjectName, queryType1, queryTypeNew); + new WaitUntil(new RestServicePathsHaveUpdated(query2ProjectName), TimePeriod.getCustom(2), false); + + /* get RESTful services from JAX-RS REST explorer for the project */ + List restServices = restfulServicesForProject(query2ProjectName); + + /* test JAX-RS REST explorer */ + assertCountOfRESTServices(restServices, 1); + assertExpectedPathOfService(restServices.get(0), + "/rest?" + queryParam1 + "={" + queryTypeNew + "}&" + + queryParam2 + "={" + queryType2 + "}"); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/validation/ApplicationValidationTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/validation/ApplicationValidationTest.java new file mode 100644 index 000000000..51fd7e6af --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/validation/ApplicationValidationTest.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2010-2012 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.jboss.tools.ws.ui.bot.test.rest.validation; + +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView.ProblemType; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.autobuilding.AutoBuildingRequirement.AutoBuilding; +import org.jboss.tools.ws.reddeer.editor.ExtendedTextEditor; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * + * @author jjankovi + * + */ +@RunWith(RedDeerSuite.class) +@AutoBuilding(value = false, cleanup = true) +public class ApplicationValidationTest extends RESTfulTestBase { + + + @Before + public void setup() { + + } + + @Test + public void testMultipleApplicationClasses() { + final String projectName = "app1"; + + /* prepare project */ + importWSTestProject(projectName); + ProjectHelper.cleanAllProjects(); + + /* test validation error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, "Multiple JAX-RS Activators", null, 2); + } + + @Test + public void testWebXmlAndApplicationClassWithWarning() { + final String projectName = "app2"; + + /* prepare project */ + importWSTestProject(projectName); + ProjectHelper.cleanAllProjects(); + + /* test validation error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, null, null, 2); + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, "Multiple JAX-RS Activators", null, 2); + } + + @Test + public void testWebXmlAndApplicationClassWithoutWarning() { + final String projectName = "app3"; + + /* prepare project */ + importWSTestProject(projectName); + ProjectHelper.cleanAllProjects(); + + /* test validation error */ + assertCountOfValidationProblemsExists(ProblemType.WARNING, projectName, null, null, 0); + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, null, null, 0); + } + + @Test + public void testNotExtendingApplicationClass() { + final String projectName = "app4"; + + /* prepare project */ + importWSTestProject(projectName); + ProjectHelper.cleanAllProjects(); + + /* test validation error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, null, null, 1); + + /* fix class - should be no error */ + openJavaFile(projectName, "test", "App.java"); + ExtendedTextEditor textEditor = new ExtendedTextEditor(); + textEditor.replace("@ApplicationPath(\"/rest\")", ""); + ProjectHelper.cleanAllProjects(); + + /* test validation error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, null, null, 0); + } + + @Test + public void testApplicationClassWithoutPath() { + final String projectName = "app5"; + + /* prepare project */ + importWSTestProject(projectName); + ProjectHelper.cleanAllProjects(); + + /* test validation error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, null, null, 1); + + /* fix class - should be no error */ + openJavaFile(projectName, "test", "App.java"); + ExtendedTextEditor textEditor = new ExtendedTextEditor(); + textEditor.replace("extends Application", ""); + ProjectHelper.cleanAllProjects(); + + /* test validation error */ + assertCountOfValidationProblemsExists(ProblemType.ERROR, projectName, null, null, 0); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/validation/JaxRsValidatorTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/validation/JaxRsValidatorTest.java new file mode 100644 index 000000000..f818f0442 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/validation/JaxRsValidatorTest.java @@ -0,0 +1,64 @@ +package org.jboss.tools.ws.ui.bot.test.rest.validation; + +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView.ProblemType; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.autobuilding.AutoBuildingRequirement.AutoBuilding; +import org.jboss.reddeer.workbench.ui.dialogs.WorkbenchPreferenceDialog; +import org.jboss.tools.ws.reddeer.ui.preferences.JAXRSValidatorPreferencePage; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * + * @author jjankovi + * + */ +@RunWith(RedDeerSuite.class) +@AutoBuilding(value = false, cleanup = true) +public class JaxRsValidatorTest extends RESTfulTestBase { + + @Override + public String getWsProjectName() { + return "restValidation2"; + } + + @Override + public void cleanup() { + + } + + @Test + public void testValidatorInPreferences() { + /* try to open JAX-RS Validator in Preferences */ + WorkbenchPreferenceDialog dialog = new WorkbenchPreferenceDialog(); + dialog.open(); + JAXRSValidatorPreferencePage page = new JAXRSValidatorPreferencePage(); + dialog.select(page); + dialog.cancel(); + } + + @Test + public void testValidatorEnabled() { + /* enable restful validation */ + restfulHelper.enableRESTValidation(); + ProjectHelper.cleanAllProjects(); + + /* test count of validation errors */ + assertCountOfProblemsExists(ProblemType.ERROR, getWsProjectName(), PATH_PARAM_VALID_ERROR, null, 1); + } + + @Test + public void testValidatorDisabled() { + /* disable restful validation */ + restfulHelper.disableRESTValidation(); + ProjectHelper.cleanAllProjects(); + + /* test count of validation errors */ + assertCountOfProblemsExists(ProblemType.ERROR, getWsProjectName(), PATH_PARAM_VALID_ERROR, null, 0); + + /* enable restful validation - to have proper test environment*/ + restfulHelper.enableRESTValidation(); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/validation/RESTfulValidationTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/validation/RESTfulValidationTest.java new file mode 100644 index 000000000..e931a364e --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/rest/validation/RESTfulValidationTest.java @@ -0,0 +1,83 @@ + /******************************************************************************* + * Copyright (c) 2007-2011 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 + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.ws.ui.bot.test.rest.validation; + +import org.jboss.reddeer.eclipse.ui.problems.ProblemsView.ProblemType; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.autobuilding.AutoBuildingRequirement.AutoBuilding; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Test operates on JAX-RS validation + * @author jjankovi + * + */ +@RunWith(RedDeerSuite.class) +@AutoBuilding(value = false, cleanup = true) +public class RESTfulValidationTest extends RESTfulTestBase { + + private static final String GET_METHOD_PATH = "/{id}"; + private static final String CORRECT_PATH_PARAM = "id"; + private static final String BAD_PATH_PARAM = "customerId"; + + @Override + protected String getWsProjectName() { + return "restEmpty"; + } + + @Test + public void testCorrectValueValidation() { + /* prepare project */ + prepareSimpleRestService(GET_METHOD_PATH, CORRECT_PATH_PARAM); + ProjectHelper.cleanAllProjects(); + + /* test count of validation errors */ + assertCountOfProblemsExists(ProblemType.ERROR, getWsProjectName(), PATH_PARAM_VALID_ERROR, null, 0); + } + + @Test + public void testBadValueValidation() { + /* prepare project */ + prepareSimpleRestService(GET_METHOD_PATH, BAD_PATH_PARAM); + ProjectHelper.cleanAllProjects(); + + /* test count of validation errors */ + assertCountOfProblemsExists(ProblemType.ERROR, getWsProjectName(), PATH_PARAM_VALID_ERROR, null, 1); + } + + @Test + public void testCorrectToBadValueValidation() { + /* prepare project */ + prepareSimpleRestService(GET_METHOD_PATH, CORRECT_PATH_PARAM); + final String pathParamPrefix = "@PathParam(\""; + replaceInRestService(pathParamPrefix + CORRECT_PATH_PARAM, + pathParamPrefix + BAD_PATH_PARAM); + ProjectHelper.cleanAllProjects(); + + /* test count of validation errors */ + assertCountOfProblemsExists(ProblemType.ERROR, getWsProjectName(), PATH_PARAM_VALID_ERROR,null, 1); + } + + @Test + public void testBadToCorrectValueValidation() { + /* prepare project */ + prepareSimpleRestService(GET_METHOD_PATH, BAD_PATH_PARAM); + replaceInRestService(BAD_PATH_PARAM, CORRECT_PATH_PARAM); + ProjectHelper.cleanAllProjects(); + + /* test count of validation errors */ + assertCountOfProblemsExists(ProblemType.ERROR, getWsProjectName(), PATH_PARAM_VALID_ERROR, null, 0); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/sample/SampleSoapServicesTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/sample/SampleSoapServicesTest.java new file mode 100644 index 000000000..ae6f5c01a --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/sample/SampleSoapServicesTest.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2010 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.jboss.tools.ws.ui.bot.test.sample; + +import java.net.MalformedURLException; +import java.net.URL; +import java.text.MessageFormat; +import java.util.logging.Level; + +import javax.xml.namespace.QName; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.eclipse.condition.ConsoleHasText; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.ws.reddeer.ui.wizards.ws.ui.SampleWebServiceWizard; +import org.jboss.tools.ws.reddeer.ui.wizards.ws.ui.SimpleWebServiceWizard; +import org.jboss.tools.ws.ui.bot.test.soap.SOAPTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.Asserts; +import org.jboss.tools.ws.ui.bot.test.utils.ResourceHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ServersViewHelper; +import org.jboss.tools.ws.ui.bot.test.wsclient.WSClient; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Tests for Sample/Simple Web Service wizard + * + * @author jjankovi + * @author Jan Richter + * + */ +@RunWith(RedDeerSuite.class) +public class SampleSoapServicesTest extends SOAPTestBase { + + private static final String SOAP_REQUEST = getSoapRequest( + "{1}"); + private static final String SERVER_URL = "localhost:8080"; + + @Override + protected String getWsProjectName() { + return "SampleSOAPWS"; + } + + @Test + public void testSampleSoapWS() { + createSampleService(getWsProjectName(), "HelloServiceSample", "sample", "SampleService"); + checkSoapService(getWsProjectName(), "HelloServiceSample", "sample", "SampleService", "You"); + } + + @Test + public void testSimpleSoapWS() { + createSimpleService(getWsProjectName(), "HelloServiceSimple", "sample", "SimpleService"); + checkSoapService(getWsProjectName(), "HelloServiceSimple", "sample", "SimpleService", "You"); + } + + private IProject getProject(String project) { + return ResourcesPlugin.getWorkspace().getRoot().getProject(project); + } + + private IFile getDeploymentDescriptor(String project) { + return getProject(project).getFile("WebContent/WEB-INF/web.xml"); + } + + private void createSampleService(String project, String name, String pkg, String cls) { + SampleWebServiceWizard w = new SampleWebServiceWizard(); + w.open(); + w.setProjectName(project); + w.setServiceName(name); + w.setPackageName(pkg); + w.setClassName(cls); + w.finish(); + } + + private void createSimpleService(String project, String name, String pkg, String cls) { + SimpleWebServiceWizard w = new SimpleWebServiceWizard(); + w.open(); + w.setProjectName(project); + w.setServiceName(name); + w.setPackageName(pkg); + w.setClassName(cls); + w.finish(); + } + + private void checkSoapService(String project, String svcName, String svcPkg, String svcClass, String msgContent) { + TextEditor editor = new TextEditor(svcClass + ".java"); + editor.activate(); + String code = editor.getText(); + Asserts.assertContain(code, "package " + svcPkg + ";"); + String dd = ResourceHelper.readFile(getDeploymentDescriptor(project)); + Asserts.assertContain(dd, "" + svcName + ""); + ServersViewHelper.removeProjectFromServer(project, getConfiguredServerName()); + ServersViewHelper.runProjectOnServer(project); + ServersViewHelper.waitForDeployment(project, getConfiguredServerName()); + try { + WSClient c = new WSClient(new URL("http://" + SERVER_URL + "/" + project + "/" + svcName), + new QName("http://" + svcPkg + "/", svcClass + "Service"), + new QName("http://" + svcPkg + "/", svcClass + "Port")); + Asserts.assertContain(c.callService(MessageFormat.format(SOAP_REQUEST, svcPkg, msgContent)), + "Hello " + msgContent + "!"); + new WaitUntil(new ConsoleHasText("Hello: " + msgContent)); + } catch (MalformedURLException e) { + LOGGER.log(Level.WARNING, e.getMessage(), e); + } + } + + @Override + protected String getEarProjectName() { + return null; + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/soap/SOAPTestBase.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/soap/SOAPTestBase.java new file mode 100644 index 000000000..58808b28e --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/soap/SOAPTestBase.java @@ -0,0 +1,118 @@ +package org.jboss.tools.ws.ui.bot.test.soap; + +import java.text.MessageFormat; +import java.util.logging.Logger; + +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.core.handler.ShellHandler; +import org.jboss.reddeer.eclipse.ui.console.ConsoleView; +import org.jboss.reddeer.eclipse.ui.perspectives.JavaEEPerspective; +import org.jboss.reddeer.junit.requirement.inject.InjectRequirement; +import org.jboss.reddeer.requirements.openperspective.OpenPerspectiveRequirement.OpenPerspective; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.tools.common.reddeer.requirements.JavaFoldingRequirement.JavaFolding; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceWizardPageBase.SliderLevel; +import org.jboss.tools.ws.ui.bot.test.WSTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ServersViewHelper; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; + +/** + * Test base for SOAP web service tests + * + * @author Jan Richter + * + */ +@OpenPerspective(JavaEEPerspective.class) +@JBossServer(state = ServerReqState.RUNNING, cleanup = false) +@JavaFolding(false) +public abstract class SOAPTestBase { + + @InjectRequirement + private static ServerRequirement serverReq; + private String wsProjectName = null; + private SliderLevel level; + + private static final String SOAP_REQUEST_TEMPLATE = "" + + "" + + "{0}" + ""; + + protected static final Logger LOGGER = Logger.getLogger(WSTestBase.class + .getName()); + + protected final String LINE_SEPARATOR = System + .getProperty("line.separator"); + + protected SliderLevel getLevel() { + return level; + } + + protected void setLevel(SliderLevel level) { + this.level = level; + } + + @Before + public void setup() { + if (getEarProjectName() != null && !ProjectHelper.projectExists(getEarProjectName())) { + ProjectHelper.createEARProject(getEarProjectName()); + if (!ProjectHelper.projectExists(getWsProjectName())) { + ProjectHelper.createProjectForEAR(getWsProjectName(), + getEarProjectName()); + } + } else if (!ProjectHelper.projectExists(getWsProjectName())) { + ProjectHelper.createProject(getWsProjectName()); + } + } + + @After + public void cleanup() { + ConsoleView console = new ConsoleView(); + if (!console.isOpened()) { + console.open(); + } + console.clearConsole(); + } + + @AfterClass + public static void deleteAll() { + ServersViewHelper.removeAllProjectsFromServer(getConfiguredServerName()); + ShellHandler.getInstance().closeAllNonWorbenchShells(); + ProjectHelper.deleteAllProjects(); + } + + protected static String getConfiguredRuntimeName() { + return serverReq.getRuntimeNameLabelText(serverReq.getConfig()); + } + + protected static String getConfiguredServerName() { + return serverReq.getServerNameLabelText(serverReq.getConfig()); + } + + protected static String getConfiguredServerType() { + return serverReq.getConfig().getServerFamily().getLabel(); + } + + protected static String getConfiguredServerVersion() { + return serverReq.getConfig().getServerFamily().getVersion(); + } + + protected String getWsProjectName() { + return wsProjectName; + } + + protected void setWsProjectName(String wsProjectName) { + this.wsProjectName = wsProjectName; + } + + protected abstract String getEarProjectName(); + + public static String getSoapRequest(String body) { + return MessageFormat.format(SOAP_REQUEST_TEMPLATE, body); + } + +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/JavaBuildPathPropertiesPage.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/JavaBuildPathPropertiesPage.java new file mode 100644 index 000000000..81ffd087d --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/JavaBuildPathPropertiesPage.java @@ -0,0 +1,41 @@ +package org.jboss.tools.ws.ui.bot.test.uiutils; + +import org.hamcrest.Matcher; +import org.jboss.reddeer.swt.api.TreeItem; +import org.jboss.reddeer.swt.impl.tab.DefaultTabItem; +import org.jboss.reddeer.swt.impl.tree.DefaultTree; + +/** + * + * @author Radoslav Rabara + * + */ +public class JavaBuildPathPropertiesPage { + + /** + * Selects this page in {@link PropertiesDialog} + */ + public void select() { + for(TreeItem ti : new DefaultTree().getItems()) { + if(ti.getCell(0).equals("Java Build Path")) { + ti.doubleClick(); + return; + } + } + throw new IllegalArgumentException("page was not found"); + } + + public void activateLibrariesTab() { + new DefaultTabItem("Libraries").activate(); + } + + public void selectLibrary(Matcher matcher) { + for(TreeItem ti : new DefaultTree(1).getItems()) { + if(matcher.matches(ti.getText())) { + ti.select(); + return; + } + } + throw new IllegalArgumentException("Item matching matcher " + matcher + " was not found"); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/PropertiesDialog.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/PropertiesDialog.java new file mode 100644 index 000000000..cc4ef68d9 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/PropertiesDialog.java @@ -0,0 +1,64 @@ +package org.jboss.tools.ws.ui.bot.test.uiutils; + +import static org.junit.Assert.assertThat; + +import org.hamcrest.core.Is; +import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; +import org.jboss.reddeer.eclipse.core.resources.Project; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.core.condition.ShellWithTextIsAvailable; +import org.jboss.reddeer.swt.impl.button.PushButton; +import org.jboss.reddeer.swt.impl.menu.ShellMenu; +import org.jboss.reddeer.swt.impl.shell.DefaultShell; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.tools.common.reddeer.label.IDELabel; + +/** + * + * @author Radoslav Rabara + * + */ +public class PropertiesDialog { + + private String projectName; + + /** + * Opens properties dialog for the specified project. + * + * @param projectName name of the project to open properties dialog + */ + public void open(String projectName) { + ProjectExplorer projectExplorer = new ProjectExplorer(); + projectExplorer.open(); + Project project = projectExplorer.getProject(projectName); + project.select(); + + // Open Project Properties + assertThat("Project name", project.getName(), Is.is(projectName)); + assertThat("Project with name '" + projectName + "' is selected", + project.isSelected(), Is.is(true)); + + new WaitWhile(new JobIsRunning(), TimePeriod.LONG); + new ShellMenu(IDELabel.Menu.PROJECT, IDELabel.Menu.PROPERTIES).select(); + + new DefaultShell(IDELabel.Shell.PROPERTIES_FOR + " " + + projectName); + this.projectName = projectName; + } + + /** + * Confirms and closes the dialog. + */ + public void finish() { + new PushButton(IDELabel.Button.OK).click(); + new WaitWhile(new ShellWithTextIsAvailable(IDELabel.Shell.PROPERTIES_FOR + " " + projectName), TimePeriod.LONG); + new WaitWhile(new JobIsRunning()); + } + + public void finish(TimePeriod timeout) { + new PushButton(IDELabel.Button.OK).click(); + new WaitWhile(new ShellWithTextIsAvailable(IDELabel.Shell.PROPERTIES_FOR + " " + projectName), TimePeriod.LONG); + new WaitWhile(new JobIsRunning(), timeout); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/RunConfigurationsDialog.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/RunConfigurationsDialog.java new file mode 100644 index 000000000..bf086f0ae --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/RunConfigurationsDialog.java @@ -0,0 +1,56 @@ +package org.jboss.tools.ws.ui.bot.test.uiutils; + +import org.jboss.reddeer.swt.api.Shell; +import org.jboss.reddeer.swt.api.TreeItem; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.swt.impl.button.PushButton; +import org.jboss.reddeer.swt.impl.ctab.DefaultCTabItem; +import org.jboss.reddeer.swt.impl.group.DefaultGroup; +import org.jboss.reddeer.swt.impl.menu.ShellMenu; +import org.jboss.reddeer.swt.impl.shell.DefaultShell; +import org.jboss.reddeer.swt.impl.text.DefaultText; +import org.jboss.reddeer.swt.impl.tree.DefaultTree; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.tools.common.reddeer.label.IDELabel; + +public class RunConfigurationsDialog { + + private Shell shell; + + public void open() { + new ShellMenu(IDELabel.Menu.RUN, "Run Configurations...").select(); + shell = new DefaultShell("Run Configurations"); + } + + public void run() { + new PushButton(IDELabel.Button.RUN).click(); + new WaitWhile(new JobIsRunning(), TimePeriod.NORMAL); + } + + public void createNewConfiguration(String typeText) { + for(TreeItem ti : new DefaultTree().getItems()) { + if(ti.getText().equals(typeText)) { + ti.doubleClick(); + return; + } + } + throw new IllegalArgumentException("Specified type text '" + typeText + + "' was not found"); + } + + public void setProjectName(String projectName) { + selectMainTab(); + new DefaultText(new DefaultGroup("Project:")).setText(projectName); + } + + public void setClassName(String className) { + selectMainTab(); + new DefaultText(new DefaultGroup("Main class:")).setText(className); + } + + private void selectMainTab() { + shell.setFocus(); + new DefaultCTabItem("Main").activate(); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/RunOnServerDialog.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/RunOnServerDialog.java new file mode 100644 index 000000000..d2d561281 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/RunOnServerDialog.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2010-2012 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.jboss.tools.ws.ui.bot.test.uiutils; + +import java.util.List; + +import org.jboss.reddeer.swt.api.TreeItem; +import org.jboss.reddeer.swt.impl.button.PushButton; +import org.jboss.reddeer.swt.impl.button.RadioButton; +import org.jboss.reddeer.swt.impl.shell.DefaultShell; +import org.jboss.reddeer.swt.impl.tree.DefaultTree; +import org.jboss.tools.common.reddeer.label.IDELabel; + +/** + * + * @author jjankovi + * @author Radoslav Rabara + */ +public class RunOnServerDialog extends DefaultShell { + + private static final String DIALOG_TITLE = "Run On Server"; + + public RunOnServerDialog() { + super(DIALOG_TITLE); + } + + public void chooseExistingServer() { + new RadioButton().click(); + } + + public List getServers() { + for(TreeItem ti : new DefaultTree().getItems()) { + if(ti.getCell(0).equals("localhost")) { + return ti.getItems(); + } + } + return null; + } + + public void selectServer(String server) { + for (TreeItem ti : getServers()) { + if(ti.getCell(0).equals(server)) { + ti.select(); + break; + } + } + } + + public void finish() { + new PushButton(IDELabel.Button.FINISH).click(); + } + + public void cancel() { + new PushButton(IDELabel.Button.CANCEL).click(); + } +} \ No newline at end of file diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/TargetedRuntimesPropertiesPage.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/TargetedRuntimesPropertiesPage.java new file mode 100644 index 000000000..20ff7e380 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/TargetedRuntimesPropertiesPage.java @@ -0,0 +1,51 @@ +package org.jboss.tools.ws.ui.bot.test.uiutils; + +import org.jboss.reddeer.swt.api.Table; +import org.jboss.reddeer.swt.api.TableItem; +import org.jboss.reddeer.swt.api.TreeItem; +import org.jboss.reddeer.swt.impl.button.CheckBox; +import org.jboss.reddeer.swt.impl.table.DefaultTable; +import org.jboss.reddeer.swt.impl.tree.DefaultTree; + +/** + * + * @author Radoslav Rabara + * + */ +public class TargetedRuntimesPropertiesPage { + + /** + * Selects this page in {@link PropertiesDialog} + */ + public void select() { + for(TreeItem ti : new DefaultTree().getItems()) { + if(ti.getCell(0).equals("Targeted Runtimes")) { + ti.doubleClick(); + return; + } + } + throw new IllegalArgumentException("page was not found"); + } + + public void setSelectAllRuntimes(boolean check) { + new CheckBox("Show all runtimes").toggle(check); + } + + public void checkRuntime(String runtimeName, boolean check) { + Table runtimes = new DefaultTable(); + for(TableItem ti : runtimes.getItems()) { + if(ti.getText().equals(runtimeName)) { + ti.setChecked(check); + return; + } + } + throw new IllegalArgumentException("Runtime '" + runtimeName + "' was not found"); + } + + public void checkAllRuntimes(boolean check) { + Table runtimes = new DefaultTable(); + for(TableItem ti : runtimes.getItems()) { + ti.setChecked(check); + } + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/Asserts.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/Asserts.java new file mode 100644 index 000000000..1f3ad5cd1 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/Asserts.java @@ -0,0 +1,16 @@ +package org.jboss.tools.ws.ui.bot.test.utils; + +import static org.junit.Assert.assertThat; + +import org.hamcrest.core.IsNot; +import org.hamcrest.core.StringContains; + +public class Asserts { + public static void assertContain(String actual, String expectedToContain) { + assertThat(actual, StringContains.containsString(expectedToContain)); + } + + public static void assertNotContain(String actual, String expectedToContain) { + assertThat(actual, IsNot.not(StringContains.containsString(expectedToContain))); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/DeploymentHelper.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/DeploymentHelper.java new file mode 100644 index 000000000..66e049f6a --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/DeploymentHelper.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2010 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.jboss.tools.ws.ui.bot.test.utils; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Scanner; +import java.util.logging.Logger; + +/** + * DeploymentHelper + * + * @author jjankovi + * @author Radoslav Rabara + * + */ +public class DeploymentHelper { + + private static final Logger LOGGER = Logger + .getLogger(DeploymentHelper.class.getName()); + + private DeploymentHelper() {}; + + /** + * Method checks if service is deployed by checking http header code + * response of entered wsdURL and timeout for this operation + * @param wsdlURL + * @param timeout + */ + public static void assertServiceDeployed(String wsdlURL, long timeout) { + long t = System.currentTimeMillis(); + int rsp = -1; + while (t + timeout > System.currentTimeMillis()) { + HttpURLConnection connection = null; + try { + URL u = new URL(wsdlURL); + connection = (HttpURLConnection) u.openConnection(); + rsp = connection.getResponseCode(); + if (rsp == HttpURLConnection.HTTP_OK) { + break; + } else { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // ignore + } + LOGGER.info("retrying..."); + } + } catch (MalformedURLException e1) { + throw new RuntimeException(e1); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + if (connection != null) { + connection.disconnect(); + } + } + } + LOGGER.info("done after: " + (System.currentTimeMillis() - t) + "ms."); + assertEquals("Service was not sucessfully deployed, WSDL '" + wsdlURL + + "' was not found", HttpURLConnection.HTTP_OK, rsp); + } + + /** + * Returns http page for entered url of page in the specified + * timeout + * + * @param url page url + * @param timeout timeout of this operation + * @return content of the http page + */ + public static String getPage(String url, long timeout) { + long t = System.currentTimeMillis(); + int rsp = -1; + String page = null; + while (t + timeout > System.currentTimeMillis()) { + HttpURLConnection connection = null; + try { + URL u = new URL(url); + connection = (HttpURLConnection) u.openConnection(); + rsp = connection.getResponseCode(); + if (rsp == HttpURLConnection.HTTP_OK) { + try(Scanner scanner = new Scanner(connection.getInputStream())) { + page = scanner.useDelimiter("\\A").next(); + } + break; + } else { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // ignore + } + LOGGER.info("retrying..."); + } + } catch (MalformedURLException e1) { + throw new RuntimeException(e1); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + if (connection != null) { + connection.disconnect(); + } + } + } + LOGGER.info("done after: " + (System.currentTimeMillis() - t) + "ms."); + assertEquals("Cannot connect to '" + url + "'", + HttpURLConnection.HTTP_OK, rsp); + return page; + } + + /** + * Returns wsdl URL determined by deployed project and web service name + * + * @param projectName name of the deployed project + * @param wsName web service name + * @return wsdl URL + */ + public static String getWSDLUrl(String projectName, String wsName) { + return "http://localhost:8080/" + projectName + "/" + + wsName + "?wsdl"; + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/ProjectHelper.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/ProjectHelper.java new file mode 100644 index 000000000..39b90fc16 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/ProjectHelper.java @@ -0,0 +1,272 @@ +/******************************************************************************* + * Copyright (c) 2010-2011 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.jboss.tools.ws.ui.bot.test.utils; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.logging.Logger; + +import org.hamcrest.core.StringContains; +import org.jboss.reddeer.common.exception.RedDeerException; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.eclipse.core.resources.Project; +import org.jboss.reddeer.eclipse.jdt.ui.NewJavaClassWizardDialog; +import org.jboss.reddeer.eclipse.jdt.ui.NewJavaClassWizardPage; +import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; +import org.jboss.reddeer.eclipse.ui.wizards.datatransfer.ExternalProjectImportWizardDialog; +import org.jboss.reddeer.eclipse.ui.wizards.datatransfer.WizardProjectsImportPage; +import org.jboss.reddeer.eclipse.utils.DeleteUtils; +import org.jboss.reddeer.swt.impl.button.CheckBox; +import org.jboss.reddeer.swt.impl.button.PushButton; +import org.jboss.reddeer.swt.impl.button.RadioButton; +import org.jboss.reddeer.swt.impl.combo.DefaultCombo; +import org.jboss.reddeer.swt.impl.ctab.DefaultCTabItem; +import org.jboss.reddeer.swt.impl.menu.ShellMenu; +import org.jboss.reddeer.swt.impl.shell.DefaultShell; +import org.jboss.reddeer.swt.impl.text.LabeledText; +import org.jboss.reddeer.workbench.condition.EditorWithTitleIsActive; +import org.jboss.reddeer.workbench.handler.EditorHandler; +import org.jboss.reddeer.workbench.impl.editor.DefaultEditor; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.common.reddeer.label.IDELabel; +import org.jboss.tools.ws.reddeer.ui.wizards.CreateNewFileWizardPage; +import org.jboss.tools.ws.reddeer.ui.wizards.jst.j2ee.EARProjectWizard; +import org.jboss.tools.ws.reddeer.ui.wizards.jst.servlet.DynamicWebProjectWizard; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.NewWsdlFileWizard; +import org.jboss.tools.ws.ui.bot.test.uiutils.JavaBuildPathPropertiesPage; +import org.jboss.tools.ws.ui.bot.test.uiutils.PropertiesDialog; +import org.jboss.tools.ws.ui.bot.test.uiutils.TargetedRuntimesPropertiesPage; + +/** + * @author jjankovi + * @author Radoslav Rabara + */ +public class ProjectHelper { + + private static final Logger LOGGER = Logger.getLogger(ProjectHelper.class.getName()); + + private ProjectHelper() { + }; + + /** + * Method creates basic java class for entered project with entered package + * and class name + * + * @param projectName + * @param pkg + * @param cName + * @return + */ + public static TextEditor createClass(String projectName, String pkg, String className) { + NewJavaClassWizardDialog wizard = new NewJavaClassWizardDialog(); + wizard.open(); + + NewJavaClassWizardPage page = new NewJavaClassWizardPage(); + page.setPackage(pkg); + page.setName(className); + page.setSourceFolder(projectName + "/src"); + wizard.finish(); + + return new TextEditor(className + ".java"); + } + + /** + * Method creates wsdl file for entered project with entered package name + * + * @param projectName + * @param wsdlFileName + */ + public static DefaultEditor createWsdl(String projectName, String wsdlFileName) { + EditorHandler.getInstance().closeAll(false); + NewWsdlFileWizard wizard = new NewWsdlFileWizard(); + wizard.open(); + + CreateNewFileWizardPage page = new CreateNewFileWizardPage(); + page.setFileName(wsdlFileName + ".wsdl"); + page.setParentFolder(projectName + "/src"); + + wizard.next(); + wizard.finish(); + + new WaitUntil(new EditorWithTitleIsActive(wsdlFileName + ".wsdl")); + new DefaultCTabItem("Source").activate(); + + return new DefaultEditor(wsdlFileName + ".wsdl"); + } + + /** + * Method creates new Dynamic Web Project with entered name + * + * @param name + */ + public static void createProject(String name) { + DynamicWebProjectWizard wizard = new DynamicWebProjectWizard(); + wizard.open(); + + wizard.setProjectName(name); + wizard.next(); + wizard.next(); + wizard.setGenerateDeploymentDescriptor(true); + wizard.finish(); + + new WaitWhile(new JobIsRunning(), TimePeriod.LONG); + ProjectExplorer projectExplorer = new ProjectExplorer(); + projectExplorer.activate(); + projectExplorer.getProject(name).select(); + } + + /** + * Method creates new Dynamic Web Project with entered name for ear project + * + * @param name + */ + public static void createProjectForEAR(String name, String earProject) { + DynamicWebProjectWizard wizard = new DynamicWebProjectWizard(); + wizard.open(); + + wizard.setProjectName(name); + wizard.addProjectToEar(earProject); + wizard.finish(); + + new WaitWhile(new JobIsRunning()); + ProjectExplorer projectExplorer = new ProjectExplorer(); + projectExplorer.activate(); + projectExplorer.getProject(name).select(); + } + + /** + * Method creates new EAR Project with entered name + * + * @param name + */ + public static void createEARProject(String name) { + EARProjectWizard wizard = new EARProjectWizard(); + wizard.open(); + + new LabeledText("Project name:").setText(name); + // set EAR version + DefaultCombo combo = new DefaultCombo(1); + combo.setSelection(combo.getItems().size() - 1); + + wizard.next(); + + new CheckBox("Generate application.xml deployment descriptor").click(); + + wizard.finish(); + } + + public static void setProjectJRE(String projectName) { + PropertiesDialog dialog = new PropertiesDialog(); + dialog.open(projectName); + + JavaBuildPathPropertiesPage page = new JavaBuildPathPropertiesPage(); + page.select(); + page.activateLibrariesTab(); + page.selectLibrary(StringContains.containsString("JRE System Library")); + + new PushButton(IDELabel.Button.EDIT).click(); + new DefaultShell("Edit Library"); + new RadioButton("Alternate JRE:").click(); + new PushButton(IDELabel.Button.FINISH).click(); + + dialog.finish(); + } + + public static boolean projectExists(String name) { + ProjectExplorer projectExplorer = new ProjectExplorer(); + projectExplorer.open(); + return projectExplorer.containsProject(name); + } + + public static void deleteAllProjects() { + ProjectExplorer projectExplorer = new ProjectExplorer(); + projectExplorer.open(); + + List projects = projectExplorer.getProjects(); + try { + for (Project project: projects) { + project.delete(true); + } + } catch(RedDeerException e) { + projectExplorer.close(); + projectExplorer.open(); + projects = projectExplorer.getProjects(); + for (Project project: projects) { + try { + LOGGER.info("Forcing removal of " + project); + DeleteUtils.forceProjectDeletion(project, true); + } catch(RuntimeException exception) { + LOGGER.info("Project " + project.getName() + " was not deleted"); + } + } + } + } + + /** + * Cleans All Projects + */ + public static void cleanAllProjects() { + new WaitWhile(new JobIsRunning()); + new ShellMenu(IDELabel.Menu.PROJECT, "Clean...").select(); + new DefaultShell("Clean"); + new RadioButton("Clean all projects").click(); + new PushButton(IDELabel.Button.OK).click(); + new WaitWhile(new JobIsRunning(), TimePeriod.LONG, false); + } + + public static void importWSTestProject(String projectName, String serverName) { + try { + importProject(new File("resources/projects/" + projectName).getCanonicalPath()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + addConfiguredRuntimeIntoProject(projectName, serverName); + setProjectJRE(projectName); + } + + /** + * Add configured runtime into project as targeted runtime + * + * @param project + */ + public static void addConfiguredRuntimeIntoProject(String projectName, String configuredRuntime) { + PropertiesDialog dialog = new PropertiesDialog(); + dialog.open(projectName); + + TargetedRuntimesPropertiesPage page = new TargetedRuntimesPropertiesPage(); + page.select(); + page.setSelectAllRuntimes(true); + page.checkAllRuntimes(false); + page.checkRuntime(configuredRuntime, true); + + dialog.finish(TimePeriod.LONG); + } + + private static void importProject(String projectLocation) { + ExternalProjectImportWizardDialog importDialog = new ExternalProjectImportWizardDialog(); + importDialog.open(); + WizardProjectsImportPage importPage = new WizardProjectsImportPage(); + importPage.setRootDirectory(projectLocation); + assertFalse("There is no project to import", importPage.getProjects().isEmpty()); + importPage.selectAllProjects(); + importPage.copyProjectsIntoWorkspace(true); + importDialog.finish(); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/ResourceHelper.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/ResourceHelper.java new file mode 100644 index 000000000..0ac512190 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/ResourceHelper.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2010-2011 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.jboss.tools.ws.ui.bot.test.utils; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.Scanner; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; + +/** + * + * @author jjankovi + * @author Radoslav Rabara + * + */ +public class ResourceHelper { + + private ResourceHelper() {}; + + /** + * Method converts input stream to text format + * @param is + * @return + */ + public static String readStream(InputStream is) { + // we don't care about performance in tests too much, so this should be + // OK + try(Scanner scanner = new Scanner(is)) { + return scanner.useDelimiter("\\A").next(); + } + } + + /** + * Method reads input file and output it as text + * @param f + * @return + */ + public static String readFile(IFile f) { + String content = null; + InputStream is = null; + try { + is = f.getContents(); + content = readStream(is); + } catch (CoreException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + // ignore + } + } + } + return content; + } + + /** + * Method copies resource to class opened in SWTBotEditor with entered parameters + */ + public static void copyResourceToClassWithSave(InputStream resource, + boolean save, Object... param) { + String s = readStream(resource); + String code = MessageFormat.format(s, param); + TextEditor editor = new TextEditor(); + editor.setText(code); + if (save) { + editor.save(); + } + } + + /** + * Open a java file of specified name in a package inside a project + * @param projectName + * @param pkgName + * @param javaFileName + */ + public static void openJavaFile(String projectName, String pkgName, String javaFileName) { + new ProjectExplorer().getProject(projectName) + .getProjectItem("Java Resources", "src", pkgName, javaFileName).open(); + } + + /** + * Method recursively searches files name in dir and returns it as File object + * @param dir + * @param searchingFileName + * @return + */ + public static File searchInTextFiles(File dir, String searchingFileName) { + File[] files = dir.listFiles(); + for (File file : files) { + if (file.isDirectory()) { + File f = searchInTextFiles(file, searchingFileName); + if (f != null) { + return f; + } + } else { + if (file.getName().equals(searchingFileName)) { + return file; + } + } + } + return null; + } + +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/ServersViewHelper.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/ServersViewHelper.java new file mode 100644 index 000000000..3e4a62628 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/ServersViewHelper.java @@ -0,0 +1,187 @@ +package org.jboss.tools.ws.ui.bot.test.utils; + +import java.util.logging.Logger; + +import org.hamcrest.core.StringContains; +import org.jboss.reddeer.common.condition.AbstractWaitCondition; +import org.jboss.reddeer.common.wait.AbstractWait; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.core.matcher.WithMnemonicTextMatcher; +import org.jboss.reddeer.eclipse.condition.ConsoleHasText; +import org.jboss.reddeer.eclipse.condition.ServerExists; +import org.jboss.reddeer.eclipse.exception.EclipseLayerException; +import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; +import org.jboss.reddeer.eclipse.ui.console.ConsoleView; +import org.jboss.reddeer.eclipse.wst.server.ui.view.Server; +import org.jboss.reddeer.eclipse.wst.server.ui.view.ServerModule; +import org.jboss.reddeer.eclipse.wst.server.ui.view.ServersView; +import org.jboss.reddeer.eclipse.wst.server.ui.view.ServersViewEnums.ServerPublishState; +import org.jboss.reddeer.eclipse.wst.server.ui.view.ServersViewEnums.ServerState; +import org.jboss.reddeer.eclipse.wst.server.ui.wizard.ModifyModulesDialog; +import org.jboss.reddeer.eclipse.wst.server.ui.wizard.ModifyModulesPage; +import org.jboss.reddeer.swt.impl.button.PushButton; +import org.jboss.reddeer.swt.impl.menu.ShellMenu; +import org.jboss.reddeer.swt.impl.shell.DefaultShell; +import org.jboss.tools.common.reddeer.label.IDELabel; + +/** + * + * @author Radoslav Rabara + * + */ +public class ServersViewHelper { + + private static final Logger LOGGER = Logger + .getLogger(ServersViewHelper.class.getName()); + + private ServersViewHelper() {}; + + /** + * Removes the specified project from the configured server. + * + * @param project project to be removed from the server + */ + public static void removeProjectFromServer(String project, String serverName) { + ServersView serversView = new ServersView(); + serversView.activate(); + Server server = serversView.getServer(serverName); + + ServerModule serverModule = null; + try { + serverModule = server.getModule(project); + } catch (EclipseLayerException e) { + LOGGER.info("Project " + project + " was not found on the server"); + return; + } + if (serverModule != null) { + String moduleName = serverModule.getLabel().getName(); + ServerState moduleState = serverModule.getLabel().getState(); + clearServerConsole(serverName); + serverModule.remove(); + + if (moduleState.equals(ServerState.STARTED)) { + new WaitUntil(new ConsoleHasText("Undeployed \"" + moduleName), TimePeriod.LONG, false); + } + } + } + + /** + * Removes all projects from the specified server. + */ + public static void removeAllProjectsFromServer(String serverName) { + ServersView serversView = new ServersView(); + if(!serversView.isOpened()) + serversView.open(); + + Server server = null; + try { + serversView.activate(); + server = serversView.getServer(serverName); + } catch (EclipseLayerException e) { + LOGGER.warning("Server " + serverName + "not found, retrying"); + serversView.activate(); + server = serversView.getServer(serverName); + } + + while(!server.getModules().isEmpty()) { + ServerModule module = server.getModules().get(0); + if (module != null) { + new WaitWhile(new JobIsRunning(), TimePeriod.LONG, false); + serversView.activate(); + String moduleName = module.getLabel().getName(); + ServerState moduleState = module.getLabel().getState(); + clearServerConsole(serverName); + + new WaitWhile(new JobIsRunning(), TimePeriod.NORMAL, false); + serversView.activate(); + module.remove(); + + if (moduleState.equals(ServerState.STARTED)) { + new WaitUntil(new ConsoleHasText("Undeployed \"" + moduleName), TimePeriod.LONG, false); + } + } + } + } + + /** + * Method runs project on the configured server + */ + public static void runProjectOnServer(String projectName) { + new ProjectExplorer().getProject(projectName).select(); + new ShellMenu(org.hamcrest.core.Is.is(IDELabel.Menu.RUN), org.hamcrest.core.Is.is(IDELabel.Menu.RUN_AS), + org.hamcrest.core.StringContains.containsString("Run on Server")).select(); + new DefaultShell("Run On Server"); + new PushButton(IDELabel.Button.FINISH).click(); + } + + /** + * Adds the specified project to the specified server + */ + public static void addProjectToServer(String projectName, String serverName) { + ServersView serversView = new ServersView(); + serversView.open(); + Server server = serversView.getServer(serverName); + ModifyModulesDialog dialog = server.addAndRemoveModules(); + ModifyModulesPage page = new ModifyModulesPage(); + page.add(projectName); + dialog.finish(); + } + + public static void serverClean(String serverName) { + ServersView serversView = new ServersView(); + serversView.open(); + Server server = null; + try { + server = serversView.getServer(serverName); + } catch (EclipseLayerException e) { + LOGGER.warning("Server " + serverName + "not found, retrying"); + server = serversView.getServer(serverName); + + } + AbstractWait.sleep(TimePeriod.SHORT); + server.clean(); + } + + public static void waitForDeployment(String projectName, String serverName) { + new WaitUntil(new ProjectIsDeployed(projectName, serverName), TimePeriod.getCustom(20), false); + } + + private static void clearServerConsole(String serverName) { + ConsoleView consoleView = new ConsoleView(); + if (!consoleView.isOpened()) { + consoleView.open(); + } + consoleView.activate(); + consoleView.switchConsole(new WithMnemonicTextMatcher(new StringContains(serverName))); + consoleView.clearConsole(); + } + + private static class ProjectIsDeployed extends AbstractWaitCondition { + + private ServerModule module; + private ServersView view = new ServersView(); + + public ProjectIsDeployed(String projectName, String serverName) { + view.activate(); + new WaitUntil(new ServerExists(serverName), TimePeriod.getCustom(2)); + Server server = view.getServer(serverName); + module = server.getModule(projectName); + } + + @Override + public boolean test() { + view.activate(); + return module.getLabel().getState().equals(ServerState.STARTED) + && module.getLabel().getPublishState().equals(ServerPublishState.SYNCHRONIZED); + } + + @Override + public String description() { + return "Module state is " + module.getLabel().getState() + ", " + module.getLabel().getPublishState(); + } + + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/WebServiceClientHelper.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/WebServiceClientHelper.java new file mode 100644 index 000000000..26d577b47 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/utils/WebServiceClientHelper.java @@ -0,0 +1,177 @@ +package org.jboss.tools.ws.ui.bot.test.utils; + +import static org.junit.Assert.fail; + +import org.eclipse.swt.SWTException; +import org.jboss.reddeer.common.condition.AbstractWaitCondition; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.core.condition.ShellWithTextIsAvailable; +import org.jboss.reddeer.core.exception.CoreLayerException; +import org.jboss.reddeer.eclipse.exception.EclipseLayerException; +import org.jboss.reddeer.eclipse.ui.console.ConsoleView; +import org.jboss.reddeer.eclipse.wst.server.ui.view.ServersView; +import org.jboss.reddeer.jface.wizard.WizardDialog; +import org.jboss.reddeer.swt.api.Label; +import org.jboss.reddeer.swt.api.Shell; +import org.jboss.reddeer.swt.impl.button.PushButton; +import org.jboss.reddeer.swt.impl.label.DefaultLabel; +import org.jboss.reddeer.swt.impl.shell.DefaultShell; +import org.jboss.reddeer.swt.impl.toolbar.DefaultToolItem; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceClientWizard; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceClientWizardPage; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceWizardPageBase.SliderLevel; +import org.jboss.tools.ws.ui.bot.test.webservice.WebServiceRuntime; +import org.junit.Assert; + +public class WebServiceClientHelper { + + private WebServiceClientHelper() {}; + + /** + * Method creates Web Service Client for entered wsdl file, web project, + * level of creation and name of package for client + * @param wsdl + * @param targetProject + * @param level + * @param pkg + */ + public static void createClient(String serverName, String wsdl, + WebServiceRuntime runtime, String targetProject, + String earProject, SliderLevel level, String pkg) { + WebServiceClientWizard wizard = new WebServiceClientWizard(); + wizard.open(); + + WebServiceClientWizardPage page = new WebServiceClientWizardPage(); + new WaitWhile(new JobIsRunning(), TimePeriod.NORMAL, false); + + page.setSource(wsdl); + new WaitUntil(new WebServiceClientPageIsValidated(), TimePeriod.getCustom(2), true); + + page.setClientSlider(level); + page.setServerRuntime(serverName); + page.setWebServiceRuntime(runtime.getName()); + + if (targetProject != null) + page.setClientProject(targetProject); + if (earProject != null) + page.setClientEARProject(earProject); + + if (pkg != null && pkg.trim().length()>0) { + wizard.next(); + new WaitWhile(new ShellWithTextIsAvailable("Progress Information")); + page.setPackageName(pkg); + } + + wizard.finish(); + + checkErrorDialog(wizard); + + //check if there is any error in console output + checkErrorInConsoleOutput(serverName, earProject); + } + + /** + * let's fail if there's some error in the wizard, + * and close error dialog and the wizard so other tests + * can continue + * + * @param wsWizard if error dialog appeared the parent wizard will be closed + */ + private static void checkErrorDialog(WizardDialog wsWizard) { + Shell shell = new DefaultShell(); + String text = shell.getText(); + if (text.contains("Error")) { + new PushButton(0).click(); + wsWizard.cancel(); + Assert.fail(text); + } + } + + private static void checkErrorInConsoleOutput(String serverName, String projectName) { + ConsoleView consoleView = new ConsoleView(); + if (!consoleView.isOpened()) { + consoleView.open(); + } + selectServerConsole(serverName, consoleView); + + String consoleText = null; + try { + consoleText = consoleView.getConsoleText(); + } catch (CoreLayerException ex) { + consoleView.activate(); + consoleText = consoleView.getConsoleText(); + } + if (consoleText.contains("ERROR")) { + consoleView.clearConsole(); + String deploymentInfoMessage = " [deployment status: "; + if(projectIsDeployed(serverName, projectName)) { + deploymentInfoMessage += "deployed"; + } else { + deploymentInfoMessage += "NOT DEPLOYED"; + } + deploymentInfoMessage += "]"; + + fail("Console contains error" + + deploymentInfoMessage + + "\n" + consoleText); + } + } + + private static void selectServerConsole(String serverName, ConsoleView view) { + view.activate(); + Label consoleName = null; + try { + consoleName = new DefaultLabel(); + } catch (CoreLayerException ex) { + view.activate(); + consoleName = new DefaultLabel(); + } + if (!consoleName.getText().contains(serverName)) { + new DefaultToolItem("Display Selected Console").click(); + consoleName = new DefaultLabel(); + if (!consoleName.getText().contains(serverName)) { + fail("Console of configured server was not found."); + } + } + } + + /** + * + * @param serverName + * @param projectName + * @return + * @throws SWTException + */ + public static boolean projectIsDeployed(String serverName, String projectName) { + try { + ServersView sw = new ServersView(); + sw.getServer(serverName).getModule(projectName); + return true; + } catch(EclipseLayerException e) { + return false; + } + } + + private static class WebServiceClientPageIsValidated extends AbstractWaitCondition { + + private WebServiceClientWizardPage page = new WebServiceClientWizardPage(); + + private static final String REQUIRED_TEXT = "Select a service definition and move the slider to set the level of client generation."; + private String infoText; + + @Override + public boolean test() { + infoText = page.getInfoText(); + return infoText.equals(REQUIRED_TEXT); + } + + @Override + public String description() { + return "Required text is '" + REQUIRED_TEXT + "' but there is '" + infoText + "'"; + } + + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/BottomUpWSTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/BottomUpWSTest.java new file mode 100644 index 000000000..9acd1aa41 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/BottomUpWSTest.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2010-2011 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.jboss.tools.ws.ui.bot.test.webservice; + +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceWizardPageBase.SliderLevel; +import org.jboss.tools.ws.ui.bot.test.utils.DeploymentHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ServersViewHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Test operates on Web Service Wizard with bottom up process of creating web + * service + * + * @author jlukas + * + */ +@RunWith(RedDeerSuite.class) +public class BottomUpWSTest extends WebServiceTestBase { + + // http://localhost:8080/BottomUpWS/ClassA?wsdl + /* + * + * + * + * 1234567890 + */ + + @Override + protected String getWsPackage() { + return "jbossws." + getLevel().toString().toLowerCase(); + } + + @Override + protected String getWsName() { + return "JavaWs_" + getLevel(); + } + + @Override + protected String getWsProjectName() { + return "BottomUpWS-web"; + } + + @Override + protected String getEarProjectName() { + return "BottomUpWS-ear"; + } + + @Test + public void testDevelopService() { + setLevel(SliderLevel.DEVELOP); + bottomUpJbossWebService(); + } + + @Test + public void testAssembleService() { + setLevel(SliderLevel.ASSEMBLE); + bottomUpJbossWebService(); + } + + @Test + public void testDeployService() { + setLevel(SliderLevel.DEPLOY); + bottomUpJbossWebService(); + } + + @Test + public void testInstallService() { + setLevel(SliderLevel.INSTALL); + bottomUpJbossWebService(); + } + + @Test + public void testStartService() { + setLevel(SliderLevel.START); + bottomUpJbossWebService(); + } + + @Test + public void testTestService() { + setLevel(SliderLevel.TEST); + bottomUpJbossWebService(); + } + + protected void bottomUpJbossWebService() { + bottomUpWS(BottomUpWSTest.class.getResourceAsStream("/resources/jbossws/ClassA.java.ws"), + WebServiceRuntime.JBOSS_WS, true); + switch (getLevel()) { + case DEVELOP: + case ASSEMBLE: + + /* + * workaround for + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=377624 choosing + * 'Deploy' should normally deploy the project automatically + */ + case DEPLOY: + ServersViewHelper.runProjectOnServer(getEarProjectName()); + + default: + ServersViewHelper.waitForDeployment(getEarProjectName(), getConfiguredServerName()); + break; + } + DeploymentHelper.assertServiceDeployed(DeploymentHelper.getWSDLUrl(getWsProjectName(), getWsName()), 10000); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/TopDownWSTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/TopDownWSTest.java new file mode 100644 index 000000000..3273f1fdb --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/TopDownWSTest.java @@ -0,0 +1,195 @@ +/******************************************************************************* + * Copyright (c) 2010-2011 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.jboss.tools.ws.ui.bot.test.webservice; + +import static org.junit.Assert.fail; + +import org.jboss.reddeer.common.exception.WaitTimeoutExpiredException; +import org.jboss.reddeer.common.matcher.RegexMatcher; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.core.condition.ShellWithTextIsAvailable; +import org.jboss.reddeer.eclipse.core.resources.ProjectItem; +import org.jboss.reddeer.eclipse.exception.EclipseLayerException; +import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer; +import org.jboss.reddeer.eclipse.wst.server.ui.view.ServerModule; +import org.jboss.reddeer.eclipse.wst.server.ui.view.ServersView; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.swt.impl.button.OkButton; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceWizardPageBase.SliderLevel; +import org.jboss.tools.ws.ui.bot.test.utils.DeploymentHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ServersViewHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Test operates on Web Service Wizard with top down process of creating web service + * @author jlukas + * + */ +@RunWith(RedDeerSuite.class) +public class TopDownWSTest extends WebServiceTestBase { + + @Override + protected String getEarProjectName() { + return "TopDownWS-ear"; + } + + @Override + protected String getWsPackage() { + return "jbossws.td." + getLevel().toString().toLowerCase(); + } + + @Override + protected String getWsName() { + return "WsdlWs" + getLevel(); + } + + @Override + protected String getWsProjectName() { + return "TopDownWS-web"; + } + + //http://localhost:8080/TopDownJbossWS/jbossws.ClassB?wsdl + /* + + + + + + + +0 + + + */ + @Test + public void testDevelopService() { + setLevel(SliderLevel.DEVELOP); + topDownWS(); + } + + @Test + public void testAssembleService() { + setLevel(SliderLevel.ASSEMBLE); + + /* There may exist WSDL and generated files created in testDefaultPkg due to using the same SliderLevel */ + prepareAssembleService(); + + topDownWS(); + } + + @Test + public void testDeployService() { + setLevel(SliderLevel.DEPLOY); + topDownWS(); + } + + @Test + public void testInstallService() { + setLevel(SliderLevel.INSTALL); + topDownWS(); + } + + /** + * Fails due to JBIDE-16066 + * @see https://issues.jboss.org/browse/JBIDE-16066 + */ + @Test + public void testStartService() { + setLevel(SliderLevel.START); + topDownWS(); + } + + /** + * Fails due to JBIDE-16066 + * @see https://issues.jboss.org/browse/JBIDE-16066 + */ + @Test + public void testTestService() { + setLevel(SliderLevel.TEST); + topDownWS(); + } + + @Test + public void testDefaultPkg() { + setLevel(SliderLevel.ASSEMBLE); + + prepareAssembleService(); + + topDownWS(null); + } + + private void removeWsdlFileFromProject(String wsdlFileName) { + ProjectItem item = null; + try { + item = new ProjectExplorer().getProject(getWsProjectName()) + .getProjectItem("Java Resources", "src", wsdlFileName); + } catch(EclipseLayerException e) { + return; + } + + item.delete(); + + ShellWithTextIsAvailable condition = new ShellWithTextIsAvailable(new RegexMatcher("Delete")); + try { + new WaitUntil(condition); + } catch(WaitTimeoutExpiredException e) { + return; + } + new OkButton().click(); + new WaitWhile(condition); + } + + private void topDownWS() { + topDownWS("ws." + getWsName().toLowerCase()); + } + + protected void topDownWS(String pkg) { + topDownWS( + TopDownWSTest.class.getResourceAsStream("/resources/jbossws/ClassB.wsdl"), + WebServiceRuntime.JBOSS_WS, pkg, true); + + switch (getLevel()) { + case DEVELOP: + case ASSEMBLE: + + /*workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=377624 + choosing 'Deploy' should normally deploy the project automatically*/ + case DEPLOY: + ProjectHelper.cleanAllProjects(); + ServersViewHelper.runProjectOnServer(getEarProjectName()); + break; + + case INSTALL: + case START: + case TEST: + ServerModule module = null; + try { + module = new ServersView().getServer(getConfiguredServerName()).getModule(getEarProjectName()); + } catch (EclipseLayerException ex) { + fail("The project was not deployed"); + } + module.remove(); + ProjectHelper.cleanAllProjects(); + ServersViewHelper.runProjectOnServer(getEarProjectName()); + break; + } + ServersViewHelper.waitForDeployment(getEarProjectName(), getConfiguredServerName()); + DeploymentHelper.assertServiceDeployed(DeploymentHelper.getWSDLUrl(getWsProjectName(), getWsName()), 10000); + } + + private void prepareAssembleService() { + /* There exists WSDL file created in testAssembleService due to using the same SliderLevel */ + removeWsdlFileFromProject(getWsName() + ".wsdl"); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/WebServiceRuntime.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/WebServiceRuntime.java new file mode 100644 index 000000000..fdc61d243 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/WebServiceRuntime.java @@ -0,0 +1,23 @@ +package org.jboss.tools.ws.ui.bot.test.webservice; + +/** + * Web Service Runtime + * Supported are JBossWS and ApacheCXF2.x + * + * @author rrabara + * + */ +public enum WebServiceRuntime { + JBOSS_WS ("JBossWS"), + APACHE_CXF2 ("Apache CXF 2.x"); + + private final String name; + + private WebServiceRuntime(String wsRuntimeName) { + this.name = wsRuntimeName; + } + + public String getName() { + return name; + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/WebServiceTestBase.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/WebServiceTestBase.java new file mode 100644 index 000000000..74dd63273 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/WebServiceTestBase.java @@ -0,0 +1,196 @@ +/******************************************************************************* + * Copyright (c) 2010 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.jboss.tools.ws.ui.bot.test.webservice; + +import static org.junit.Assert.assertNotNull; + +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.logging.Level; + +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.core.condition.ShellWithTextIsAvailable; +import org.jboss.reddeer.jface.wizard.WizardDialog; +import org.jboss.reddeer.requirements.autobuilding.AutoBuildingRequirement.AutoBuilding; +import org.jboss.reddeer.swt.api.Shell; +import org.jboss.reddeer.swt.api.StyledText; +import org.jboss.reddeer.swt.condition.WidgetIsEnabled; +import org.jboss.reddeer.swt.exception.SWTLayerException; +import org.jboss.reddeer.swt.impl.button.FinishButton; +import org.jboss.reddeer.swt.impl.button.NextButton; +import org.jboss.reddeer.swt.impl.button.OkButton; +import org.jboss.reddeer.swt.impl.button.PushButton; +import org.jboss.reddeer.swt.impl.shell.DefaultShell; +import org.jboss.reddeer.swt.impl.styledtext.DefaultStyledText; +import org.jboss.reddeer.swt.impl.text.DefaultText; +import org.jboss.reddeer.workbench.impl.editor.DefaultEditor; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceFirstWizardPage; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceFirstWizardPage.ServiceType; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceSecondWizardPage; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceWizard; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceWizardPageBase.SliderLevel; +import org.jboss.tools.ws.ui.bot.test.soap.SOAPTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ResourceHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ServersViewHelper; +import org.junit.After; +import org.junit.Assert; + +/** + * Base class for Web Service wizard tests + * + * @author jjankovi + * + */ +@AutoBuilding(value = false, cleanup = true) +public abstract class WebServiceTestBase extends SOAPTestBase { + + protected abstract String getWsPackage(); + + protected abstract String getWsName(); + + @After + public void undeploy() { + ServersViewHelper.removeAllProjectsFromServer(getConfiguredServerName()); + } + + protected void bottomUpWS(InputStream input, WebServiceRuntime serviceRuntime, boolean useDefaultProjects) { + String source = ResourceHelper.readStream(input); + String src = MessageFormat.format(source, getWsPackage(), getWsName()); + createService(ServiceType.BOTTOM_UP, getWsPackage() + "." + + getWsName(), getLevel(), null, src, serviceRuntime, useDefaultProjects); + } + + protected void topDownWS(InputStream input, WebServiceRuntime serviceRuntime, String pkg, boolean useDefaultProjects) { + String s = ResourceHelper.readStream(input); + String[] tns = getWsPackage().split("\\."); + StringBuilder sb = new StringBuilder(); + for (int i = tns.length - 1; i > 0; i--) { + sb.append(tns[i]); + sb.append("."); + } + sb.append(tns[0]); + String src = MessageFormat.format(s, sb.toString(), getWsName()); + createService(ServiceType.TOP_DOWN, "/" + getWsProjectName() + "/src/" + + getWsName() + ".wsdl", getLevel(), pkg, src, serviceRuntime, useDefaultProjects); + } + + private void createService(ServiceType type, String source, + SliderLevel level, String pkg, String code, WebServiceRuntime serviceRuntime, boolean useDefaultProjects) { + // create ws source - java class or wsdl + switch (type) { + case BOTTOM_UP: + TextEditor editor = ProjectHelper.createClass(getWsProjectName(), getWsPackage(), getWsName()); + assertNotNull(editor); + + // replace default content of java class w/ code + editor.setText(code); + editor.save(); + editor.close(); + break; + case TOP_DOWN: + DefaultEditor ed = ProjectHelper.createWsdl(getWsProjectName(),getWsName()); + assertNotNull(ed); + StyledText text = new DefaultStyledText(); + assertNotNull(text); + + text.setText(code); + ed.save(); + ed.close(); + break; + } + + ProjectHelper.cleanAllProjects(); + + // create a web service + WebServiceWizard wizard = new WebServiceWizard(); + wizard.open(); + + WebServiceFirstWizardPage page = new WebServiceFirstWizardPage(); + page.setServiceType(type); + page.setSource(source); + page.setServerRuntime(getConfiguredServerName()); + page.setWebServiceRuntime(serviceRuntime.getName()); + if (!useDefaultProjects) { + page.setServiceProject(getWsProjectName()); + page.setServiceEARProject(getEarProjectName()); + } + new DefaultShell("Web Service"); + page.setServiceSlider(level); + if (page.isClientEnabled()) { + page.setClientSlider(SliderLevel.NO_CLIENT); + } + new WaitUntil(new WidgetIsEnabled(new NextButton()), TimePeriod.getCustom(5), false); + wizard.next(); + + checkErrorDialog(wizard); + + if (pkg != null && pkg.trim().length() > 0) { + WebServiceSecondWizardPage page2 = new WebServiceSecondWizardPage(); + page2.setPackageName(pkg); + wizard.next(); + } + + if (pkg == null && type == ServiceType.TOP_DOWN && getLevel() == SliderLevel.ASSEMBLE) { + new FinishButton().click(); + confirmWebServiceNameOverwrite(); + + new WaitWhile(new ShellWithTextIsAvailable("Web Service")); + new WaitWhile(new JobIsRunning()); + } else { + wizard.finish(); + } + + // let's fail if there's some error in the wizard, + // and close error dialog and the wizard so other tests + // can continue + if (new DefaultShell() != null) { + if (new DefaultShell().getText().contains("Error")) { + String msg = new DefaultText().getText(); + new PushButton(0).click(); + wizard.cancel(); + Assert.fail(msg); + } + } + } + + private void checkErrorDialog(WizardDialog openedWizard) { + Shell shell = new DefaultShell(); + String text = shell.getText(); + if (text.contains("Error")) { + String msg = ""; + try { + msg = new DefaultText().getText(); + } catch (SWTLayerException e) { + + } + new PushButton(0).click(); + openedWizard.cancel(); + Assert.fail(text + msg); + } + } + + private void confirmWebServiceNameOverwrite() { + // look up shell + try { + new DefaultShell("Confirm Web Service Name Overwrite"); + new OkButton().click(); + } catch(SWTLayerException e) { + LOGGER.log(Level.SEVERE, "No \"Confirm Web Service Name Overwrite\" dialog found!", e); + return; + } + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/eap/EAPCompAllTests.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/eap/EAPCompAllTests.java new file mode 100644 index 000000000..0d24e68d2 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/eap/EAPCompAllTests.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2011 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.jboss.tools.ws.ui.bot.test.webservice.eap; + +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; + +/** + * Documentation/description is available at Docspace} + * + * @author jlukas, jjankovi + * @see DOC-43675 + */ +@SuiteClasses({ + EAPFromJavaTest.class, + EAPFromWSDLTest.class +}) +@RunWith(RedDeerSuite.class) +public class EAPCompAllTests { +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/eap/EAPFromJavaTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/eap/EAPFromJavaTest.java new file mode 100644 index 000000000..c9008f9bf --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/eap/EAPFromJavaTest.java @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2011 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.jboss.tools.ws.ui.bot.test.webservice.eap; + +import java.util.logging.Level; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.jboss.reddeer.eclipse.ui.perspectives.JavaEEPerspective; +import org.jboss.reddeer.requirements.openperspective.OpenPerspectiveRequirement.OpenPerspective; +import org.jboss.reddeer.common.wait.AbstractWait; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.ws.reddeer.ui.wizards.CreateNewFileWizardPage; +import org.jboss.tools.ws.reddeer.ui.wizards.jst.jsp.NewJSPFileWizard; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceWizardPageBase.SliderLevel; +import org.jboss.tools.ws.ui.bot.test.utils.DeploymentHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ResourceHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ServersViewHelper; +import org.jboss.tools.ws.ui.bot.test.utils.WebServiceClientHelper; +import org.jboss.tools.ws.ui.bot.test.webservice.WebServiceRuntime; +import org.jboss.tools.ws.ui.bot.test.webservice.WebServiceTestBase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * Test operates on creating non-trivial EAP project from Java class + * + * @author jlukas + * + */ +@OpenPerspective(JavaEEPerspective.class) +public class EAPFromJavaTest extends WebServiceTestBase { + + private static boolean servicePassed = false; + + @Before + @Override + public void setup() { + if (!ProjectHelper.projectExists(getWsProjectName())) { + ProjectHelper.createProject(getWsProjectName()); + } + if (!ProjectHelper.projectExists(getWsClientProjectName())) { + ProjectHelper.createProject(getWsClientProjectName()); + } + } + + @Override + protected String getWsProjectName() { + return "TestWSProject"; + } + + @Override + protected String getEarProjectName() { + return getWsProjectName() + "EAR"; + } + + protected String getWsClientProjectName() { + return "TestWSClientProject"; + } + + @Override + protected String getWsPackage() { + return "test.ws"; + } + + @Override + protected String getWsName() { + return "Echo"; + } + + @Override + protected SliderLevel getLevel() { + return SliderLevel.DEPLOY; + } + + @Test + public void testEAPFromJava() { + testService(); + testClient(); + } + + private void testService() { + // create a class representing some complex type + TextEditor editor = ProjectHelper.createClass(getWsProjectName(), "test", "Person"); + editor.setText(ResourceHelper + .readStream(EAPFromJavaTest.class.getResourceAsStream("/resources/jbossws/Person.java.ws"))); + editor.save(); + editor.close(); + + // refresh workspace - workaround??? for JBIDE-6731 + try { + ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IWorkspaceRoot.DEPTH_INFINITE, + new NullProgressMonitor()); + } catch (CoreException e) { + LOGGER.log(Level.WARNING, e.getMessage(), e); + } + bottomUpWS(EAPFromJavaTest.class.getResourceAsStream("/resources/jbossws/Echo.java.ws"), + WebServiceRuntime.JBOSS_WS, false); + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(getWsProjectName()); + IFile f = project.getFile("WebContent/WEB-INF/web.xml"); + String content = ResourceHelper.readFile(f); + Assert.assertNotNull(content); + Assert.assertTrue(content.contains("test.ws.Echo")); + Assert.assertTrue(content.contains("/Echo")); + ServersViewHelper.runProjectOnServer(getEarProjectName()); + ServersViewHelper.waitForDeployment(getEarProjectName(), getConfiguredServerName()); + DeploymentHelper.assertServiceDeployed(DeploymentHelper.getWSDLUrl(getWsProjectName(), getWsName()), 10000); + servicePassed = true; + } + + private void testClient() { + Assert.assertTrue("service must exist", servicePassed); + WebServiceClientHelper.createClient(getConfiguredServerName(), + DeploymentHelper.getWSDLUrl(getWsProjectName(), getWsName()), WebServiceRuntime.JBOSS_WS, + getWsClientProjectName(), getEarProjectName(), getLevel(), ""); + IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(getWsClientProjectName()); + String pkg = "test/ws"; + String cls = "src/" + pkg + "/EchoService.java"; + Assert.assertTrue(p.getFile(cls).exists()); + cls = "src/" + pkg + "/clientsample/ClientSample.java"; + Assert.assertTrue(p.getFile(cls).exists()); + + createJSPFile(); + + /** + * Workaround for 4.x branch + * + * bot.activeShell().bot().button("Skip").click(); bot.sleep(TIME_5S); + */ + setJSPFileContent(); + AbstractWait.sleep(TimePeriod.getCustom(2)); + ServersViewHelper.runProjectOnServer(getEarProjectName()); + ServersViewHelper.waitForDeployment(getEarProjectName(), getConfiguredServerName()); + ServersViewHelper.serverClean(getConfiguredServerName()); + String pageContent = DeploymentHelper + .getPage("http://localhost:8080/" + getWsClientProjectName() + "/index.jsp", 15000); + LOGGER.info(pageContent); + Assert.assertTrue(pageContent.contains("BartSimpson(age: 12)")); + Assert.assertTrue(pageContent.contains("Homer(age: 44)")); + } + + private void createJSPFile() { + NewJSPFileWizard wizard = new NewJSPFileWizard(); + wizard.open(); + + CreateNewFileWizardPage page = new CreateNewFileWizardPage(); + page.setFileName("index"); + page.setParentFolder(getWsClientProjectName() + "/WebContent"); + + wizard.finish(); + } + + private void setJSPFileContent() { + TextEditor editor = new TextEditor("index.jsp"); + editor.setText(ResourceHelper + .readStream(EAPFromJavaTest.class.getResourceAsStream("/resources/jbossws/index.jsp.ws"))); + editor.save(); + editor.close(); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/eap/EAPFromWSDLTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/eap/EAPFromWSDLTest.java new file mode 100644 index 000000000..2ed51e663 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/webservice/eap/EAPFromWSDLTest.java @@ -0,0 +1,247 @@ +/******************************************************************************* + * Copyright (c) 2011 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.jboss.tools.ws.ui.bot.test.webservice.eap; + +import java.io.IOException; +import java.io.InputStream; +import java.util.logging.Level; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.common.wait.WaitWhile; +import org.jboss.reddeer.core.condition.JobIsRunning; +import org.jboss.reddeer.eclipse.condition.ConsoleHasText; +import org.jboss.reddeer.eclipse.ui.console.ConsoleView; +import org.jboss.reddeer.eclipse.ui.perspectives.JavaEEPerspective; +import org.jboss.reddeer.requirements.openperspective.OpenPerspectiveRequirement.OpenPerspective; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceWizardPageBase.SliderLevel; +import org.jboss.tools.ws.ui.bot.test.uiutils.RunConfigurationsDialog; +import org.jboss.tools.ws.ui.bot.test.utils.DeploymentHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ResourceHelper; +import org.jboss.tools.ws.ui.bot.test.utils.ServersViewHelper; +import org.jboss.tools.ws.ui.bot.test.utils.WebServiceClientHelper; +import org.jboss.tools.ws.ui.bot.test.webservice.TopDownWSTest; +import org.jboss.tools.ws.ui.bot.test.webservice.WebServiceRuntime; +import org.jboss.tools.ws.ui.bot.test.webservice.WebServiceTestBase; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * Test operates on creating non-trivial EAP project from wsdl file + * + * @author jlukas + * + */ +@OpenPerspective(JavaEEPerspective.class) +public class EAPFromWSDLTest extends WebServiceTestBase { + + private static boolean servicePassed = false; + + @Before + @Override + public void setup() { + if (!ProjectHelper.projectExists(getWsProjectName())) { + ProjectHelper.createProject(getWsProjectName()); + } + if (!ProjectHelper.projectExists(getWsClientProjectName())) { + ProjectHelper.createProject(getWsClientProjectName()); + } + } + + @Override + protected String getWsProjectName() { + return "AreaWSProject"; + } + + @Override + protected String getEarProjectName() { + return getWsProjectName() + "EAR"; + } + + protected String getWsClientProjectName() { + return "AreaWSClientProject"; + } + + protected String getWsClientPackage() { + return "org.jboss.wsclient"; + } + + protected String getClientEarProjectName() { + return getWsClientProjectName() + "EAR"; + } + + @Override + protected String getWsPackage() { + return "org.jboss.ws"; + } + + @Override + protected String getWsName() { + return "AreaService"; + } + + @Override + protected SliderLevel getLevel() { + return SliderLevel.DEPLOY; + } + + @Test + public void testEAPFromWSDL() { + testService(); + testClient(); + } + + private void testService() { + topDownWS(TopDownWSTest.class.getResourceAsStream("/resources/jbossws/AreaService.wsdl"), + WebServiceRuntime.JBOSS_WS, getWsPackage(), false); + + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(getWsProjectName()); + IFile f = project.getFile("src/" + getWsPackage().replace(".", "/") + "/impl" + "/AreaServiceImpl.java"); + + /* + * workaround when package is not typed + */ + if (f == null) { + f = project.getFile("src/" + "org.tempuri.areaservice" + "/AreaServiceImpl.java"); + } + String content = ResourceHelper.readFile(f); + + Assert.assertNotNull(content); + Assert.assertTrue(content.contains("public class AreaServiceImpl implements AreaService {")); + Assert.assertTrue(content.contains("public float calculateRectArea(Dimensions parameters)")); + replaceContent(f, "/resources/jbossws/AreaWS.java.ws"); + + f = project.getFile("WebContent/WEB-INF/web.xml"); + content = ResourceHelper.readFile(f); + Assert.assertNotNull(content); + Assert.assertTrue(content.contains("org.jboss.ws.impl.AreaServiceImpl")); + Assert.assertTrue(content.contains("/AreaService")); + + /* + * workaround problems with generated code that require JAX-WS API 2.2 + */ + jaxWsApi22RequirementWorkaround(getWsProjectName(), getWsPackage()); + + ServersViewHelper.runProjectOnServer(getEarProjectName()); + ServersViewHelper.waitForDeployment(getEarProjectName(), getConfiguredServerName()); + DeploymentHelper.assertServiceDeployed(DeploymentHelper.getWSDLUrl(getWsProjectName(), getWsName()), 10000); + servicePassed = true; + } + + private void testClient() { + Assert.assertTrue("service must exist", servicePassed); + WebServiceClientHelper.createClient(getConfiguredServerName(), + DeploymentHelper.getWSDLUrl(getWsProjectName(), getWsName()), WebServiceRuntime.JBOSS_WS, + getWsClientProjectName(), getEarProjectName(), SliderLevel.DEVELOP, getWsClientPackage()); + IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(getWsClientProjectName()); + String pkg = "org/jboss/wsclient"; + String cls = "src/" + pkg + "/AreaService.java"; + Assert.assertTrue(p.getFile(cls).exists()); + cls = "src/" + pkg + "/clientsample/ClientSample.java"; + IFile f = p.getFile(cls); + Assert.assertTrue(f.exists()); + replaceContent(f, "/resources/jbossws/clientsample.java.ws"); + + /* + * workaround problems with generated code that require JAX-WS API 2.2 + */ + jaxWsApi22RequirementWorkaround(getWsClientProjectName(), getWsClientPackage()); + + runJavaApplication(); + + // wait until the client ends (prints the last line) + new WaitUntil(new ConsoleHasText("Call Over!"), TimePeriod.NORMAL); + + ConsoleView cw = new ConsoleView(); + String consoleOutput = cw.getConsoleText(); + LOGGER.info("Console output: " + consoleOutput); + Assert.assertTrue(consoleOutput, consoleOutput.contains("Server said: 37.5")); + Assert.assertTrue(consoleOutput.contains("Server said: 3512.3699")); + } + + private void replaceContent(IFile f, String content) { + try { + f.delete(true, new NullProgressMonitor()); + } catch (CoreException ce) { + LOGGER.log(Level.WARNING, ce.getMessage(), ce); + } + InputStream is = null; + try { + is = EAPFromWSDLTest.class.getResourceAsStream(content); + f.create(is, true, new NullProgressMonitor()); + } catch (CoreException ce) { + LOGGER.log(Level.WARNING, ce.getMessage(), ce); + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException ioe) { + // ignore + } + } + } + try { + ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IWorkspaceRoot.DEPTH_INFINITE, + new NullProgressMonitor()); + } catch (CoreException e) { + LOGGER.log(Level.WARNING, e.getMessage(), e); + } + new WaitWhile(new JobIsRunning(), TimePeriod.NORMAL); + } + + /** + * @see https://community.jboss.org/message/732539#732539 + */ + private void jaxWsApi22RequirementWorkaround(String projectName, String pkgName) { + final String fileName = "AreaService_Service.java"; + ResourceHelper.openJavaFile(projectName, pkgName, fileName); + TextEditor editor = new TextEditor(fileName); + + String text = editor.getText(); + boolean putComment = false; + StringBuilder output = new StringBuilder(); + for (String line : text.split(System.getProperty("line.separator"))) { + if (line.contains("This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2")) { + putComment = true; + } + if (putComment) { + output.append("//"); + if (line.contains("}")) { + putComment = false; + } + } + output.append(line); + output.append(System.getProperty("line.separator")); + } + editor.setText(output.toString()); + editor.save(); + editor.close(); + } + + private void runJavaApplication() { + RunConfigurationsDialog dialog = new RunConfigurationsDialog(); + dialog.open(); + dialog.createNewConfiguration("Java Application"); + dialog.setProjectName(getWsClientProjectName()); + dialog.setClassName("org.jboss.wsclient.clientsample.ClientSample"); + dialog.run(); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/websocket/StubMethodsHelper.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/websocket/StubMethodsHelper.java new file mode 100644 index 000000000..5220a7602 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/websocket/StubMethodsHelper.java @@ -0,0 +1,217 @@ +/******************************************************************************* + * Copyright (c) 2017 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 + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.ws.ui.bot.test.websocket; + +import org.apache.commons.lang.StringUtils; +import org.eclipse.swt.SWT; +import org.jboss.reddeer.eclipse.ui.views.contentoutline.OutlineView; +import org.jboss.reddeer.jface.text.contentassist.ContentAssistant; +import org.jboss.reddeer.swt.api.TreeItem; +import org.jboss.reddeer.swt.impl.label.DefaultLabel; +import org.jboss.reddeer.swt.impl.styledtext.DefaultStyledText; +import org.jboss.reddeer.swt.keyboard.KeyboardFactory; +import org.jboss.reddeer.workbench.impl.editor.Marker; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; + +import java.util.*; + +import static org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper.createClass; +import static org.jboss.tools.ws.ui.bot.test.websocket.StubMethodsTest.Constants.*; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +class StubMethodsHelper { + + /** + * Shell with this label is used. Initialized in first usage (requires opened editor). + */ + private static String CORRECT_CONTENT_ASSISTANT_LABEL = null; + + static void callAllStubProposals(TextEditor editor) { + Set remainingProposals = new HashSet<>(EXPECTED_PROPOSALS); + + for (String proposal : EXPECTED_PROPOSALS) { + //Call proposal + ContentAssistant contentAssistant = openContentAssistant(editor); + contentAssistant.chooseProposal(proposal); + + //Update tmp collection + remainingProposals.remove(proposal); + + //Asserts + assertNoMarkerError(editor.getMarkers()); + assertThereAreOnlySpecifiedStubProposals(editor, remainingProposals); + assertOutlineViewContainsNewMethod(editor, proposal); + } + } + + //ASSERTS: + private static void assertNoMarkerError(List markers) { + for (Marker marker : markers) { + if (marker.getText().contains("error")) { + fail("There is an error in the markers! " + marker.getText()); + } + } + } + + /** + * Stub proposal should be in current proposals if and only if + * collection shouldBe contains it. + * + * @param editor + * @param shouldBe + */ + static void assertThereAreOnlySpecifiedStubProposals( + TextEditor editor, Collection shouldBe) { + + //Preparing collections + List proposals = new ArrayList<>(EXPECTED_PROPOSALS); + proposals.removeAll(shouldBe); + List shouldNotBe = proposals; + + ContentAssistant contentAssistant = openContentAssistant(editor); + List actualProposals = contentAssistant.getProposals(); + contentAssistant.close(); + + //check + assertTrue("There are not all expected proposals!", actualProposals.containsAll(shouldBe)); + assertTrue("There are proposals those should not be there!", Collections.disjoint(actualProposals, shouldNotBe)); + } + + private static void assertOutlineViewContainsNewMethod(TextEditor editor, String proposal) { + String newMethodName = proposal.split("[(]")[0]; + + for (TreeItem outlineItem : new OutlineView().outlineElements()) { + if (SERVER_CLASS_NAME.equals(outlineItem.getText()) || CLIENT_CLASS_NAME.equals(outlineItem.getText())) { + for(TreeItem classItem : outlineItem.getItems()){ + if (classItem.getText().startsWith(newMethodName)) { + //OK + editor.activate(); + return; + } + } + fail("New method not found in Class. Method: " + newMethodName); + } + } + fail("Class not found in Outline View!"); + } + + //Open ContentAssistant methods: + /** + * In first call methods finds ContentAssistant with StubMethodsTest.Constants.EXPECTED_PROPOSALS + * and remembers its label in CORRECT_CONTENT_ASSISTANT_LABEL. + * + * @return opened content assistant + */ + static ContentAssistant openContentAssistant(TextEditor editor) { + + //first call + if (CORRECT_CONTENT_ASSISTANT_LABEL == null) { + findCorrectContentAssistantLabel(editor); + } + + //finding the correct content assistant + ContentAssistant contentAssistant = editor.openContentAssistant(); + String labelValue = new DefaultLabel(contentAssistant).getText(); + while (!CORRECT_CONTENT_ASSISTANT_LABEL.equals(labelValue)) { + KeyboardFactory.getKeyboard().invokeKeyCombination(SWT.CTRL, SWT.SPACE); + labelValue = new DefaultLabel(contentAssistant).getText(); + } + return contentAssistant; + } + + private static void findCorrectContentAssistantLabel(TextEditor editor) { + ContentAssistant contentAssistant = editor.openContentAssistant(); + + //studio behavior fix + KeyboardFactory.getKeyboard().invokeKeyCombination(SWT.ESC); + contentAssistant = editor.openContentAssistant(); + + String labelValue = new DefaultLabel(contentAssistant).getText(); + while (!contentAssistant.getProposals().containsAll(EXPECTED_PROPOSALS)) { + KeyboardFactory.getKeyboard().invokeKeyCombination(SWT.CTRL, SWT.SPACE); + labelValue = new DefaultLabel(contentAssistant).getText(); + } + CORRECT_CONTENT_ASSISTANT_LABEL = labelValue; + contentAssistant.close(); + } + + //Prepare class methods: + static TextEditor prepareClass(String className) { + switch (className) { + case SERVER_CLASS_NAME: + return prepareClass(SERVER_CLASS_NAME, + "import javax.websocket.server.ServerEndpoint;", + "@ServerEndpoint(\"/test/\")"); + case CLIENT_CLASS_NAME: + return prepareClass(CLIENT_CLASS_NAME, + "import javax.websocket.ClientEndpoint;", + "@ClientEndpoint"); + default: + throw new RuntimeException("Unknown class to prepare!"); + } + } + + private static TextEditor prepareClass( + String className, String importCommand, String annotation) { + + TextEditor editor = createClass(PROJECT_NAME, PROJECT_PACKAGE, className); + DefaultStyledText text = new DefaultStyledText(); + text.insertText(1, 0, System.lineSeparator()); + text.insertText(2, 0, importCommand); + text.insertText(3, 0, System.lineSeparator()); + text.insertText(3, 0, annotation); + + //set cursor position at the first line in the class, column 0 + int firstLineInClassIndex = getLineOfClassDefinition(editor) + 1; + editor.setCursorPosition(firstLineInClassIndex, 0); + + return editor; + } + + static int getLineOfClassDefinition(TextEditor editor) { + return editor.getLineOfText("public class"); + } + + //Prefixes methods: + static List filterStubProposalsWithPrefix(String prefix) { + List matches = new ArrayList<>(); + for (String proposal : EXPECTED_PROPOSALS) { + if (proposal.startsWith(prefix)) + matches.add(proposal); + } + return matches; + } + + static void setPrefixIntoFirstClassLine(TextEditor editor, String prefix) { + int firstLineInClassIndex = getLineOfClassDefinition(editor) + 1; + new DefaultStyledText().insertText(firstLineInClassIndex, 0, prefix); + + //jump to the end of the line + editor.setCursorPosition(firstLineInClassIndex, editor.getTextAtLine(firstLineInClassIndex).length()); + } + + static void clearFirstClassLine(TextEditor editor) { + delFirstClassLine(editor); + int firstLineInClassIndex = getLineOfClassDefinition(editor) + 1; + new DefaultStyledText().insertText(firstLineInClassIndex, 0, System.lineSeparator()); + } + + static void delFirstClassLine(TextEditor editor) { + int firstLineInClassIndex = getLineOfClassDefinition(editor) + 1; + editor.selectLine(firstLineInClassIndex); + KeyboardFactory.getKeyboard().invokeKeyCombination(SWT.DEL); + } + + static int countImports(TextEditor editor) { + return StringUtils.countMatches(editor.getText(), "import "); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/websocket/StubMethodsTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/websocket/StubMethodsTest.java new file mode 100644 index 000000000..e32c4692c --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/websocket/StubMethodsTest.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2017 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 + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.jboss.tools.ws.ui.bot.test.websocket; + +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.jface.text.contentassist.ContentAssistant; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.reddeer.workbench.impl.editor.TextEditor; +import org.jboss.tools.ws.ui.bot.test.WSTestBase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import static org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper.createProject; +import static org.jboss.tools.ws.ui.bot.test.websocket.StubMethodsHelper.*; +import static org.jboss.tools.ws.ui.bot.test.websocket.StubMethodsTest.Constants.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Testing WebSocket stub methods integration in ContentAssistant proposals. + * + * @author Jan Novak + * + * @see http://tools.jboss.org/documentation/whatsnew/jbosstools/4.3.0.Final.html#webservices + */ +@JBossServer(state=ServerReqState.PRESENT) +public class StubMethodsTest extends WSTestBase { + + @Before + public void setup() { + if (!projectExists(getWsProjectName())) + createProject(getWsProjectName()); + } + + @After + public void tearDown() { + deleteAllProjects(); + } + + @Test + public void testStubMethods() { + callAllStubProposals(prepareClass(SERVER_CLASS_NAME)); + callAllStubProposals(prepareClass(CLIENT_CLASS_NAME)); + } + + @Test + public void testProposalsWithPrefixes() { + TextEditor editor = prepareClass(SERVER_CLASS_NAME); + String[] prefixes = {"o", "on", "onC", "onClose"}; + + for (String prefix : prefixes) { + setPrefixIntoFirstClassLine(editor, prefix); + Collection matchingProposals = filterStubProposalsWithPrefix(prefix); + assertThereAreOnlySpecifiedStubProposals(editor, matchingProposals); + clearFirstClassLine(editor); + } + } + + @Test + public void testDeleteGeneratedMethod() { + TextEditor editor = prepareClass(SERVER_CLASS_NAME); + String proposal = EXPECTED_PROPOSALS.get(0); + + int numberOfLinesBeforeProposalCall = editor.getNumberOfLines(); + int numberOfImportsBeforeProposalCall = countImports(editor); + + //call first proposal + ContentAssistant contentAssistant = openContentAssistant(editor); + contentAssistant.chooseProposal(proposal); + + //after call the proposal it should NOT be in contentAssistant + contentAssistant = openContentAssistant(editor); + assertFalse(contentAssistant.getProposals().contains(proposal)); + contentAssistant.close(); + + //delete generated method + int linesAdded = editor.getNumberOfLines() - numberOfLinesBeforeProposalCall; + int newImportsCount = countImports(editor) - numberOfImportsBeforeProposalCall; + for (int i = 0; i < linesAdded - newImportsCount; i++) { + delFirstClassLine(editor); + } + + //check if there is the called proposal again + contentAssistant = openContentAssistant(editor); + assertTrue(contentAssistant.getProposals().contains(proposal)); + contentAssistant.close(); + } + + @Override + protected String getWsProjectName() { + return PROJECT_NAME; + } + + static class Constants { + static final String PROJECT_NAME = "stubMethodTestProject"; + static final String PROJECT_PACKAGE = "org.websocket.test"; + static final String SERVER_CLASS_NAME = "ServerEndpointExample"; + static final String CLIENT_CLASS_NAME = "ClientEndpointExample"; + static final List EXPECTED_PROPOSALS = Arrays.asList( + "onClose(Session session, CloseReason closeReason): void - @OnClose method for WebSocket endpoint", + "onError(Session session, Throwable throwable): void - @OnError method for WebSocket endpoint", + "onMessage(byte[] message): void - @OnMessage method with binary message for WebSocket endpoint", + "onMessage(PongMessage message): void - @OnMessage method with pong message for WebSocket endpoint", + "onMessage(String message): void - @OnMessage method with text message for WebSocket endpoint", + "onOpen(Session session, EndpointConfig endpointConfig): void - @OnOpen method for WebSocket endpoint" + ); + } + +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wsclient/WSClient.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wsclient/WSClient.java new file mode 100644 index 000000000..9e0de7e29 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wsclient/WSClient.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2010 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.jboss.tools.ws.ui.bot.test.wsclient; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.net.URL; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.namespace.QName; +import javax.xml.soap.MessageFactory; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPMessage; +import javax.xml.ws.Dispatch; +import javax.xml.ws.Service; +import javax.xml.ws.Service.Mode; + +public class WSClient { + + private static final Logger L = Logger.getLogger(WSClient.class.getName()); + private Dispatch d; + + public WSClient(URL location, QName serviceName, QName portName) { + Service s = Service.create(location, serviceName); + d = s.createDispatch(portName, SOAPMessage.class, Mode.MESSAGE); + } + + public String callService(String message) { + SOAPMessage result = null; + try { + SOAPMessage msg = MessageFactory.newInstance().createMessage( null, new ByteArrayInputStream(message.getBytes())); + msg.saveChanges(); + result = d.invoke(msg); + } catch (SOAPException e) { + L.log(Level.WARNING, e.getMessage(), e); + } catch (IOException e) { + L.log(Level.WARNING, e.getMessage(), e); + } + String s = msgToString(result); + L.fine("SOAP Request :\n" + message); + L.fine("SOAP Response:\n" + s); + return s; + } + + private String msgToString(SOAPMessage msg) { + if (msg == null) { + return ""; + } + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try { + msg.writeTo(out); + } catch (SOAPException e) { + L.log(Level.WARNING, e.getMessage(), e); + } catch (IOException e) { + L.log(Level.WARNING, e.getMessage(), e); + } finally { + try { + out.close(); + } catch (IOException e) { + //ignore + L.log(Level.WARNING, e.getMessage(), e); + } + } + return out.toString(); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wsclient/WSClientTestTemplate.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wsclient/WSClientTestTemplate.java new file mode 100644 index 000000000..8ad010e74 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wsclient/WSClientTestTemplate.java @@ -0,0 +1,199 @@ +/******************************************************************************* + * Copyright (c) 2011 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.jboss.tools.ws.ui.bot.test.wsclient; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.List; + +import org.jboss.reddeer.common.exception.RedDeerException; +import org.jboss.reddeer.eclipse.core.resources.Project; +import org.jboss.reddeer.eclipse.core.resources.ProjectItem; +import org.jboss.reddeer.eclipse.jdt.ui.packageexplorer.PackageExplorer; +import org.jboss.reddeer.eclipse.ui.views.navigator.ResourceNavigator; +import org.jboss.tools.ws.reddeer.ui.wizards.wst.WebServiceWizardPageBase.SliderLevel; +import org.jboss.tools.ws.ui.bot.test.soap.SOAPTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ServersViewHelper; +import org.jboss.tools.ws.ui.bot.test.utils.WebServiceClientHelper; +import org.jboss.tools.ws.ui.bot.test.webservice.WebServiceRuntime; +import org.junit.After; +import org.junit.Test; + +/** + * Test template operates on Web Service Client Wizard + * + * @author jlukas + * @author Radoslav Rabara + */ +public class WSClientTestTemplate extends SOAPTestBase { + + protected final WebServiceRuntime serviceRuntime; + + public WSClientTestTemplate(WebServiceRuntime serviceRuntime) { + this.serviceRuntime = serviceRuntime; + } + + @After + public void undeploy() { + ServersViewHelper.removeAllProjectsFromServer(getConfiguredServerName()); + } + + @Override + protected String getWsProjectName() { + return "client"; + } + + protected String getWsPackage() { + return "client." + getLevel().toString().toLowerCase(); + } + + @Override + protected String getEarProjectName() { + return "clientEAR"; + } + + protected String getSampleClientFileName() { + return "clientsample/ClientSample.java"; + } + + @Test + public void testDeployClient() { + setLevel(SliderLevel.DEPLOY); + clientTest(getWsPackage()); + } + + @Test + public void testAssembleClient() { + setLevel(SliderLevel.ASSEMBLE); + clientTest(getWsPackage()); + } + + @Test + public void testDevelopClient() { + setLevel(SliderLevel.DEVELOP); + clientTest(getWsPackage()); + } + + @Test + public void testInstallClient() { + setLevel(SliderLevel.INSTALL); + clientTest(getWsPackage()); + } + + @Test + public void testStartClient() { + setLevel(SliderLevel.START); + clientTest(getWsPackage()); + } + + @Test + public void testTestClient() { + setLevel(SliderLevel.TEST); + clientTest(getWsPackage()); + } + + @Test + public void testDefaultPkg() { + setLevel(SliderLevel.ASSEMBLE); + clientTest(null); + } + + @After + @Override + public void cleanup() { + super.cleanup(); + deleteAllPackages(); + } + + protected void clientTest(String targetPkg) { + WebServiceClientHelper.createClient( + getConfiguredServerName(), + "http://soaptest.parasoft.com/calculator.wsdl", + serviceRuntime, + null, + null, + getLevel(), + targetPkg); + + assertThatExpectedFilesExists(targetPkg); + + assertThatEARProjectIsDeployed(); + } + + private void assertThatExpectedFilesExists(String targetPkg) { + ResourceNavigator navigator = new ResourceNavigator(); + navigator.open(); + Project project = navigator.getProject(getWsProjectName()); + project.refresh(); + + String pkg = (targetPkg != null && !"".equals(targetPkg.trim())) ? getWsPackage() : + "com.parasoft.wsdl.calculator"; + String src = "src/" + pkg.replace('.', '/') + "/"; + String[] expectedFiles = { + src + "ICalculator.java", + src + "Add.java", + src + "AddResponse.java", + src + "Divide.java", + src + "DivideResponse.java", + src + "Multiply.java", + src + "MultiplyResponse.java", + src + "Subtract.java", + src + "SubtractResponse.java", + src + getSampleClientFileName()}; + for(String file : expectedFiles) { + assertTrue("File " + file + " was not created", project.containsItem(file.split("/"))); + } + } + + private void assertThatEARProjectIsDeployed() { + switch (getLevel()) { + + /*workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=428982 + choosing 'Deploy' should normally deploy the project automatically*/ + case DEPLOY: + ServersViewHelper.runProjectOnServer(getEarProjectName()); + + case TEST: + case START: + case INSTALL: + ServersViewHelper.waitForDeployment(getEarProjectName(), getConfiguredServerName()); + if(!WebServiceClientHelper.projectIsDeployed(getConfiguredServerName(), getEarProjectName())) { + fail("Project was not found on the server."); + } + default: + break; + } + } + + private void deleteAllPackages() { + PackageExplorer pe = new PackageExplorer(); + pe.open(); + Project p = pe.getProject(getWsProjectName()); + ProjectItem src = p.getProjectItem("src"); + try { + for(ProjectItem pkg: src.getChildren()) { + pkg.select(); + pkg.delete(); + } + } catch(RedDeerException e) { + pe.open(); + src = p.getProjectItem("src"); + List pkgs = src.getChildren(); + for(ProjectItem pkg: pkgs) { + pkg.select(); + pkg.delete(); + } + } + + } +} + diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wsclient/WsClientTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wsclient/WsClientTest.java new file mode 100644 index 000000000..e18d1a32c --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wsclient/WsClientTest.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2011 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.jboss.tools.ws.ui.bot.test.wsclient; + +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.tools.ws.ui.bot.test.webservice.WebServiceRuntime; +import org.junit.runner.RunWith; + +/** + * Test operates on Web Service Client Wizard, tests inherited + * from {@link WSClientTestTemplate} + * + * @author jlukas + * + */ +@RunWith(RedDeerSuite.class) +public class WsClientTest extends WSClientTestTemplate { + public WsClientTest() { + super(WebServiceRuntime.JBOSS_WS); + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wstester/WSTesterPromptValuesSupportTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wstester/WSTesterPromptValuesSupportTest.java new file mode 100644 index 000000000..f745c204a --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wstester/WSTesterPromptValuesSupportTest.java @@ -0,0 +1,210 @@ +/******************************************************************************* + * Copyright (c) 2010-2011 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.jboss.tools.ws.ui.bot.test.wstester; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.hamcrest.core.Is; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.core.condition.ShellWithTextIsAvailable; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.reddeer.swt.api.TreeItem; +import org.jboss.reddeer.swt.impl.text.DefaultText; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebServicesNode; +import org.jboss.tools.ws.reddeer.ui.dialogs.WSTesterParametersDialog; +import org.jboss.tools.ws.reddeer.ui.tester.views.WsTesterView; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ServersViewHelper; +import org.junit.AfterClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Tests WS Parameters dialog which is invoked when parameters values + * need to be set + * + * @author jjankovi + * @author Radoslav Rabara + */ +@RunWith(RedDeerSuite.class) +@JBossServer(state=ServerReqState.RUNNING, cleanup=false) +public class WSTesterPromptValuesSupportTest extends RESTfulTestBase { + + private String wsProjectName = "wsPromptTestProject"; + + private WsTesterView testerView; + + private WSTesterParametersDialog dialog; + + private RESTfulWebServicesNode restWebServicesNode; + + @Override + public void setup() { + if (!projectExists(wsProjectName)) { + importWSTestProject(wsProjectName); + } + ServersViewHelper.runProjectOnServer(wsProjectName); + ServersViewHelper.waitForDeployment(wsProjectName, getConfiguredServerName()); + testerView = new WsTesterView(); + testerView.open(); + } + + @Override + public void cleanup() { + if (dialog != null && dialog.isOpened()) { + dialog.cancel(); + } + if (testerView != null && testerView.isOpened()) { + testerView.close(); + } + ServersViewHelper.removeAllProjectsFromServer(getConfiguredServerName()); + } + + @AfterClass + public static void cleanEnvironment() { + deleteAllProjects(); + } + + @Override + protected String getWsProjectName() { + return wsProjectName; + } + + /** + * Tests if the parameter dialog can be invoked in WS Tester + */ + @Test + public void testInvokeWsParameterDialog() { + invokeWSParametersDialog(); + } + + /** + * Fails due to JBIDE-12027/JBIDE-22377 + * + * Tests if the parameters were loaded with the specified type + * and default values + * + * @see https://issues.jboss.org/browse/JBIDE-12027 + */ + @Test(expected=AssertionError.class) + public void testParameters() { + invokeWSParametersDialog(); + checkWSParametersDialog(); + } + + /** + * Tests the response + */ + @Test + public void testResponse() { + invokeWSParametersDialog(); + + List parameters = dialog.getAllParameters(); + setParametersValues(parameters); + dialog.ok(); + + checkWSResponse(); + } + + private void invokeWSParametersDialog() { + restWebServicesNode = new RESTfulWebServicesNode(getWsProjectName()); + + runRestServiceOnServer(restWebServicesNode.getWebServices().get(0)); + + testerView.open(); + testerView.invoke(); + + new WaitUntil(new ShellWithTextIsAvailable(WSTesterParametersDialog.DIALOG_TITLE)); + + dialog = new WSTesterParametersDialog(); + } + + private void checkWSParametersDialog() { + //button is always enabled until JBIDE-13111 is resolved + //@see https://issues.jboss.org/browse/JBIDE-13111 +// assertThat(dialog.isOkButtonEnabled(), Is.is(false)); + + List parameters = dialog.getAllParameters(); + assertThat(dialog.getAllParameters().size(), Is.is(3)); + + checkAllParametersWereLoaded(parameters); + checkAllDefaultParametersValues(parameters); + checkAllParametersTypes(parameters); + checkThereIsMandatoryValueWarning(); + + setParametersValues(parameters); + + checkThereIsNoWarning(); + + assertThat(dialog.isOkButtonEnabled(), Is.is(true)); + + dialog.ok(); + } + + private void checkThereIsNoWarning() { + String warning = getWarningText(); + assertTrue("There is unexpected warning: " + warning, warning.length() == 0); + } + + private void checkThereIsMandatoryValueWarning() { + assertThat(getWarningText(), Is.is(" id's value is mandatory but missing.")); + } + + private String getWarningText() { + return new DefaultText(0).getText(); + } + + private void checkAllParametersWereLoaded(List parameters) { + + assertThat("First parameter name is wrong", + dialog.getParameterName(parameters.get(0)), Is.is("id* ")); + assertThat("Second parameter name is wrong", + dialog.getParameterName(parameters.get(1)), Is.is("m1")); + assertThat("Third parameter name is wrong", + dialog.getParameterName(parameters.get(2)), Is.is("q1")); + } + + private void checkAllDefaultParametersValues(List parameters) { + assertThat("JBIDE-12027/JBIDE-22377: Default value of id is wrong", + dialog.getParameterValue(parameters.get(0)), Is.is("0")); + assertThat("Default value of m1 is wrong", + dialog.getParameterValue(parameters.get(1)), Is.is("m1")); + assertThat("Default value of q1 is wrong", + dialog.getParameterValue(parameters.get(2)), Is.is("q1")); + } + + private void checkAllParametersTypes(List parameters) { + assertThat("Type of id is wrong", + dialog.getParameterType(parameters.get(0)), Is.is("Integer")); + assertThat("Type of m1 is wrong", + dialog.getParameterType(parameters.get(1)), Is.is("String")); + assertThat("Type of q1 is wrong", + dialog.getParameterType(parameters.get(2)), Is.is("String")); + } + + private void setParametersValues(List parameters) { + dialog.setParameterValue(parameters.get(0), "1"); + dialog.setParameterValue(parameters.get(1), "matrix"); + dialog.setParameterValue(parameters.get(2), "query"); + + } + + private void checkWSResponse() { + assertThat("JAX-RS Response on GET method is wrong", + testerView.getResponseBody(), Is.is("1 matrix query")); + + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wstester/WsTesterTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wstester/WsTesterTest.java new file mode 100644 index 000000000..45389c860 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wstester/WsTesterTest.java @@ -0,0 +1,435 @@ +/******************************************************************************* + * Copyright (c) 2010 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.jboss.tools.ws.ui.bot.test.wstester; + +import static org.junit.Assert.assertEquals; + +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.jboss.reddeer.common.wait.AbstractWait; +import org.jboss.reddeer.common.wait.TimePeriod; +import org.jboss.reddeer.common.wait.WaitUntil; +import org.jboss.reddeer.core.condition.ShellWithTextIsAvailable; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.swt.impl.button.OkButton; +import org.jboss.reddeer.swt.impl.shell.DefaultShell; +import org.jboss.reddeer.swt.impl.text.DefaultText; +import org.jboss.reddeer.uiforms.impl.expandablecomposite.DefaultExpandableComposite; +import org.jboss.tools.ws.reddeer.swt.condition.WsTesterNotEmptyResponseText; +import org.jboss.tools.ws.reddeer.ui.dialogs.InputDialog; +import org.jboss.tools.ws.reddeer.ui.tester.views.SelectWSDLDialog; +import org.jboss.tools.ws.reddeer.ui.tester.views.WsTesterView; +import org.jboss.tools.ws.reddeer.ui.tester.views.WsTesterView.RequestType; +import org.jboss.tools.ws.ui.bot.test.utils.ProjectHelper; +import org.jboss.tools.ws.ui.messages.JBossWSUIMessages; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Tests for Web Service Tester + * + * @author jlukas + */ +@RunWith(RedDeerSuite.class) +public class WsTesterTest { + + private static final String SERVICE_URL = "http://www.webservicex.net/BibleWebservice.asmx"; + private static final Logger LOGGER = Logger.getLogger(WsTesterTest.class.getName()); + + private WsTesterView wstv; + + @Before + public void openWsTester() { + wstv = wstv == null ? new WsTesterView() : wstv; + if (!wstv.isOpened()) { + wstv.open(); + } + } + + @AfterClass + public static void deleteProjects() { + ProjectHelper.deleteAllProjects(); + } + + @After + public void clearResponseBody() { + wstv.activate(); + new DefaultText(new DefaultExpandableComposite(JBossWSUIMessages.JAXRSWSTestView2_ResponseBody_Section)) + .setText(""); + } + + /** + * Test behavior of UI + */ + @Test + public void testUI() { + wstv.setRequestType(RequestType.PUT); + Assert.assertEquals(RequestType.PUT, wstv.getRequestType()); + wstv.setRequestType(RequestType.JAX_WS); + Assert.assertEquals(RequestType.JAX_WS, wstv.getRequestType()); + wstv.setRequestType(RequestType.DELETE); + Assert.assertEquals(RequestType.DELETE, wstv.getRequestType()); + + wstv.setRequestHeadersSectionExpansion(true); + wstv.addHeaderRequestArg("a", "1"); + wstv.addHeaderRequestArg("b", "2"); + wstv.addHeaderRequestArg("c", "3"); + Assert.assertEquals(3, wstv.getHeaderRequestArgs().keySet().size()); + Assert.assertTrue(wstv.getHeaderRequestArgs().containsKey("b")); + + wstv.addHeaderRequestArg("d", "4"); + Assert.assertEquals(4, wstv.getHeaderRequestArgs().keySet().size()); + Assert.assertTrue(wstv.getHeaderRequestArgs().containsKey("d")); + Assert.assertEquals(4, wstv.getHeaderRequestArgs().keySet().size()); + + wstv.removeHeaderRequestArg("a", "1"); + wstv.removeHeaderRequestArg("c", "3"); + Assert.assertEquals(2, wstv.getHeaderRequestArgs().keySet().size()); + + wstv.clearHeaderRequestArgs(); + Assert.assertEquals(0, wstv.getHeaderRequestArgs().keySet().size()); + + wstv.setRequestType(RequestType.JAX_WS); + selectPort(wstv, "BibleWebserviceSoap"); + Assert.assertTrue(wstv.getRequestBody().contains("http://schemas.xmlsoap.org/soap/envelope/")); + + selectPort(wstv, "BibleWebserviceSoap12"); + Assert.assertTrue("Got: " + wstv.getRequestBody(), + wstv.getRequestBody().contains("http://www.w3.org/2003/05/soap-envelope")); + } + + /** + * Test refreshing body requests in the UI + */ + @Test + public void testNamespaces() { + String uri = new File(prepareWsdl(), "original.wsdl").toURI().toString(); + SelectWSDLDialog dlg = wstv.invokeGetFromWSDL(); + dlg.setURI(uri); + AbstractWait.sleep(TimePeriod.SHORT); + List items = dlg.getServices(); + + LOGGER.log(Level.FINE, "Services: {0}", items); + Assert.assertEquals(2, items.size()); + Assert.assertTrue(items.contains("EchoService")); + dlg.selectService("EchoService"); + items = dlg.getPorts(); + + LOGGER.log(Level.FINE, "Ports: {0}", items); + Assert.assertEquals(1, items.size()); + Assert.assertTrue(items.contains("EchoPort")); + items = dlg.getOperations(); + + LOGGER.log(Level.FINE, "Operations: {0}", items); + Assert.assertEquals(1, items.size()); + Assert.assertTrue(items.contains("echo")); + dlg.ok(); + + LOGGER.log(Level.INFO, "Request: {0}", wstv.getRequestBody()); + Assert.assertTrue(wstv.getRequestBody().contains(" 0); + checkResponse(rsp, "<BookTitle>Mark</BookTitle>"); + } + + /** + * Test SOAP 1.2 service invocation + * Fails due to JBDS-3907 + * + * @see https://issues.jboss.org/browse/JBDS-3907 + */ + @Test + public void testSOAP12Service() { + wstv.setRequestType(RequestType.JAX_WS); + assertEquals(RequestType.JAX_WS, wstv.getRequestType()); + + SelectWSDLDialog selectWSDLDialog = wstv.invokeGetFromWSDL(); + try { + selectWSDLDialog.openURL(); + final String wsdlURLDialogTitle = "WSDL URL"; + InputDialog wsdlURLDialog = new InputDialog(wsdlURLDialogTitle); + wsdlURLDialog.setInputText(SERVICE_URL + "?WSDL"); + wsdlURLDialog.ok(); + new DefaultShell(selectWSDLDialog.TITLE); + assertEquals(SERVICE_URL + "?WSDL", selectWSDLDialog.getURI()); + selectWSDLDialog.selectPort("BibleWebserviceSoap12"); + selectWSDLDialog.ok(); + } finally { + if (new ShellWithTextIsAvailable(selectWSDLDialog.TITLE).test()) { + selectWSDLDialog.close(); + } + } + Assert.assertEquals(SERVICE_URL + "?WSDL", wstv.getServiceURL()); + InputStream is = WsTesterTest.class.getResourceAsStream("/resources/jbossws/message_soap12_out.xml"); + wstv.setRequestBody(readResource(is)); + wstv.invoke(); + + String rsp = wstv.getResponseBody(); + LOGGER.log(Level.FINE, "SOAP response: {0}", rsp); + Assert.assertTrue(rsp.trim().length() > 0); + checkResponse(rsp, "<BookTitle>Mark</BookTitle>"); + } + + /** + * Test REST service invocation (GET request) + */ + @Test + public void testRESTGETService() { + wstv.setRequestType(RequestType.GET); + wstv.setServiceURL(SERVICE_URL + "/GetBibleWordsByChapterAndVerse"); + wstv.setRequestParametersSectionExpansion(true); + wstv.addParameterRequestArg("BookTitle", "Luke"); + wstv.addParameterRequestArg("chapter", "2"); + wstv.addParameterRequestArg("Verse", "2"); + wstv.editParameterRequestArg("chapter", "2", "chapter", "1"); + + try { + wstv.invoke(); + new WaitUntil(new WsTesterNotEmptyResponseText(), TimePeriod.getCustom(5), false); + String rsp = wstv.getResponseBody(); + String[] rspHeaders = wstv.getResponseHeaders(); + LOGGER.log(Level.FINE, "REST response: {0}", rsp); + LOGGER.log(Level.FINE, "Response headers: {0}", Arrays.asList(rspHeaders)); + Assert.assertTrue(rsp.trim().length() > 0); + checkResponse(rsp, "<Chapter>1</Chapter>"); + checkResponse(rsp, "ministers of the word"); + } finally { + wstv.clearParameterRequestArgs(); + } + } + + /** + * Test REST service invocation (POST request) + */ + @Test + public void testRESTPOSTService() { + wstv.setRequestType(WsTesterView.RequestType.POST); + wstv.setServiceURL(SERVICE_URL + "/GetBibleWordsByChapterAndVerse"); + String requestBody = "BookTitle=John&chapter=3&Verse=1\r"; + wstv.setRequestBody(requestBody); + wstv.setResponseHeadersSectionExpansion(true); + wstv.addHeaderRequestArg("Content-Type", "application/x-www-form-urlencoded"); + wstv.addHeaderRequestArg("Content-Length", String.valueOf(requestBody.length())); + + try { + wstv.invoke(); + new WaitUntil(new WsTesterNotEmptyResponseText(), TimePeriod.getCustom(5), false); + String rsp = wstv.getResponseBody(); + String[] rspHeaders = wstv.getResponseHeaders(); + LOGGER.log(Level.FINE, "REST response: {0}", rsp); + LOGGER.log(Level.FINE, "Response headers: {0}", Arrays.asList(rspHeaders)); + Assert.assertTrue("Empty response body", rsp.trim().length() > 0); + checkResponse(rsp, "<Chapter>3</Chapter>"); + checkResponse(rsp, "There was a man of the Pharisees, named Nicodemus, a ruler of the Jews"); + } finally { + wstv.clearHeaderRequestArgs(); + } + } + + @Test + public void testErrorResponse() { + wstv.setRequestType(RequestType.GET); + wstv.setServiceURL("https://watchful.li/api/v1/sites"); + wstv.invoke(); + + new WaitUntil(new ShellWithTextIsAvailable("")); + new OkButton().click(); + new WaitUntil(new WsTesterNotEmptyResponseText(), TimePeriod.getCustom(5), false); + Assert.assertEquals(0, wstv.getParameterRequestArgs().size()); + + String rsp = wstv.getResponseBody(); + String[] rspHeaders = wstv.getResponseHeaders(); + LOGGER.log(Level.FINE, "REST response: {0}", rsp); + LOGGER.log(Level.FINE, "Response headers: {0}", Arrays.asList(rspHeaders)); + Assert.assertTrue(rsp.trim().length() > 0); + checkResponse(rsp, "Invalid API key"); + } + + private String readResource(InputStream is) { + StringBuilder sb = new StringBuilder(); + BufferedReader br = null; + try { + br = new BufferedReader(new InputStreamReader(is)); + String s; + while ((s = br.readLine()) != null) { + sb.append(s); + sb.append('\n'); + } + } catch (IOException e) { + LOGGER.log(Level.WARNING, e.getMessage(), e); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + LOGGER.log(Level.FINEST, e.getMessage(), e); + } + } + } + return sb.toString(); + } + + private void checkResponse(String rsp, String expContent) { + if (!rsp.contains(expContent)) { + if (rsp.contains("503")) { // 503 Service Unavailable + throw new AssertionError("Service Unavailable: " + SERVICE_URL); + } else { + throw new AssertionError("Response doesn't contain \"" + expContent + "\"" + "\nResponse was:" + rsp); + } + } + } + + private File prepareWsdl() { + String[] files = { "imported.wsdl", "original.wsdl", "schema.xsd" }; + File targetFolder = new File(System.getProperty("java.io.tmpdir"), "WsTesterTest"); + targetFolder.mkdirs(); + for (String file : files) { + InputStream is = WsTesterTest.class.getResourceAsStream("/resources/wsdl/" + file); + File target = new File(targetFolder, file); + if (target.exists()) { + target.delete(); + } + try { + OutputStream os = new BufferedOutputStream(new FileOutputStream(target)); + copy(is, os); + } catch (FileNotFoundException fnfe) { + throw new RuntimeException(fnfe); + } + } + return targetFolder; + } + + private void copy(InputStream in, OutputStream out) { + byte[] buf = new byte[1024]; + int len; + try { + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + } catch (IOException ioe) { + throw new RuntimeException(ioe); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException ioe2) { + LOGGER.log(Level.WARNING, ioe2.getMessage(), ioe2); + } + } + if (out != null) { + try { + out.close(); + } catch (IOException ioe2) { + LOGGER.log(Level.WARNING, ioe2.getMessage(), ioe2); + } + } + } + } + + private void selectPort(WsTesterView wstv, String portName) { + SelectWSDLDialog dlg = wstv.invokeGetFromWSDL(); + + try { + dlg.openURL(); + InputDialog wsdUrlDialog = new InputDialog("WSDL URL"); + wsdUrlDialog.typeInputText(SERVICE_URL + "?WSDL"); + wsdUrlDialog.ok(); + new DefaultShell(dlg.TITLE); + + Assert.assertEquals(SERVICE_URL + "?WSDL", dlg.getURI()); + List items = dlg.getServices(); + LOGGER.log(Level.INFO, "Services: {0}", items); + Assert.assertEquals(1, items.size()); + Assert.assertTrue(items.contains("BibleWebservice")); + items = dlg.getPorts(); + + LOGGER.log(Level.INFO, "Ports: {0}", items); + Assert.assertEquals(2, items.size()); + Assert.assertTrue(items.contains("BibleWebserviceSoap")); + Assert.assertTrue(items.contains("BibleWebserviceSoap12")); + dlg.selectPort(portName); + items = dlg.getOperations(); + + LOGGER.log(Level.INFO, "Operations: {0}", items); + Assert.assertEquals(4, items.size()); + Assert.assertTrue(items.contains("GetBookTitles")); + Assert.assertTrue(items.contains("GetBibleWordsByChapterAndVerse")); + dlg.selectOperation("GetBibleWordsbyKeyWord"); + dlg.ok(); + Assert.assertEquals("http://www.webservicex.net/BibleWebservice.asmx?WSDL", wstv.getServiceURL()); + } finally { + if (new ShellWithTextIsAvailable(dlg.TITLE).test()) { + dlg.close(); + } + } + } +} diff --git a/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wstester/XmlJsonFormattingTest.java b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wstester/XmlJsonFormattingTest.java new file mode 100644 index 000000000..b99e0ea01 --- /dev/null +++ b/itests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/wstester/XmlJsonFormattingTest.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2010-2013 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.jboss.tools.ws.ui.bot.test.wstester; + +import static org.hamcrest.MatcherAssert.assertThat; + +import org.hamcrest.core.IsEqual; +import org.jboss.ide.eclipse.as.reddeer.server.requirement.ServerRequirement.JBossServer; +import org.jboss.reddeer.junit.runner.RedDeerSuite; +import org.jboss.reddeer.requirements.server.ServerReqState; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebService; +import org.jboss.tools.ws.reddeer.jaxrs.core.RESTfulWebServicesNode; +import org.jboss.tools.ws.reddeer.ui.tester.views.WsTesterView; +import org.jboss.tools.ws.reddeer.ui.tester.views.WsTesterView.RequestType; +import org.jboss.tools.ws.ui.bot.test.rest.RESTfulTestBase; +import org.jboss.tools.ws.ui.bot.test.utils.ServersViewHelper; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(RedDeerSuite.class) +@JBossServer(state=ServerReqState.RUNNING, cleanup=false) +public class XmlJsonFormattingTest extends RESTfulTestBase { + + private static String projectName = "usersRestManager"; + private WsTesterView wsTesterView; + + private static final String LINE_SEPARATOR = System.getProperty("line.separator", "\n"); + + private final static String XML_RESPONSE_FORMAT = + "" + LINE_SEPARATOR + + "" + LINE_SEPARATOR + " " + LINE_SEPARATOR + " 1" + LINE_SEPARATOR + " " + + "James" + LINE_SEPARATOR + " 6545646" + + "" + LINE_SEPARATOR + " " + LINE_SEPARATOR + " " + LINE_SEPARATOR + " 2" + LINE_SEPARATOR + " " + + "John" + LINE_SEPARATOR + " 8546544" + LINE_SEPARATOR + " " + + "" + LINE_SEPARATOR + " " + LINE_SEPARATOR + " 3" + LINE_SEPARATOR + " Paul" + + "" + LINE_SEPARATOR + " 1287475" + LINE_SEPARATOR + " " + LINE_SEPARATOR + "" + LINE_SEPARATOR; + + private final static String JSON_RESPONSE_FORMAT = + "[\r\n{\r\n \"id\":1,\r\n \"name\":\"James\"," + + "\r\n \"phoneNumber\":6545646\r\n},\r\n {\r\n " + + "\"id\":2,\r\n \"name\":\"John\",\r\n " + + "\"phoneNumber\":8546544\r\n},\r\n {\r\n \"id\":3,\r\n " + + "\"name\":\"Paul\",\r\n \"phoneNumber\":1287475\r\n}\r\n]"; + + @Override + public void setup() { + if (!projectExists(getWsProjectName())) { + importWSTestProject(getWsProjectName()); + } + ServersViewHelper.runProjectOnServer(getWsProjectName()); + ServersViewHelper.waitForDeployment(getWsProjectName(), getConfiguredServerName()); + wsTesterView = new WsTesterView(); + wsTesterView.open(); + } + + @Override + public void cleanup() { + if (wsTesterView.isOpened()) { + wsTesterView.close(); + } + ServersViewHelper.removeAllProjectsFromServer(getConfiguredServerName()); + } + + @Override + protected String getWsProjectName() { + return projectName; + } + + @Test + public void testWSTesterXMLFormatting() { + testWSTesterFormatting(Format.XML); + } + + @Test + public void testWSTesterJSONFormatting() { + testWSTesterFormatting(Format.JSON); + } + + private void testWSTesterFormatting(Format format) { + restWebServicesNode = new RESTfulWebServicesNode(getWsProjectName()); + + runRestServiceOnServer(getProperRestService(restWebServicesNode, format)); + + assertWebServiceTesterIsActive(); + + invokeMethodInWSTester(wsTesterView, RequestType.GET); + + assertThat(wsTesterView.getResponseBody(), + IsEqual.equalTo(format.formattedMessage)); + } + + private RESTfulWebService getProperRestService(RESTfulWebServicesNode restWebServicesNode, + Format format) { + for (RESTfulWebService service : restWebServicesNode.getWebServices()) { + if (service.getPath().contains(format.formatType)) { + return service; + } + } + return null; + } + + enum Format { + XML("xml", XML_RESPONSE_FORMAT), JSON("json", JSON_RESPONSE_FORMAT); + + private String formatType; + + private String formattedMessage; + + private Format(String formatType, String formattedMessage) { + this.formatType = formatType; + this.formattedMessage = formattedMessage; + } + + public String formatType() { + return formatType; + } + + public String expectedFormattedMessage() { + return formattedMessage; + } + } +} diff --git a/itests/pom.xml b/itests/pom.xml new file mode 100644 index 000000000..2b1822e59 --- /dev/null +++ b/itests/pom.xml @@ -0,0 +1,40 @@ + + 4.0.0 + + org.jboss.tools + ws + 1.9.3-SNAPSHOT + + org.jboss.tools.ws + itests + ws.itests + pom + + org.jboss.tools.ws.ui.bot.test + + + + false + true + true + true + -Dreddeer.close.shells=${reddeer.close.shells} -Dreddeer.close.welcome.screen=${reddeer.close.welcome.screen} -Dreddeer.disable.maven.download.repo.index.on.startup=${reddeer.disable.maven.download.repo.index.on.startup} + -Dswt.bot.test.record.screencast=${swt.bot.test.record.screencast} -Dorg.eclipse.swtbot.screenshots.dir=${project.build.directory}/screenshots -Dusage_reporting_enabled=false -Dcom.atlassian.connector.eclipse.monitor.usage.first.time=false -Dcom.atlassian.connector.eclipse.monitor.usage.enabled=false ${junitExtensionsProperties} + + + + + org.eclipse.tycho + tycho-surefire-plugin + + ${skipITests} + ${skipITests} + ${surefire.itests.timeout} + false + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index fff32c548..35e2f53be 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ plugins tests test-framework + itests features site