Permalink
Browse files

[5] First JPA Use Case Application

  • Loading branch information...
1 parent d81a265 commit acda5582728bd3c76958f894a44f42297b6b4b8b @aslakknutsen aslakknutsen committed with ALRubinger Sep 11, 2012
Showing with 1,800 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +37 −0 application/application/pom.xml
  3. +25 −0 application/domain/attachment/pom.xml
  4. +17 −0 application/domain/attachment/src/main/java/org/ced/domain/attachment/Attachment.java
  5. +25 −0 application/domain/conference/pom.xml
  6. +14 −0 application/domain/conference/src/main/java/org/ced/domain/conference/ConferenceRepository.java
  7. +86 −0 application/domain/conference/src/main/java/org/ced/domain/conference/model/Conference.java
  8. +49 −0 application/domain/conference/src/main/java/org/ced/domain/conference/model/Duration.java
  9. +58 −0 application/domain/conference/src/main/java/org/ced/domain/conference/model/Session.java
  10. +66 −0 application/domain/conference/src/test/java/org/ced/domain/conference/DomainValidationTestCase.java
  11. +18 −0 application/domain/core/pom.xml
  12. +7 −0 application/domain/core/src/main/java/org/ced/domain/Identifiable.java
  13. +29 −0 application/domain/core/src/main/java/org/ced/domain/Repository.java
  14. +68 −0 application/domain/pom.xml
  15. +24 −0 application/domain/relation/pom.xml
  16. +105 −0 application/domain/relation/src/main/java/org/ced/domain/relation/Relation.java
  17. +39 −0 application/domain/relation/src/main/java/org/ced/domain/relation/RelationRepository.java
  18. +32 −0 application/domain/relation/src/test/java/org/ced/domain/relation/test/Deployments.java
  19. +87 −0 application/domain/relation/src/test/java/org/ced/domain/relation/test/RelationTestCase.java
  20. +25 −0 application/domain/relation/src/test/java/org/ced/domain/relation/test/SourceObject.java
  21. +25 −0 application/domain/relation/src/test/java/org/ced/domain/relation/test/TargetObject.java
  22. +7 −0 application/domain/relation/src/test/resources/arquillian.xml
  23. +12 −0 application/domain/relation/src/test/resources/datasets/test_object_relations.yml
  24. +13 −0 application/domain/relation/src/test/resources/datasets/test_objects.yml
  25. +25 −0 application/domain/user/pom.xml
  26. +32 −0 application/domain/user/src/main/java/org/ced/domain/user/User.java
  27. +13 −0 application/domain/user/src/main/java/org/ced/domain/user/UserRepository.java
  28. +25 −0 application/domain/venue/pom.xml
  29. +33 −0 application/domain/venue/src/main/java/org/ced/domain/venue/Room.java
  30. +46 −0 application/domain/venue/src/main/java/org/ced/domain/venue/Venue.java
  31. +13 −0 application/domain/venue/src/main/java/org/ced/domain/venue/VenueRepository.java
  32. +239 −0 application/pom.xml
  33. +28 −0 application/web/conference/pom.xml
  34. +18 −0 application/web/conference/src/main/java/org/ced/web/conference/ConferenceBean.java
  35. +14 −0 application/web/conference/src/main/java/org/ced/web/conference/Current.java
  36. +6 −0 application/web/conference/src/main/webapp/WEB-INF/faces-config.xml
  37. +6 −0 application/web/conference/src/main/webapp/conference.xhtml
  38. +97 −0 application/web/conference/src/test/java/org/ced/web/conference/test/ConferenceTestCase.java
  39. +22 −0 application/web/conference/src/test/java/org/ced/web/conference/test/TestConferenceProducer.java
  40. +7 −0 application/web/conference/src/test/resources/arquillian.xml
  41. +10 −0 application/web/conference/src/test/resources/beans.xml
  42. +18 −0 application/web/core/pom.xml
  43. +6 −0 application/web/core/src/main/java/org/ced/web/core/layout/Attachment.java
  44. +29 −0 application/web/core/src/main/java/org/ced/web/core/layout/PageExtension.java
  45. +6 −0 application/web/core/src/main/webapp/WEB-INF/faces-config.xml
  46. +10 −0 application/web/core/src/main/webapp/WEB-INF/web.xml
  47. BIN application/web/core/src/main/webapp/images/logo.png
  48. +68 −0 application/web/core/src/main/webapp/index.html
  49. +24 −0 application/web/core/src/main/webapp/page.xhtml
  50. +8 −0 application/web/core/src/main/webapp/styles/base.css
  51. +38 −0 application/web/core/src/test/java/org/ced/web/core/layout/PageExtensionTestCase.java
  52. +9 −0 application/web/core/src/test/java/org/ced/web/core/layout/TestAttachment.java
  53. +10 −0 application/web/core/src/test/resources/arquillian.xml
  54. +6 −0 application/web/core/src/test/resources/jsf/page_fragment.xhtml
  55. +65 −0 application/web/pom.xml
View
@@ -3,3 +3,4 @@ target
.project
.settings
test-output
+log.txt
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+
+ <parent>
+ <groupId>org.continuous.enterprise</groupId>
+ <artifactId>continuous-enterprise</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.continuous.enterprise.application</groupId>
+ <artifactId>application</artifactId>
+ <packaging>war</packaging>
+ <name>Continuous Enterprise Application</name>
+ <description></description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.continuous.enterprise.web</groupId>
+ <artifactId>web-conference</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+
+ <parent>
+ <groupId>org.continuous.enterprise.domain</groupId>
+ <artifactId>continuous-enterprise-domain</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>domain-attachment</artifactId>
+ <packaging>jar</packaging>
+ <name>Continuous Enterprise Domain: Attachment</name>
+ <description></description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.continuous.enterprise.domain</groupId>
+ <artifactId>domain-core</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
@@ -0,0 +1,17 @@
+package org.ced.domain.attachment;
+
+import java.util.UUID;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity
+public class Attachment {
+
+ @Id
+ public String id;
+
+ public Attachment() {
+ this.id = UUID.randomUUID().toString();
+ }
+}
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+
+ <parent>
+ <groupId>org.continuous.enterprise.domain</groupId>
+ <artifactId>continuous-enterprise-domain</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>domain-conference</artifactId>
+ <packaging>jar</packaging>
+ <name>Continuous Enterprise Domain: Conference</name>
+ <description></description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.continuous.enterprise.domain</groupId>
+ <artifactId>domain-core</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
@@ -0,0 +1,14 @@
+package org.ced.domain.conference;
+
+import javax.ejb.Stateless;
+
+import org.ced.domain.Repository;
+import org.ced.domain.conference.model.Conference;
+
+@Stateless
+public class ConferenceRepository extends Repository<Conference> {
+
+ public ConferenceRepository() {
+ super(Conference.class);
+ }
+}
@@ -0,0 +1,86 @@
+package org.ced.domain.conference.model;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+
+import org.ced.domain.Identifiable;
+
+@Entity
+public class Conference implements Identifiable, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ private String id;
+
+ @NotNull
+ private String name;
+
+ private String tagLine;
+
+ @Embedded @Valid @NotNull
+ private Duration duration;
+
+ @OneToMany(fetch = FetchType.EAGER, orphanRemoval = true) @Valid
+ private Set<Session> sessions;
+
+ public Conference() {
+ this.id = UUID.randomUUID().toString();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Conference setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public String getTagLine() {
+ return tagLine;
+ }
+
+ public Conference setTagLine(String tagLine) {
+ this.tagLine = tagLine;
+ return this;
+ }
+
+ public Conference setDuration(Duration duration) {
+ this.duration = duration;
+ return this;
+ }
+
+ public Duration getDuration() {
+ return duration;
+ }
+
+ public Set<Session> getSessions() {
+ return Collections.unmodifiableSet(sessions);
+ }
+
+ public Conference addSession(Session session) {
+ if(sessions == null) {
+ this.sessions = new HashSet<Session>();
+ }
+ if(!sessions.contains(session)) {
+ sessions.add(session);
+ }
+ return this;
+ }
+}
@@ -0,0 +1,49 @@
+package org.ced.domain.conference.model;
+
+import java.util.Date;
+
+import javax.validation.constraints.NotNull;
+
+public class Duration {
+
+ @NotNull
+ private Date start;
+
+ @NotNull
+ private Date end;
+
+ // hidden constructor for Persistence
+ Duration() {
+ }
+
+ public Duration(Date start, Date end) {
+ if(start == null) {
+ throw new IllegalArgumentException("Start must be provided");
+ }
+ if(end == null) {
+ throw new IllegalArgumentException("End must be provided");
+ }
+ if(end.before(start)) {
+ throw new IllegalArgumentException("End can not be before Start");
+ }
+ this.start = start;
+ this.end = end;
+
+ }
+
+ public Date getEnd() {
+ return (Date)end.clone();
+ }
+
+ public Date getStart() {
+ return (Date)start.clone();
+ }
+
+ public Integer getNumberOfDays() {
+ return -1;
+ }
+
+ public Integer getNumberOfHours() {
+ return -1;
+ }
+}
@@ -0,0 +1,58 @@
+package org.ced.domain.conference.model;
+
+import java.io.Serializable;
+import java.util.UUID;
+
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+
+@Entity
+public class Session implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ private String id;
+
+ @Embedded @NotNull @Valid
+ private Duration duration;
+
+ @NotNull
+ private String title;
+ private String outline;
+
+ public Session() {
+ this.id = UUID.randomUUID().toString();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public Duration getDuration() {
+ return duration;
+ }
+
+ public void setDuration(Duration duration) {
+ this.duration = duration;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getOutline() {
+ return outline;
+ }
+
+ public void setOutline(String outline) {
+ this.outline = outline;
+ }
+}
@@ -0,0 +1,66 @@
+package org.ced.domain.conference;
+
+import java.util.Date;
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+
+import junit.framework.Assert;
+
+import org.ced.domain.conference.model.Conference;
+import org.ced.domain.conference.model.Duration;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DomainValidationTestCase {
+
+ private Validator validator;
+
+ @Before
+ public void setupValidationFactory() {
+ validator = Validation.buildDefaultValidatorFactory().getValidator();
+ }
+
+ @Test
+ public void shouldNotAllowNullName() {
+ Conference conference = new Conference();
+ assertValidationConsraint(conference, "NotNull", "name");
+ }
+
+ @Test
+ public void shouldNotAllowNullDuration() {
+ Conference conference = new Conference();
+ assertValidationConsraint(conference, "NotNull", "duration");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void shouldNotAllowEndBeforeStart() {
+ new Duration(new Date(), new Date(System.currentTimeMillis()-1000));
+ }
+
+ private <T> void assertValidationConsraint(T object, String type, String... properties) {
+ Set<ConstraintViolation<T>> errors = validator.validate(object);
+
+ Assert.assertFalse("Expecting vaidation errors", errors.isEmpty());
+
+ for (String property : properties) {
+ ConstraintViolation<T> validationFound = null;
+ for (ConstraintViolation<T> cv : errors) {
+ if(property.equals(cv.getPropertyPath().toString())) {
+ validationFound = cv;
+ break;
+ }
+ }
+ if(validationFound == null) {
+ String msg = "Expected validation error on property [%s] but non found. Found errors [%s]";
+ Assert.fail(String.format(msg, property, errors));
+ } else if(!validationFound.getMessageTemplate().contains(type)) {
+ String msg = "Expected validation error on property [%s] of type [%s]. Found error [%s]";
+ Assert.fail(String.format(msg, property, type, validationFound));
+ }
+ }
+
+ }
+}
Oops, something went wrong.

0 comments on commit acda558

Please sign in to comment.