# # Copyright (c) 2003, Benja Fallenstein # # This file is part of Storm. # # Storm is free software; you can redistribute it and/or modify it under # the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # Storm is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General # Public License for more details. # # You should have received a copy of the GNU Lesser General # Public License along with Storm; if not, write to the Free # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307 USA # # # Tests for IndexedPool implementations # Requires attribute: # pool(indexTypes) -- a method taking a list of index types # and returning the appropriate IndexedPool import gzz, java import jarray def set(list): set = java.util.HashSet() for el in list: set.add(el) return set def testNonavailableIndexRaisesException(): p = pool([]) try: p.getIndex("http://example.com/no-such-index") except java.util.NoSuchElementException: pass else: assert 0 def testContentTypeIndex(): p = pool([org.nongnu.storm.ContentTypeIndexType()]) i = p.getIndex(org.nongnu.storm.ContentTypeIndexType.contentTypeIndexTypeURI) assert i != None assert i.getBlocks("text/plain") == set([]) os = p.getBlockOutputStream("text/plain") os.close() id1 = os.getBlockId() os = p.getBlockOutputStream("text/plain") os.close() id2 = os.getBlockId() os = p.getBlockOutputStream("text/html") os.close() id3 = os.getBlockId() assert i.getBlocks("text/plain") == set([id1, id2]) assert i.getBlocks("text/html") == set([id3]) assert i.getBlocks("text/enriched") == set([]) assert i == p.getIndex(org.nongnu.storm.ContentTypeIndexType.contentTypeIndexTypeURI)