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

sft.decorators.Breadcrumb 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.UseCaseResult;

import java.util.List;

public class Breadcrumb 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 .text-center").append("
    " + printFirstUseCase(useCaseResult.useCase,useCaseResult.useCase) + "
"); return parse.toString(); } private String printFirstUseCase(UseCase initialUseCase,UseCase useCaseToBreadcrumb) { String result = ""; if (useCaseToBreadcrumb.parent != null) { result = printFirstUseCase(initialUseCase,useCaseToBreadcrumb.parent); } if(initialUseCase == useCaseToBreadcrumb){ return result + "
  • " + useCaseToBreadcrumb.getName() + "
  • "; }else{ final RelativeHtmlPathResolver relativeHtmlPathResolver = configuration.getReport().pathResolver; final String origin = relativeHtmlPathResolver.getPathOf(initialUseCase.classUnderTest, ".html"); final String target = relativeHtmlPathResolver.getPathOf(useCaseToBreadcrumb.classUnderTest, ".html"); final String pathToUseCaseToBreadcrumb = relativeHtmlPathResolver.getRelativePathToFile(origin, target); return result + "
  • " + useCaseToBreadcrumb.getName() + "
  • "; } } @Override public String applyOnScenario(String result) { throw new RuntimeException("Breadcrumb can't be apply on scenario"); } @Override public String applyOnFixtures(List result, List fixtureCallResuts) { throw new RuntimeException("Breadcrumb can't be apply on scenario"); } @Override public boolean comply(Decorator other) { return other instanceof Breadcrumb; } }




    © 2015 - 2024 Weber Informatics LLC | Privacy Policy