public Resource getParent() { if (getPath().equals("/")) { return null; } StringBuilder parentPath = new StringBuilder(); parentPath.append("/"); for (int i = 1; i < parts.length - 1; i++) { parentPath .append(parts[i]).append("/"); } return new Resource(parentPath.toString()); }
public Resource getParent() { if (getPath().equals("/")) { return null; } StringBuilder parentPath = new StringBuilder(); parentPath.append("/"); for (int i = 1; i < parts.length - 1; i++) { parentPath .append(parts[i]).append("/"); } return new Resource(parentPath.toString()); }
private void copyResources(Source resourceSource) { for (Entry<String, Resource> resourceToCopy : resourceToCopyMap.entrySet()) { String sourcePath = resourceToCopy.getKey(); Resource targetResource = resourceToCopy.getValue(); try { InputStream inputStream = resourceSource.createInputStream(new Resource(sourcePath)); target.copyTo(targetResource, inputStream); } catch (IOException e) { throw new RuntimeException("Failed to copy " + sourcePath + " to target " + targetResource, e); } } }
private void copyResources(Source resourceSource) { for (Entry<String, Resource> resourceToCopy : resourceToCopyMap.entrySet()) { String sourcePath = resourceToCopy.getKey(); Resource targetResource = resourceToCopy.getValue(); try { InputStream inputStream = resourceSource.createInputStream(new Resource(sourcePath)); target.copyTo(targetResource, inputStream); } catch (IOException e) { throw new RuntimeException("Failed to copy " + sourcePath + " to target " + targetResource, e); } } }
public static Resource toSpecificationResource(FixtureDeclarations fixtureDeclarations, String specificationSuffix) { String slashedClassName = fixtureDeclarations.getFixtureClass().getName().replaceAll("\\.", "/"); String fixturePath = removeSuffixFromFixtureName(slashedClassName); String resourcePath = "/" + fixturePath + "." + specificationSuffix; return new Resource(resourcePath); }
public static Resource toSpecificationResource(FixtureDeclarations fixtureDeclarations, String specificationSuffix) { String slashedClassName = fixtureDeclarations.getFixtureClass().getName().replaceAll("\\.", "/"); String fixturePath = removeSuffixFromFixtureName(slashedClassName); String resourcePath = "/" + fixturePath + "." + specificationSuffix; return new Resource(resourcePath); }
private InputStream copySourceHtml(Resource resource, InputStream inputStream) throws IOException { Resource sourceHtmlResource = new Resource(resource.getPath() + ".html"); System.out.println(SimpleFormatter.format("[Source: %s]", copySourceHtmlTarget.resolvedPathFor(sourceHtmlResource))); String html = asString(inputStream); copySourceHtmlTarget.write(sourceHtmlResource, html); inputStream = new ByteArrayInputStream(html.getBytes("UTF-8")); return inputStream; } }
private InputStream copySourceHtml(Resource resource, InputStream inputStream) throws IOException { Resource sourceHtmlResource = new Resource(resource.getPath() + ".html"); System.out.println(SimpleFormatter.format("[Source: %s]", copySourceHtmlTarget.resolvedPathFor(sourceHtmlResource))); String html = asString(inputStream); copySourceHtmlTarget.write(sourceHtmlResource, html); inputStream = new ByteArrayInputStream(html.getBytes("UTF-8")); return inputStream; } }
private void createResourceInTarget() { try { target.copyTo(new Resource("/resource/my.txt"), new ByteArrayInputStream("success".getBytes())); } catch (IOException e) { e.printStackTrace(); } } }
private Resource rename(Resource resource) { return new Resource(resource.getPath().replaceFirst("\\..*$", "\\." + suffix)); } }
public boolean isCopied(String expectedResource) { if (!expectedResource.startsWith("/")) { expectedResource = "/" + expectedResource; } return testRig.hasCopiedResource(new Resource(expectedResource)); } }
private ProcessingResult process(String htmlHead, String htmlFragment, Object fixture) { testRig = new TestRig(); ProcessingResult result = testRig .withFixture(fixture) .withResource(new Resource("/resources.css"), "") .withResource(new Resource("/resources/test/resources.js"), "") .withResource(new Resource("/resources/test/resources.txt"), "") .withResource(new Resource("/resources/test/resources with space.txt"), "") .withResource(new Resource("/resources/test/subfolder/resources with space.js"), "") .withResource(new Resource("/resources/test/../../resources.css"), "") .processFragment("/resources/test/ResourcesTest.html", htmlHead, htmlFragment); return result; }
public Iterable<String> getResources() { List<String> resources = new ArrayList<String>(); List<Resource> resourceList = testRig.getCopiedResources(); for (Resource resource : resourceList) { resources.add(new Resource("/resources/test/ResourcesTest.html").getRelativePath(resource)); } return resources; }
private Element createBreadcrumbElement(Resource documentResource, Resource indexPageResource, SpecificationConverter specificationConverter) throws IOException { String breadcrumbWording = getBreadcrumbWordingForResource(indexPageResource, specificationConverter); Element a = new Element("a"); Resource indexPageAsHtmlResource = new Resource(indexPageResource.getPath().replaceFirst("\\..*$", "\\.html")); a.addAttribute("href", documentResource.getRelativePath(indexPageAsHtmlResource)); a.appendText(breadcrumbWording); return a; }
private Element createBreadcrumbElement(Resource documentResource, Resource indexPageResource, SpecificationConverter specificationConverter) throws IOException { String breadcrumbWording = getBreadcrumbWordingForResource(indexPageResource, specificationConverter); Element a = new Element("a"); Resource indexPageAsHtmlResource = new Resource(indexPageResource.getPath().replaceFirst("\\..*$", "\\.html")); a.addAttribute("href", documentResource.getRelativePath(indexPageAsHtmlResource)); a.appendText(breadcrumbWording); return a; }
@Test public void failsWithIOExceptionOnCreateInputStreamWithMissingResource() throws Exception { try { source.createInputStream(new Resource(MISSING_RESOURCE_NAME)); fail("Expected IOException"); } catch (IOException e) { assertThat(e.getMessage(), containsString("not found")); assertThat(e.getMessage(), containsString(SimpleFormatter.format("[%s: %s]", EXPECTED_SOURCE_NAME, MISSING_RESOURCE_NAME))); } } }
@Test public void logsNameOfErroneousHtmlFileOnParseError() { stubSource.addResource(BAD_PACKAGE_RESOURCE_NAME, ERRONEOUS_HTML); SpecificationProcessingEvent event = new SpecificationProcessingEvent(new Resource(BAD_SPEC_RESOURCE_NAME), null); renderer.afterProcessingSpecification(event); String logMessage = systemErrRule.getLog(); assertThat(logMessage, containsString("Failed to parse XML document")); assertThat(logMessage, containsString(SimpleFormatter.format("[%s: %s]", EXPECTED_SOURCE_NAME, BAD_PACKAGE_RESOURCE_NAME))); }
@Test public void createsBodyIfNoneExists() { stubSource.addResource(PACKAGE_RESOURCE_NAME, GOOD_HTML); Element rootElement = new Element("html"); SpecificationProcessingEvent event = new SpecificationProcessingEvent(new Resource(SPEC_RESOURCE_NAME), new org.concordion.api.Element(rootElement)); renderer.afterProcessingSpecification(event); String logMessage = systemErrRule.getLog(); assertThat(logMessage, is("")); assertThat(rootElement.getChildElements("body").size(), is(1)); }
@Test public void includesSourceAndResourceNameOnFailure() throws Exception { try { stubSource.addResource(SPEC_RESOURCE_NAME, ERRONEOUS_HTML); reader.readSpecification(new Resource(SPEC_RESOURCE_NAME)); fail("Expected ParsingException"); } catch (ParsingException e) { assertThat(e.getMessage(), containsString("Failed to parse XML document")); assertThat(e.getMessage(), containsString(SimpleFormatter.format("[%s: %s]", EXPECTED_SOURCE_NAME, SPEC_RESOURCE_NAME))); } } }
public String processFragment(String fragment, String actualData) throws Exception { users = parse(actualData); Document document = new TestRig() .withFixture(this) .withResource(new Resource("/spec/concordion/common/command/verifyRows/strategies/toggle_html.js"), "") .withResource(new Resource("/spec/concordion/common/command/verifyRows/strategies/toggle_html.css"), "") .processFragment(fragment) .getXOMDocument(); String xml = document.getRootElement().query("//table").get(0).toXML(); return xml; }