Skip to content
This repository has been archived by the owner on Mar 10, 2018. It is now read-only.

Commit

Permalink
update project to load ptagora dummy data
Browse files Browse the repository at this point in the history
  • Loading branch information
dialex committed Dec 1, 2013
1 parent 58648e6 commit 71e24c5
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 203 deletions.
4 changes: 2 additions & 2 deletions app/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
public class Global extends GlobalSettings {
@Override
public void onStart(Application app) {
if (User.find.findRowCount() == 0) { // if DB is empty
Ebean.save((List) Yaml.load("test-data.yml")); // populate it
if (User.find.findRowCount() == 0) { // if DB is empty
Ebean.save((List) Yaml.load("ptagora-data.yml")); // populate it
}
}
}
17 changes: 9 additions & 8 deletions conf/evolutions/default/1.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# --- Created by Ebean DDL
# To stop Ebean DDL generation, remove this comment and start using Evolutions

# --- !Ups

# --- Created by Ebean DDL
# To stop Ebean DDL generation, remove this comment and start using Evolutions

# --- !Ups

create table proposal (
id bigint not null,
title varchar(255),
Expand All @@ -14,6 +14,7 @@ create table proposal (
downvotes integer,
timestamp timestamp,
proposer_email varchar(255),
tag varchar(255),
constraint pk_proposal primary key (id))
;

Expand All @@ -32,9 +33,9 @@ alter table proposal add constraint fk_proposal_proposer_1 foreign key (proposer
create index ix_proposal_proposer_1 on proposal (proposer_email);



# --- !Downs


# --- !Downs

SET REFERENTIAL_INTEGRITY FALSE;

drop table if exists proposal;
Expand Down
101 changes: 41 additions & 60 deletions conf/ptagora-data.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,41 @@

# ==== Users ====

- &user1 !!models.User
email: [email protected]
name: Utilizador Administrador
password: admin

- &user2 !!models.User
email: [email protected]
name: Gonçalo Fortes
password: segredo


# ==== Tags ====

- &tag1 !!models.Tag
title: Portugal-atractivo
description: Aqui fica a descrição deste tema...

- &tag2 !!models.Tag
title: Portugal-do-conhecimento
description: Aqui fica a descrição deste tema...

- &tag3 !!models.Tag
title: Portugal-empreendedor
description: Aqui fica a descrição deste tema...

- &tag4 !!models.Tag
title: Geral
description: Todas as propostas que não encaixam nos outros temas


# ==== Proposals ====

- &prop1 !!models.Proposal
id: 1
title: Costa da inovação
problem: Eixo Atracção Profissional
solution: Promover Portugal como lugar de residência e trabalho para pessoas com profissões que são independente de qualquer local (IT por exemplo)
benefits: Mais empresas, mais postos de trabalho altemente qualificados, sinergias, efeitos de “bola de neve” (uns araem outros tipo “Silicon Valley”
views: 968
upvotes: 8624
downvotes: 17
timestamp: 2013-03-08 14:59:30.252
tag: Portugal-Atractivo
proposer: *user1

- &prop2 !!models.Proposal
id: 2
title: Fazer do turismo um grande desígnio nacional
problem: Eixo Turismo e Eventos
solution: Fazer, fazer, fazer
benefits: À vista de todos
views: 200
upvotes: 1
downvotes: 624
timestamp: 2012-09-04 14:16:12
tag: Portugal-Empreendedor
proposer: *user2

# ==== Users ====

- &user1 !!models.User
email: [email protected]
name: Utilizador Administrador
password: admin

- &user2 !!models.User
email: [email protected]
name: Gonçalo Fortes
password: segredo


# ==== Proposals ====

- &prop1 !!models.Proposal
id: 1
title: Costa da inovação
problem: Eixo Atracção Profissional
solution: Promover Portugal como lugar de residência e trabalho para pessoas com profissões que são independente de qualquer local (IT por exemplo)
benefits: Mais empresas, mais postos de trabalho altemente qualificados, sinergias, efeitos de “bola de neve” (uns araem outros tipo “Silicon Valley”
views: 968
upvotes: 8624
downvotes: 17
timestamp: 2013-03-08 14:59:30.252
tag: Portugal-Atractivo
proposer: *user1

- &prop2 !!models.Proposal
id: 2
title: Fazer do turismo um grande desígnio nacional
problem: Eixo Turismo e Eventos
solution: Fazer, fazer, fazer
benefits: À vista de todos
views: 200
upvotes: 1
downvotes: 624
timestamp: 2012-09-04 14:16:12
tag: Portugal-Empreendedor
proposer: *user2
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.0
sbt.version=0.13.0
14 changes: 7 additions & 7 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")
84 changes: 42 additions & 42 deletions test/ApplicationTest.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.*;

import play.mvc.*;
import play.test.*;
import play.data.DynamicForm;
import play.data.validation.ValidationError;
import play.data.validation.Constraints.RequiredValidator;
import play.i18n.Lang;
import play.libs.F;
import play.libs.F.*;

import static play.test.Helpers.*;
import static org.fest.assertions.Assertions.*;


/**
*
* Simple (JUnit) tests that can call all parts of a play app.
* If you are interested in mocking a whole application, see the wiki for more details.
*
*/
public class ApplicationTest {

// @Test
// public void simpleCheck() {
// int a = 1 + 1;
// assertThat(a).isEqualTo(2);
// }
//
// @Test
// public void renderTemplate() {
// Content html = views.html.main.render("Page Title");
// assertThat(contentType(html)).isEqualTo("text/html");
// assertThat(contentAsString(html)).contains("DCID");
// }

}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.*;

import play.mvc.*;
import play.test.*;
import play.data.DynamicForm;
import play.data.validation.ValidationError;
import play.data.validation.Constraints.RequiredValidator;
import play.i18n.Lang;
import play.libs.F;
import play.libs.F.*;

import static play.test.Helpers.*;
import static org.fest.assertions.Assertions.*;


/**
*
* Simple (JUnit) tests that can call all parts of a play app.
* If you are interested in mocking a whole application, see the wiki for more details.
*
*/
public class ApplicationTest {

// @Test
// public void simpleCheck() {
// int a = 1 + 1;
// assertThat(a).isEqualTo(2);
// }
//
// @Test
// public void renderTemplate() {
// Content html = views.html.main.render("Page Title");
// assertThat(contentType(html)).isEqualTo("text/html");
// assertThat(contentAsString(html)).contains("DCID");
// }

}
88 changes: 44 additions & 44 deletions test/models/ProposalTest.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
package models;

import models.*;

import org.junit.*;

import com.avaje.ebean.Ebean;

import static org.junit.Assert.*;
import play.libs.Yaml;
import play.test.WithApplication;
import static play.test.Helpers.*;

public class ProposalTest extends WithApplication {

@Before
public void setUp() {
start(fakeApplication(inMemoryDatabase()));
}

// creation and retrieval of a proposal
@Test
public void createAndRetrieveProposal() {
new User("[email protected]", "Bob", "secret").save();
Proposal prop = Proposal.createAndSave("Build a new park", "There is none.", "We build it.", "We get happy.", "[email protected]");

assertNotNull(prop); // test retrieval
assertEquals("Build a new park", prop.title); // test correct creation and storage
assertEquals("Bob", prop.proposer.getName()); // test correct storage of User
}

// test the calculation of (positive and negative) scores
@Test
public void calculateScore() {
new User("[email protected]", "Bob", "secret").save();
Proposal prop = Proposal.createAndSave("Build a new park", "There is none.", "We build it.", "We get happy.", "[email protected]");

prop.upvotes = 300;
prop.downvotes = 100;
assertEquals(200, prop.getScore()); // score = upvotes - downvotes
prop.upvotes = 100; // switch values...
prop.downvotes = 300;
assertEquals(-200, prop.getScore()); // and test negative score (they are acceptable)
}
package models;

import models.*;

import org.junit.*;

import com.avaje.ebean.Ebean;

import static org.junit.Assert.*;
import play.libs.Yaml;
import play.test.WithApplication;
import static play.test.Helpers.*;

public class ProposalTest extends WithApplication {

@Before
public void setUp() {
start(fakeApplication(inMemoryDatabase()));
}

// creation and retrieval of a proposal
@Test
public void createAndRetrieveProposal() {
new User("[email protected]", "Bob", "secret").save();
Proposal prop = Proposal.createAndSave("Build a new park", "There is none.", "We build it.", "We get happy.", "[email protected]");

assertNotNull(prop); // test retrieval
assertEquals("Build a new park", prop.title); // test correct creation and storage
assertEquals("Bob", prop.proposer.getName()); // test correct storage of User
}

// test the calculation of (positive and negative) scores
@Test
public void calculateScore() {
new User("[email protected]", "Bob", "secret").save();
Proposal prop = Proposal.createAndSave("Build a new park", "There is none.", "We build it.", "We get happy.", "[email protected]");

prop.upvotes = 300;
prop.downvotes = 100;
assertEquals(200, prop.getScore()); // score = upvotes - downvotes
prop.upvotes = 100; // switch values...
prop.downvotes = 300;
assertEquals(-200, prop.getScore()); // and test negative score (they are acceptable)
}
}
Loading

0 comments on commit 71e24c5

Please sign in to comment.