Package org.xorm.tests

Source Code of org.xorm.tests.TestXMLDriver

package org.xorm.tests;

import junit.framework.*;

import org.xorm.XORM;
import org.xorm.tests.xml.*;
import javax.jdo.PersistenceManager;
import javax.jdo.JDOHelper;
import java.util.Collection;
import java.util.Iterator;

public class TestXMLDriver extends XORMTestCase {
    public void testRead() {
  PersistenceManager mgr = factory.getPersistenceManager();
  Collection roots = (Collection) mgr.newQuery(Library.class).execute();
  Library lib = (Library) roots.iterator().next();
  System.out.println("Library name: " + lib.getName());
  System.out.println("Books:");
  Iterator i = lib.getBooks().iterator();
  while (i.hasNext()) {
      Book b = (Book) i.next();
      System.out.println("Title: " + b.getTitle());
      System.out.println("Author: " + b.getAuthor());
      System.out.println("Description: " + b.getDescription());
  }
  mgr.close();
    }

    public void testWrite() {
  PersistenceManager mgr = factory.getPersistenceManager();
  mgr.currentTransaction().begin();
  Collection roots = (Collection) mgr.newQuery(Library.class).execute();
  Library lib = (Library) roots.iterator().next();

  lib.setName("Nonfiction");
  Book b = (Book) XORM.newInstance(mgr, Book.class);
  b.setTitle("The Three Musketeers");
  b.setAuthor("Alexandre Dumas");
  b.setDescription("French men on adventures.");
  mgr.makePersistent(b);

  // Add it to the library
  lib.getBooks().add(b);
  b.setLibrary(lib);

  mgr.currentTransaction().commit();


  System.out.println("Library name: " + lib.getName());
  System.out.println("Books:");
  Iterator i = lib.getBooks().iterator();
  while (i.hasNext()) {
      b = (Book) i.next();
      System.out.println("Title: " + b.getTitle());
      System.out.println("Author: " + b.getAuthor());
      System.out.println("Description: " + b.getDescription());
  }

  mgr.close();
    }


    public static void main(String args[]) {
        String[] testCaseName = {TestXMLDriver.class.getName()};
        junit.textui.TestRunner.main(testCaseName);
    }
     
     public static Test suite() {
        return new TestSuite(TestXMLDriver.class);
    }
 
}
TOP

Related Classes of org.xorm.tests.TestXMLDriver

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.