Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test sql server for Ebean #2314 ZonedDateTime #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@

<!-- test dependencies -->

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>9.4.0.jre8</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
Expand Down
32 changes: 13 additions & 19 deletions src/main/java/org/example/domain/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import io.ebean.Model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;
import java.time.ZonedDateTime;

@Entity
public class Customer extends Model {
Expand All @@ -16,6 +18,9 @@ public class Customer extends Model {

String notes;

@Column(name = "MyDate", nullable = false)
ZonedDateTime mydate;

@Version
Long version;

Expand All @@ -26,36 +31,25 @@ public Customer(String name) {
public Customer() {
}

public Long getId() {
public Long id() {
return id;
}

public void setId(Long id) {
public void id(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getNotes() {
return notes;
}

public void setNotes(String notes) {
public void notes(String notes) {
this.notes = notes;
}

public Long getVersion() {
return version;
public ZonedDateTime mydate() {
return mydate;
}

public void setVersion(Long version) {
this.version = version;
public Customer mydate(ZonedDateTime mydate) {
this.mydate = mydate;
return this;
}

}
16 changes: 11 additions & 5 deletions src/test/java/org/example/domain/CustomerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io.ebean.Database;
import org.junit.jupiter.api.Test;

import java.time.ZonedDateTime;

import static org.junit.jupiter.api.Assertions.assertNotNull;


Expand All @@ -22,11 +24,12 @@ public class CustomerTest {
public void insert_via_database() {

Customer rob = new Customer("Rob");
rob.mydate(ZonedDateTime.now());

Database server = DB.getDefault();
server.save(rob);

assertNotNull(rob.getId());
assertNotNull(rob.id());
}

/**
Expand All @@ -36,9 +39,10 @@ public void insert_via_database() {
public void insert_via_model() {

Customer jim = new Customer("Jim");
jim.mydate(ZonedDateTime.now());
jim.save();

assertNotNull(jim.getId());
assertNotNull(jim.id());
}


Expand All @@ -49,13 +53,14 @@ public void insert_via_model() {
public void updateRob() {

Customer newBob = new Customer("Bob");
newBob.mydate(ZonedDateTime.now());
newBob.save();

Customer bob = DB.find(Customer.class)
.where().eq("name", "Bob")
.findOne();

bob.setNotes("Doing an update");
bob.notes("Doing an update");
bob.save();
}

Expand All @@ -66,11 +71,12 @@ public void updateRob() {
public void statelessUpdate() {

Customer newMob = new Customer("Mob");
newMob.mydate(ZonedDateTime.now());
newMob.save();

Customer upd = new Customer();
upd.setId(newMob.getId());
upd.setNotes("Update without a fetch");
upd.id(newMob.id());
upd.notes("Update without a fetch");

upd.update();
}
Expand Down
5 changes: 4 additions & 1 deletion src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ ebean:
test:
# useDocker: false
# shutdown: stop # stop | remove
platform: h2 # h2, postgres, mysql, oracle, sqlserver, sqlite
platform: sqlserver # h2, postgres, mysql, oracle, sqlserver, sqlite
ddlMode: dropCreate # none | dropCreate | create | migration | createOnly | migrationDropCreate
dbName: myapp

databasePlatformName: sqlserver17
allQuotedIdentifiers: true