From 05be04e12a1762460c51e376fe6cab5e228b1e43 Mon Sep 17 00:00:00 2001 From: Cleverson Sacramento Date: Thu, 15 Aug 2013 10:39:30 -0300 Subject: [PATCH] Modificando a estrutura do teste de template --- impl/core/src/test/java/template/CrudImpl.java | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/template/DummyEntity.java | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/core/src/test/java/template/TemplateDelegateCrud.java | 11 +++++++++++ impl/core/src/test/java/template/TemplateTest.java | 8 ++++---- impl/core/src/test/java/template/business/TemplateDelegateCrud.java | 11 ----------- impl/core/src/test/java/template/crud/CrudImpl.java | 131 ----------------------------------------------------------------------------------------------------------------------------------- impl/core/src/test/java/template/model/DummyEntity.java | 100 ---------------------------------------------------------------------------------------------------- 7 files changed, 247 insertions(+), 246 deletions(-) create mode 100644 impl/core/src/test/java/template/CrudImpl.java create mode 100644 impl/core/src/test/java/template/DummyEntity.java create mode 100644 impl/core/src/test/java/template/TemplateDelegateCrud.java delete mode 100644 impl/core/src/test/java/template/business/TemplateDelegateCrud.java delete mode 100644 impl/core/src/test/java/template/crud/CrudImpl.java delete mode 100644 impl/core/src/test/java/template/model/DummyEntity.java diff --git a/impl/core/src/test/java/template/CrudImpl.java b/impl/core/src/test/java/template/CrudImpl.java new file mode 100644 index 0000000..bf222ac --- /dev/null +++ b/impl/core/src/test/java/template/CrudImpl.java @@ -0,0 +1,132 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package template; + +import java.util.ArrayList; +import java.util.List; + +import javax.enterprise.context.RequestScoped; + +import br.gov.frameworkdemoiselle.DemoiselleException; +import br.gov.frameworkdemoiselle.template.Crud; + +@RequestScoped +public class CrudImpl implements Crud { + + private static final long serialVersionUID = 1L; + + private List entities; + + public CrudImpl() { + + super(); + + this.entities = new ArrayList(); + + } + + public void resetEntities() { + + this.entities.clear(); + + this.entities.add(new DummyEntity(1L, "Dummy1 Label 1")); + this.entities.add(new DummyEntity(2L, "Dummy1 Label 2")); + this.entities.add(new DummyEntity(3L, "Dummy1 Label 3")); + this.entities.add(new DummyEntity(4L, "Dummy1 Label 4")); + this.entities.add(new DummyEntity(5L, "Dummy1 Label 5")); + this.entities.add(new DummyEntity(6L, "Dummy1 Label 6")); + this.entities.add(new DummyEntity(7L, "Dummy1 Label 7")); + this.entities.add(new DummyEntity(8L, "Dummy1 Label 8")); + this.entities.add(new DummyEntity(9L, "Dummy1 Label 9")); + this.entities.add(new DummyEntity(10L, "Dummy1 Label 10")); + + } + + @Override + public void delete(Long id) { + + this.entities.remove(this.load(id)); + + } + + @Override + public List findAll() { + + return this.entities; + + } + + @Override + public DummyEntity insert(DummyEntity bean) { + + if (this.entities.add(bean)) { + return bean; + } else { + throw new DemoiselleException("Erro ao inserir entity"); + } + + } + + @Override + public DummyEntity load(Long id) { + + for (DummyEntity dummyEntity : this.entities) { + + if (dummyEntity.getId().equals(id)) { + + return dummyEntity; + + } + + } + + return null; + + } + + @Override + public DummyEntity update(DummyEntity bean) { + + DummyEntity dummyEntity = this.load(bean.getId()); + + dummyEntity.setName(bean.getName()); + + return dummyEntity; + + } + +} diff --git a/impl/core/src/test/java/template/DummyEntity.java b/impl/core/src/test/java/template/DummyEntity.java new file mode 100644 index 0000000..0605cca --- /dev/null +++ b/impl/core/src/test/java/template/DummyEntity.java @@ -0,0 +1,100 @@ +/* + * Demoiselle Framework + * Copyright (C) 2010 SERPRO + * ---------------------------------------------------------------------------- + * This file is part of Demoiselle Framework. + * + * Demoiselle Framework is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 + * along with this program; if not, see + * or write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301, USA. + * ---------------------------------------------------------------------------- + * Este arquivo é parte do Framework Demoiselle. + * + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação + * do Software Livre (FSF). + * + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português + * para maiores detalhes. + * + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título + * "LICENCA.txt", junto com esse programa. Se não, acesse + * ou escreva para a Fundação do Software Livre (FSF) Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. + */ +package template; + +public class DummyEntity { + + private Long id; + private String name; + + public DummyEntity(Long id, String name) { + + super(); + + this.id = id; + this.name = name; + + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DummyEntity other = (DummyEntity) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + +} diff --git a/impl/core/src/test/java/template/TemplateDelegateCrud.java b/impl/core/src/test/java/template/TemplateDelegateCrud.java new file mode 100644 index 0000000..a24e3ec --- /dev/null +++ b/impl/core/src/test/java/template/TemplateDelegateCrud.java @@ -0,0 +1,11 @@ +package template; + +import br.gov.frameworkdemoiselle.stereotype.BusinessController; +import br.gov.frameworkdemoiselle.template.DelegateCrud; + +@BusinessController +public class TemplateDelegateCrud extends DelegateCrud{ + + private static final long serialVersionUID = 1L; + +} diff --git a/impl/core/src/test/java/template/TemplateTest.java b/impl/core/src/test/java/template/TemplateTest.java index d69b628..050e9ca 100644 --- a/impl/core/src/test/java/template/TemplateTest.java +++ b/impl/core/src/test/java/template/TemplateTest.java @@ -36,7 +36,10 @@ */ package template; -import static junit.framework.Assert.*; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertNull; import java.util.List; @@ -51,9 +54,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import template.business.TemplateDelegateCrud; -import template.crud.CrudImpl; -import template.model.DummyEntity; import test.Tests; import br.gov.frameworkdemoiselle.internal.context.ContextManager; import br.gov.frameworkdemoiselle.internal.context.ManagedContext; diff --git a/impl/core/src/test/java/template/business/TemplateDelegateCrud.java b/impl/core/src/test/java/template/business/TemplateDelegateCrud.java deleted file mode 100644 index c882cc1..0000000 --- a/impl/core/src/test/java/template/business/TemplateDelegateCrud.java +++ /dev/null @@ -1,11 +0,0 @@ -package template.business; - -import template.crud.CrudImpl; -import template.model.DummyEntity; -import br.gov.frameworkdemoiselle.stereotype.BusinessController; -import br.gov.frameworkdemoiselle.template.DelegateCrud; - -@BusinessController -public class TemplateDelegateCrud extends DelegateCrud{ - -} diff --git a/impl/core/src/test/java/template/crud/CrudImpl.java b/impl/core/src/test/java/template/crud/CrudImpl.java deleted file mode 100644 index 26ea747..0000000 --- a/impl/core/src/test/java/template/crud/CrudImpl.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Demoiselle Framework - * Copyright (C) 2010 SERPRO - * ---------------------------------------------------------------------------- - * This file is part of Demoiselle Framework. - * - * Demoiselle Framework is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License version 3 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License version 3 - * along with this program; if not, see - * or write to the Free Software Foundation, Inc., 51 Franklin Street, - * Fifth Floor, Boston, MA 02110-1301, USA. - * ---------------------------------------------------------------------------- - * Este arquivo é parte do Framework Demoiselle. - * - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação - * do Software Livre (FSF). - * - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português - * para maiores detalhes. - * - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título - * "LICENCA.txt", junto com esse programa. Se não, acesse - * ou escreva para a Fundação do Software Livre (FSF) Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. - */ -package template.crud; - -import java.util.ArrayList; -import java.util.List; - -import javax.enterprise.context.RequestScoped; - -import template.model.DummyEntity; -import br.gov.frameworkdemoiselle.DemoiselleException; -import br.gov.frameworkdemoiselle.template.Crud; - -@RequestScoped -public class CrudImpl implements Crud { - - private List entities; - - public CrudImpl() { - - super(); - - this.entities = new ArrayList(); - - } - - public void resetEntities() { - - this.entities.clear(); - - this.entities.add(new DummyEntity(1L, "Dummy1 Label 1")); - this.entities.add(new DummyEntity(2L, "Dummy1 Label 2")); - this.entities.add(new DummyEntity(3L, "Dummy1 Label 3")); - this.entities.add(new DummyEntity(4L, "Dummy1 Label 4")); - this.entities.add(new DummyEntity(5L, "Dummy1 Label 5")); - this.entities.add(new DummyEntity(6L, "Dummy1 Label 6")); - this.entities.add(new DummyEntity(7L, "Dummy1 Label 7")); - this.entities.add(new DummyEntity(8L, "Dummy1 Label 8")); - this.entities.add(new DummyEntity(9L, "Dummy1 Label 9")); - this.entities.add(new DummyEntity(10L, "Dummy1 Label 10")); - - } - - @Override - public void delete(Long id) { - - this.entities.remove(this.load(id)); - - } - - @Override - public List findAll() { - - return this.entities; - - } - - @Override - public DummyEntity insert(DummyEntity bean) { - - if (this.entities.add(bean)) { - return bean; - } else { - throw new DemoiselleException("Erro ao inserir entity"); - } - - } - - @Override - public DummyEntity load(Long id) { - - for (DummyEntity dummyEntity : this.entities) { - - if (dummyEntity.getId().equals(id)) { - - return dummyEntity; - - } - - } - - return null; - - } - - @Override - public DummyEntity update(DummyEntity bean) { - - DummyEntity dummyEntity = this.load(bean.getId()); - - dummyEntity.setName(bean.getName()); - - return dummyEntity; - - } - -} diff --git a/impl/core/src/test/java/template/model/DummyEntity.java b/impl/core/src/test/java/template/model/DummyEntity.java deleted file mode 100644 index f31db41..0000000 --- a/impl/core/src/test/java/template/model/DummyEntity.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Demoiselle Framework - * Copyright (C) 2010 SERPRO - * ---------------------------------------------------------------------------- - * This file is part of Demoiselle Framework. - * - * Demoiselle Framework is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License version 3 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License version 3 - * along with this program; if not, see - * or write to the Free Software Foundation, Inc., 51 Franklin Street, - * Fifth Floor, Boston, MA 02110-1301, USA. - * ---------------------------------------------------------------------------- - * Este arquivo é parte do Framework Demoiselle. - * - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação - * do Software Livre (FSF). - * - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português - * para maiores detalhes. - * - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título - * "LICENCA.txt", junto com esse programa. Se não, acesse - * ou escreva para a Fundação do Software Livre (FSF) Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. - */ -package template.model; - -public class DummyEntity { - - private Long id; - private String name; - - public DummyEntity(Long id, String name) { - - super(); - - this.id = id; - this.name = name; - - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - DummyEntity other = (DummyEntity) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - return true; - } - -} -- libgit2 0.21.2