public final void testQueryResource2() throws Exception {
    VirtualCollection vc = (VirtualCollection) this.dbColl.getChildCollection("vcl-data/myvc");

    VirtualResource vr = (VirtualResource) vc.getResource("virtual_autoren3.vxml");

    Document doc = (Document) vr.getContentAsDOM();
    Element articles = (Element) doc.getElementsByTagName("articles").item(0);

    assertEquals(4, articles.getElementsByTagName("*").getLength());
  }
  public final void testCreateResourceFail() throws Exception {

    VirtualCollection vcoll = this.getMyVC();
    try {
      vcoll.createResource("", XMLResource.RESOURCE_TYPE);
      assertTrue(EXPECTED_EXCEPTION + " a resource.", false);
    } catch (XMLDBException e) {
      assertTrue(INVALID_COLL_MSG + e.errorCode, isInvalidColl(e.errorCode));
    }
  }
  public final void testCreateIdFail() throws Exception {

    VirtualCollection vcoll = this.getMyVC();

    try {
      vcoll.createId();
      assertTrue(EXPECTED_EXCEPTION + " an id.", false);
    } catch (XMLDBException e) {
      assertTrue(INVALID_COLL_MSG + e.errorCode, e.errorCode == ErrorCodes.INVALID_COLLECTION);
    }
  }
 public void testGetServicesClosedFail() throws Exception {
   this.getMyVC();
   VirtualCollection vc = this.getMyVC();
   vc.close();
   try {
     vc.getServices();
     assertTrue(false);
   } catch (XMLDBException e) {
     assertEquals(ErrorCodes.COLLECTION_CLOSED, e.errorCode);
   }
 }
  public final void testGetResourceSuccess() throws Exception {

    VirtualCollection vcoll = this.getMyVC();

    String[] names = vcoll.listResources();
    assertTrue("Expected resource names and not an empty array.", 0 != names.length);

    Resource res = vcoll.getResource(names[0]);
    assertTrue(
        "Expected instance of VirtualResource and not " + res.getClass(),
        res instanceof VirtualResource);
  }
  public void testSetStylesheetClosedFail() throws Exception {
    VirtualCollection vc = this.getMyVC();
    vc.close();

    try {
      URL url = null;
      vc.setStylesheet(url);
      assertTrue(false);
    } catch (XMLDBException e) {
      assertEquals(ErrorCodes.COLLECTION_CLOSED, e.errorCode);
    }
  }
  public final void testRemoveResourceFail() throws Exception {

    VirtualCollection vcoll = this.getMyVC();
    String[] names = vcoll.listResources();

    for (int i = 0; i < names.length; i++) {
      Resource r = vcoll.getResource(names[i]);
      try {
        vcoll.removeResource(r);
        assertTrue(EXPECTED_EXCEPTION, false);
      } catch (XMLDBException e) {
        assertTrue(INVALID_COLL_MSG + e.errorCode, this.isInvalidColl(e.errorCode));
      }
    }
  }
  public final void testGetPCVResourceSuccess() throws Exception {
    VirtualCollection vcoll = this.getMyVC();

    String[] names = vcoll.listResources();
    assertTrue("Expected resource names and not an empty array.", 0 != names.length);

    Resource res = vcoll.getResource(names[0]);
    assertTrue(
        "Expected instance of VirtualResource and not " + res.getClass(),
        res instanceof VirtualResource);

    VirtualResource vres = (VirtualResource) res;

    PCVResource pres = vres.getPreCompiledResource();
    assertNotNull("Expected pres to be not null", pres);

    assertTrue(
        "Expected instance of PCVResource and not " + res.getClass(), pres instanceof PCVResource);

    assertEquals(vres.getId(), pres.getId());
  }
  public final void testCreateVirtualCollectionSuccess() throws Exception {
    Collection testColl = this.db.getCollection("/db/vc-colls", "sa", "");

    VirtualCollectionManagementService vcms =
        (VirtualCollectionManagementService)
            testColl.getService("VirtualCollectionManagementService", "1.0");

    int size = testColl.getChildCollectionCount();

    VirtualCollection vc =
        vcms.createVirtualCollection(
            "test-vc", new File("data/vcl-schema/author-articles.no.dtd.vcs").toURL());

    assertNotNull("Expected that an instance of VirtualCollection is returned and not null", vc);
    assertTrue(
        "Expected the returns instance is an instance of VirtualCollection and not "
            + vc.getClass(),
        vc instanceof VirtualCollection);

    assertEquals(
        "Why is the virtual collection not inserted but returned?",
        size + 1,
        testColl.getChildCollectionCount());
  }
 protected Service getService(String name) throws Exception {
   VirtualCollection vcoll = this.getMyVC();
   return vcoll.getService(name, "1.0");
 }
 public void testGetChildCollectionNullSuccess() throws Exception {
   VirtualCollection vc = this.getMyVC();
   assertNull(vc.getChildCollection("$vcl-schema"));
 }
 public void testGetChildCollectionCountSuccess() throws Exception {
   VirtualCollection vc = this.getMyVC();
   assertEquals(0, vc.getChildCollectionCount());
 }