db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/ejb/org/apache/ojb/ejb CommonTestClient.java ArticleManagerPBBean.java ArticleManagerODMGBean.java
Date Wed, 04 Jun 2003 06:12:14 GMT
arminw      2003/06/03 23:12:14

  Modified:    src/ejb/org/apache/ojb/ejb CommonTestClient.java
                        ArticleManagerPBBean.java
                        ArticleManagerODMGBean.java
  Log:
  add more test
  
  Revision  Changes    Path
  1.3       +101 -33   db-ojb/src/ejb/org/apache/ojb/ejb/CommonTestClient.java
  
  Index: CommonTestClient.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/CommonTestClient.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CommonTestClient.java	3 Jun 2003 14:54:43 -0000	1.2
  +++ CommonTestClient.java	4 Jun 2003 06:12:14 -0000	1.3
  @@ -91,14 +91,100 @@
       public void testPBCollectionRetrieve() throws Exception
       {
           long timestamp = System.currentTimeMillis();
  -        String name = "collection_test_" + timestamp;
  -        CategoryVO cat = VOHelper.createNewCategory("category_" + timestamp);
  +        String articleame = "collection_test_article" + timestamp;
  +        String categoryName = "collection_test_category" + timestamp;
  +        CategoryVO cat = pbCreatePersistentCategoryWithArticles(categoryName, articleame,
5);
  +
  +        assertNotNull(cat.getObjId());
  +        assertNotNull(cat.getAssignedArticles());
  +        assertEquals("Wrong number of referenced articles found", 5, cat.getAssignedArticles().size());
  +
  +        Collection result = pbArticleBean.getCategoryByName(categoryName);
  +        assertNotNull(result);
  +        assertEquals(1, result.size());
  +        cat = (CategoryVO) result.iterator().next();
  +        Collection articlesCol = cat.getAssignedArticles();
  +        assertNotNull(articlesCol);
  +        assertEquals("Wrong number of referenced articles found", 5, articlesCol.size());
  +    }
  +
  +    public void testODMGCollectionRetrieve() throws Exception
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        String articleame = "collection_test_article" + timestamp;
  +        String categoryName = "collection_test_category" + timestamp;
  +        CategoryVO cat = odmgCreatePersistentCategoryWithArticles(categoryName, articleame,
5);
  +
  +        assertNotNull(cat.getObjId());
  +        assertNotNull(cat.getAssignedArticles());
  +        assertEquals("Wrong number of referenced articles found", 5, cat.getAssignedArticles().size());
  +
  +        Collection result = odmgArticleBean.getCategoryByName(categoryName);
  +        assertNotNull(result);
  +        assertEquals(1, result.size());
  +        cat = (CategoryVO) result.iterator().next();
  +        Collection articlesCol = cat.getAssignedArticles();
  +        assertNotNull(articlesCol);
  +        assertEquals("Wrong number of referenced articles found", 5, articlesCol.size());
  +    }
  +
  +
  +    public void testPBQueryObjects() throws Exception
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        String articleName = "query_test_article_" + timestamp;
  +        String categoryName = "query_test_category_" + timestamp;
  +        CategoryVO cat1 = pbCreatePersistentCategoryWithArticles(categoryName, articleName,
6);
  +        CategoryVO cat2 = pbCreatePersistentCategoryWithArticles(categoryName, articleName,
6);
  +        CategoryVO cat3 = pbCreatePersistentCategoryWithArticles(categoryName, articleName,
6);
  +
  +        Collection result = pbArticleBean.getArticles(articleName);
  +        assertNotNull(result);
  +        assertEquals("Wrong number of articles", 18, result.size());
  +
  +        result = pbArticleBean.getCategoryByName(categoryName);
  +        assertNotNull(result);
  +        assertEquals("Wrong number of returned category objects", 3, result.size());
  +        CategoryVO cat = (CategoryVO) result.iterator().next();
  +        assertNotNull(cat);
  +        Collection articles = (Collection) cat.getAssignedArticles();
  +        assertNotNull(articles);
  +        assertEquals("Wrong number of referenced articles", 6, articles.size());
  +    }
  +
  +    public void testODMGQueryObjects() throws Exception
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        String articleName = "query_test_article_" + timestamp;
  +        String categoryName = "query_test_category_" + timestamp;
  +        CategoryVO cat1 = odmgCreatePersistentCategoryWithArticles(categoryName, articleName,
6);
  +        CategoryVO cat2 = odmgCreatePersistentCategoryWithArticles(categoryName, articleName,
6);
  +        CategoryVO cat3 = odmgCreatePersistentCategoryWithArticles(categoryName, articleName,
6);
  +
  +        Collection result = odmgArticleBean.getArticles(articleName);
  +        assertNotNull(result);
  +        assertEquals("Wrong number of articles", 18, result.size());
  +
  +        result = odmgArticleBean.getCategoryByName(categoryName);
  +        assertNotNull(result);
  +        assertEquals("Wrong number of returned category objects", 3, result.size());
  +        CategoryVO cat = (CategoryVO) result.iterator().next();
  +        assertNotNull(cat);
  +        Collection articles = (Collection) cat.getAssignedArticles();
  +        assertNotNull(articles);
  +        assertEquals("Wrong number of referenced articles", 6, articles.size());
  +    }
  +
  +    private CategoryVO pbCreatePersistentCategoryWithArticles(
  +            String categoryName, String articleName, int articleCount) throws Exception
  +    {
  +        CategoryVO cat = VOHelper.createNewCategory(categoryName);
           // store new category
           cat = pbArticleBean.storeCategory(cat);
           ArrayList articles = new ArrayList();
  -        for (int i = 0; i < 5; i++)
  +        for (int i = 0; i < articleCount; i++)
           {
  -            ArticleVO art = VOHelper.createNewArticle(name, 1);
  +            ArticleVO art = VOHelper.createNewArticle(articleName, 1);
               // set category
               art.setCategory(cat);
               // store article
  @@ -106,33 +192,23 @@
               articles.add(art);
           }
           // set article collection
  -        cat.setAssignedArticles(articles);
  +        if(articles.size() > 0) cat.setAssignedArticles(articles);
           // persist updated category
           cat = pbArticleBean.storeCategory(cat);
  -        assertNotNull(cat.getObjId());
  -        assertNotNull(cat.getAssignedArticles());
  -        assertEquals("Wrong number of referenced articles found", 5, cat.getAssignedArticles().size());
   
  -        Collection result = pbArticleBean.getCategoryByName("category_" + timestamp);
  -        assertNotNull(result);
  -        assertEquals(1, result.size());
  -        cat = (CategoryVO) result.iterator().next();
  -        Collection articlesCol = cat.getAssignedArticles();
  -        assertNotNull(articlesCol);
  -        assertEquals("Wrong number of referenced articles found", 5, articlesCol.size());
  +        return cat;
       }
   
  -    public void testODMGCollectionRetrieve() throws Exception
  +    private CategoryVO odmgCreatePersistentCategoryWithArticles(
  +            String categoryName, String articleName, int articleCount) throws Exception
       {
  -        long timestamp = System.currentTimeMillis();
  -        String name = "collection_test_" + timestamp;
  -        CategoryVO cat = VOHelper.createNewCategory("category_" + timestamp);
  +        CategoryVO cat = VOHelper.createNewCategory(categoryName);
           // store new category
           cat = odmgArticleBean.storeCategory(cat);
           ArrayList articles = new ArrayList();
  -        for (int i = 0; i < 5; i++)
  +        for (int i = 0; i < articleCount; i++)
           {
  -            ArticleVO art = VOHelper.createNewArticle(name, 1);
  +            ArticleVO art = VOHelper.createNewArticle(articleName, 1);
               // set category
               art.setCategory(cat);
               // store article
  @@ -140,21 +216,13 @@
               articles.add(art);
           }
           // set article collection
  -        cat.setAssignedArticles(articles);
  +        if(articles.size() > 0) cat.setAssignedArticles(articles);
           // persist updated category
           cat = odmgArticleBean.storeCategory(cat);
  -        assertNotNull(cat.getObjId());
  -        assertNotNull(cat.getAssignedArticles());
  -        assertEquals("Wrong number of referenced articles found", 5, cat.getAssignedArticles().size());
   
  -        Collection result = odmgArticleBean.getCategoryByName("category_" + timestamp);
  -        assertNotNull(result);
  -        assertEquals(1, result.size());
  -        cat = (CategoryVO) result.iterator().next();
  -        Collection articlesCol = cat.getAssignedArticles();
  -        assertNotNull(articlesCol);
  -        assertEquals("Wrong number of referenced articles found", 5, articlesCol.size());
  +        return cat;
       }
  +
   
       protected void setUp() throws Exception
       {
  
  
  
  1.8       +2 -2      db-ojb/src/ejb/org/apache/ojb/ejb/ArticleManagerPBBean.java
  
  Index: ArticleManagerPBBean.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/ArticleManagerPBBean.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ArticleManagerPBBean.java	3 Jun 2003 14:54:43 -0000	1.7
  +++ ArticleManagerPBBean.java	4 Jun 2003 06:12:14 -0000	1.8
  @@ -168,7 +168,7 @@
           try
           {
               Criteria criteria = new Criteria();
  -            if (articleName != null) criteria.addEqualTo("articleName", articleName);
  +            if (articleName != null) criteria.addEqualTo("name", articleName);
               Query q = new QueryByCriteria(ArticleVO.class, criteria);
               result = broker.getCollectionByQuery(q);
           }
  
  
  
  1.7       +3 -3      db-ojb/src/ejb/org/apache/ojb/ejb/ArticleManagerODMGBean.java
  
  Index: ArticleManagerODMGBean.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/ArticleManagerODMGBean.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ArticleManagerODMGBean.java	3 Jun 2003 14:54:43 -0000	1.6
  +++ ArticleManagerODMGBean.java	4 Jun 2003 06:12:14 -0000	1.7
  @@ -170,9 +170,9 @@
               StringBuffer buf = new StringBuffer("select allObjects from " + ArticleVO.class.getName());
               // buf.append(" where articleId not null");
               if (articleName != null)
  -                buf.append(" where articleName = $1");
  +                buf.append(" where name = $1");
               else
  -                buf.append(" where articleName is null");
  +                buf.append(" where name is null");
               query.create(buf.toString());
               if (articleName != null) query.bind(articleName);
               return (Collection) query.execute();
  
  
  

Mime
View raw message