com.epam.reportportal.service.Launch Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of client-java Show documentation
Show all versions of client-java Show documentation
A application used as an example on how to set up pushing its components to the Central Repository .
The newest version!
/*
* Copyright 2019 EPAM Systems
*
* Licensed 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 com.epam.reportportal.service;
import com.epam.reportportal.listeners.ListenerParameters;
import com.epam.reportportal.service.step.DefaultStepReporter;
import com.epam.reportportal.service.step.StepReporter;
import com.epam.ta.reportportal.ws.model.FinishExecutionRQ;
import com.epam.ta.reportportal.ws.model.FinishTestItemRQ;
import com.epam.ta.reportportal.ws.model.OperationCompletionRS;
import com.epam.ta.reportportal.ws.model.StartTestItemRQ;
import com.epam.ta.reportportal.ws.model.issue.Issue;
import io.reactivex.Maybe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.reflect.Proxy;
import java.util.Set;
import static java.util.Objects.requireNonNull;
/**
* @author Andrei Varabyeu
*/
public abstract class Launch {
private static final ThreadLocal CURRENT_LAUNCH = new InheritableThreadLocal<>();
static final Logger LOGGER = LoggerFactory.getLogger(Launch.class);
private final ListenerParameters parameters;
private final StepReporter stepReporter;
protected final ReportPortalClient client;
Launch(@Nonnull ReportPortalClient reportPortalClient, @Nonnull ListenerParameters listenerParameters, @Nonnull StepReporter reporter) {
parameters = requireNonNull(listenerParameters, "ListenerParameters shouldn't be NULL");
stepReporter = requireNonNull(reporter, "StepReporter shouldn't be NULL");
CURRENT_LAUNCH.set(this);
client = reportPortalClient;
}
Launch(@Nonnull ReportPortalClient reportPortalClient, @Nonnull ListenerParameters listenerParameters) {
parameters = requireNonNull(listenerParameters, "ListenerParameters shouldn't be NULL");
stepReporter = new DefaultStepReporter(this);
CURRENT_LAUNCH.set(this);
client = requireNonNull(reportPortalClient, "ReportPortalClient shouldn't be NULL");
}
@Nonnull
abstract public Maybe start();
/**
* Finishes launch in ReportPortal. Blocks until all items are reported correctly
*
* @param rq Finish RQ
*/
abstract public void finish(final FinishExecutionRQ rq);
/**
* Starts new test item in ReportPortal asynchronously (non-blocking)
*
* @param rq Start RQ
* @return Test Item ID promise
*/
@Nonnull
abstract public Maybe startTestItem(final StartTestItemRQ rq);
/**
* Starts new test item in ReportPortal asynchronously (non-blocking)
*
* @param rq Start RQ
* @param parentId Parent ID
* @return Test Item ID promise
*/
@Nonnull
abstract public Maybe startTestItem(final Maybe parentId, final StartTestItemRQ rq);
/**
* Starts new test item in ReportPortal in respect of provided retry item ID.
*
* @param parentId promise of ID of parent
* @param retryOf previous item ID promise
* @param rq promise of ID of request
* @return Promise of Test Item ID
*/
@Nonnull
abstract public Maybe startTestItem(final Maybe parentId, final Maybe retryOf, final StartTestItemRQ rq);
/**
* Finishes Test Item in ReportPortal. Non-blocking. Schedules finish after success of all child items
*
* @param itemId Item ID promise
* @param rq Finish request
* @return Promise of Test Item finish response
*/
@Nonnull
abstract public Maybe finishTestItem(Maybe itemId, final FinishTestItemRQ rq);
@Nonnull
public ListenerParameters getParameters() {
// Sticking any thread which makes this call to the current Launch to be able to use Step Reporter and other methods
CURRENT_LAUNCH.set(this);
return parameters;
}
/**
* Returns a current launch in a link to the current thread.
*
* @return launch instance
*/
@Nullable
public static Launch currentLaunch() {
return CURRENT_LAUNCH.get();
}
/**
* Returns Nested Step reporter for the current launch.
*
* @return a {@link StepReporter} instance
*/
@Nonnull
public StepReporter getStepReporter() {
return stepReporter;
}
/**
* Returns Report Portal client for the launch.
*
* @return a {@link ReportPortalClient} instance
*/
@Nonnull
public ReportPortalClient getClient() {
return client;
}
/**
* Returns current launch UUID {@link Maybe}, empty if the launch is not started.
*
* @return Launch UUID promise
*/
@Nonnull
public abstract Maybe getLaunch();
/**
* Implementation for disabled Reporting
*/
public static final Launch NOOP_LAUNCH = new Launch((ReportPortalClient) Proxy.newProxyInstance(Launch.class.getClassLoader(),
new Class[] { ReportPortalClient.class },
new DummyReportPortalClientHandler()
),
new ListenerParameters(),
StepReporter.NOOP_STEP_REPORTER
) {
@Override
@Nonnull
public Maybe start() {
return Maybe.empty();
}
@Override
public void finish(FinishExecutionRQ rq) {
}
@Override
@Nonnull
public Maybe startTestItem(StartTestItemRQ rq) {
return Maybe.empty();
}
@Override
@Nonnull
public Maybe startTestItem(Maybe parentId, StartTestItemRQ rq) {
return Maybe.empty();
}
@Override
@Nonnull
public Maybe startTestItem(Maybe parentId, Maybe retryOf, StartTestItemRQ rq) {
return Maybe.empty();
}
@Override
@Nonnull
public Maybe finishTestItem(Maybe itemId, FinishTestItemRQ rq) {
return Maybe.empty();
}
@Nonnull
@Override
public Maybe getLaunch() {
return Maybe.empty();
}
};
/**
* An Issue to remove 'To Investigate' mark from a skipped/failed Test Item
*/
public static final Issue NOT_ISSUE = new Issue() {
public static final String NOT_ISSUE = "NOT_ISSUE";
@Override
public String getIssueType() {
return NOT_ISSUE;
}
@Override
public void setComment(String comment) {
throw new UnsupportedOperationException();
}
@Override
public void setIssueType(String type) {
throw new UnsupportedOperationException();
}
@Override
public void setAutoAnalyzed(boolean autoAnalyzed) {
throw new UnsupportedOperationException();
}
@Override
public void setIgnoreAnalyzer(boolean ignoreAnalyzer) {
throw new UnsupportedOperationException();
}
@Override
public void setExternalSystemIssues(Set externalSystemIssues) {
throw new UnsupportedOperationException();
}
};
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy