Return-Path: Delivered-To: apmail-incubator-oodt-commits-archive@minotaur.apache.org Received: (qmail 57840 invoked from network); 12 Jul 2010 17:45:56 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 12 Jul 2010 17:45:56 -0000 Received: (qmail 71805 invoked by uid 500); 12 Jul 2010 17:45:56 -0000 Delivered-To: apmail-incubator-oodt-commits-archive@incubator.apache.org Received: (qmail 71787 invoked by uid 500); 12 Jul 2010 17:45:56 -0000 Mailing-List: contact oodt-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oodt-dev@incubator.apache.org Delivered-To: mailing list oodt-commits@incubator.apache.org Received: (qmail 71779 invoked by uid 99); 12 Jul 2010 17:45:56 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Jul 2010 17:45:56 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Jul 2010 17:45:52 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 896D22388903; Mon, 12 Jul 2010 17:44:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r963394 - /incubator/oodt/trunk/catalog/src/test/org/apache/oodt/cas/catalog/system/impl/TestCatalogServiceLocal.java Date: Mon, 12 Jul 2010 17:44:59 -0000 To: oodt-commits@incubator.apache.org From: mattmann@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100712174459.896D22388903@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mattmann Date: Mon Jul 12 17:44:59 2010 New Revision: 963394 URL: http://svn.apache.org/viewvc?rev=963394&view=rev Log: - progress towards OODT-15 One trunk for all OODT components with top level build Modified: incubator/oodt/trunk/catalog/src/test/org/apache/oodt/cas/catalog/system/impl/TestCatalogServiceLocal.java Modified: incubator/oodt/trunk/catalog/src/test/org/apache/oodt/cas/catalog/system/impl/TestCatalogServiceLocal.java URL: http://svn.apache.org/viewvc/incubator/oodt/trunk/catalog/src/test/org/apache/oodt/cas/catalog/system/impl/TestCatalogServiceLocal.java?rev=963394&r1=963393&r2=963394&view=diff ============================================================================== --- incubator/oodt/trunk/catalog/src/test/org/apache/oodt/cas/catalog/system/impl/TestCatalogServiceLocal.java (original) +++ incubator/oodt/trunk/catalog/src/test/org/apache/oodt/cas/catalog/system/impl/TestCatalogServiceLocal.java Mon Jul 12 17:44:59 2010 @@ -1,4 +1,21 @@ -package gov.nasa.jpl.oodt.cas.catalog.system.impl; +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.oodt.cas.catalog.system.impl; import java.io.File; import java.io.IOException; @@ -33,140 +50,158 @@ import junit.framework.TestCase; /** * - * @author bfoster - * + * + * Test suite for the Local Catalog Service. + * */ public class TestCatalogServiceLocal extends TestCase { - private CatalogServiceLocal cs; - - public TestCatalogServiceLocal() throws ClassNotFoundException, InstantiationException, IllegalAccessException, CatalogServiceException, IOException, SQLException { - File tempFile = File.createTempFile("foo", "bar"); - tempFile.deleteOnExit(); - File tempDir = tempFile.getParentFile(); - String tmpDirPath = tempDir.getAbsolutePath(); - - CatalogServiceLocalFactory factory = new CatalogServiceLocalFactory(); - factory.setCatalogRepositoryFactory(new MemoryBasedCatalogRepositoryFactory()); - factory.setIngestMapperFactory(this.getOracleIngestMapperFactory(tmpDirPath)); - factory.setOneCatalogFailsAllFail(true); - factory.setSimplifyQueries(true); - factory.setPluginStorageDir("/dev/null"); - factory.setRestrictIngestPermissions(false); - factory.setRestrictQueryPermissions(false); - factory.setTransactionIdFactory(UuidTransactionIdFactory.class.getCanonicalName()); - cs = factory.createCatalogService(); - - CatalogFactory catalogFactory = new CatalogFactory(); - catalogFactory.setCatalogId("TestCatalog1"); - catalogFactory.setDictionaryFactories(null); - catalogFactory.setIndexFactory(getInMemoryDSFactory(tmpDirPath + "/1/")); - catalogFactory.setRestrictIngestPermissions(false); - catalogFactory.setRestrictQueryPermissions(false); - cs.addCatalog(catalogFactory.createCatalog()); - catalogFactory.setCatalogId("TestCatalog2"); - catalogFactory.setIndexFactory(getInMemoryDSFactory(tmpDirPath + "/2/")); - cs.addCatalog(catalogFactory.createCatalog()); - } - - public void testDataSourceCatalogIngestQueryAndDelete() throws CatalogServiceException, ParseException, TokenMgrError { - //test ingest - Metadata m = new Metadata(); - m.addMetadata("testkey1", "testval1"); - TransactionReceipt tr = cs.ingest(m); - Vector receipts = new Vector(); - receipts.add(tr); - List metadatas = cs.getMetadata(receipts); - assertEquals(metadatas.size(), 1); - Metadata ingestedMetadata = metadatas.get(0).getMetadata(); - assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); - assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2); - - //test ingest update - m.replaceMetadata(CatalogServiceLocal.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY.toString(), tr.getTransactionId().toString()); - tr = cs.ingest(m); - receipts = new Vector(); - receipts.add(tr); - metadatas = cs.getMetadata(receipts); - assertEquals(metadatas.size(), 1); - ingestedMetadata = metadatas.get(0).getMetadata(); - assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); - assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2); - - //test query using querypager - QueryExpression qe = QueryParser.parseQueryExpression("testkey1 == 'testval1'"); - QueryPager pager = cs.query(qe); - metadatas = cs.getNextPage(pager); - assertEquals(metadatas.size(), 1); - ingestedMetadata = metadatas.get(0).getMetadata(); - assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); - assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2); - - //test query using std paging - qe = QueryParser.parseQueryExpression("testkey1 == 'testval1'"); - Page page = cs.getPage(new PageInfo(20, PageInfo.FIRST_PAGE), qe); - metadatas = cs.getMetadata(page); - assertEquals(metadatas.size(), 1); - ingestedMetadata = metadatas.get(0).getMetadata(); - assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); - assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2); - - //test query using std paging with catalog restriction - qe = QueryParser.parseQueryExpression("testkey1 == 'testval1'"); - page = cs.getPage(new PageInfo(20, PageInfo.FIRST_PAGE), qe, Collections.singleton("TestCatalog1")); - metadatas = cs.getMetadata(page); - assertEquals(metadatas.size(), 1); - ingestedMetadata = metadatas.get(0).getMetadata(); - assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); - assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 1); - - //test delete - m = new Metadata(); - m.addMetadata(CatalogServiceLocal.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY.toString(), tr.getTransactionId().toString()); - cs.delete(m); - assertEquals(cs.getMetadata(Collections.singletonList(tr)).size(), 0); - } - - private OracleIngestMapperFactory getOracleIngestMapperFactory(String tmpDirPath) throws SQLException, IOException { - new File(tmpDirPath).deleteOnExit(); - - OracleIngestMapperFactory factory = new OracleIngestMapperFactory(); - String user = "sa"; - String pass = ""; - String driver = "org.hsqldb.jdbcDriver"; - String url = "jdbc:hsqldb:file:" + tmpDirPath + "/testMapperCat;shutdown=true"; - DataSource ds = DatabaseConnectionBuilder.buildDataSource(user, pass, - driver, url); - SqlScript coreSchemaScript = new SqlScript(new File("./src/testdata/test-mapper-cat.sql").getAbsolutePath(), ds); - coreSchemaScript.loadScript(); - coreSchemaScript.execute(); - - factory.setDriver(driver); - factory.setJdbcUrl(url); - factory.setPass(pass); - factory.setUser(user); - return factory; - } - - private DataSourceIndexFactory getInMemoryDSFactory(String tmpDirPath) throws IOException, SQLException { - new File(tmpDirPath).deleteOnExit(); - - String user = "sa"; - String pass = ""; - String driver = "org.hsqldb.jdbcDriver"; - String url = "jdbc:hsqldb:file:" + tmpDirPath + "/testIndexCat;shutdown=true"; - DataSource ds = DatabaseConnectionBuilder.buildDataSource(user, pass, - driver, url); - SqlScript coreSchemaScript = new SqlScript(new File("./src/testdata/test-index-cat.sql").getAbsolutePath(), ds); - coreSchemaScript.loadScript(); - coreSchemaScript.execute(); - - DataSourceIndexFactory indexFactory = new DataSourceIndexFactory(); - indexFactory.setDriver(driver); - indexFactory.setJdbcUrl(url); - indexFactory.setPass(pass); - indexFactory.setUser(user); - return indexFactory; - } - + private CatalogServiceLocal cs; + + public TestCatalogServiceLocal() throws ClassNotFoundException, + InstantiationException, IllegalAccessException, CatalogServiceException, + IOException, SQLException { + File tempFile = File.createTempFile("foo", "bar"); + tempFile.deleteOnExit(); + File tempDir = tempFile.getParentFile(); + String tmpDirPath = tempDir.getAbsolutePath(); + + CatalogServiceLocalFactory factory = new CatalogServiceLocalFactory(); + factory + .setCatalogRepositoryFactory(new MemoryBasedCatalogRepositoryFactory()); + factory.setIngestMapperFactory(this + .getOracleIngestMapperFactory(tmpDirPath)); + factory.setOneCatalogFailsAllFail(true); + factory.setSimplifyQueries(true); + factory.setPluginStorageDir("/dev/null"); + factory.setRestrictIngestPermissions(false); + factory.setRestrictQueryPermissions(false); + factory.setTransactionIdFactory(UuidTransactionIdFactory.class + .getCanonicalName()); + cs = factory.createCatalogService(); + + CatalogFactory catalogFactory = new CatalogFactory(); + catalogFactory.setCatalogId("TestCatalog1"); + catalogFactory.setDictionaryFactories(null); + catalogFactory.setIndexFactory(getInMemoryDSFactory(tmpDirPath + "/1/")); + catalogFactory.setRestrictIngestPermissions(false); + catalogFactory.setRestrictQueryPermissions(false); + cs.addCatalog(catalogFactory.createCatalog()); + catalogFactory.setCatalogId("TestCatalog2"); + catalogFactory.setIndexFactory(getInMemoryDSFactory(tmpDirPath + "/2/")); + cs.addCatalog(catalogFactory.createCatalog()); + } + + public void testDataSourceCatalogIngestQueryAndDelete() + throws CatalogServiceException, ParseException, TokenMgrError { + // test ingest + Metadata m = new Metadata(); + m.addMetadata("testkey1", "testval1"); + TransactionReceipt tr = cs.ingest(m); + Vector receipts = new Vector(); + receipts.add(tr); + List metadatas = cs.getMetadata(receipts); + assertEquals(metadatas.size(), 1); + Metadata ingestedMetadata = metadatas.get(0).getMetadata(); + assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); + assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2); + + // test ingest update + m.replaceMetadata( + CatalogServiceLocal.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY.toString(), + tr.getTransactionId().toString()); + tr = cs.ingest(m); + receipts = new Vector(); + receipts.add(tr); + metadatas = cs.getMetadata(receipts); + assertEquals(metadatas.size(), 1); + ingestedMetadata = metadatas.get(0).getMetadata(); + assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); + assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2); + + // test query using querypager + QueryExpression qe = QueryParser + .parseQueryExpression("testkey1 == 'testval1'"); + QueryPager pager = cs.query(qe); + metadatas = cs.getNextPage(pager); + assertEquals(metadatas.size(), 1); + ingestedMetadata = metadatas.get(0).getMetadata(); + assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); + assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2); + + // test query using std paging + qe = QueryParser.parseQueryExpression("testkey1 == 'testval1'"); + Page page = cs.getPage(new PageInfo(20, PageInfo.FIRST_PAGE), qe); + metadatas = cs.getMetadata(page); + assertEquals(metadatas.size(), 1); + ingestedMetadata = metadatas.get(0).getMetadata(); + assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); + assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2); + + // test query using std paging with catalog restriction + qe = QueryParser.parseQueryExpression("testkey1 == 'testval1'"); + page = cs.getPage(new PageInfo(20, PageInfo.FIRST_PAGE), qe, Collections + .singleton("TestCatalog1")); + metadatas = cs.getMetadata(page); + assertEquals(metadatas.size(), 1); + ingestedMetadata = metadatas.get(0).getMetadata(); + assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); + assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 1); + + // test delete + m = new Metadata(); + m.addMetadata(CatalogServiceLocal.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY + .toString(), tr.getTransactionId().toString()); + cs.delete(m); + assertEquals(cs.getMetadata(Collections.singletonList(tr)).size(), 0); + } + + private OracleIngestMapperFactory getOracleIngestMapperFactory( + String tmpDirPath) throws SQLException, IOException { + new File(tmpDirPath).deleteOnExit(); + + OracleIngestMapperFactory factory = new OracleIngestMapperFactory(); + String user = "sa"; + String pass = ""; + String driver = "org.hsqldb.jdbcDriver"; + String url = "jdbc:hsqldb:file:" + tmpDirPath + + "/testMapperCat;shutdown=true"; + DataSource ds = DatabaseConnectionBuilder.buildDataSource(user, pass, + driver, url); + SqlScript coreSchemaScript = new SqlScript(new File( + "./src/testdata/test-mapper-cat.sql").getAbsolutePath(), ds); + coreSchemaScript.loadScript(); + coreSchemaScript.execute(); + + factory.setDriver(driver); + factory.setJdbcUrl(url); + factory.setPass(pass); + factory.setUser(user); + return factory; + } + + private DataSourceIndexFactory getInMemoryDSFactory(String tmpDirPath) + throws IOException, SQLException { + new File(tmpDirPath).deleteOnExit(); + + String user = "sa"; + String pass = ""; + String driver = "org.hsqldb.jdbcDriver"; + String url = "jdbc:hsqldb:file:" + tmpDirPath + + "/testIndexCat;shutdown=true"; + DataSource ds = DatabaseConnectionBuilder.buildDataSource(user, pass, + driver, url); + SqlScript coreSchemaScript = new SqlScript(new File( + "./src/testdata/test-index-cat.sql").getAbsolutePath(), ds); + coreSchemaScript.loadScript(); + coreSchemaScript.execute(); + + DataSourceIndexFactory indexFactory = new DataSourceIndexFactory(); + indexFactory.setDriver(driver); + indexFactory.setJdbcUrl(url); + indexFactory.setPass(pass); + indexFactory.setUser(user); + return indexFactory; + } + }