Search in sources :

Example 1 with Catalog

use of org.eclipse.wst.xml.core.internal.catalog.Catalog in project webtools.sourceediting by eclipse.

the class CatalogReaderTest method testReadComplexCatalog.

/*
	 * Class under test for void read(ICatalog, String)
	 */
public void testReadComplexCatalog() throws Exception {
    // read catalog
    String catalogFile = "/data/delegateAndRewrite/catalog11.xml";
    URL catalogUrl = TestPlugin.getDefault().getBundle().getEntry(catalogFile);
    assertNotNull(catalogUrl);
    URL base = FileLocator.resolve(catalogUrl);
    Catalog catalog = (Catalog) getCatalog("catalog11", base.toString());
    // CatalogReader.read(catalog, catalogFilePath);
    assertNotNull(catalog);
    // test main catalog - catalog1.xml
    // assertEquals("cat1", catalog.getId());
    assertEquals(13, catalog.getCatalogElements().length);
    // test public entries
    assertEquals(2, CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_PUBLIC).size());
    // test system entries
    assertEquals(2, CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_SYSTEM).size());
    // test uri entries
    assertEquals(1, CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_URI).size());
    // test next catalog - catalog2.xml
    INextCatalog[] nextCatalogEntries = catalog.getNextCatalogs();
    assertEquals(1, nextCatalogEntries.length);
    INextCatalog nextCatalogEntry = (INextCatalog) nextCatalogEntries[0];
    assertNotNull(nextCatalogEntry);
    assertEquals("catalog.xml", nextCatalogEntry.getCatalogLocation());
}
Also used : INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) URL(java.net.URL) INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) Catalog(org.eclipse.wst.xml.core.internal.catalog.Catalog) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Example 2 with Catalog

use of org.eclipse.wst.xml.core.internal.catalog.Catalog in project webtools.sourceediting by eclipse.

the class CatalogReaderTest method testReadCatalog.

/*
	 * Class under test for void read(ICatalog, String)
	 */
public void testReadCatalog() throws Exception {
    // read catalog
    String catalogFile = "/data/catalog1.xml";
    URL catalogUrl = TestPlugin.getDefault().getBundle().getEntry(catalogFile);
    assertNotNull(catalogUrl);
    URL base = FileLocator.resolve(catalogUrl);
    Catalog catalog = (Catalog) getCatalog("catalog1", base.toString());
    // CatalogReader.read(catalog, catalogFilePath);
    assertNotNull(catalog);
    // test main catalog - catalog1.xml
    // assertEquals("cat1", catalog.getId());
    assertEquals(3, catalog.getCatalogEntries().length);
    // test public entries
    List entries = CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_PUBLIC);
    assertEquals(1, entries.size());
    ICatalogEntry entry = (ICatalogEntry) entries.get(0);
    // String resolvedURI = URIHelper.makeAbsolute(base, "./Invoice/Invoice.dtd");
    assertEquals(getFileLocation("/data/Invoice/Invoice.dtd"), entry.getURI());
    assertEquals("InvoiceId_test", entry.getKey());
    assertEquals("http://webURL", entry.getAttributeValue("webURL"));
    // test system entries
    entries = CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_SYSTEM);
    assertEquals(1, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    assertEquals(getFileLocation("/data/Invoice/Invoice.dtd"), entry.getURI());
    assertEquals("Invoice.dtd", entry.getKey());
    assertEquals("yes", entry.getAttributeValue("chached"));
    assertEquals("value1", entry.getAttributeValue("property"));
    // test uri entries
    entries = CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_URI);
    assertEquals(1, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    assertEquals(getFileLocation("/data/Invoice/Invoice.dtd"), entry.getURI());
    assertEquals("http://www.test.com/Invoice.dtd", entry.getKey());
    assertEquals("no", entry.getAttributeValue("chached"));
    assertEquals("value2", entry.getAttributeValue("property"));
    // test next catalog - catalog2.xml
    INextCatalog[] nextCatalogEntries = catalog.getNextCatalogs();
    assertEquals(1, nextCatalogEntries.length);
    INextCatalog nextCatalogEntry = (INextCatalog) nextCatalogEntries[0];
    assertNotNull(nextCatalogEntry);
    // String catalogRefId = nextCatalogEntry.getCatalogRefId();
    // assertEquals("nextCatalog1", catalogRefId);
    // resolvedURI = URIHelper.makeAbsolute(base, "catalog2.xml");
    assertEquals("catalog2.xml", nextCatalogEntry.getCatalogLocation());
    ICatalog nextCatalog = nextCatalogEntry.getReferencedCatalog();
    assertNotNull(nextCatalog);
    assertEquals(4, nextCatalog.getCatalogEntries().length);
    // test public entries
    entries = CatalogTest.getCatalogEntries(nextCatalog, ICatalogEntry.ENTRY_TYPE_PUBLIC);
    assertEquals(2, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    // resolvedURI = URIHelper.makeAbsolute(nextCatalog.getBase(), "./PublicationCatalogue/Catalogue.xsd");
    assertEquals(getFileLocation("/data/PublicationCatalogue/Catalogue.xsd"), entry.getURI());
    assertEquals("http://www.eclipse.org/webtools/Catalogue_001", entry.getKey());
    // test public entry from a group
    entry = (ICatalogEntry) entries.get(1);
    // resolvedURI = URIHelper.makeAbsolute(nextCatalog.getBase(), "./PublicationCatalogue/Catalogue.xsd");
    assertEquals(getFileLocation("/data/PublicationCatalogue/Catalogue.xsd"), entry.getURI());
    assertEquals("http://www.eclipse.org/webtools/Catalogue_002", entry.getKey());
    // test system entries
    entries = CatalogTest.getCatalogEntries(nextCatalog, ICatalogEntry.ENTRY_TYPE_SYSTEM);
    assertEquals(1, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    assertEquals(getFileLocation("/data/PublicationCatalogue/Catalogue.xsd"), entry.getURI());
    assertEquals("Catalogue.xsd", entry.getKey());
    // test uri entries
    entries = CatalogTest.getCatalogEntries(nextCatalog, ICatalogEntry.ENTRY_TYPE_URI);
    assertEquals(1, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    assertEquals("http://www.eclipse.org/webtools/Catalogue/Catalogue.xsd", entry.getURI());
    assertEquals("http://www.eclipse.org/webtools/Catalogue.xsd", entry.getKey());
}
Also used : INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) List(java.util.List) ICatalogEntry(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog) URL(java.net.URL) INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) Catalog(org.eclipse.wst.xml.core.internal.catalog.Catalog) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Example 3 with Catalog

use of org.eclipse.wst.xml.core.internal.catalog.Catalog in project webtools.sourceediting by eclipse.

the class CatalogReaderTest method testCompatabilityReader.

public void testCompatabilityReader() throws Exception {
    // read catalog
    String catalogFile = "/data/compatabilityTest.xmlcatalog";
    URL catalogUrl = TestPlugin.getDefault().getBundle().getEntry(catalogFile);
    assertNotNull(catalogUrl);
    URL base = FileLocator.resolve(catalogUrl);
    Catalog catalog = (Catalog) getCatalog("compatabilityCatalog", base.toString());
    // CatalogReader.read(catalog, catalogFilePath);
    assertNotNull(catalog);
    List entries = CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_PUBLIC);
    assertEquals(1, entries.size());
    ICatalogEntry entry = (ICatalogEntry) entries.get(0);
    assertEquals("platform:/resource/XMLExamples/Invoice2/Invoice.dtd", entry.getURI());
    assertEquals("InvoiceId", entry.getKey());
}
Also used : List(java.util.List) ICatalogEntry(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry) URL(java.net.URL) INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) Catalog(org.eclipse.wst.xml.core.internal.catalog.Catalog) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Example 4 with Catalog

use of org.eclipse.wst.xml.core.internal.catalog.Catalog in project webtools.sourceediting by eclipse.

the class CatalogWriterTest method testWrite.

public final void testWrite() throws Exception {
    // read catalog
    String catalogFile = "/data/catalog1.xml";
    URL catalogUrl = TestPlugin.getDefault().getBundle().getEntry(catalogFile);
    assertNotNull(catalogUrl);
    URL resolvedURL = FileLocator.resolve(catalogUrl);
    Catalog testCatalog = (Catalog) getCatalog("catalog1", resolvedURL.toString());
    assertNotNull(testCatalog);
    testCatalog.setBase(resolvedURL.toString());
    // CatalogReader.read(testCatalog, resolvedURL.getFile());
    assertNotNull(testCatalog);
    // write catalog
    URL resultsFolder = TestPlugin.getDefault().getBundle().getEntry("/");
    IPath path = new Path(FileLocator.resolve(resultsFolder).getFile());
    String resultCatalogFile = path.append("/catalog1.xml").toFile().toURI().toString();
    testCatalog.setLocation(resultCatalogFile);
    // write catalog
    testCatalog.save();
    // read catalog file from the saved location and test its content
    Catalog catalog = (Catalog) getCatalog("catalog2", testCatalog.getLocation());
    assertNotNull(catalog);
    // test saved catalog - catalog1.xml
    assertEquals(3, catalog.getCatalogEntries().length);
    // test public entries
    List entries = CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_PUBLIC);
    assertEquals(1, entries.size());
    ICatalogEntry entry = (ICatalogEntry) entries.get(0);
    assertEquals(getFileLocation("data/Invoice/Invoice.dtd"), entry.getURI());
    assertEquals("InvoiceId_test", entry.getKey());
    assertEquals("http://webURL", entry.getAttributeValue("webURL"));
    // test system entries
    entries = CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_SYSTEM);
    assertEquals(1, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    assertEquals(getFileLocation("data/Invoice/Invoice.dtd"), entry.getURI());
    assertEquals("Invoice.dtd", entry.getKey());
    assertEquals("yes", entry.getAttributeValue("chached"));
    assertEquals("value1", entry.getAttributeValue("property"));
    // test uri entries
    entries = CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_URI);
    assertEquals(1, entries.size());
    entry = (ICatalogEntry) entries.get(0);
    assertEquals(getFileLocation("data/Invoice/Invoice.dtd"), entry.getURI());
    assertEquals("http://www.test.com/Invoice.dtd", entry.getKey());
    assertEquals("no", entry.getAttributeValue("chached"));
    assertEquals("value2", entry.getAttributeValue("property"));
    // test next catalog - catalog2.xml
    INextCatalog[] nextCatalogEntries = catalog.getNextCatalogs();
    assertEquals(1, nextCatalogEntries.length);
    INextCatalog nextCatalogEntry = (INextCatalog) nextCatalogEntries[0];
    assertNotNull(nextCatalogEntry);
    assertEquals("catalog2.xml", nextCatalogEntry.getCatalogLocation());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) List(java.util.List) ICatalogEntry(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry) URL(java.net.URL) INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) Catalog(org.eclipse.wst.xml.core.internal.catalog.Catalog)

Example 5 with Catalog

use of org.eclipse.wst.xml.core.internal.catalog.Catalog in project webtools.sourceediting by eclipse.

the class CatalogWriterTest method testBug235445.

public final void testBug235445() throws Exception {
    // read catalog
    String catalogFile = "/data/deletemecatalog.xml";
    URL catalogUrl = TestPlugin.getDefault().getBundle().getEntry(catalogFile);
    assertNotNull(catalogUrl);
    URL resolvedURL = FileLocator.resolve(catalogUrl);
    Catalog testCatalog = (Catalog) getCatalog("deletemecatalog", resolvedURL.toString());
    assertNotNull(testCatalog);
    testCatalog.setBase(resolvedURL.toString());
    // CatalogReader.read(testCatalog, resolvedURL.getFile());
    assertNotNull(testCatalog);
    // write catalog
    URL resultsFolder = TestPlugin.getDefault().getBundle().getEntry("/");
    IPath path = new Path(FileLocator.resolve(resultsFolder).getFile());
    final File catalogIOFile = path.append("/deletemecatalog.xml").toFile();
    String resultCatalogFile = catalogIOFile.toURI().toString();
    testCatalog.setLocation(resultCatalogFile);
    // write catalog
    testCatalog.save();
    IWorkspaceRunnable deleteOp = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            try {
                catalogIOFile.delete();
            } catch (Exception e) {
                assertTrue("exception thrown when trying to delete catalog", false);
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(deleteOp, null);
    assertFalse("catalog file was not deleted", catalogIOFile.exists());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPath(org.eclipse.core.runtime.IPath) File(java.io.File) URL(java.net.URL) INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) Catalog(org.eclipse.wst.xml.core.internal.catalog.Catalog) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

Catalog (org.eclipse.wst.xml.core.internal.catalog.Catalog)8 URL (java.net.URL)6 INextCatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog)6 List (java.util.List)4 ICatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)4 ICatalogEntry (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry)4 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 File (java.io.File)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Point (org.eclipse.swt.graphics.Point)1 ICatalogElement (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement)1