Skip to content

Instantly share code, notes, and snippets.

@artem-sh
artem-sh / pom.xml
Created March 22, 2012 11:58
Maven config dor project 'jsf2-cdi-jetty-maven'
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>sh.app.sample-projects</groupId>
<artifactId>sample-projects</artifactId>
<version>SNAPSHOT</version>
@artem-sh
artem-sh / web.xml
Created March 22, 2012 12:10
web.xml for the project 'jsf2-cdi-jetty-maven'
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
@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>
@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 / 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
@Entity
public class User {
@Id @GeneratedValue
private Integer id;
@Column
private String firstname;
@Column
private String lastname;
public Integer getId() {
public interface UserRepository extends CrudRepository<User, Integer> {
List<User> findByLastnameIgnoreCase(String lastname);
}
@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");
@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 {}
@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));
}