Page History

Axis1UtilTest

Seiji Sogabe edited this page on 16 Apr

Clone this wiki locally

    @Test(expected = IllegalArgumentException.class)
    public void testResolveFilePathNull() throws Exception {
        String uri = null;

        Axis1Utils.resolveFilePath(uri);

        fail();
    }

    @Test
    public void testResolveFilePathNotFile() throws Exception {
        String uri = "http://www.nttcom.co.jp";

        String answer = Axis1Utils.resolveFilePath(uri);

        assertThat(answer, nullValue());
    }

    @Test
    public void testResolveFilePathAbsolute() throws Exception {
        String uri = "file:" + new File("src/test/resources/test1.wsdl").getCanonicalPath();

        String answer = Axis1Utils.resolveFilePath(uri);

        assertThat(answer, nullValue());
    }

    @Test
    public void testResolveFilePathOutside() throws Exception {
        String uri = "file:../Component.Direct/src/test/resources/log4j.xml";

        String answer = Axis1Utils.resolveFilePath(uri);

        assertThat(answer, nullValue());
    }

    @Test
    public void testResolveFilePathNotExists() throws Exception {
        String uri = "file:notExists.wsdl";

        String answer = Axis1Utils.resolveFilePath(uri);

        assertThat(answer, nullValue());
    }

    @Test
    public void testResolveFilePathSimple() throws Exception {
        String uri = "file:pom.xml";

        String answer = Axis1Utils.resolveFilePath(uri);

        String expected = FileUtil.normalizePath("pom.xml");
        assertThat(answer, is(expected));
    }

    @Test
    public void testResolveFilePath() throws Exception {
        String uri = "file:src/test/resources/test1.wsdl";

        String answer = Axis1Utils.resolveFilePath(uri);

        String expected = FileUtil.normalizePath("src/test/resources/test1.wsdl");
        assertThat(answer, is(expected));
    }

    @Test
    public void testResolveFilePathWindows() throws Exception {
        String uri = "file:src\\test\\resources\\test1.wsdl";

        String answer = Axis1Utils.resolveFilePath(uri);

        String expected = FileUtil.normalizePath("src/test/resources/test1.wsdl");
        assertThat(answer, is(expected));
    }

    @Test
    public void testResolveFilePathNotCanonical() throws Exception {
        String uri = "file:src/test/../test/./resources/test1.wsdl";

        String answer = Axis1Utils.resolveFilePath(uri);

        String expected = FileUtil.normalizePath("src/test/resources/test1.wsdl");
        assertThat(answer, is(expected));
    }


    @Test(expected = IllegalArgumentException.class)
    public void testResolveClassPathNull() throws Exception {
        String uri = null;

        Axis1Utils.resolveClassPath(uri);

        fail();
    }

    @Test
    public void testResolveClassPathNotClass() throws Exception {
        String uri = "http://www.nttcom.co.jp";

        String answer = Axis1Utils.resolveClassPath(uri);

        assertThat(answer, nullValue());
    }

    @Test
    public void testResolveClassPathNotExists() throws Exception {
        String uri = "classpath:jp/co/nttcom/eai/component/axis1/noExists.wsdl";

        String answer = Axis1Utils.resolveClassPath(uri);

        assertThat(answer, nullValue());
    }

    @Test
    public void testResolveClassPath() throws Exception {
        String uri = "classpath:jp/co/nttcom/eai/component/axis1/test3.wsdl";

        String answer = Axis1Utils.resolveClassPath(uri);

        String expected = new File("target/test-classes/jp/co/nttcom/eai/component/axis1/test3.wsdl").getCanonicalPath();
        expected = FileUtil.normalizePath(expected);

        assertThat(answer, is(expected));
    }

    @Test
    public void testResolveClassWisndowsSeparator() throws Exception {
        String uri = "classpath:jp\\co\\nttcom\\eai\\component\\axis1\\test3.wsdl";

        String answer = Axis1Utils.resolveClassPath(uri);

        String expected = new File("target/test-classes/jp/co/nttcom/eai/component/axis1/test3.wsdl").getCanonicalPath();
        expected = FileUtil.normalizePath(expected);

        assertThat(answer, is(expected));
    }

    @Test(expected = IllegalArgumentException.class)
    public void testResolvePath() throws Exception {
        String uri = null;

        String answer = Axis1Utils.resolveClassPath(uri);

        fail();
    }

    @Test
    public void testResolvePathNoScheme() throws Exception {
        String uri = "test1.wsdl";

        String answer = Axis1Utils.resolveClassPath(uri);

        assertThat(answer, nullValue());
    }

    @Test
    public void testResolveSchemeFile() throws Exception {
        String uri = "file:src/test/resources/test1.wsdl";

        String answer = Axis1Utils.resolvePath(uri);

        String expected = FileUtil.normalizePath("src/test/resources/test1.wsdl");
        assertThat(answer, is(expected));
    }

    @Test
    public void testResolveSchemeClass() throws Exception {
        String uri = "classpath:test1.wsdl";

        String answer = Axis1Utils.resolvePath(uri);

        String expected = FileUtil.normalizePath(
                new File("target/test-classes/test1.wsdl").getCanonicalPath());
        assertThat(answer, is(expected));
    }

    @Test
    public void testResolveSchemeHttp() throws Exception {
        String uri = "http://www.nttcom.co.jp";

        String answer = Axis1Utils.resolvePath(uri);

        assertThat(answer, nullValue());
    }

    private static final Logger LOG = LoggerFactory.getLogger(Axis1Utils.class);