-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
ebean-test/src/test/java/org/tests/o2m/StatefulO2MSoftDelete.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.tests.o2m; | ||
|
||
import io.ebean.DB; | ||
import io.ebean.test.LoggedSql; | ||
import io.ebean.xtest.BaseTestCase; | ||
import org.junit.jupiter.api.Test; | ||
import org.tests.o2m.dm.GoodsEntity; | ||
import org.tests.o2m.dm.WorkflowEntity; | ||
import org.tests.o2m.dm.WorkflowOperationEntity; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class StatefulO2MSoftDelete extends BaseTestCase { | ||
@Test | ||
void statefulUpdateShouldntDelete() { | ||
var bomGoods = new GoodsEntity(); | ||
DB.save(bomGoods); | ||
|
||
var goods = new GoodsEntity(); | ||
var workflow = new WorkflowEntity(); | ||
var operation1 = new WorkflowOperationEntity(); | ||
operation1.setName("operation 1"); | ||
goods.setWorkflowEntity(workflow); | ||
workflow.setOperations(List.of(operation1)); | ||
|
||
DB.save(goods); | ||
|
||
LoggedSql.start(); | ||
// replace workflow entity | ||
var goodsFromDB = DB.find(GoodsEntity.class, goods.getId()); | ||
goodsFromDB.setWorkflowEntity(new WorkflowEntity()); | ||
|
||
DB.update(goodsFromDB); | ||
var updateSql = LoggedSql.stop(); | ||
updateSql.forEach(System.out::println); | ||
updateSql.forEach(sql -> assertThat(sql).doesNotContain("delete from workflow_entity")); | ||
} | ||
} |