Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pedrootorres/rgms into pe…
Browse files Browse the repository at this point in the history
…drootorres-master

Conflicts:
	.gitignore
	test/cucumber/Orientation.feature
  • Loading branch information
pauloborba committed Feb 5, 2014
2 parents 0007fd8 + 9f9e38d commit 50121af
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 9 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,3 @@ target/test-reports/plain/TEST-functional-cucumber-orientations-out.txt

target/test-reports/plain/TEST-functional-cucumber-orientations.txt


Binary file added chromedrivers/chromedriver
Binary file not shown.
Binary file added chromedrivers/chromedriverwindowsx86.exe
Binary file not shown.
5 changes: 2 additions & 3 deletions grails-app/controllers/rgms/news/NewsController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ class NewsController {
flash.message = message(code: 'default.deleted.message', args: [message(code: 'news.label', default: 'News'), params.id])
redirect(action: "list")
}
catch (DataIntegrityViolationException e) {
catch (DataIntegrityViolationException ignored) {
flash.message = message(code: 'default.not.deleted.message', args: [message(code: 'news.label', default: 'News'), params.id])
redirect(action: "show", id: params.id)
}
}

def save = {
if (!grailsApplication.config.grails.mail.username) {
throw new RuntimeException(message(code: 'mail.plugin.not.configured', 'default': 'Mail plugin not configured'))
throw new RuntimeException(message(code: 'mail.plugin.not.configured', 'default': 'Mail plugin not configured') as Throwable)
}

def newsInstance = new News(params)
Expand Down Expand Up @@ -81,7 +81,6 @@ class NewsController {

if (!newsInstance.save(flush: true)) {
render(view: "create", model: [newsInstance: newsInstance])
return
}
}

Expand Down
33 changes: 32 additions & 1 deletion test/cucumber/News.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,35 @@ Feature: news
Given the research group "SPG" in the system has a Twitter account "@HumanBrainProj" associated
And twitter account associated with "SPG" research group has been updated once
When I request to update the news from Twitter to research group "SPG"
Then there is no duplicated news in Twitter account associated with research group "SPG"
Then there is no duplicated news in Twitter account associated with research group "SPG"


Scenario: new news web
Given I am at the publications menu
When I select the "News" option at the publications menu
And I select the novo noticias option at the news page
Then I can fill the news details


Scenario: new invalid news (Description blank)
Given the system has no news with description "" and date "17-12-2013" for "SPG" research group
When I create a news with description "" and date "17-12-2013" for "SPG" research group
Then the news with description "", date "17-12-2013" and "SPG" research group is not stored by the system because it is invalid


Scenario: edit existing news
Given the system has a news with description "noticiaTeste" and date "07-04-2012" for "SPG" research group
When I edit the news with description "noticiaTeste" to "newDescription", date "07-04-2012" and "SPG" research group
Then the news "newDescription", date "07-04-2012" and "SPG" research group is properly updated by the system

Scenario: remove existing news web
Given I am at the publications menu
When I select the news page and the new "Noticia1" is stored in the system
And I select to view new "Noticia1" in resulting list
And I select the option to remove in news show page
Then the new "Noticia1" is properly removed by the system

Scenario: new invalid news (invalid date)
Given the system has no news with description "teste" and date "31-02-2013" for "SPG" research group
When I create a news with description "teste" and date "31-02-2013" for "SPG" research group
Then the news with description "teste", date "31-02-2013" and "SPG" research group is not stored by the system because it is invalid
74 changes: 70 additions & 4 deletions test/cucumber/steps/NewsSteps.groovy
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pages.LoginPage
import pages.PublicationsPage
import pages.ResearchGroup.ResearchGroupCreatePage
import pages.news.NewsCreatePage
Expand All @@ -6,6 +7,7 @@ import rgms.member.ResearchGroup
import rgms.news.News
import steps.TestDataAndOperations
import steps.NewsTestDataAndOperations
import pages.news.NewsShowPage

import static cucumber.api.groovy.EN.*

Expand All @@ -14,9 +16,11 @@ Given(~'^the system has no news with description "([^"]*)" and date "([^"]*)" fo
}

When(~'^I create a news with description "([^"]*)" and date "([^"]*)" for "([^"]*)" research group$') { String description, String date, String group ->
Date dateAsDateObj = Date.parse("dd-MM-yyyy", date)
def researchGroup = ResearchGroup.findByName(group)
NewsTestDataAndOperations.createNews(description, dateAsDateObj, researchGroup)
if(NewsTestDataAndOperations.checkValidDate(date)) {
Date dateAsDateObj = Date.parse("dd-MM-yyyy", date)
def researchGroup = ResearchGroup.findByName(group)
NewsTestDataAndOperations.createNews(description, dateAsDateObj, researchGroup)
}
}

Then(~'^the news with description "([^"]*)", date "([^"]*)" and "([^"]*)" research group is properly stored by the system$') { String description, String date, String group ->
Expand Down Expand Up @@ -151,4 +155,66 @@ Then(~'^The system generate a HTML report with the news "([^"]*)" in it$'){ Stri
Then(~'^I can not select the option Export to HTML at the News list page$'){ ->
assert !page.canSelectExportHTMLReport()
}
//#end
//#end


When(~'^I select the novo noticias option at the news page$') {->
selectNovoNoticiasInNewsPage()
}

def selectNovoNoticiasInNewsPage(){

at NewsPage
page.selectCreateNews()
at NewsCreatePage

}

Then(~'^I can fill the news details$') { ->
at NewsCreatePage
page.fillNewDetails("essa eh a descricao")
}

Then(~'^the news with description "([^"]*)", date "([^"]*)" and "([^"]*)" research group is not stored by the system because it is invalid$') { String description, String date, String group ->
Date dateAsDateObj = Date.parse("dd-MM-yyyy", date)
def researchGroup = ResearchGroup.findByName(group)
news = News.findByDescriptionAndDateAndResearchGroup(description, dateAsDateObj, researchGroup)
assert news == null
}

When(~'^I edit the news with description "([^"]*)" to "([^"]*)", date "([^"]*)" and "([^"]*)" research group$') { String description, String newDescr, String date, String group ->
Date dateAsDateObj = Date.parse("dd-MM-yyyy", date)
def researchGroup = ResearchGroup.findByName(group)
NewsTestDataAndOperations.editNewsDescription(description, newDescr, dateAsDateObj, researchGroup)
}

Then(~'^the news "([^"]*)", date "([^"]*)" and "([^"]*)" research group is properly updated by the system$') { String description, String date, String group ->
assert NewsTestDataAndOperations.checkExistingNews(description,date,group)
}


Given(~'^I select the news page and the new "([^"]*)" is stored in the system$') { String description ->
page.select("News")
selectNovoNoticiasInNewsPage()

at NewsCreatePage
page.fillNewDetails(description)
page.clickOnCreate();

to NewsPage
at NewsPage
}

When(~'^I select to view new "([^"]*)" in resulting list$') { String title ->
page.selectViewNew(title)
to NewsShowPage
}

And(~'I select the option to remove in news show page$') {->
to NewsShowPage
page.select('input', 'remove')
}

Then(~'^the new "([^"]*)" is properly removed by the system$') { String description ->
assert !NewsTestDataAndOperations.checkExistingNewsByDescription(description)
}
6 changes: 6 additions & 0 deletions test/functional/pages/news/NewsPage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ class NewsPage extends Page {
$("p span", text: desc).size() == 1
}
//#end

def selectViewNew(title) {
getRow()
def showLink = getRow().find('td').find([text:title])
showLink.click()
}
}
36 changes: 36 additions & 0 deletions test/functional/pages/news/NewsShowPage.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package pages.news

/**
* Created with IntelliJ IDEA.
* User: dyego
* Date: 09/01/14
* Time: 18:30
* To change this template use File | Settings | File Templates.
*/

import geb.Page
import pages.GetPageTitle

class NewsShowPage extends Page {
static url = "news/show/1"

static at = {
//title ==~ /Ver News/
GetPageTitle gp = new GetPageTitle()
def currentNews = gp.msg("default.news.label")
def currentTitle = gp.msg("default.show.label", [currentNews])

title ==~ currentTitle
}

static content = {
}

def select(String e, v) {
if (v == 'delete') {
assert withConfirm(true) { $("form").find(e, class: v).click() }
} else {
$("form").find(e, class: v).click()
}
}
}
40 changes: 40 additions & 0 deletions test/functional/steps/NewsTestDataAndOperations.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,44 @@ class NewsTestDataAndOperations {
def news = News.findByDescriptionAndDateAndResearchGroup(description, dateAsDateObj, researchGroup)
return news != null
}

static public boolean checkExistingNewsByDescription(String description) {
def news = News.findByDescription(description)
return news != null
}

static public void editNewsDescription(String description, String newDescription, Date date, ResearchGroup researchGroup) {
def cont = new NewsController()
def news = News.findByDescriptionAndDateAndResearchGroup(description, date, researchGroup)
news.setDescription(newDescription)
cont.params << news.properties
cont.update(news.id)
cont.response.reset()
}

static public boolean checkValidDate(String date) {

boolean retorno

String diaStr = "" + date.charAt(0) + date.charAt(1)
String mesStr = "" + date.charAt(3) + date.charAt(4)
int dia = Integer.valueOf(diaStr)
int mes = Integer.valueOf(mesStr)

if( (dia > 28) && (mes == 2) ) { // fevereiro
retorno = false
}
else if ( (dia > 30) && (mes == 4) ) { // abril
retorno = false
}
else if ( (dia > 30) && (mes == 6) ) { // junho
retorno = false
}
else if ( (dia > 30) && (mes == 7) ) { // setembro
retorno = false
}
else retorno = !((dia > 30) && (mes == 11))

return retorno
}
}

0 comments on commit 50121af

Please sign in to comment.