Package org.exist

Examples of org.exist.Database


public class xUnit {
 
  Collection rootCollection;

    public void test(String source) {
      Database db = null;
      DBBroker broker = null;
        try {
          db = BrokerPool.getInstance();
          broker = db.get(db.getSecurityManager().getGuestSubject());
         
          XQuery xquery = broker.getXQueryService();
         
          XQueryContext context = xquery.newContext(AccessContext.TEST);
          //context.setModuleLoadPath();
         
            Source query = new ClassLoaderSource(source);
           
            CompiledXQuery compiledQuery = xquery.compile(context, query);
           
      for(Iterator<UserDefinedFunction> i = context.localFunctions(); i.hasNext(); ) {
        UserDefinedFunction func = i.next();
        FunctionSignature sig = func.getSignature();
       
        for (Annotation ann : sig.getAnnotations()) {
          if ("http://exist-db.org/xquery/xUnit".equals( ann.getName().getNamespaceURI())) {
            System.out.println(ann.getName().getLocalName());
           
            FunctionCall call = new FunctionCall(context, func);
            call.eval(Sequence.EMPTY_SEQUENCE);
          }
        }
            }

        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        } finally {
          if (db != null) db.release(broker);
        }
    }
View Full Code Here


        // success
       
        String accountName = AccountImpl.escape(verified.getIdentifier());
        AbstractAccount account = (AbstractAccount) OpenIDRealm.instance.getAccount(accountName);
        if (account == null) {
          Database db = OpenIDRealm.instance.getDatabase();
          org.exist.security.Subject currentSubject = db.getSubject();
          try {
            db.setSubject(db.getSecurityManager().getSystemSubject());
         
            //XXX: set OpenID group by default
            account = (AbstractAccount) OpenIDRealm.instance.addAccount(
                new UserAider(OpenIDRealm.instance.getId(), accountName)
              );
          } finally {
            db.setSubject(currentSubject);
          }
        }
       
        org.exist.security.Subject principal =
          new SubjectAccreditedImpl( account, verified );
       
        AuthSuccess authSuccess = (AuthSuccess) verification.getAuthResponse();
        authSuccess.getExtensions();

        if (authSuccess.hasExtension(SRegMessage.OPENID_NS_SREG)) {
          MessageExtension ext = authSuccess.getExtension(SRegMessage.OPENID_NS_SREG);
          if (ext instanceof SRegResponse) {
            SRegResponse sregResp = (SRegResponse) ext;
            for (Iterator iter = sregResp.getAttributeNames().iterator(); iter.hasNext();) {
              String name = (String) iter.next();
              if (LOG.isDebugEnabled())
                LOG.debug(name + " : " + sregResp.getParameterValue(name));
              principal.setMetadataValue(AXSchemaType.valueOfNamespace(name), sregResp.getParameterValue(name));
            }
          }
        }
        if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) {
          FetchResponse fetchResp = (FetchResponse) authSuccess.getExtension(AxMessage.OPENID_NS_AX);

          List aliases = fetchResp.getAttributeAliases();
          for (Iterator iter = aliases.iterator(); iter.hasNext();) {
            String alias = (String) iter.next();
            List values = fetchResp.getAttributeValues(alias);
            if (values.size() > 0) {
              if (LOG.isDebugEnabled())
                LOG.debug(alias + " : " + values.get(0));
              principal.setMetadataValue(AXSchemaType.valueOfAlias(alias), (String)values.get(0));
            }
          }
        }
        //update metadata
        Database db = OpenIDRealm.instance.getDatabase();
        org.exist.security.Subject currentSubject = db.getSubject();
        try {
          db.setSubject(db.getSecurityManager().getSystemSubject());
       
          OpenIDRealm.instance.updateAccount(principal);
        } finally {
          db.setSubject(currentSubject);
        }
       
                OpenIDUtility.registerUser(principal);
        return principal;
      }
View Full Code Here

    @Test
    public void updateGroup_calls_assertCanModifyGroup() throws PermissionDeniedException, EXistException {
        SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
        Configuration mockConfiguration = EasyMock.createMock(Configuration.class);
        Database mockDatabase = EasyMock.createMock(Database.class);
        DBBroker mockBroker = EasyMock.createMock(DBBroker.class);
        Subject mockSubject = EasyMock.createMock(Subject.class);

        Group mockGroup = EasyMock.createMockBuilder(AbstractGroup.class)
                .addMockedMethod("getName", new Class[0])
                .addMockedMethod("getManagers", new Class[0])
                .addMockedMethod("assertCanModifyGroup", new Class[]{Account.class})
                .createNiceMock();
        final String groupName = "someGroup";

        AbstractRealm mockRealm = EasyMock
                .createMockBuilder(AbstractRealm.class)
                .withConstructor(SecurityManager.class, Configuration.class)
                .withArgs(mockSecurityManager, mockConfiguration)
                .addMockedMethod("getDatabase", new Class[0])
                .addMockedMethod("getGroup", new Class[]{Subject.class, String.class})
                .createNiceMock();

        Group mockUpdatingGroup = EasyMock.createNiceMock(Group.class);

        //expectations
        expect(mockRealm.getDatabase()).andReturn(mockDatabase);
        expect(mockDatabase.get(null)).andReturn(mockBroker);
        expect(mockBroker.getSubject()).andReturn(mockSubject);
        mockGroup.assertCanModifyGroup(mockSubject);
        expect(mockGroup.getName()).andReturn(groupName);
        expect(mockRealm.getGroup(groupName)).andReturn(mockUpdatingGroup);
        expect(mockRealm.getDatabase()).andReturn(mockDatabase);
        expect(mockGroup.getManagers()).andReturn(new ArrayList<Account>());
        mockGroup.save();
        expect(mockUpdatingGroup.getManagers()).andReturn(new ArrayList<Account>());
        mockDatabase.release(mockBroker);

        replay(mockRealm, mockDatabase, mockBroker, mockGroup, mockSubject, mockUpdatingGroup);

        mockRealm.updateGroup(mockGroup);
View Full Code Here

        }
    }

    private BinaryDocument getBinary(XmldbURI uri) throws EXistException {
        BinaryDocument binaryDoc = null;
        Database pool = BrokerPool.getInstance();;

        DBBroker broker = null;
        try {
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            assertNotNull(broker);

            Collection root = broker.getCollection(TestConstants.TEST_COLLECTION_URI);
            assertNotNull(root);

            binaryDoc = (BinaryDocument)root.getDocument(broker, uri);

        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        } finally {
            pool.release(broker);
        }

        return binaryDoc;
    }
View Full Code Here

        return binaryDoc;
    }

    private BinaryDocument storeBinary(String name,  String data, String mimeType) throws EXistException {
      BinaryDocument binaryDoc = null;
        Database pool = BrokerPool.getInstance();;

        DBBroker broker = null;
        TransactionManager transact = null;
        Txn transaction = null;
        try {
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            assertNotNull(broker);
            transact = pool.getTransactionManager();
            assertNotNull(transact);
            transaction = transact.beginTransaction();
            assertNotNull(transaction);

            Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        broker.saveCollection(transaction, root);
            assertNotNull(root);

            binaryDoc = root.addBinaryResource(transaction, broker, XmldbURI.create(name), data.getBytes(), mimeType);

            if(transact != null) {
                transact.commit(transaction);
            }
        } catch (Exception e) {
            if (transact != null)
                transact.abort(transaction);
            e.printStackTrace();
            fail(e.getMessage());
        } finally {
            pool.release(broker);
        }

        return binaryDoc;
    }
View Full Code Here

            SearchCallback<NodeProxy> callback)
                    throws IOException, ParseException, TerminatedException {

        final LuceneIndex index = worker.index;

        final Database db = index.getBrokerPool();

        IndexSearcher searcher = null;
        try {
            searcher = index.getSearcher();
            final TaxonomyReader taxonomyReader = index.getTaxonomyReader();
View Full Code Here

        qnames = worker.getDefinedIndexes(qnames);

        final LuceneIndex index = worker.index;

        final Database db = index.getBrokerPool();
       
        DBBroker broker = db.getActiveBroker();
       
        IndexSearcher searcher = null;
        try {
            searcher = index.getSearcher();
            final TaxonomyReader taxonomyReader = index.getTaxonomyReader();

            DocumentHitCollector collector = new DocumentHitCollector(db, worker, null, null, contextId, docs, callback, searchParams, taxonomyReader);

            for (QName qname : qnames) {

                String field = LuceneUtil.encodeQName(qname, db.getSymbols());

                Analyzer analyzer = worker.getAnalyzer(null, qname, broker, docs);

                QueryParser parser = new QueryParser(LuceneIndex.LUCENE_VERSION_IN_USE, field, analyzer);
View Full Code Here

    private final static int ALL = Permission.READ | Permission.WRITE | Permission.EXECUTE;

    @Test
    public void add() throws PermissionDeniedException {
        final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
        final Database mockDatabase = EasyMock.createMock(Database.class);
        final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
       
        //expect(mockSecurityManager.getDatabase()).andReturn(mockDatabase);
        //expect(mockDatabase.getSubject()).andReturn(mockCurrentSubject);
        //expect(mockCurrentSubject.hasDbaRole()).andReturn(true);
View Full Code Here

    }

    @Test
    public void addACE_ForUserWithModeString() throws PermissionDeniedException {
        final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
        final Database mockDatabase = EasyMock.createMock(Database.class);
        final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
        final Account mockAccount = EasyMock.createMock(Account.class);

        SimpleACLPermission permission = new SimpleACLPermission(mockSecurityManager);
        assertEquals(0, permission.getACECount());
View Full Code Here

    }

    @Test
    public void addACE_ForGroupWithModeString() throws PermissionDeniedException {
        final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
        final Database mockDatabase = EasyMock.createMock(Database.class);
        final Subject mockCurrentSubject = EasyMock.createMock(Subject.class);
        final Group mockGroup = EasyMock.createMock(Group.class);

        SimpleACLPermission permission = new SimpleACLPermission(mockSecurityManager);
        assertEquals(0, permission.getACECount());
View Full Code Here

TOP

Related Classes of org.exist.Database

Copyright © 2018 www.massapicom. 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.