use of com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource in project service-api by reportportal.
the class StopLaunchHandlerImpl method stopLaunch.
@Override
public OperationCompletionRS stopLaunch(Long launchId, FinishExecutionRQ finishLaunchRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
Launch launch = launchRepository.findById(launchId).orElseThrow(() -> new ReportPortalException(ErrorType.LAUNCH_NOT_FOUND, launchId));
validateRoles(launch, user, projectDetails);
validate(launch, finishLaunchRQ);
launch = new LaunchBuilder(launch).addDescription(ofNullable(finishLaunchRQ.getDescription()).orElse(ofNullable(launch.getDescription()).orElse("")).concat(LAUNCH_STOP_DESCRIPTION)).addStatus(ofNullable(finishLaunchRQ.getStatus()).orElse(STOPPED.name())).addEndTime(ofNullable(finishLaunchRQ.getEndTime()).orElse(new Date())).addAttributes(finishLaunchRQ.getAttributes()).addAttribute(new ItemAttributeResource("status", "stopped")).get();
launchRepository.save(launch);
testItemRepository.interruptInProgressItems(launch.getId());
messageBus.publishActivity(new LaunchFinishForcedEvent(TO_ACTIVITY_RESOURCE.apply(launch), user.getUserId(), user.getUsername()));
eventPublisher.publishEvent(new LaunchFinishedEvent(TO_ACTIVITY_RESOURCE.apply(launch), user.getUserId(), user.getUsername()));
return new OperationCompletionRS("Launch with ID = '" + launchId + "' successfully stopped.");
}
use of com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource in project service-api by reportportal.
the class TestItemControllerTest method updateTestItemPositive.
@Test
void updateTestItemPositive() throws Exception {
UpdateTestItemRQ rq = new UpdateTestItemRQ();
rq.setDescription("updated");
rq.setAttributes(Sets.newHashSet(new ItemAttributeResource("test", "test")));
mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + "/item/1/update").with(token(oAuthHelper.getDefaultToken())).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(rq))).andExpect(status().isOk());
}
use of com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource in project service-api by reportportal.
the class TestItemControllerTest method bulkUpdateItemAttributes.
@Test
void bulkUpdateItemAttributes() throws Exception {
BulkInfoUpdateRQ request = new BulkInfoUpdateRQ();
List<Long> launchIds = Arrays.asList(1L, 2L, 3L, 4L, 5L, 6L);
request.setIds(launchIds);
BulkInfoUpdateRQ.Description description = new BulkInfoUpdateRQ.Description();
description.setAction(BulkInfoUpdateRQ.Action.CREATE);
String comment = "created";
description.setComment(comment);
request.setDescription(description);
UpdateItemAttributeRQ updateItemAttributeRQ = new UpdateItemAttributeRQ();
updateItemAttributeRQ.setAction(BulkInfoUpdateRQ.Action.UPDATE);
updateItemAttributeRQ.setFrom(new ItemAttributeResource("testKey", "testValue"));
updateItemAttributeRQ.setTo(new ItemAttributeResource("updatedKey", "updatedValue"));
request.setAttributes(Lists.newArrayList(updateItemAttributeRQ));
mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + "/item/info").with(token(oAuthHelper.getDefaultToken())).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(request))).andExpect(status().isOk());
List<TestItem> items = testItemRepository.findAllById(launchIds);
items.forEach(it -> testItemRepository.refresh(it));
items.forEach(it -> {
assertTrue(it.getAttributes().stream().noneMatch(attr -> "testKey".equals(attr.getKey()) && attr.getValue().equals("testValue") && !attr.isSystem()));
assertTrue(it.getAttributes().stream().anyMatch(attr -> "updatedKey".equals(attr.getKey()) && attr.getValue().equals("updatedValue") && !attr.isSystem()));
assertEquals(comment, it.getDescription());
});
}
use of com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource in project service-api by reportportal.
the class TestItemControllerTest method bulkDeleteAttributes.
@Test
void bulkDeleteAttributes() throws Exception {
BulkInfoUpdateRQ request = new BulkInfoUpdateRQ();
List<Long> launchIds = Arrays.asList(1L, 2L, 3L, 4L, 5L, 6L);
request.setIds(launchIds);
BulkInfoUpdateRQ.Description description = new BulkInfoUpdateRQ.Description();
description.setAction(BulkInfoUpdateRQ.Action.CREATE);
String comment = "created";
description.setComment(comment);
request.setDescription(description);
UpdateItemAttributeRQ updateItemAttributeRQ = new UpdateItemAttributeRQ();
updateItemAttributeRQ.setAction(BulkInfoUpdateRQ.Action.DELETE);
updateItemAttributeRQ.setFrom(new ItemAttributeResource("testKey", "testValue"));
request.setAttributes(Lists.newArrayList(updateItemAttributeRQ));
mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + "/item/info").with(token(oAuthHelper.getDefaultToken())).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(request))).andExpect(status().isOk());
List<TestItem> items = testItemRepository.findAllById(launchIds);
items.forEach(it -> testItemRepository.refresh(it));
items.forEach(it -> {
assertTrue(it.getAttributes().stream().noneMatch(attr -> "testKey".equals(attr.getKey()) && attr.getValue().equals("testValue") && !attr.isSystem()));
assertEquals(comment, it.getDescription());
});
}
use of com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource in project service-api by reportportal.
the class TestItemControllerTest method bulkCreateAttributes.
@Test
void bulkCreateAttributes() throws Exception {
BulkInfoUpdateRQ request = new BulkInfoUpdateRQ();
List<Long> launchIds = Arrays.asList(1L, 2L, 3L, 4L, 5L, 6L);
request.setIds(launchIds);
BulkInfoUpdateRQ.Description description = new BulkInfoUpdateRQ.Description();
description.setAction(BulkInfoUpdateRQ.Action.UPDATE);
String comment = "updated";
description.setComment(comment);
request.setDescription(description);
UpdateItemAttributeRQ updateItemAttributeRQ = new UpdateItemAttributeRQ();
updateItemAttributeRQ.setAction(BulkInfoUpdateRQ.Action.CREATE);
updateItemAttributeRQ.setTo(new ItemAttributeResource("createdKey", "createdValue"));
request.setAttributes(Lists.newArrayList(updateItemAttributeRQ));
mockMvc.perform(put(DEFAULT_PROJECT_BASE_URL + "/item/info").with(token(oAuthHelper.getDefaultToken())).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(request))).andExpect(status().isOk());
List<TestItem> items = testItemRepository.findAllById(launchIds);
items.forEach(it -> testItemRepository.refresh(it));
items.forEach(it -> {
assertTrue(it.getAttributes().stream().anyMatch(attr -> "createdKey".equals(attr.getKey()) && attr.getValue().equals("createdValue") && !attr.isSystem()));
assertTrue(it.getDescription().length() > comment.length() && it.getDescription().contains(comment));
});
}
Aggregations