Browse Source

Added tests for AFPResourceAccessor


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1371702 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-2_0
Mehdi Houshmand 11 years ago
parent
commit
f7b41bf07e
1 changed files with 84 additions and 0 deletions
  1. 84
    0
      test/java/org/apache/fop/afp/util/AFPResourceAccessorTestCase.java

+ 84
- 0
test/java/org/apache/fop/afp/util/AFPResourceAccessorTestCase.java View File

@@ -0,0 +1,84 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.fop.afp.util;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import org.apache.fop.apps.io.InternalResourceResolver;

public class AFPResourceAccessorTestCase {

private InternalResourceResolver nullBaseResourceResolver;
private InternalResourceResolver absoluteBaseResourceResolver;
private InternalResourceResolver relativeBaseResourceResolver;
private final URI absoluteBaseURI = URI.create("this:///purely.for.testing");
private final URI relativeBaseURI = URI.create("./this.is.purely.for.testing");
private AFPResourceAccessor nullBaseURISut;
private AFPResourceAccessor absoluteBaseURISut;
private AFPResourceAccessor relativeBaseURISut;

@Before
public void setUp() {
nullBaseResourceResolver = mock(InternalResourceResolver.class);
absoluteBaseResourceResolver = mock(InternalResourceResolver.class);
relativeBaseResourceResolver = mock(InternalResourceResolver.class);
nullBaseURISut = new AFPResourceAccessor(nullBaseResourceResolver);
absoluteBaseURISut = new AFPResourceAccessor(absoluteBaseResourceResolver,
absoluteBaseURI.toASCIIString());
relativeBaseURISut = new AFPResourceAccessor(relativeBaseResourceResolver,
relativeBaseURI.toASCIIString());
}

@Test
public void testCreateInputStream() throws IOException, URISyntaxException {
URI testURI = URI.create("test");
nullBaseURISut.createInputStream(testURI);
verify(nullBaseResourceResolver).getResource(testURI);

absoluteBaseURISut.createInputStream(testURI);
verify(absoluteBaseResourceResolver).getResource(getActualURI(absoluteBaseURI, testURI));

relativeBaseURISut.createInputStream(testURI);
verify(relativeBaseResourceResolver).getResource(getActualURI(relativeBaseURI, testURI));
}

private URI getActualURI(URI baseURI, URI testURI) throws URISyntaxException {
return InternalResourceResolver.getBaseURI(baseURI.toASCIIString()).resolve(testURI);
}

@Test
public void testResolveURI() throws URISyntaxException {
String testURI = "anotherTestURI";
assertEquals(URI.create("./" + testURI), nullBaseURISut.resolveURI(testURI));

assertEquals(getActualURI(absoluteBaseURI, URI.create(testURI)),
absoluteBaseURISut.resolveURI(testURI));

assertEquals(getActualURI(relativeBaseURI, URI.create(testURI)),
relativeBaseURISut.resolveURI(testURI));
}
}

Loading…
Cancel
Save