add tests
This commit is contained in:
@ -1,14 +1,19 @@
|
||||
package com.iluwatar.cqrs;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.iluwatar.cqrs.app.App;
|
||||
|
||||
/**
|
||||
* Application test
|
||||
*
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
fail("Not yet implemented");
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
100
cqrs/src/test/java/com/iluwatar/cqrs/IntegrationTest.java
Normal file
100
cqrs/src/test/java/com/iluwatar/cqrs/IntegrationTest.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.iluwatar.cqrs;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.iluwatar.cqrs.commandes.CommandServiceImpl;
|
||||
import com.iluwatar.cqrs.commandes.ICommandService;
|
||||
import com.iluwatar.cqrs.dto.Author;
|
||||
import com.iluwatar.cqrs.dto.Book;
|
||||
import com.iluwatar.cqrs.queries.IQueryService;
|
||||
import com.iluwatar.cqrs.queries.QueryServiceImpl;
|
||||
import com.iluwatar.cqrs.util.HibernateUtil;
|
||||
|
||||
/**
|
||||
* Integration test of IQueryService and ICommandService with h2 data
|
||||
*
|
||||
*/
|
||||
public class IntegrationTest {
|
||||
|
||||
private static IQueryService queryService;
|
||||
private static ICommandService commandService;
|
||||
|
||||
@BeforeClass
|
||||
public static void initialize() {
|
||||
commandService = new CommandServiceImpl();
|
||||
queryService = new QueryServiceImpl();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void populateDatabase() {
|
||||
// create first author1
|
||||
commandService.authorCreated("username1", "name1", "email1");
|
||||
|
||||
// create author1 and update all its data
|
||||
commandService.authorCreated("username2", "name2", "email2");
|
||||
commandService.authorEmailUpdated("username2", "new_email2");
|
||||
commandService.authorNameUpdated("username2", "new_name2");
|
||||
commandService.authorUsernameUpdated("username2", "new_username2");
|
||||
|
||||
// add book1 to author1
|
||||
commandService.bookAddedToAuthor("title1", 10, "username1");
|
||||
|
||||
// add book2 to author1 and update all its data
|
||||
commandService.bookAddedToAuthor("title2", 20, "username1");
|
||||
commandService.bookPriceUpdated("title2", 30);
|
||||
commandService.bookTitleUpdated("title2", "new_title2");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAuthorByUsername() {
|
||||
Author author = queryService.getAuthorByUsername("username1");
|
||||
assertEquals("username1", author.getUsername());
|
||||
assertEquals("name1", author.getName());
|
||||
assertEquals("email1", author.getEmail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUpdatedAuthorByUsername() {
|
||||
Author author = queryService.getAuthorByUsername("new_username2");
|
||||
Author expectedAuthor = new Author("new_name2", "new_email2", "new_username2");
|
||||
assertEquals(expectedAuthor, author);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBook() {
|
||||
Book book = queryService.getBook("title1");
|
||||
assertEquals("title1", book.getTitle());
|
||||
assertEquals(10, book.getPrice(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAuthorBooks() {
|
||||
List<Book> books = queryService.getAuthorBooks("username1");
|
||||
assertTrue(books.size() == 2);
|
||||
assertTrue(books.contains(new Book("title1", 10)));
|
||||
assertTrue(books.contains(new Book("new_title2", 30)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAuthorBooksCount() {
|
||||
BigInteger bookCount = queryService.getAuthorBooksCount("username1");
|
||||
assertEquals(new BigInteger("2"), bookCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAuthorsCount() {
|
||||
BigInteger authorCount = queryService.getAuthorsCount();
|
||||
assertEquals(new BigInteger("2"), authorCount);
|
||||
}
|
||||
|
||||
}
|
15
cqrs/src/test/resources/hibernate.cfg.xml
Normal file
15
cqrs/src/test/resources/hibernate.cfg.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE hibernate-configuration SYSTEM
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
|
||||
<property name="connection.driver_class">org.h2.Driver</property>
|
||||
<property name="connection.url">jdbc:h2:mem:test</property>
|
||||
<property name="connection.username">sa</property>
|
||||
<property name="hbm2ddl.auto">create</property>
|
||||
<mapping class="com.iluwatar.cqrs.domain.model.Author" />
|
||||
<mapping class="com.iluwatar.cqrs.domain.model.Book" />
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
13
cqrs/src/test/resources/logback.xml
Normal file
13
cqrs/src/test/resources/logback.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
Reference in New Issue
Block a user