Commit 70f681185f2d568bdcac548ef955f974a8041c9b
1 parent
6304f7c6
Exists in
master
Adição de testes da extensão JDBC
Showing
8 changed files
with
140 additions
and
132 deletions
Show diff stats
impl/extension/jdbc/src/test/java/connection/producer/ConnectionProducerMultipleConnectionsTest.java
0 → 100644
| @@ -0,0 +1,55 @@ | @@ -0,0 +1,55 @@ | ||
| 1 | +package connection.producer; | ||
| 2 | + | ||
| 3 | +import static org.junit.Assert.assertEquals; | ||
| 4 | + | ||
| 5 | +import java.sql.Connection; | ||
| 6 | +import java.sql.SQLException; | ||
| 7 | + | ||
| 8 | +import javax.inject.Inject; | ||
| 9 | + | ||
| 10 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
| 11 | +import org.jboss.arquillian.junit.Arquillian; | ||
| 12 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
| 13 | +import org.junit.Test; | ||
| 14 | +import org.junit.runner.RunWith; | ||
| 15 | + | ||
| 16 | +import test.Tests; | ||
| 17 | +import br.gov.frameworkdemoiselle.annotation.Name; | ||
| 18 | + | ||
| 19 | +@RunWith(Arquillian.class) | ||
| 20 | +public class ConnectionProducerMultipleConnectionsTest { | ||
| 21 | + | ||
| 22 | + private static String PATH = "src/test/resources/producer/multiple-connections"; | ||
| 23 | + | ||
| 24 | + @Inject | ||
| 25 | + @Name("conn1") | ||
| 26 | + private Connection conn1; | ||
| 27 | + | ||
| 28 | + @Inject | ||
| 29 | + @Name("conn2") | ||
| 30 | + private Connection conn2; | ||
| 31 | + | ||
| 32 | + // Conexão Default | ||
| 33 | + @Inject | ||
| 34 | + private Connection conn3; | ||
| 35 | + | ||
| 36 | + @Inject | ||
| 37 | + @Name("conn4") | ||
| 38 | + private Connection conn4; | ||
| 39 | + | ||
| 40 | + @Deployment | ||
| 41 | + public static WebArchive createDeployment() { | ||
| 42 | + WebArchive deployment = Tests.createDeployment(ConnectionProducerMultipleConnectionsTest.class); | ||
| 43 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | ||
| 44 | + return deployment; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Test | ||
| 48 | + public void createConnection() throws SQLException { | ||
| 49 | + assertEquals(conn1.getMetaData().getURL(), "jdbc:hsqldb:hsql1"); | ||
| 50 | + assertEquals(conn2.getMetaData().getURL(), "jdbc:hsqldb:hsql2"); | ||
| 51 | + assertEquals(conn3.getMetaData().getURL(), "jdbc:hsqldb:hsql3"); | ||
| 52 | + assertEquals(conn4.getMetaData().getURL(), "jdbc:derby:target/databases/derby"); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | +} |
impl/extension/jdbc/src/test/java/connection/producer/ConnectionProducerNoConnectionTest.java
0 → 100644
| @@ -0,0 +1,40 @@ | @@ -0,0 +1,40 @@ | ||
| 1 | +package connection.producer; | ||
| 2 | + | ||
| 3 | +import java.sql.Connection; | ||
| 4 | +import java.sql.SQLException; | ||
| 5 | + | ||
| 6 | +import javax.enterprise.inject.Instance; | ||
| 7 | +import javax.inject.Inject; | ||
| 8 | + | ||
| 9 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
| 10 | +import org.jboss.arquillian.junit.Arquillian; | ||
| 11 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
| 12 | +import org.junit.Test; | ||
| 13 | +import org.junit.runner.RunWith; | ||
| 14 | + | ||
| 15 | +import test.Tests; | ||
| 16 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
| 17 | +import br.gov.frameworkdemoiselle.annotation.Name; | ||
| 18 | + | ||
| 19 | +@RunWith(Arquillian.class) | ||
| 20 | +public class ConnectionProducerNoConnectionTest { | ||
| 21 | + | ||
| 22 | + private static String PATH = "src/test/resources/producer/no-connection"; | ||
| 23 | + | ||
| 24 | + @Inject | ||
| 25 | + @Name("conn1") | ||
| 26 | + private Instance<Connection> conn1; | ||
| 27 | + | ||
| 28 | + @Deployment | ||
| 29 | + public static WebArchive createDeployment() { | ||
| 30 | + WebArchive deployment = Tests.createDeployment(ConnectionProducerNoConnectionTest.class); | ||
| 31 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | ||
| 32 | + return deployment; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @Test(expected = DemoiselleException.class) | ||
| 36 | + public void failOnCreateConnection() throws SQLException { | ||
| 37 | + String url = ((Connection)conn1).getMetaData().getURL(); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | +} |
impl/extension/jdbc/src/test/java/connection/producer/ConnectionProducerTest.java
| @@ -1,46 +0,0 @@ | @@ -1,46 +0,0 @@ | ||
| 1 | -package connection.producer; | ||
| 2 | - | ||
| 3 | -import static org.junit.Assert.assertNotNull; | ||
| 4 | - | ||
| 5 | -import java.sql.Connection; | ||
| 6 | - | ||
| 7 | -import javax.inject.Inject; | ||
| 8 | - | ||
| 9 | -import org.jboss.arquillian.container.test.api.Deployment; | ||
| 10 | -import org.jboss.arquillian.junit.Arquillian; | ||
| 11 | -import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
| 12 | -import org.junit.Test; | ||
| 13 | -import org.junit.runner.RunWith; | ||
| 14 | - | ||
| 15 | -import test.Tests; | ||
| 16 | -import br.gov.frameworkdemoiselle.annotation.Name; | ||
| 17 | - | ||
| 18 | -@RunWith(Arquillian.class) | ||
| 19 | -public class ConnectionProducerTest { | ||
| 20 | - | ||
| 21 | - private static String PATH = "src/test/resources/producer"; | ||
| 22 | - | ||
| 23 | - @Inject | ||
| 24 | - @Name("conn1") | ||
| 25 | - private Connection connectionWithName; | ||
| 26 | - | ||
| 27 | - @Inject | ||
| 28 | - private Connection connectionWithoutName; | ||
| 29 | - | ||
| 30 | - @Deployment | ||
| 31 | - public static WebArchive createDeployment() { | ||
| 32 | - WebArchive deployment = Tests.createDeployment(ConnectionProducerTest.class); | ||
| 33 | - deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | ||
| 34 | - return deployment; | ||
| 35 | - } | ||
| 36 | - | ||
| 37 | - @Test | ||
| 38 | - public void createDefaultConnectionWithName(){ | ||
| 39 | - assertNotNull(connectionWithName); | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - @Test | ||
| 43 | - public void createDefaultConnectionWithoutName(){ | ||
| 44 | - assertNotNull(connectionWithoutName); | ||
| 45 | - } | ||
| 46 | -} |
impl/extension/jdbc/src/test/java/connection/producer/ConnectionProducerWithNameTest.java
0 → 100644
| @@ -0,0 +1,41 @@ | @@ -0,0 +1,41 @@ | ||
| 1 | +package connection.producer; | ||
| 2 | + | ||
| 3 | +import static org.junit.Assert.assertNotNull; | ||
| 4 | + | ||
| 5 | +import java.sql.Connection; | ||
| 6 | +import java.sql.ResultSet; | ||
| 7 | +import java.sql.SQLException; | ||
| 8 | + | ||
| 9 | +import javax.inject.Inject; | ||
| 10 | + | ||
| 11 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
| 12 | +import org.jboss.arquillian.junit.Arquillian; | ||
| 13 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
| 14 | +import org.junit.Test; | ||
| 15 | +import org.junit.runner.RunWith; | ||
| 16 | + | ||
| 17 | +import test.Tests; | ||
| 18 | +import br.gov.frameworkdemoiselle.annotation.Name; | ||
| 19 | + | ||
| 20 | +@RunWith(Arquillian.class) | ||
| 21 | +public class ConnectionProducerWithNameTest { | ||
| 22 | + | ||
| 23 | + private static String PATH = "src/test/resources/producer/with-name"; | ||
| 24 | + | ||
| 25 | + @Inject | ||
| 26 | + @Name("conn1") | ||
| 27 | + private Connection connection; | ||
| 28 | + | ||
| 29 | + @Deployment | ||
| 30 | + public static WebArchive createDeployment() { | ||
| 31 | + WebArchive deployment = Tests.createDeployment(ConnectionProducerWithNameTest.class); | ||
| 32 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | ||
| 33 | + return deployment; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Test | ||
| 37 | + public void createConnection() { | ||
| 38 | + assertNotNull(connection); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | +} |
impl/extension/jdbc/src/test/java/xxx/XTest.java
| @@ -1,38 +0,0 @@ | @@ -1,38 +0,0 @@ | ||
| 1 | -package xxx; | ||
| 2 | - | ||
| 3 | -import static junit.framework.Assert.assertNotNull; | ||
| 4 | - | ||
| 5 | -import java.sql.Connection; | ||
| 6 | - | ||
| 7 | -import javax.inject.Inject; | ||
| 8 | - | ||
| 9 | -import org.jboss.arquillian.container.test.api.Deployment; | ||
| 10 | -import org.jboss.arquillian.junit.Arquillian; | ||
| 11 | -import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
| 12 | -import org.junit.Test; | ||
| 13 | -import org.junit.runner.RunWith; | ||
| 14 | - | ||
| 15 | -import test.Tests; | ||
| 16 | - | ||
| 17 | -@RunWith(Arquillian.class) | ||
| 18 | -public class XTest { | ||
| 19 | - | ||
| 20 | - private static final String PATH = "src/test/resources/xxx"; | ||
| 21 | - | ||
| 22 | - @Inject | ||
| 23 | - private Connection conn; | ||
| 24 | - | ||
| 25 | - @Deployment | ||
| 26 | - public static WebArchive createDeployment() { | ||
| 27 | - WebArchive deployment = Tests.createDeployment(XTest.class); | ||
| 28 | - deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), | ||
| 29 | - "demoiselle.properties"); | ||
| 30 | - | ||
| 31 | - return deployment; | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - @Test | ||
| 35 | - public void x() { | ||
| 36 | - assertNotNull(conn); | ||
| 37 | - } | ||
| 38 | -} |
impl/extension/jdbc/src/test/resources/producer/demoiselle.properties
| @@ -1,9 +0,0 @@ | @@ -1,9 +0,0 @@ | ||
| 1 | -frameworkdemoiselle.persistence.driver.class=org.hsqldb.jdbcDriver | ||
| 2 | -frameworkdemoiselle.persistence.url=jdbc:hsqldb:hsql | ||
| 3 | -frameworkdemoiselle.persistence.username=sa | ||
| 4 | -frameworkdemoiselle.persistence.password= | ||
| 5 | - | ||
| 6 | -frameworkdemoiselle.persistence.conn1.driver.class=org.hsqldb.jdbcDriver | ||
| 7 | -frameworkdemoiselle.persistence.conn1.url=jdbc:hsqldb:hsql | ||
| 8 | -frameworkdemoiselle.persistence.conn1.username=sa | ||
| 9 | -frameworkdemoiselle.persistence.conn1.password= | ||
| 10 | \ No newline at end of file | 0 | \ No newline at end of file |
impl/extension/jdbc/src/test/resources/producer/without-name/demoiselle.properties
0 → 100644
| @@ -0,0 +1,4 @@ | @@ -0,0 +1,4 @@ | ||
| 1 | +frameworkdemoiselle.persistence.driver.class=org.hsqldb.jdbcDriver | ||
| 2 | +frameworkdemoiselle.persistence.url=jdbc:hsqldb:hsql | ||
| 3 | +frameworkdemoiselle.persistence.username=sa | ||
| 4 | +frameworkdemoiselle.persistence.password= | ||
| 0 | \ No newline at end of file | 5 | \ No newline at end of file |
impl/extension/jdbc/src/test/resources/xxx/demoiselle.properties
| @@ -1,39 +0,0 @@ | @@ -1,39 +0,0 @@ | ||
| 1 | -# Demoiselle Framework | ||
| 2 | -# Copyright (C) 2010 SERPRO | ||
| 3 | -# ---------------------------------------------------------------------------- | ||
| 4 | -# This file is part of Demoiselle Framework. | ||
| 5 | -# | ||
| 6 | -# Demoiselle Framework is free software; you can redistribute it and/or | ||
| 7 | -# modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 8 | -# as published by the Free Software Foundation. | ||
| 9 | -# | ||
| 10 | -# This program is distributed in the hope that it will be useful, | ||
| 11 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | -# GNU General Public License for more details. | ||
| 14 | -# | ||
| 15 | -# You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 16 | -# along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 17 | -# or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 18 | -# Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 19 | -# ---------------------------------------------------------------------------- | ||
| 20 | -# Este arquivo é parte do Framework Demoiselle. | ||
| 21 | -# | ||
| 22 | -# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 23 | -# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 24 | -# do Software Livre (FSF). | ||
| 25 | -# | ||
| 26 | -# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 27 | -# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 28 | -# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 29 | -# para maiores detalhes. | ||
| 30 | -# | ||
| 31 | -# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 32 | -# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 33 | -# ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 34 | -# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 35 | - | ||
| 36 | -frameworkdemoiselle.persistence.driver.class=org.hsqldb.jdbcDriver | ||
| 37 | -frameworkdemoiselle.persistence.url=jdbc:hsqldb:mem:xxx | ||
| 38 | -frameworkdemoiselle.persistence.username=sa | ||
| 39 | -frameworkdemoiselle.persistence.password= |