~ubuntu-branches/ubuntu/utopic/jing-trang/utopic

« back to all changes in this revision

Viewing changes to mod/catalog/src/test/com/thaiopensource/resolver/catalog/CatalogResolverTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Thibault
  • Date: 2009-09-01 15:53:03 UTC
  • Revision ID: james.westby@ubuntu.com-20090901155303-2kweef05h5v9j3ni
Tags: upstream-20090818
ImportĀ upstreamĀ versionĀ 20090818

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.thaiopensource.resolver.catalog;
 
2
 
 
3
import com.thaiopensource.resolver.Input;
 
4
import com.thaiopensource.resolver.Resolver;
 
5
import com.thaiopensource.resolver.ResolverException;
 
6
import com.thaiopensource.resolver.xml.ExternalIdentifier;
 
7
import com.thaiopensource.resolver.xml.sax.SAXResolver;
 
8
import org.testng.Assert;
 
9
import org.testng.annotations.Test;
 
10
 
 
11
import java.io.IOException;
 
12
import java.util.ArrayList;
 
13
import java.util.List;
 
14
 
 
15
/**
 
16
 * Tests CatalogResolver.
 
17
 */
 
18
public class CatalogResolverTest {
 
19
  @Test
 
20
  public void testResolve() throws IOException, ResolverException {
 
21
    List<String> catalogs = new ArrayList<String>();
 
22
    catalogs.add(resourceUri("catalog.xml"));
 
23
    Resolver resolver = new CatalogResolver(catalogs, new SAXResolver(null));
 
24
    ExternalIdentifier xid = new ExternalIdentifier("foo.xml", "http://www.example.com/index.html", "The Great Foo");
 
25
    Input input = new Input();
 
26
    resolver.resolve(xid, input);
 
27
    Assert.assertEquals(input.getUri(), "http://www.example.com/bar.xml");
 
28
  }
 
29
 
 
30
  static String resourceUri(String fileName) {
 
31
    String className = CatalogResolverTest.class.getName();
 
32
    int dotIndex = className.lastIndexOf('.');
 
33
    String resourceName = className.substring(0, dotIndex + 1).replace('.', '/') + fileName;
 
34
    return CatalogResolverTest.class.getClassLoader().getResource(resourceName).toString();
 
35
  }
 
36
}