public class ModelTestCase extends BaseTestCase {
protected final static Logger logger = Logger.getLogger(ModelTestCase.class);
public void testSHost() {
SHost host;
// create the record
Session session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
host = new SHost();
host.setHost("localhost");
host.setExportRoot("/");
host.setUserOnHost("root");
host.setUserPassword("password");
session.saveOrUpdate(host);
txn.commit();
} finally {
session.close();
}
Assert.assertTrue(host.getId() != 0);
// retrive the record
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
host = (SHost)session.get(SHost.class, (long)host.getId());
txn.commit();
Assert.assertTrue(host.getHost().equals("localhost"));
Assert.assertTrue(host.getUserOnHost().equals("root"));
Assert.assertTrue(host.getUserPassword().equals("password"));
logger.info("Retrived record, host:" + host.getHost()
+ ", user: " + host.getUserOnHost()
+ ", password: " + host.getUserPassword());
} finally {
session.close();
}
// delete the record
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
host = (SHost)session.get(SHost.class, (long)host.getId());
session.delete(host);
txn.commit();
} finally {
session.close();
}
session = CloudSessionFactory.getInstance().openSession();
try {
Transaction txn = session.beginTransaction();
host = (SHost)session.get(SHost.class, (long)host.getId());
txn.commit();
Assert.assertTrue(host == null);
} finally {
session.close();