use of com.epam.ta.reportportal.entity.ItemAttribute in project service-api by reportportal.
the class TestItemBuilderTest method addResultsTest.
@Test
void addResultsTest() {
TestItem item = new TestItem();
final LocalDateTime now = LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS);
item.setStartTime(now);
final TestItemResults itemResults = new TestItemResults();
itemResults.setEndTime(now.plusSeconds(120));
item.setItemResults(itemResults);
final ItemAttribute systemAttribute = new ItemAttribute("key", "val", true);
item.setAttributes(Sets.newHashSet(new ItemAttribute("key", "val", false), systemAttribute));
final TestItem resultItem = new TestItemBuilder(item).addTestItemResults(itemResults).addStatus(StatusEnum.PASSED).overwriteAttributes(Sets.newHashSet(new ItemAttributeResource("k", "v"))).get();
assertEquals(120, resultItem.getItemResults().getDuration(), 0.1);
assertEquals(StatusEnum.PASSED, resultItem.getItemResults().getStatus());
assertThat(resultItem.getAttributes()).containsExactlyInAnyOrder(systemAttribute, new ItemAttribute("k", "v", false));
}
use of com.epam.ta.reportportal.entity.ItemAttribute in project service-api by reportportal.
the class AbstractFinishHierarchyHandler method finishItem.
private void finishItem(TestItem testItem, StatusEnum status, LocalDateTime endTime) {
testItem.getItemResults().setStatus(status);
testItem.getItemResults().setEndTime(endTime);
ItemAttribute interruptedAttribute = new ItemAttribute(ATTRIBUTE_KEY_STATUS, ATTRIBUTE_VALUE_INTERRUPTED, false);
interruptedAttribute.setTestItem(testItem);
testItem.getAttributes().add(interruptedAttribute);
if (testItem.isHasRetries()) {
retryHandler.finishRetries(testItem.getItemId(), JStatusEnum.valueOf(status.name()), endTime);
}
}
use of com.epam.ta.reportportal.entity.ItemAttribute in project service-api by reportportal.
the class UpdateTestItemHandlerImplTest method shouldNotCreateInitialStatusAttribute.
@Test
void shouldNotCreateInitialStatusAttribute() {
ReportPortalUser user = getRpUser("user", UserRole.ADMINISTRATOR, ProjectRole.PROJECT_MANAGER, 1L);
UpdateTestItemRQ rq = new UpdateTestItemRQ();
rq.setStatus("PASSED");
long itemId = 1L;
TestItem item = new TestItem();
item.setItemId(itemId);
item.setHasChildren(false);
item.setType(TestItemTypeEnum.STEP);
item.setAttributes(Sets.newHashSet(new ItemAttribute(INITIAL_STATUS_ATTRIBUTE_KEY, "passed", true)));
TestItemResults itemResults = new TestItemResults();
itemResults.setStatus(StatusEnum.FAILED);
item.setItemResults(itemResults);
Launch launch = new Launch();
launch.setId(2L);
item.setLaunchId(launch.getId());
when(testItemService.getEffectiveLaunch(item)).thenReturn(launch);
when(itemRepository.findById(itemId)).thenReturn(Optional.of(item));
doNothing().when(messageBus).publishActivity(any());
when(statusChangingStrategyMapping.get(StatusEnum.PASSED)).thenReturn(statusChangingStrategy);
doNothing().when(statusChangingStrategy).changeStatus(item, StatusEnum.PASSED, user);
handler.updateTestItem(extractProjectDetails(user, "test_project"), itemId, rq, user);
assertTrue(item.getAttributes().stream().anyMatch(attribute -> INITIAL_STATUS_ATTRIBUTE_KEY.equalsIgnoreCase(attribute.getKey()) && StatusEnum.PASSED.getExecutionCounterField().equalsIgnoreCase("passed")));
}
use of com.epam.ta.reportportal.entity.ItemAttribute in project service-api by reportportal.
the class UpdateTestItemHandlerImpl method checkInitialStatusAttribute.
private void checkInitialStatusAttribute(TestItem item, UpdateTestItemRQ request) {
Runnable addInitialStatusAttribute = () -> {
ItemAttribute initialStatusAttribute = new ItemAttribute(INITIAL_STATUS_ATTRIBUTE_KEY, item.getItemResults().getStatus().getExecutionCounterField(), true);
initialStatusAttribute.setTestItem(item);
item.getAttributes().add(initialStatusAttribute);
};
Consumer<ItemAttribute> removeManuallyStatusAttributeIfSameAsInitial = statusAttribute -> extractAttributeResource(request.getAttributes(), MANUALLY_CHANGED_STATUS_ATTRIBUTE_KEY).filter(it -> it.getValue().equalsIgnoreCase(statusAttribute.getValue())).ifPresent(it -> request.getAttributes().remove(it));
extractAttribute(item.getAttributes(), INITIAL_STATUS_ATTRIBUTE_KEY).ifPresentOrElse(removeManuallyStatusAttributeIfSameAsInitial, addInitialStatusAttribute);
}
use of com.epam.ta.reportportal.entity.ItemAttribute in project service-api by reportportal.
the class LaunchResourceAttributeUpdaterTest method shouldUpdate.
@Test
void shouldUpdate() {
final LaunchResource launchResource = new LaunchResource();
final List<ItemAttribute> attributes = List.of(new ItemAttribute("k1", "v1", false), new ItemAttribute("k2", "v2", false));
launchResourceAttributeUpdater.handle(launchResource, attributes);
final Set<ItemAttributeResource> resourceAttributes = launchResource.getAttributes();
Assertions.assertEquals(2, resourceAttributes.size());
final Map<String, List<ItemAttributeResource>> mapping = resourceAttributes.stream().collect(groupingBy(ItemAttributeResource::getKey));
final ItemAttributeResource firstResource = mapping.get("k1").get(0);
final ItemAttributeResource secondResource = mapping.get("k2").get(0);
final ItemAttribute firstAttribute = attributes.get(0);
final ItemAttribute secondAttribute = attributes.get(1);
shouldEqual(firstAttribute, firstResource);
shouldEqual(secondAttribute, secondResource);
}
Aggregations