Skip to content

Commit

Permalink
Merge pull request #14 from conwetlab/develop
Browse files Browse the repository at this point in the history
Bug fixing
  • Loading branch information
aitormagan committed Oct 16, 2015
2 parents f7e3f60 + 7c69f92 commit 77f5391
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.fiware.apps.marketplace</groupId>
<artifactId>WMarket</artifactId>
<packaging>war</packaging>
<version>4.4.3-SNAPSHOT</version>
<version>4.4.4-SNAPSHOT</version>
<name>WMarket</name>
<url>http://maven.apache.org</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public List<Offering> resolveOfferingsFromServiceDescription(Description descrip
List<String> offeringUris = getOfferingUris(rdfHelper);
List<Offering> offerings = new ArrayList<Offering>();

if (offeringUris == null) {
if (offeringUris == null || offeringUris.size() == 0) {
throw new ParseException("Offerings URLs cannot be retrieved");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/resources/marketplace/js/views/stores/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
8 changes: 7 additions & 1 deletion src/test/java/org/fiware/apps/marketplace/it/AbstractIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -248,14 +249,19 @@ 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();

// Set server URL
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<Offering> defaultUSDLPathOfferings = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/fiware/apps/marketplace/it/SeleniumIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/__files/empty.rdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
</rdf:RDF>
40 changes: 40 additions & 0 deletions utils/README.md
Original file line number Diff line number Diff line change
@@ -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
```
110 changes: 110 additions & 0 deletions utils/autoinstall.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions utils/test.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 77f5391

Please sign in to comment.