All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sft.decorators.TableOfContent Maven / Gradle / Ivy

There is a newer version: 1.9
Show newest version
/*******************************************************************************
 * Copyright (c) 2013, 2014 Sylvain Lézier.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Sylvain Lézier - initial implementation
 *******************************************************************************/
package sft.decorators;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import sft.DefaultConfiguration;
import sft.UseCase;
import sft.report.RelativeHtmlPathResolver;
import sft.result.FixtureCallResult;
import sft.result.ScenarioResult;
import sft.result.UseCaseResult;

import java.util.List;

public class TableOfContent implements Decorator {

    private DefaultConfiguration configuration;

    @Override
    public Decorator withParameters(String... parameters) {

        return this;
    }

    @Override
    public Decorator withConfiguration(DefaultConfiguration configuration) {
        this.configuration = configuration;
        return this;
    }

    @Override
    public String applyOnUseCase(UseCaseResult useCaseResult, String result) {
        final Document parse = Jsoup.parse(result);
        parse.select(".page-header").after("
"+printUseCase(useCaseResult.useCase, useCaseResult)+"
"); return parse.toString(); } private String printUseCase(UseCase initialUseCase, UseCaseResult useCaseResult) { String result = "
    "; for (UseCaseResult subUseCaseResult : useCaseResult.subUseCaseResults) { final RelativeHtmlPathResolver relativeHtmlPathResolver = configuration.getReport().pathResolver; final String origin = relativeHtmlPathResolver.getPathOf(initialUseCase.classUnderTest, ".html"); final String target = relativeHtmlPathResolver.getPathOf(subUseCaseResult.useCase.classUnderTest, ".html"); final String pathToUseCaseToBreadcrumb = relativeHtmlPathResolver.getRelativePathToFile(origin, target); result += "
  1. " + ""+subUseCaseResult.useCase.getName()+""+ printScenario(subUseCaseResult) + printUseCase(initialUseCase, subUseCaseResult) + "
  2. "; } return result+"
"; } private String printScenario(UseCaseResult useCaseResult) { String result = "
    "; for (ScenarioResult scenarioResult : useCaseResult.scenarioResults) { result += "
  • " + ""+scenarioResult.scenario.getName()+""+ "
  • "; } return result+ "
"; } @Override public String applyOnScenario(String result) { throw new RuntimeException("TableOfContent can't be apply on scenario"); } @Override public String applyOnFixtures(List result, List fixtureCallResuts) { throw new RuntimeException("TableOfContent can't be apply on fixture"); } @Override public boolean comply(Decorator other) { return other instanceof TableOfContent; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy