Skip to content

Instantly share code, notes, and snippets.

@artem-sh
artem-sh / pom.xml
Created November 27, 2012 17:09
Maven configuration file
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/test/java</directory>
<includes>
<include>**/*</include>
@artem-sh
artem-sh / userRepository.xml
Created November 27, 2012 16:27
DbUnit initial data for integration test
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<user id="1" firstname="Firstname1" lastname="Lastname1"/>
<user id="2" firstname="Firstname2" lastname="Lastname2"/>
</dataset>
@DatabaseSetup("userRepository.dbxml")
public class UserRepositoryTest extends BaseIntegrationTest {
@Autowired
UserRepository userRepository;
@Test
public void findByLastnameIgnoreCase_noSuchUser() throws Exception {
assertThat(userRepository.findByLastnameIgnoreCase("Lastname").size(), is(0));
}
@artem-sh
artem-sh / sh.app.sample_projects.it_spring_dbunit.BaseIntegrationTest.java
Created November 27, 2012 12:22
Base class for all integration tests in the project
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationConfiguration.xml")
@Transactional
@TestExecutionListeners({
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
TransactionDbUnitTestExecutionListener.class})
public class BaseIntegrationTest {}
@artem-sh
artem-sh / sh.app.sample_projects.it_spring_dbunit.Main.java
Created November 27, 2012 10:06
Clasic approach to test persistence
public class Main {
private static final Logger log = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationConfiguration.xml");
UserRepository repository = context.getBean(UserRepository.class);
User user = new User();
user.setFirstname("Bon");
user.setLastname("Jovi");
public interface UserRepository extends CrudRepository<User, Integer> {
List<User> findByLastnameIgnoreCase(String lastname);
}
@Entity
public class User {
@Id @GeneratedValue
private Integer id;
@Column
private String firstname;
@Column
private String lastname;
public Integer getId() {
@artem-sh
artem-sh / Visitor.java
Created March 22, 2012 12:45
The ony Java bean in project 'jsf2-cdi-jetty-maven'
package sh.app.sample_projects.jsf2_cdi_jetty_maven;
import javax.inject.Named;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
@Named
@SessionScoped
@artem-sh
artem-sh / faces-config.xml
Created March 22, 2012 12:27
JSF 2.0 config for project 'jsf2-cdi-jetty-maven'
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0" metadata-complete="false">
</faces-config>
@artem-sh
artem-sh / beans.xml
Created March 22, 2012 12:14
CDI config dor project 'jsf2-cdi-jetty-maven'
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:s="urn:java:ee"
xmlns:in="urn:java:javax.inject"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>