Skip to content

Commit

Permalink
[Equipe 7] Casos de teste e correção de bug.
Browse files Browse the repository at this point in the history
Implementação dos casos de teste relativos a feature Reports e correção
da issue #85.
  • Loading branch information
hugonmelo committed Mar 11, 2013
1 parent 4d39a70 commit 277779e
Show file tree
Hide file tree
Showing 18 changed files with 402 additions and 1 deletion.
14 changes: 14 additions & 0 deletions grails-app/conf/BootStrap.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import rgms.member.Member
import rgms.member.MemberController
import rgms.member.MemberControllerMixin
import rgms.member.Record
import rgms.member.ResearchGroup
import rgms.publication.ResearchLine

class BootStrap {
Expand Down Expand Up @@ -47,6 +48,19 @@ class BootStrap {
rl.setName("Teoria da informacao - Complexidade no espaco")
rl.setDescription("P=NP")
rl.save()

ResearchGroup r2 = new ResearchGroup()
ResearchGroup r3 = new ResearchGroup()
ResearchGroup r4 = new ResearchGroup()
r2.name = "testehugo1"
r2.description = "testehugo1"
r3.name = "testehugo12"
r3.description = "testehugo12"
r4.name = "testehugo123"
r4.description = "testehugo123"
r2.save()
r3.save()
r4.save()
}
}

Expand Down
Binary file added lib/itext-pdfa-5.4.0-javadoc.jar
Binary file not shown.
Binary file added lib/itext-pdfa-5.4.0-sources.jar
Binary file not shown.
Binary file added lib/itext-pdfa-5.4.0.jar
Binary file not shown.
Binary file added lib/itext-xtra-5.4.0-javadoc.jar
Binary file not shown.
Binary file added lib/itext-xtra-5.4.0-sources.jar
Binary file not shown.
Binary file added lib/itext-xtra-5.4.0.jar
Binary file not shown.
Binary file added lib/itextpdf-5.4.0-javadoc.jar
Binary file not shown.
Binary file added lib/itextpdf-5.4.0-sources.jar
Binary file not shown.
Binary file added lib/itextpdf-5.4.0.jar
Binary file not shown.
40 changes: 40 additions & 0 deletions test/cucumber/Reports.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@i10n
Feature: Reports
I want to generate PDF, HTML or XML report files of Members and Research Groups

Scenario: export member report to pdf
Given I am at the Member list page
When I select the "1" option at the Member list
And I can select the option Export to PDF at the Member show
Then I can generate a PDF report about Member "1"

Scenario: export member report to html
Given I am at the Member list page
When I select the "1" option at the Member list
And I can select the option Export to HTML at the Member show
Then I can generate a HTML report about Member "1"

Scenario: export member report to xml
Given I am at the Member list page
When I select the "1" option at the Member list
And I can select the option Export to XML at the Member show
Then I can generate a XML report about Member "1"

Scenario: export research group report to pdf
Given I am at the Research Group list page and I select the "testehugo1" group
When I select the "testehugo1" option at the Research Group list
And I can select the option Export to PDF at the Research Group show
Then I can generate a PDF report about Research Group "testehugo1"

Scenario: export research group report to html
Given I am at the Research Group list page and I select the "testehugo12" group
When I select the "testehugo12" option at the Research Group list
And I can select the option Export to HTML at the Research Group show
Then I can generate a HTML report about Research Group "testehugo12"

Scenario: export research group report to xml
Given I am at the Research Group list page and I select the "testehugo123" group
When I select the "testehugo123" option at the Research Group list
And I can select the option Export to XML at the Research Group show
Then I can generate a XML report about Research Group "testehugo123"

144 changes: 144 additions & 0 deletions test/cucumber/steps/ReportsSteps.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import pages.LoginPage
import pages.MemberListPage
import pages.MemberPage

import pages.PublicationsPage
import pages.ResearchGroupListPage
import pages.ResearchGroupPage

import static cucumber.api.groovy.EN.*

this.metaClass.mixin(cucumber.api.groovy.Hooks)
this.metaClass.mixin(cucumber.api.groovy.EN)

Given(~'^I am at the Member list page$') {->
to LoginPage
at LoginPage
page.fillLoginData("admin", "adminadmin")
at PublicationsPage
to MemberListPage
at MemberListPage
}

When(~'^I select the "([^"]*)" option at the Member list$') { String memberName ->
page.selectMember(memberName)
}

And(~'^I can select the option Export to PDF at the Member show$') { ->
at MemberPage
page.checkPdf()
}

Then(~'^I can generate a PDF report about Member "([^"]*)"$') { String memberName ->
page.comparePDF(memberName)
}
//-----------------------------------------------------------------------------------------------
/*Given(~'^I am at the Member list page$') { ->
to LoginPage
at LoginPage
page.fillLoginData("admin", "adminadmin")
at PublicationsPage
to MemberListPage
at MemberListPage
}
When(~'^I select the "([^"]*)" option at the Member list$') { String memberName ->
page.selectMember(memberName)
} */

And(~'^I can select the option Export to HTML at the Member show$') { ->
at MemberPage
page.checkHtml()
}

Then(~'^I can generate a HTML report about Member "([^"]*)"$') { String memberName ->
page.compareHTML(memberName)
}
//-------------------------------------------------------------------------------------------------
/*Given(~'^I am at the Member list page$') { ->
to LoginPage
at LoginPage
page.fillLoginData("admin", "adminadmin")
at PublicationsPage
to MemberListPage
at MemberListPage
}
When(~'^I select the "([^"]*)" option at the Member list$') { String memberName ->
page.selectMember(memberName)
} */

And(~'^I can select the option Export to XML at the Member show$') { ->
at MemberPage
page.checkXml()
}

Then(~'^I can generate a XML report about Member "([^"]*)"$') { String memberName ->
page.compareXML(memberName)
}
//-------------------------------------------------------------------------------------------------
Given(~'^I am at the Research Group list page and I select the "([^"]*)" group$') { String researchGroupName ->
to LoginPage
at LoginPage
page.fillLoginData("admin", "adminadmin")
at PublicationsPage
to ResearchGroupListPage
at ResearchGroupListPage
}

When(~'^I select the "([^"]*)" option at the Research Group list$') { String researchGroupName ->
page.selectResearchGroup(researchGroupName)
}

And(~'^I can select the option Export to PDF at the Research Group show$') { ->
at ResearchGroupPage
page.checkPDF()
}

Then(~'^I can generate a PDF report about Research Group "([^"]*)"$') { String researchGroupName ->
page.comparePDF(researchGroupName)
}
//-------------------------------------------------------------------------------------------------
/*Given(~'^I am at the Research Group list page and I select the "([^"]*)" group$') { String researchGroupName ->
to LoginPage
at LoginPage
page.fillLoginData("admin", "adminadmin")
at PublicationsPage
to ResearchGroupListPage
at ResearchGroupListPage
}
/*
When(~'^I select the "([^"]*)" option at the Research Group list$') { String researchGroupName ->
page.selectResearchGroup(researchGroupName)
} */

And(~'^I can select the option Export to HTML at the Research Group show$') { ->
at ResearchGroupPage
page.checkHtml()
}

Then(~'^I can generate a HTML report about Research Group "([^"]*)"$') { String researchGroupName ->
page.compareHTML(researchGroupName)
}
//-------------------------------------------------------------------------------------------------
/*Given(~'^I am at the Research Group list page and I select the "([^"]*)" group$') { String researchGroupName ->
to LoginPage
at LoginPage
page.fillLoginData("admin", "adminadmin")
at PublicationsPage
to ResearchGroupListPage
at ResearchGroupListPage
}
/*
When(~'^I select the "([^"]*)" option at the Research Group list$') { String researchGroupName ->
page.selectResearchGroup(researchGroupName)
} */

And(~'^I can select the option Export to XML at the Research Group show$') { ->
at ResearchGroupPage
page.checkXml()
}

Then(~'^I can generate a XML report about Research Group "([^"]*)"$') { String researchGroupName ->
page.compareXML(researchGroupName)
}
18 changes: 18 additions & 0 deletions test/functional/pages/MemberListPage.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pages

import geb.Page

class MemberListPage extends Page {
static url = "member/list"

static at = {
title ==~ /Member Listagem/
}

static content = {
}

def selectMember(String s) {
$('div').find('a', text: s).click()
}
}
86 changes: 86 additions & 0 deletions test/functional/pages/MemberPage.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package pages

import com.itextpdf.text.pdf.PdfReader
import geb.Page
import com.itextpdf.text.pdf.parser.PdfTextExtractor
import org.xml.sax.InputSource
import rgms.member.Member

import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilder
import javax.xml.parsers.DocumentBuilderFactory

class MemberPage extends Page {
static url = "member/show"

static at = {
title ==~ /Ver Member/
}

static content = {
}

def checkPdf() {
def pdf = $('form').find([title: "PDF"])
assert pdf != null
}

def checkHtml() {
def html = $('form').find([title: "HTML"])
assert html != null
}

def checkXml() {
def xml = $('form').find([title: "XML"])
assert xml != null
}

def comparePDF(String s)
{
def downloadLink = $('form').find([title: "PDF"]).@href
def bytes = downloadBytes(downloadLink)
PdfReader reader = new PdfReader(bytes)
def page = PdfTextExtractor.getTextFromPage(reader, 1)
Member m = Member.findById(Integer.getInteger(s))
def name = page.find(m.name)
def university = page.find(m.university)
def email = page.find(m.email)
assert name != null
assert university != null
assert email != null
}

def compareHTML(String s)
{
def downloadLink = $('form').find([title: "PDF"]).@href
def xml = new XmlSlurper()
xml.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
def parser = xml.parse(downloadLink)
Member m = Member.findById(Integer.getInteger(s))
def name = parser.find(m.name)
def university = parser.find(m.university)
def email = parser.find(m.email)
assert name != null
assert university != null
assert email != null
}

def compareXML(String s)
{
def downloadLink = $('form').find([title: "XML"]).@href
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder()
Document doc = db.parse(downloadLink)
Element langs = doc.getDocumentElement()
NodeList list = langs.getElementsByTagName("name")
Element name = (Element) list.item(0)
NodeList list2 = langs.getElementsByTagName("university")
Element university = (Element) list2.item(0)
NodeList list3 = langs.getElementsByTagName("email")
Element email = (Element) list3.item(0)
Member m = Member.findById(Integer.getInteger(s))
assert name.textContent == m.name
assert university.textContent == m.university
assert email.textContent == m.email
}
}
18 changes: 18 additions & 0 deletions test/functional/pages/ResearchGroupListPage.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pages

import geb.Page

class ResearchGroupListPage extends Page {
static url = "researchGroup/list"

static at = {
title ==~ /Research Group Listagem/
}

static content = {
}

def selectResearchGroup(String s) {
$('div').find('a', text: s).click()
}
}
Loading

0 comments on commit 277779e

Please sign in to comment.