@Test public void testGenJPAEntity() { JPAResponderGen rg = new JPAResponderGen(); FieldInfo keyInfo = new FieldInfo("flightID", "Long", null); List<FieldInfo> properties = new ArrayList<FieldInfo>(); properties.add(new FieldInfo("number", "String", null)); properties.add(new FieldInfo("fitHostiesName", "String", null)); properties.add(new FieldInfo("runway", "String", null)); properties.add(new FieldInfo("passengers", "Integer", null)); List<String> annotations = new ArrayList<String>(); annotations.add("@Temporal(TemporalType.TIMESTAMP)"); properties.add(new FieldInfo("departureDT", "java.util.Date", annotations)); properties.add(new FieldInfo("dinnerServed", "java.sql.Timestamp", null)); EntityInfo jpaEntity = new EntityInfo("Flight", "AirlineModel.model", keyInfo, properties); String generatedClass = rg.generateJPAEntityClass(jpaEntity); assertTrue(generatedClass.contains("package AirlineModel.model;")); assertTrue(generatedClass.contains("import javax.persistence.Entity;")); assertTrue(generatedClass.contains("@Entity")); assertTrue(generatedClass.contains("public class Flight {")); assertTrue(generatedClass.contains("@Id")); assertTrue(generatedClass.contains("@Basic(optional = false)")); assertTrue(generatedClass.contains("private Long flightID;")); assertTrue(generatedClass.contains("private String number;")); assertTrue(generatedClass.contains("private String fitHostiesName;")); assertTrue(generatedClass.contains("private String runway;")); assertTrue(generatedClass.contains("private Integer passengers;")); // date handling needs some special support assertTrue(generatedClass.contains("@Temporal(TemporalType.TIMESTAMP)")); assertTrue(generatedClass.contains("private java.util.Date departureDT;")); assertTrue(generatedClass.contains("private java.sql.Timestamp dinnerServed;")); assertTrue(generatedClass.contains("public Flight() {")); }
@Test public void testGenJPAEntitySimpleJoin() { JPAResponderGen rg = new JPAResponderGen(); FieldInfo keyInfo = new FieldInfo("flightID", "Long", null); List<FieldInfo> properties = new ArrayList<FieldInfo>(); properties.add(new FieldInfo("number", "String", null)); List<String> annotations = new ArrayList<String>(); annotations.add("@Temporal(TemporalType.TIMESTAMP)"); properties.add(new FieldInfo("departureDT", "java.util.Date", annotations)); List<JoinInfo> joins = new ArrayList<JoinInfo>(); List<String> joinAnnotations = new ArrayList<String>(); joinAnnotations.add("@ManyToMany(mappedBy=\"Flight\")"); joins.add(new JoinInfo("passengers", "Person", joinAnnotations)); EntityInfo jpaEntity = new EntityInfo("Flight", "AirlineModel.model", keyInfo, properties, joins, true); String generatedClass = rg.generateJPAEntityClass(jpaEntity); assertTrue(generatedClass.contains("package AirlineModel.model;")); assertTrue(generatedClass.contains("import javax.persistence.Entity;")); assertTrue(generatedClass.contains("@Entity")); assertTrue(generatedClass.contains("public class Flight {")); assertTrue(generatedClass.contains("@Id")); assertTrue(generatedClass.contains("@Basic(optional = false)")); assertTrue(generatedClass.contains("private Long flightID;")); assertTrue(generatedClass.contains("private String number;")); assertTrue(generatedClass.contains("@Temporal(TemporalType.TIMESTAMP)")); assertTrue(generatedClass.contains("private java.util.Date departureDT;")); assertTrue(generatedClass.contains("@ManyToMany(mappedBy=\"Flight\")")); assertTrue(generatedClass.contains("private Collection<Person> passengers;")); assertTrue(generatedClass.contains("public Flight() {")); }
@Test(expected = AssertionError.class) public void testGenJPAEntityNull() { JPAResponderGen rg = new JPAResponderGen(); assertNull(rg.generateJPAEntityClass(null)); }