-
Notifications
You must be signed in to change notification settings - Fork 74
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
8 changed files
with
289 additions
and
26 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
This file was deleted.
Oops, something went wrong.
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
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
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,68 @@ | ||
package com.blinkfox.fenix.entity.ar; | ||
|
||
import com.blinkfox.fenix.ar.FenixModel; | ||
import java.time.LocalDateTime; | ||
import java.util.Date; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.experimental.Accessors; | ||
import org.hibernate.annotations.GenericGenerator; | ||
|
||
/** | ||
* 用来测试 Active Record 的实体类. | ||
* | ||
* @author blinkfox on 2022-03-28. | ||
* @since 2.7.0 | ||
*/ | ||
@Getter | ||
@Setter | ||
@Accessors(chain = true) | ||
@Entity | ||
@Table(name = "t_ar_table") | ||
public class ArEntity extends FenixModel<ArEntity, String> { | ||
|
||
/** | ||
* ID. | ||
*/ | ||
@Id | ||
@Column(name = "c_id") | ||
@GeneratedValue(generator = "nanoId") | ||
@GenericGenerator(name = "nanoId", strategy = "com.blinkfox.fenix.id.NanoIdGenerator") | ||
private String id; | ||
|
||
/** | ||
* 标题. | ||
*/ | ||
@Column(name = "c_title") | ||
private String title; | ||
|
||
/** | ||
* 描述. | ||
*/ | ||
@Column(name = "c_desc") | ||
private String desc; | ||
|
||
/** | ||
* 年龄. | ||
*/ | ||
@Column(name = "n_age") | ||
private Integer age; | ||
|
||
/** | ||
* 创建时间. | ||
*/ | ||
@Column(name = "dt_create_time") | ||
private Date createTime; | ||
|
||
/** | ||
* 最后更新时间. | ||
*/ | ||
@Column(name = "dt_update_time") | ||
private LocalDateTime lastUpdateTime; | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/test/java/com/blinkfox/fenix/repository/ar/ArEntityRepository.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,16 @@ | ||
package com.blinkfox.fenix.repository.ar; | ||
|
||
import com.blinkfox.fenix.entity.ar.ArEntity; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/** | ||
* ArEntity 所对应的 Repository. | ||
* | ||
* @author blinkfox on 2022-03-28. | ||
* @since 1.0.0 | ||
*/ | ||
@Repository | ||
public interface ArEntityRepository extends CrudRepository<ArEntity, String> { | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
src/test/java/com/blinkfox/fenix/repository/ar/ArEntityRepositoryTest.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,66 @@ | ||
package com.blinkfox.fenix.repository.ar; | ||
|
||
import com.blinkfox.fenix.FenixTestApplication; | ||
import com.blinkfox.fenix.entity.ar.ArEntity; | ||
import java.time.LocalDateTime; | ||
import java.util.Date; | ||
import java.util.Optional; | ||
import javax.annotation.PostConstruct; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
/** | ||
* ArEntityRepository 的单元测试类. | ||
* | ||
* @author blinkfox on 2022-03-28. | ||
* @since v2.7.0 | ||
*/ | ||
@Slf4j | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(classes = FenixTestApplication.class) | ||
public class ArEntityRepositoryTest extends BaseRepositoryTest { | ||
|
||
public static final String TITLE = "这是测试标题"; | ||
|
||
/** | ||
* 初始化. | ||
*/ | ||
@PostConstruct | ||
public void init() { | ||
super.initLoad(); | ||
} | ||
|
||
@Test | ||
public void saveEntity() { | ||
ArEntity arEntity = new ArEntity() | ||
.setTitle(TITLE) | ||
.setDesc("这是测试的描述信息") | ||
.setAge(20) | ||
.setCreateTime(new Date()) | ||
.setLastUpdateTime(LocalDateTime.now()) | ||
.save(); | ||
|
||
// 查询保存的结果. | ||
Optional<ArEntity> arOption = arEntity.findById(); | ||
Assert.assertTrue(arOption.isPresent()); | ||
|
||
// 断言查询结果是否正确. | ||
ArEntity newArEntity = arOption.get(); | ||
Assert.assertNotNull(newArEntity.getId()); | ||
Assert.assertEquals(newArEntity.getTitle(), TITLE); | ||
Assert.assertNotNull(newArEntity.getDesc()); | ||
Assert.assertNotNull(newArEntity.getAge()); | ||
Assert.assertNotNull(newArEntity.getCreateTime()); | ||
Assert.assertNotNull(newArEntity.getLastUpdateTime()); | ||
|
||
// 再次查询断言. | ||
Optional<ArEntity> arOption2 = newArEntity.getRepository().findById(newArEntity.getId()); | ||
Assert.assertTrue(arOption2.isPresent()); | ||
Assert.assertEquals(arOption2.get().getTitle(), newArEntity.getTitle()); | ||
} | ||
|
||
} |
Oops, something went wrong.