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

com.testfabrik.webmate.javasdk.testmgmt.spec.ExpeditionComparisonSpec Maven / Gradle / Ivy

There is a newer version: 0.56
Show newest version
package com.testfabrik.webmate.javasdk.testmgmt.spec;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.testfabrik.webmate.javasdk.Tag;
import com.testfabrik.webmate.javasdk.WebmateAPISession;
import com.testfabrik.webmate.javasdk.WebmateApiClientException;
import com.testfabrik.webmate.javasdk.browsersession.ExpeditionSpec;
import com.testfabrik.webmate.javasdk.jobs.WMValueFactory;
import com.testfabrik.webmate.javasdk.testmgmt.ApplicationModelId;
import com.testfabrik.webmate.javasdk.testmgmt.TestExecutionSpecBuilder;
import com.testfabrik.webmate.javasdk.testmgmt.TestMgmtClient;
import com.testfabrik.webmate.javasdk.testmgmt.TestSessionId;
import com.testfabrik.webmate.javasdk.testmgmt.testtypes.StandardTestTypes;

import java.util.List;

/**
 * A TestRun specification for a Test of type "ExpeditionComparison".
 */
public class ExpeditionComparisonSpec extends TestExecutionSpec {

    private ExpeditionSpec referenceSpec;
    private List compareSpecs;

    private ExpeditionComparisonSpec(String executionName, List tags, List models,
                                     List testSessions, ExpeditionSpec referenceSpec,
                                     List compareSpecs) {
            super(executionName, StandardTestTypes.ExpeditionComparison.getTestType(),
                    "Default Expedition Comparison Test", tags, models, testSessions);

            this.referenceSpec = referenceSpec;
            this.compareSpecs = compareSpecs;
    }

    @Override
    public TestMgmtClient.SingleTestRunCreationSpec makeTestRunCreationSpec() {
        return new TestMgmtClient.SingleTestRunCreationSpec(ImmutableMap.of(
                "referenceExpeditionSpec", WMValueFactory.makeExpeditionSpec(referenceSpec),
                "comparisonExpeditionSpecs", WMValueFactory.makeExpeditionSpecList(compareSpecs)
        ));
    }

    /**
     * Builder that can/should be used for creating the specification.
     */
    public static class ExpeditionComparisonCheckBuilder extends TestExecutionSpecBuilder {
        private final String executionName;
        private final ExpeditionSpec referenceSpec;
        private final List compareSpecs;

        private ExpeditionComparisonCheckBuilder(final String executionName, final ExpeditionSpec referenceSpec,
                                                 final List compareSpecs) {
            this.executionName = executionName;
            this.referenceSpec = referenceSpec;
            this.compareSpecs = ImmutableList.copyOf(compareSpecs);
        }

        public static ExpeditionComparisonCheckBuilder builder(final String executionName, final ExpeditionSpec referenceSpec,
                                                         final List compareSpecs) {
            return new ExpeditionComparisonCheckBuilder(executionName, referenceSpec, compareSpecs);
        }

        @Override
        public ExpeditionComparisonSpec build() {
            WebmateAPISession session;
            if (optSession.isPresent()) {
                session = optSession.get();
            } else {
                throw new WebmateApiClientException("Session not available. This is an internal error.");
            }

            List allTestSessionsToAssociate = Lists.newArrayList(Iterables.concat(session.getAssociatedTestSessions(),
                    this.testSessionIds));

            List allModels = Lists.newArrayList(Iterables.concat(session.getAssociatedModels(),
                    this.models));

            List allTags = Lists.newArrayList(Iterables.concat(session.getAssociatedTags(),
                    this.tags));

            return new ExpeditionComparisonSpec(this.executionName, allTags, allModels, allTestSessionsToAssociate, referenceSpec, compareSpecs);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy