-
Notifications
You must be signed in to change notification settings - Fork 36
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
4 changed files
with
126 additions
and
8 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 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
112 changes: 112 additions & 0 deletions
112
src/test/java/com/dieselpoint/norm/TestGeneratedId.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,112 @@ | ||
package com.dieselpoint.norm; | ||
|
||
import java.util.List; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.dieselpoint.norm.Database; | ||
|
||
|
||
public class TestGeneratedId { | ||
|
||
static String DB_DRIVER_CLASS_NAME = "org.postgresql.ds.PGSimpleDataSource"; | ||
static String DB_SERVER_NAME = "localhost"; | ||
static String DB_DATABASE = "testdb"; | ||
static String DB_USERNAME = "postgres"; | ||
static String DB_PASSWORD = "rootpassword"; | ||
|
||
private Database db; | ||
|
||
@Before | ||
public void setUp() { | ||
System.setProperty("norm.dataSourceClassName", DB_DRIVER_CLASS_NAME); | ||
System.setProperty("norm.serverName", DB_SERVER_NAME); | ||
System.setProperty("norm.databaseName", DB_DATABASE); | ||
System.setProperty("norm.user", DB_USERNAME); | ||
System.setProperty("norm.password", DB_PASSWORD); | ||
|
||
db = new Database(); | ||
} | ||
|
||
@Test | ||
public void testCreate() { | ||
NormPojo np = new NormPojo(); | ||
np.setId("MyID"); | ||
np.setName("My name"); | ||
db.insert(np); | ||
Assert.assertNotNull(np.getDatabaseId()); | ||
} | ||
|
||
@Test | ||
public void testRetrieval() { | ||
List<NormPojo> npList = null; | ||
npList = db.results(NormPojo.class); | ||
Assert.assertNotNull(npList); | ||
Assert.assertTrue(npList.size() > 0); | ||
} | ||
|
||
@Table(name = "pojo") | ||
public static class NormPojo { | ||
|
||
/** Database record ID. */ | ||
private Integer databaseId; | ||
|
||
/** Unique identifier of the object. */ | ||
private String id; | ||
|
||
/** Human readable name. */ | ||
private String name; | ||
|
||
/** | ||
* @return the id | ||
*/ | ||
@Column(name = "object_id", unique = true) | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* @param id the id to set | ||
*/ | ||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* @return the name | ||
*/ | ||
@Column(name = "name") | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* @param name the name to set | ||
*/ | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Id | ||
@GeneratedValue | ||
@Column(name = "id") | ||
public Integer getDatabaseId() { | ||
return databaseId; | ||
} | ||
|
||
public void setDatabaseId(Integer databaseId) { | ||
this.databaseId = databaseId; | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
} |