From cf8ea5e54883d2038f5a1991464367e8ac4bcfa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 5 Oct 2015 16:02:51 +0200 Subject: [PATCH 1/4] Include autoinstallation script + test to check that the service is running --- utils/autoinstallation.sh | 110 ++++++++++++++++++++++++++++++++++++++ utils/test.sh | 10 ++++ 2 files changed, 120 insertions(+) create mode 100644 utils/autoinstallation.sh create mode 100644 utils/test.sh diff --git a/utils/autoinstallation.sh b/utils/autoinstallation.sh new file mode 100644 index 0000000..0ca4d29 --- /dev/null +++ b/utils/autoinstallation.sh @@ -0,0 +1,110 @@ +#!/bin/bash + +export MYSQL_PASS=root +export WEBAPPS_PATH=/var/lib/tomcat7/webapps + +# Avoid interactivity (e.g. ask for a root password when installing MySQL) +export DEBIAN_FRONTEND=noninteractive + +# Exit on failure +set -e + + +################################################# +#################### GET WAR #################### +################################################# + +# Use GitHub API to get latest release +# 1.- Check GitHub API +# 2.- Get browser_download_url +# 3.- Remove json field, quotes, colons and white spaces +export URL_DOWNLOAD_LATEST=`curl https://api.github.com/repos/conwetlab/WMarket/releases/latest 2>/dev/null | grep browser_download_url | sed 's/.*"browser_download_url": "\(.*\)".*/\1/'` +wget $URL_DOWNLOAD_LATEST + + +################################################# +########### DEPENDENCIES INSTALLATION ########### +################################################# + +# Install +sudo apt-get update -q +sudo apt-get install -q -y unzip + +# Install MySQL +# Avoid installation script to ask for a password +sudo -E apt-get install -q -y mysql-server mysql-client +# Set root password +sudo mysqladmin -u root password $MYSQL_PASS + +# Install Java +sudo apt-get install -q -y openjdk-7-jdk + +# Install Tomcat +sudo apt-get install -y -q tomcat7 tomcat7-docs tomcat7-admin + +# Start up +sudo service mysql restart +sudo service tomcat7 stop + + +################################################# +################# CONFIGURATION ################# +################################################# + +# Create Marketplace Database +mysqladmin -u root -p$MYSQL_PASS create marketplace + +# Unzip WMarket +unzip -q WMarket.war -d WMarket + +# Configure Marketplace +sed -i "s|^jdbc.username.*$|jdbc.username=root|g" WMarket/WEB-INF/classes/properties/database.properties +sed -i "s|^jdbc.password.*$|jdbc.password=$MYSQL_PASS|g" WMarket/WEB-INF/classes/properties/database.properties + +# Index +export PATH_INDEX=/opt/index + +sed -i "s|lucene.IndexPath=.*$|lucene.IndexPath=$PATH_INDEX|g" WMarket/WEB-INF/classes/properties/marketplace.properties + +sudo mkdir $PATH_INDEX +sudo chmod a+rw $PATH_INDEX + +# Media Files +export PATH_MEDIA=/opt/media +# 3 MB +export MAX_SIZE_MEDIA_FILES=3145728 + +sed -i "s|^media.folder.*$|media.folder=$PATH_MEDIA|g" WMarket/WEB-INF/classes/properties/marketplace.properties +sed -i "s|^media.maxSize.*$|media.maxSize=$MAX_SIZE_MEDIA_FILES|g" WMarket/WEB-INF/classes/properties/marketplace.properties + +sudo mkdir $PATH_MEDIA +sudo chmod a+rw $PATH_MEDIA + +# Descriptions Autoupdate (24 hours) +export PERIOD_UPDATE_DESCRIPTIONS=43200 + +sed -i "s|^descriptions.updatePeriod.*$|descriptions.updatePeriod=$PERIOD_UPDATE_DESCRIPTIONS|g" WMarket/WEB-INF/classes/properties/marketplace.properties + +# Update war file +cd WMarket +sudo jar uf ../WMarket.war WEB-INF/classes/properties/database.properties WEB-INF/classes/properties/marketplace.properties WEB-INF/classes/spring/config/BeanLocations.xml +cd .. + + +################################################# +################### DEPLOYMENT ################## +################################################# + +sudo chmod a+r WMarket.war +sudo cp -p WMarket.war $WEBAPPS_PATH/WMarket.war +sudo service tomcat7 start + + +################################################# +################## WAIT TOMCAT ################## +################################################# + +tail -f /var/log/tomcat7/catalina.out | while read LOGLINE +do + [[ "${LOGLINE}" == *"Server startup"* ]] && pkill -P $$ tail +done \ No newline at end of file diff --git a/utils/test.sh b/utils/test.sh new file mode 100644 index 0000000..1cceee6 --- /dev/null +++ b/utils/test.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# The script is aborted if any command fails. If it is OK that a comand fails, +# use ./mycomand || true +set -e + +# Checks that the service is up and running. +# If the service has not been deployed, the server will return 404 and the command will fail +# If the server cannot connect with the DB, the server will return 500 and the command will fail +wget http://$IP:8080/WMarket/api/v2/user -o /dev/null \ No newline at end of file From 19671745ab4e1eca0ba9565363839a9ded3be9c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Mon, 5 Oct 2015 16:37:27 +0200 Subject: [PATCH 2/4] Include README to explain scripts --- utils/README.md | 40 +++++++++++++++++++ utils/{autoinstallation.sh => autoinstall.sh} | 0 2 files changed, 40 insertions(+) create mode 100644 utils/README.md rename utils/{autoinstallation.sh => autoinstall.sh} (100%) diff --git a/utils/README.md b/utils/README.md new file mode 100644 index 0000000..e032938 --- /dev/null +++ b/utils/README.md @@ -0,0 +1,40 @@ +# Utilities + +This folder contains utilities that can be used to install WMarket in a easier +way. To install WMarket, you can use these to scripts: + +* `install.sh`: + * Ready for Ubuntu 14.04 LTS & CentOS 7 + * It installs all the required dependencies + * It requires interaction to set the following parameters: + * **Database**: user name and password + * **Index**: path to Store Lucene indexes + * **Media**: path to Store media files and the maximum size of these files + * **Autoupdate period**: period to upload the descriptions and retrieve new + offerings + * **OAuth2**: enable or disable OAuth2. If OAuth2 is enabled, some parameters + will be required (IdM URL, client ID, client secret, machine IP...) +* `autoinstall.sh`: + * Ready for Ubuntu 14.04 LTS + * It installs all the required dependencies + * It does not require interaction. Parameters are set with default values: + * **Database**: + * User: `root` + * Password: `admin` + * **Index**: `/opt/index` + * **Media**: + * Path: `/opt/media` + * Max Size: 3145728 (3 MB) + * **Autoupdate period**: 43200 (1 day) + * **OAuth2**: No + +Additionally, you can use the `test.sh` script to check if the service is +properly running. The script needs to know the IP where the service is running. +You can specify it by setting the `IP` environment variable. For example, if +your instance is running on `localhost`, you can run the script by executing the +following commands: + +``` +export IP=127.0.0.1 +./test.sh +``` diff --git a/utils/autoinstallation.sh b/utils/autoinstall.sh similarity index 100% rename from utils/autoinstallation.sh rename to utils/autoinstall.sh From 8e88d986cac196f91346fb39be7c37873a372728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Fri, 16 Oct 2015 10:48:02 +0200 Subject: [PATCH 3/4] Fix #12 --- pom.xml | 2 +- .../marketplace/helpers/OfferingResolver.java | 2 +- .../marketplace/helpers/OfferingResolverTest.java | 15 +++++++++++++++ .../fiware/apps/marketplace/it/AbstractIT.java | 8 +++++++- .../apps/marketplace/it/DescriptionServiceIT.java | 8 ++++++++ src/test/resources/__files/empty.rdf | 3 +++ 6 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/test/resources/__files/empty.rdf diff --git a/pom.xml b/pom.xml index 1a35f1d..b0bd29d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.fiware.apps.marketplace WMarket war - 4.4.3-SNAPSHOT + 4.4.4-SNAPSHOT WMarket http://maven.apache.org diff --git a/src/main/java/org/fiware/apps/marketplace/helpers/OfferingResolver.java b/src/main/java/org/fiware/apps/marketplace/helpers/OfferingResolver.java index 36ef7e5..3ba7601 100644 --- a/src/main/java/org/fiware/apps/marketplace/helpers/OfferingResolver.java +++ b/src/main/java/org/fiware/apps/marketplace/helpers/OfferingResolver.java @@ -379,7 +379,7 @@ public List resolveOfferingsFromServiceDescription(Description descrip List offeringUris = getOfferingUris(rdfHelper); List offerings = new ArrayList(); - if (offeringUris == null) { + if (offeringUris == null || offeringUris.size() == 0) { throw new ParseException("Offerings URLs cannot be retrieved"); } diff --git a/src/test/java/org/fiware/apps/marketplace/helpers/OfferingResolverTest.java b/src/test/java/org/fiware/apps/marketplace/helpers/OfferingResolverTest.java index af3618c..5e3fd84 100644 --- a/src/test/java/org/fiware/apps/marketplace/helpers/OfferingResolverTest.java +++ b/src/test/java/org/fiware/apps/marketplace/helpers/OfferingResolverTest.java @@ -933,4 +933,19 @@ public void testOfferingPriceComponentInvalidValue() { "Offering %s contains a price component with an invalid currency value"); } + // Test for empty descriptions (Issue #12) + @Test + public void testEmptyDescription() { + + // Call the function + Description description = mock(Description.class); + when(description.getUrl()).thenReturn(DESCRIPTION_URI); + + try { + offeringResolver.resolveOfferingsFromServiceDescription(description); + failBecauseExceptionWasNotThrown(ParseException.class); + } catch (ParseException ex) { + assertThat(ex.getMessage()).isEqualTo("Offerings URLs cannot be retrieved"); + } + } } diff --git a/src/test/java/org/fiware/apps/marketplace/it/AbstractIT.java b/src/test/java/org/fiware/apps/marketplace/it/AbstractIT.java index b435059..9d2bac9 100644 --- a/src/test/java/org/fiware/apps/marketplace/it/AbstractIT.java +++ b/src/test/java/org/fiware/apps/marketplace/it/AbstractIT.java @@ -74,6 +74,7 @@ public abstract class AbstractIT { protected String serverUrl; protected String defaultUSDLPath; protected String secondaryUSDLPath; + protected String emptyUSDLPath; protected String complexDescriptionUSDLPath; // Mock server @@ -248,7 +249,11 @@ protected void startMockServer() { .willReturn(aResponse() .withStatus(200) .withBodyFile("secondary.rdf"))); - + + stubFor(get(urlMatching("/empty.rdf")) + .willReturn(aResponse() + .withStatus(200) + .withBodyFile("empty.rdf"))); // Start up server wireMock.start(); @@ -256,6 +261,7 @@ protected void startMockServer() { serverUrl = "http://127.0.0.1:" + wireMock.port(); defaultUSDLPath = serverUrl + "/default.rdf"; secondaryUSDLPath = serverUrl + "/secondary.rdf"; + emptyUSDLPath = serverUrl + "/empty.rdf"; complexDescriptionUSDLPath = serverUrl + "/extra_complex.rdf"; List defaultUSDLPathOfferings = new ArrayList<>(); diff --git a/src/test/java/org/fiware/apps/marketplace/it/DescriptionServiceIT.java b/src/test/java/org/fiware/apps/marketplace/it/DescriptionServiceIT.java index 1295279..887aa35 100644 --- a/src/test/java/org/fiware/apps/marketplace/it/DescriptionServiceIT.java +++ b/src/test/java/org/fiware/apps/marketplace/it/DescriptionServiceIT.java @@ -261,6 +261,14 @@ public void testCreationSecondaryUSDL() { testCreation(secondaryUSDLPath); } + @Test + public void testCreationEmptyUSDL() { + Response response = createDescription(USER_NAME, PASSWORD, FIRST_STORE_NAME, "description-1", + emptyUSDLPath, ""); + checkAPIError(response, 400, "url", "Your RDF could not be parsed: Offerings URLs cannot be retrieved", + ErrorType.VALIDATION_ERROR); + } + private void testCreationInvalidField(String displayName, String url, String comment, String invalidField, String message) { diff --git a/src/test/resources/__files/empty.rdf b/src/test/resources/__files/empty.rdf new file mode 100644 index 0000000..23af3df --- /dev/null +++ b/src/test/resources/__files/empty.rdf @@ -0,0 +1,3 @@ + + \ No newline at end of file From 7c69f926697f7c96462bd057923e1719bfcc717c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Fri, 16 Oct 2015 11:16:07 +0200 Subject: [PATCH 4/4] Fix #13 --- .../resources/marketplace/js/views/descriptions/create.js | 4 ++-- .../resources/marketplace/js/views/descriptions/detail.js | 6 +++--- .../webapp/resources/marketplace/js/views/stores/form.js | 4 ++-- .../java/org/fiware/apps/marketplace/it/SeleniumIT.java | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/webapp/resources/marketplace/js/views/descriptions/create.js b/src/main/webapp/resources/marketplace/js/views/descriptions/create.js index f1982ac..c417934 100644 --- a/src/main/webapp/resources/marketplace/js/views/descriptions/create.js +++ b/src/main/webapp/resources/marketplace/js/views/descriptions/create.js @@ -18,9 +18,9 @@ label: "Name", minlength: 3, maxlength: 100, - regexp: new RegExp("^[A-Z]+[\\w.-]*( [\\w.-]+)*$", "i"), + regexp: new RegExp("^[a-zA-Z0-9. -]+$", "i"), errorMessages: { - invalid: "This field must contain alphanumerics (and -,_,.)." + invalid: "This field only accepts letters, numbers, white spaces, dots and hyphens." } }), new app.fields.URLField('url', { diff --git a/src/main/webapp/resources/marketplace/js/views/descriptions/detail.js b/src/main/webapp/resources/marketplace/js/views/descriptions/detail.js index ac1f69e..384bdcb 100644 --- a/src/main/webapp/resources/marketplace/js/views/descriptions/detail.js +++ b/src/main/webapp/resources/marketplace/js/views/descriptions/detail.js @@ -14,10 +14,10 @@ new app.fields.TextField('displayName', { label: "Name", minlength: 3, - maxlength: 20, - regexp: new RegExp("^[A-Z]+[\\w.-]*( [\\w.-]+)*$", "i"), + maxlength: 100, + regexp: new RegExp("^[a-zA-Z0-9. -]+$", "i"), errorMessages: { - invalid: "This field must contain alphanumerics (and -,_,.)." + invalid: "This field only accepts letters, numbers, white spaces, dots and hyphens." } }), new app.fields.URLField('url', { diff --git a/src/main/webapp/resources/marketplace/js/views/stores/form.js b/src/main/webapp/resources/marketplace/js/views/stores/form.js index 3a47474..723689a 100644 --- a/src/main/webapp/resources/marketplace/js/views/stores/form.js +++ b/src/main/webapp/resources/marketplace/js/views/stores/form.js @@ -12,9 +12,9 @@ label: "Name", minlength: 3, maxlength: 100, - regexp: new RegExp("^[A-Z]+[\\w.-]*( [\\w.-]+)*$", "i"), + regexp: new RegExp("^[a-zA-Z0-9. -]+$", "i"), errorMessages: { - invalid: "This field must contain alphanumerics (and -,_,.)." + invalid: "This field only accepts letters, numbers, white spaces, dots and hyphens." } }), new app.fields.URLField('url', { diff --git a/src/test/java/org/fiware/apps/marketplace/it/SeleniumIT.java b/src/test/java/org/fiware/apps/marketplace/it/SeleniumIT.java index df7963b..d143e71 100644 --- a/src/test/java/org/fiware/apps/marketplace/it/SeleniumIT.java +++ b/src/test/java/org/fiware/apps/marketplace/it/SeleniumIT.java @@ -791,7 +791,8 @@ public void should_DisplayErrorMessage_When_DescriptionCreateFormIsSubmitted_And formElement = submitFormExpectError(formElement, "displayName", String.format(MAX_LENGTH, 100)); fillField(formElement, "displayName", "FIWARE $invalid"); - formElement = submitFormExpectError(formElement, "displayName", "This field must contain alphanumerics (and -,_,.)."); + formElement = submitFormExpectError(formElement, "displayName", + "This field only accepts letters, numbers, white spaces, dots and hyphens."); fillField(formElement, "displayName", descriptionDisplayName); fillField(formElement, "url", defaultUSDLPath);