Skip to content

Commit

Permalink
Minor JSE test failure fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Will Dazey <dazeydev.3@gmail.com>
  • Loading branch information
dazey3 authored and lukasj committed Aug 6, 2021
1 parent 60ccb27 commit 8775292
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
// Oracle - initial API and implementation
package org.eclipse.persistence.jpa.returninsert;

import java.time.Instant;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import jakarta.persistence.EntityManager;
Expand Down Expand Up @@ -305,7 +306,11 @@ private ReturnInsertMaster insertReturnInsertMaster(EntityManager em) {
//Prepare primary key for ReturnInsertMaster
private ReturnInsertMasterPK createReturnInsertMasterPK() {
ReturnInsertMasterPK ReturnInsertMasterPK = new ReturnInsertMasterPK();
ReturnInsertMasterPK.setId(Date.from(Instant.ofEpochMilli(0)));
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date date = dateFormat.parse("1970-01-01 00:00:00.0");
ReturnInsertMasterPK.setId(date);
} catch (Exception e) { }
ReturnInsertMasterPK.setCol1(1L);
return ReturnInsertMasterPK;
}
Expand Down Expand Up @@ -339,7 +344,11 @@ private ReturnInsertDetail insertReturnInsertDetail(EntityManager em, ReturnInse
//Prepare primary key for ReturnInsertDetail
private ReturnInsertDetailPK createReturnInsertDetailPK() {
ReturnInsertDetailPK returnInsertDetailPK = new ReturnInsertDetailPK();
returnInsertDetailPK.setId(Date.from(Instant.ofEpochMilli(0)));
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date date = dateFormat.parse("1970-01-01 00:00:00.0");
returnInsertDetailPK.setId(date);
} catch (Exception e) { }
returnInsertDetailPK.setCol1(1L);
returnInsertDetailPK.setCol2("abc");
return returnInsertDetailPK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public void setup() {
} catch (Exception ignore) {
}
try {
session.executeNonSelectingSQL("CREATE TABLE cachedeadlock_master (id integer PRIMARY KEY, name varchar(200))");
session.executeNonSelectingSQL("CREATE TABLE cachedeadlock_detail (id integer PRIMARY KEY, id_fk integer , name varchar(200))");
session.executeNonSelectingSQL("CREATE TABLE cachedeadlock_master (id integer NOT NULL, name varchar(200), PRIMARY KEY(id))");
session.executeNonSelectingSQL("CREATE TABLE cachedeadlock_detail (id integer NOT NULL, id_fk integer , name varchar(200), PRIMARY KEY(id))");
session.executeNonSelectingSQL("ALTER TABLE cachedeadlock_detail ADD CONSTRAINT fk_cachedeadlock_detail FOREIGN KEY ( id_fk ) REFERENCES cachedeadlock_master (ID)");
} catch (Exception ignore) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.eclipse.persistence.jpa.test.conversion;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
Expand All @@ -27,8 +30,6 @@
import java.util.Calendar;
import java.util.Date;

import java.util.TimeZone;

import org.eclipse.persistence.exceptions.ConversionException;
import org.eclipse.persistence.internal.helper.ClassConstants;
import org.eclipse.persistence.internal.helper.ConversionManager;
Expand Down Expand Up @@ -63,24 +64,21 @@ public void timeConvertCalendarToLocalDate() {
Assert.assertEquals(1, ld.getDayOfMonth());
Assert.assertEquals(2020, ld.getYear());
}

@Test
public void timeConvertUtilDateToLocalDate() {
Calendar cal = Calendar.getInstance();

cal.setTimeZone(TimeZone.getTimeZone("UTC"));
cal.set(2020, 0, 1, 0, 0, 0);
Date date = cal.getTime();
@Test
public void timeConvertUtilDateToLocalDate() throws ParseException {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date date = dateFormat.parse("2020-01-01 24:00:00.000");
Assert.assertEquals(2020 - 1900, date.getYear());
Assert.assertEquals(0, date.getMonth());
Assert.assertEquals(1, date.getDate());
Assert.assertEquals(2, date.getDate());

LocalDate ld = (LocalDate) cm.convertObject(date, ClassConstants.TIME_LDATE);

Assert.assertNotNull(ld);
Assert.assertEquals(Month.JANUARY, ld.getMonth());
Assert.assertEquals(1, ld.getDayOfMonth());
Assert.assertEquals(2020, ld.getYear());
Assert.assertEquals(Month.JANUARY, ld.getMonth());
Assert.assertEquals(2, ld.getDayOfMonth());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void testCoalesceFunction3Date() throws Exception {

Subquery<Date> countQuery = criteriaQuery.subquery(Date.class);
Root<CoalesceEntity> countRoot = countQuery.from(CoalesceEntity.class);
countQuery.select(countRoot.get(CoalesceEntity_.date));
countQuery.select(countRoot.get(CoalesceEntity_.dateValue));

// Pass the literal value directly
Expression<Date> coalesceExp = builder.coalesce(countQuery, new Date());
Expand Down Expand Up @@ -206,7 +206,7 @@ public void testCoalesceFunction3Date() throws Exception {

Subquery<Date> countQuery = criteriaQuery.subquery(Date.class);
Root<CoalesceEntity> countRoot = countQuery.from(CoalesceEntity.class);
countQuery.select(countRoot.get(CoalesceEntity_.date));
countQuery.select(countRoot.get(CoalesceEntity_.dateValue));

// create a ConstantExpression from the literal value
Expression<Date> coalesceExp = builder.coalesce(countQuery, builder.literal(new Date()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public class CoalesceEntity {
private java.math.BigDecimal bigDecimal;

@Temporal(TemporalType.DATE)
private java.util.Date date;
private java.util.Date dateValue;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ public class CoalesceEntity_ {
public static volatile SingularAttribute<CoalesceEntity, Integer> id;
public static volatile SingularAttribute<CoalesceEntity, String> description;
public static volatile SingularAttribute<CoalesceEntity, java.math.BigDecimal> bigDecimal;
public static volatile SingularAttribute<CoalesceEntity, java.util.Date> date;
public static volatile SingularAttribute<CoalesceEntity, java.util.Date> dateValue;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.eclipse.persistence.jpa.test.framework.Emf;
import org.eclipse.persistence.jpa.test.framework.EmfRunner;
import org.eclipse.persistence.jpa.test.framework.PUPropertiesProvider;
import org.eclipse.persistence.jpa.test.query.TestQueryProperties.PreparedStatementInvocationHandler;
import org.eclipse.persistence.jpa.test.query.model.QueryEmployee;
import org.eclipse.persistence.queries.ScrollableCursor;
import org.eclipse.persistence.sessions.Connector;
Expand Down

0 comments on commit 8775292

Please sign in to comment.