Search in sources :

Example 1 with ItemAttributeResource

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.");
}
Also used : ItemAttributeResource(com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource) LaunchFinishForcedEvent(com.epam.ta.reportportal.core.events.activity.LaunchFinishForcedEvent) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) LaunchFinishedEvent(com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent) Launch(com.epam.ta.reportportal.entity.launch.Launch) Date(java.util.Date) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 2 with ItemAttributeResource

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());
}
Also used : ItemAttributeResource(com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 3 with ItemAttributeResource

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());
    });
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) Issue(com.epam.ta.reportportal.ws.model.issue.Issue) TestItem(com.epam.ta.reportportal.entity.item.TestItem) BulkInfoUpdateRQ(com.epam.ta.reportportal.ws.model.BulkInfoUpdateRQ) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) DefineIssueRQ(com.epam.ta.reportportal.ws.model.issue.DefineIssueRQ) UnlinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.UnlinkExternalIssueRQ) ParameterResource(com.epam.ta.reportportal.ws.model.ParameterResource) ItemAttributeResource(com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource) FinishTestItemRQ(com.epam.ta.reportportal.ws.model.FinishTestItemRQ) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) UpdateItemAttributeRQ(com.epam.ta.reportportal.ws.model.attribute.UpdateItemAttributeRQ) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) IssueDefinition(com.epam.ta.reportportal.ws.model.issue.IssueDefinition) Matchers.hasSize(org.hamcrest.Matchers.hasSize) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) SuggestInfo(com.epam.ta.reportportal.core.analyzer.auto.client.model.SuggestInfo) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Mockito.times(org.mockito.Mockito.times) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Sql(org.springframework.test.context.jdbc.Sql) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) LinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ) Sets(com.google.common.collect.Sets) ZoneId(java.time.ZoneId) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) Assertions(org.junit.jupiter.api.Assertions) ItemAttributeResource(com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource) UpdateItemAttributeRQ(com.epam.ta.reportportal.ws.model.attribute.UpdateItemAttributeRQ) BulkInfoUpdateRQ(com.epam.ta.reportportal.ws.model.BulkInfoUpdateRQ) TestItem(com.epam.ta.reportportal.entity.item.TestItem) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 4 with ItemAttributeResource

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());
    });
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) Issue(com.epam.ta.reportportal.ws.model.issue.Issue) TestItem(com.epam.ta.reportportal.entity.item.TestItem) BulkInfoUpdateRQ(com.epam.ta.reportportal.ws.model.BulkInfoUpdateRQ) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) DefineIssueRQ(com.epam.ta.reportportal.ws.model.issue.DefineIssueRQ) UnlinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.UnlinkExternalIssueRQ) ParameterResource(com.epam.ta.reportportal.ws.model.ParameterResource) ItemAttributeResource(com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource) FinishTestItemRQ(com.epam.ta.reportportal.ws.model.FinishTestItemRQ) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) UpdateItemAttributeRQ(com.epam.ta.reportportal.ws.model.attribute.UpdateItemAttributeRQ) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) IssueDefinition(com.epam.ta.reportportal.ws.model.issue.IssueDefinition) Matchers.hasSize(org.hamcrest.Matchers.hasSize) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) SuggestInfo(com.epam.ta.reportportal.core.analyzer.auto.client.model.SuggestInfo) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Mockito.times(org.mockito.Mockito.times) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Sql(org.springframework.test.context.jdbc.Sql) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) LinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ) Sets(com.google.common.collect.Sets) ZoneId(java.time.ZoneId) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) Assertions(org.junit.jupiter.api.Assertions) ItemAttributeResource(com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource) UpdateItemAttributeRQ(com.epam.ta.reportportal.ws.model.attribute.UpdateItemAttributeRQ) BulkInfoUpdateRQ(com.epam.ta.reportportal.ws.model.BulkInfoUpdateRQ) TestItem(com.epam.ta.reportportal.entity.item.TestItem) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 5 with ItemAttributeResource

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));
    });
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) Issue(com.epam.ta.reportportal.ws.model.issue.Issue) TestItem(com.epam.ta.reportportal.entity.item.TestItem) BulkInfoUpdateRQ(com.epam.ta.reportportal.ws.model.BulkInfoUpdateRQ) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) DefineIssueRQ(com.epam.ta.reportportal.ws.model.issue.DefineIssueRQ) UnlinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.UnlinkExternalIssueRQ) ParameterResource(com.epam.ta.reportportal.ws.model.ParameterResource) ItemAttributeResource(com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource) FinishTestItemRQ(com.epam.ta.reportportal.ws.model.FinishTestItemRQ) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) UpdateItemAttributeRQ(com.epam.ta.reportportal.ws.model.attribute.UpdateItemAttributeRQ) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) IssueDefinition(com.epam.ta.reportportal.ws.model.issue.IssueDefinition) Matchers.hasSize(org.hamcrest.Matchers.hasSize) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) SuggestInfo(com.epam.ta.reportportal.core.analyzer.auto.client.model.SuggestInfo) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Mockito.times(org.mockito.Mockito.times) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Sql(org.springframework.test.context.jdbc.Sql) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) LinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ) Sets(com.google.common.collect.Sets) ZoneId(java.time.ZoneId) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) Assertions(org.junit.jupiter.api.Assertions) ItemAttributeResource(com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource) UpdateItemAttributeRQ(com.epam.ta.reportportal.ws.model.attribute.UpdateItemAttributeRQ) BulkInfoUpdateRQ(com.epam.ta.reportportal.ws.model.BulkInfoUpdateRQ) TestItem(com.epam.ta.reportportal.entity.item.TestItem) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Aggregations

ItemAttributeResource (com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource)19 Test (org.junit.jupiter.api.Test)16 Launch (com.epam.ta.reportportal.entity.launch.Launch)10 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)9 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)9 LocalDateTime (java.time.LocalDateTime)8 LaunchRepository (com.epam.ta.reportportal.dao.LaunchRepository)7 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 BulkInfoUpdateRQ (com.epam.ta.reportportal.ws.model.BulkInfoUpdateRQ)6 UpdateItemAttributeRQ (com.epam.ta.reportportal.ws.model.attribute.UpdateItemAttributeRQ)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Lists (com.google.common.collect.Lists)5 Sets (com.google.common.collect.Sets)5 ZoneId (java.time.ZoneId)5 java.util (java.util)5 Matchers.hasSize (org.hamcrest.Matchers.hasSize)5 Assertions (org.junit.jupiter.api.Assertions)5 APPLICATION_JSON (org.springframework.http.MediaType.APPLICATION_JSON)5 Sql (org.springframework.test.context.jdbc.Sql)5