use of com.epam.ta.reportportal.ws.model.launch.StartLaunchRS in project service-api by reportportal.
the class StartLaunchHandlerImpl method startLaunch.
@Override
@Transactional
public StartLaunchRS startLaunch(ReportPortalUser user, ReportPortalUser.ProjectDetails projectDetails, StartLaunchRQ request) {
validateRoles(projectDetails, request);
final Launch savedLaunch = Optional.of(request.isRerun()).filter(Boolean::booleanValue).map(rerun -> rerunHandler.handleLaunch(request, projectDetails.getProjectId(), user)).orElseGet(() -> {
Launch launch = new LaunchBuilder().addStartRQ(request).addAttributes(request.getAttributes()).addProject(projectDetails.getProjectId()).addUserId(user.getUserId()).get();
launchRepository.save(launch);
launchRepository.refresh(launch);
return launch;
});
eventPublisher.publishEvent(new StartLaunchEvent(savedLaunch.getId()));
messageBus.publishActivity(new LaunchStartedEvent(TO_ACTIVITY_RESOURCE.apply(savedLaunch), user.getUserId(), user.getUsername()));
StartLaunchRS response = new StartLaunchRS();
response.setId(savedLaunch.getUuid());
response.setNumber(savedLaunch.getNumber());
return response;
}
use of com.epam.ta.reportportal.ws.model.launch.StartLaunchRS in project allure-java by reportportal.
the class TestUtils method mockLaunch.
@SuppressWarnings("unchecked")
public static <T extends Collection<String>> void mockLaunch(ReportPortalClient client, String launchUuid, String suiteUuid, Collection<Pair<String, T>> testSteps) {
when(client.startLaunch(any())).thenReturn(createMaybe(new StartLaunchRS(launchUuid, 1L)));
Maybe<ItemCreatedRS> suiteMaybe = createMaybe(new ItemCreatedRS(suiteUuid, suiteUuid));
when(client.startTestItem(any())).thenReturn(suiteMaybe);
List<Maybe<ItemCreatedRS>> testResponses = testSteps.stream().map(Pair::getKey).map(uuid -> createMaybe(new ItemCreatedRS(uuid, uuid))).collect(Collectors.toList());
Maybe<ItemCreatedRS> first = testResponses.get(0);
Maybe<ItemCreatedRS>[] other = testResponses.subList(1, testResponses.size()).toArray(new Maybe[0]);
when(client.startTestItem(same(suiteUuid), any())).thenReturn(first, other);
testSteps.forEach(test -> {
String testClassUuid = test.getKey();
List<Maybe<ItemCreatedRS>> stepResponses = test.getValue().stream().map(uuid -> createMaybe(new ItemCreatedRS(uuid, uuid))).collect(Collectors.toList());
Maybe<ItemCreatedRS> myFirst = stepResponses.get(0);
Maybe<ItemCreatedRS>[] myOther = stepResponses.subList(1, stepResponses.size()).toArray(new Maybe[0]);
when(client.startTestItem(same(testClassUuid), any())).thenReturn(myFirst, myOther);
new HashSet<>(test.getValue()).forEach(testMethodUuid -> when(client.finishTestItem(same(testMethodUuid), any())).thenReturn(createMaybe(new OperationCompletionRS())));
when(client.finishTestItem(same(testClassUuid), any())).thenReturn(createMaybe(new OperationCompletionRS()));
});
Maybe<OperationCompletionRS> suiteFinishMaybe = createMaybe(new OperationCompletionRS());
when(client.finishTestItem(eq(suiteUuid), any())).thenReturn(suiteFinishMaybe);
when(client.finishLaunch(eq(launchUuid), any())).thenReturn(createMaybe(new OperationCompletionRS()));
}
use of com.epam.ta.reportportal.ws.model.launch.StartLaunchRS in project service-api by reportportal.
the class StartLaunchHandlerImplTest method startLaunch.
@Test
void startLaunch() {
final ReportPortalUser rpUser = getRpUser("test", UserRole.ADMINISTRATOR, ProjectRole.PROJECT_MANAGER, 1L);
StartLaunchRQ startLaunchRQ = new StartLaunchRQ();
startLaunchRQ.setStartTime(new Date());
startLaunchRQ.setName("test");
Launch launch = new Launch();
launch.setId(1L);
when(launchRepository.save(any(Launch.class))).then(a -> {
Launch l = a.getArgument(0);
l.setId(1L);
return l;
}).thenReturn(launch);
final StartLaunchRS startLaunchRS = startLaunchHandlerImpl.startLaunch(rpUser, extractProjectDetails(rpUser, "test_project"), startLaunchRQ);
verify(launchRepository, times(1)).refresh(any(Launch.class));
verify(eventPublisher, times(1)).publishEvent(any());
assertNotNull(startLaunchRS);
}
use of com.epam.ta.reportportal.ws.model.launch.StartLaunchRS in project service-api by reportportal.
the class StartLaunchHandlerAsyncImpl method startLaunch.
@Override
public StartLaunchRS startLaunch(ReportPortalUser user, ReportPortalUser.ProjectDetails projectDetails, StartLaunchRQ request) {
validateRoles(projectDetails, request);
if (request.getUuid() == null) {
request.setUuid(UUID.randomUUID().toString());
}
amqpTemplate.convertAndSend(EXCHANGE_REPORTING, reportingQueueService.getReportingQueueKey(request.getUuid()), request, message -> {
Map<String, Object> headers = message.getMessageProperties().getHeaders();
headers.put(MessageHeaders.REQUEST_TYPE, RequestType.START_LAUNCH);
headers.put(MessageHeaders.USERNAME, user.getUsername());
headers.put(MessageHeaders.PROJECT_NAME, projectDetails.getProjectName());
return message;
});
StartLaunchRS response = new StartLaunchRS();
response.setId(request.getUuid());
return response;
}
use of com.epam.ta.reportportal.ws.model.launch.StartLaunchRS in project agent-java-testNG by reportportal.
the class CallbackReportingIntegrationTest method initMocks.
@BeforeEach
@SuppressWarnings("unchecked")
public void initMocks() {
ReportPortalClient reportPortalClient = mock(ReportPortalClient.class);
when(reportPortalClient.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS("launchUuid", 1L)));
Maybe<ItemCreatedRS> suiteMaybe = Maybe.just(new ItemCreatedRS(suitedUuid, suitedUuid));
when(reportPortalClient.startTestItem(any())).thenReturn(suiteMaybe);
Maybe<ItemCreatedRS> testClassMaybe = Maybe.just(new ItemCreatedRS(testClassUuid, testClassUuid));
when(reportPortalClient.startTestItem(eq(suiteMaybe.blockingGet().getId()), any())).thenReturn(testClassMaybe);
Maybe<ItemCreatedRS> testMethodMaybe = Maybe.just(new ItemCreatedRS(testMethodUuid, testMethodUuid));
when(reportPortalClient.startTestItem(eq(testClassMaybe.blockingGet().getId()), any())).thenReturn(testMethodMaybe);
Maybe<OperationCompletionRS> finishResponse = Maybe.just(new OperationCompletionRS("finished"));
when(reportPortalClient.finishTestItem(eq(testMethodUuid), any())).thenReturn(finishResponse);
when(reportPortalClient.log(any(List.class))).thenReturn(Maybe.just(new BatchSaveOperatingRS()));
when(reportPortalClient.log(any(SaveLogRQ.class))).thenReturn(Maybe.just(new EntryCreatedAsyncRS("logId")));
ListenerParameters params = standardParameters();
params.setCallbackReportingEnabled(true);
final ReportPortal reportPortal = ReportPortal.create(reportPortalClient, params);
CallbackReportingListener.initReportPortal(reportPortal);
}
Aggregations