use of io.gravitee.rest.api.model.TaskEntity in project gravitee-management-rest-api by gravitee-io.
the class PromotionTasksServiceImplTest method shouldGetPromotionTasks_withApiCreationBecauseItHasBeenDeleted.
@Test
public void shouldGetPromotionTasks_withApiCreationBecauseItHasBeenDeleted() throws JsonProcessingException {
PromotionEntity aPromotionEntity = getAPromotionEntity();
when(promotionService.search(argThat(query -> query != null && query.getStatuses().get(0) == PromotionEntityStatus.TO_BE_VALIDATED), any(), any())).thenReturn(new Page<>(singletonList(aPromotionEntity), 0, 0, 0));
when(environmentService.findByOrganization(any())).thenReturn(singletonList(getAnEnvironmentEntity()));
PromotionEntity previousPromotionEntity = getAPromotionEntity();
previousPromotionEntity.setTargetApiId("api#target");
when(promotionService.search(argThat(query -> query != null && query.getStatuses().get(0) == PromotionEntityStatus.ACCEPTED), any(), any())).thenReturn(new Page<>(singletonList(previousPromotionEntity), 0, 0, 0));
when(permissionService.hasPermission(RolePermission.ENVIRONMENT_API, "env#1", CREATE)).thenReturn(true);
when(permissionService.hasPermission(RolePermission.ENVIRONMENT_API, "env#1", UPDATE)).thenReturn(false);
when(objectMapper.readValue(aPromotionEntity.getApiDefinition(), ApiEntity.class)).thenReturn(getAnApiEntity());
when(apiService.exists("api#target")).thenReturn(false);
final List<TaskEntity> result = cut.getPromotionTasks("org#1");
assertThat(result).hasSize(1);
Map<String, Object> taskData = (Map<String, Object>) result.get(0).getData();
assertThat(taskData.get("apiName")).isEqualTo("API Name");
assertThat(taskData.get("sourceEnvironmentName")).isEqualTo("Source Env");
assertThat(taskData.get("targetEnvironmentName")).isEqualTo("Target Env");
assertThat(taskData.get("authorDisplayName")).isEqualTo("Author");
assertThat(taskData.get("authorEmail")).isEqualTo("author@gv.io");
assertThat(taskData.get("authorPicture")).isEqualTo("https://picture.png");
assertThat(taskData.get("apiId")).isEqualTo("api id");
assertThat(taskData.get("isApiUpdate")).isEqualTo(false);
}
Aggregations