Search in sources :

Example 16 with PromotionEntity

use of io.gravitee.rest.api.model.promotion.PromotionEntity in project gravitee-management-rest-api by gravitee-io.

the class PromotionTasksServiceImplTest method getAPromotionEntity.

private PromotionEntity getAPromotionEntity() {
    final PromotionEntity promotion = new PromotionEntity();
    promotion.setApiDefinition("{\"id\" : \"api#1\",\"name\" : \"API Name\",\"version\" : \"1\",\"proxy\" : {  \"context_path\" : \"/product\",  \"endpoint\" : \"http://toto.com\",  \"endpoints\" : [ {    \"target\" : \"http://toto.com\",    \"weight\" : 1,    \"name\" : \"endpointName\"  } ],  \"strip_context_path\" : false,  \"http\" : {    \"configuration\" : {      \"connectTimeout\" : 5000,      \"idleTimeout\" : 60000,      \"keepAlive\" : true,      \"dumpRequest\" : false    }  }},\"paths\" : {  \"/\" : [ {    \"methods\" : [ ],    \"api-key\" : {}  } ]},\"tags\" : [ ]\n}");
    promotion.setTargetEnvCockpitId("env#1-cockpit-id");
    promotion.setTargetEnvName("Target Env");
    promotion.setSourceEnvCockpitId("env#2-cockpit-id");
    promotion.setSourceEnvName("Source Env");
    promotion.setApiId("api id");
    promotion.setTargetApiId("target api id");
    PromotionEntityAuthor author = new PromotionEntityAuthor();
    author.setDisplayName("Author");
    author.setEmail("author@gv.io");
    author.setPicture("https://picture.png");
    promotion.setAuthor(author);
    return promotion;
}
Also used : PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) PromotionEntityAuthor(io.gravitee.rest.api.model.promotion.PromotionEntityAuthor)

Example 17 with PromotionEntity

use of io.gravitee.rest.api.model.promotion.PromotionEntity in project gravitee-management-rest-api by gravitee-io.

the class PromotionTasksServiceImplTest method shouldGetPromotionTasks_withApiCreation.

@Test
public void shouldGetPromotionTasks_withApiCreation() 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()));
    when(promotionService.search(argThat(query -> query != null && query.getStatuses().get(0) == PromotionEntityStatus.ACCEPTED), any(), any())).thenReturn(new Page<>(emptyList(), 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());
    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);
    assertThat(taskData.get("targetApiId")).isNull();
}
Also used : java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Page(io.gravitee.common.data.domain.Page) RunWith(org.junit.runner.RunWith) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) PromotionEntityStatus(io.gravitee.rest.api.model.promotion.PromotionEntityStatus) ApiService(io.gravitee.rest.api.service.ApiService) UPDATE(io.gravitee.rest.api.model.permissions.RolePermissionAction.UPDATE) Collections.singletonList(java.util.Collections.singletonList) PromotionEntityAuthor(io.gravitee.rest.api.model.promotion.PromotionEntityAuthor) PermissionService(io.gravitee.rest.api.service.PermissionService) Before(org.junit.Before) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) TaskEntity(io.gravitee.rest.api.model.TaskEntity) Collections.emptyList(java.util.Collections.emptyList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EnvironmentService(io.gravitee.rest.api.service.EnvironmentService) PromotionService(io.gravitee.rest.api.service.promotion.PromotionService) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) CREATE(io.gravitee.rest.api.model.permissions.RolePermissionAction.CREATE) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) PromotionTasksService(io.gravitee.rest.api.service.promotion.PromotionTasksService) RolePermission(io.gravitee.rest.api.model.permissions.RolePermission) TaskEntity(io.gravitee.rest.api.model.TaskEntity) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) Test(org.junit.Test)

Example 18 with PromotionEntity

use of io.gravitee.rest.api.model.promotion.PromotionEntity 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);
}
Also used : java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Page(io.gravitee.common.data.domain.Page) RunWith(org.junit.runner.RunWith) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) PromotionEntityStatus(io.gravitee.rest.api.model.promotion.PromotionEntityStatus) ApiService(io.gravitee.rest.api.service.ApiService) UPDATE(io.gravitee.rest.api.model.permissions.RolePermissionAction.UPDATE) Collections.singletonList(java.util.Collections.singletonList) PromotionEntityAuthor(io.gravitee.rest.api.model.promotion.PromotionEntityAuthor) PermissionService(io.gravitee.rest.api.service.PermissionService) Before(org.junit.Before) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) TaskEntity(io.gravitee.rest.api.model.TaskEntity) Collections.emptyList(java.util.Collections.emptyList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EnvironmentService(io.gravitee.rest.api.service.EnvironmentService) PromotionService(io.gravitee.rest.api.service.promotion.PromotionService) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) CREATE(io.gravitee.rest.api.model.permissions.RolePermissionAction.CREATE) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) PromotionTasksService(io.gravitee.rest.api.service.promotion.PromotionTasksService) RolePermission(io.gravitee.rest.api.model.permissions.RolePermission) TaskEntity(io.gravitee.rest.api.model.TaskEntity) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) Test(org.junit.Test)

Aggregations

PromotionEntity (io.gravitee.rest.api.model.promotion.PromotionEntity)18 Test (org.junit.Test)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 BridgeSimpleReply (io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply)6 PromotionEntityAuthor (io.gravitee.rest.api.model.promotion.PromotionEntityAuthor)6 PromotionEntityStatus (io.gravitee.rest.api.model.promotion.PromotionEntityStatus)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Page (io.gravitee.common.data.domain.Page)5 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)5 TaskEntity (io.gravitee.rest.api.model.TaskEntity)5 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)5 CREATE (io.gravitee.rest.api.model.permissions.RolePermissionAction.CREATE)5 UPDATE (io.gravitee.rest.api.model.permissions.RolePermissionAction.UPDATE)5 ApiService (io.gravitee.rest.api.service.ApiService)5 EnvironmentService (io.gravitee.rest.api.service.EnvironmentService)5 PermissionService (io.gravitee.rest.api.service.PermissionService)5 PromotionService (io.gravitee.rest.api.service.promotion.PromotionService)5 PromotionTasksService (io.gravitee.rest.api.service.promotion.PromotionTasksService)5 java.util (java.util)5 Collections.emptyList (java.util.Collections.emptyList)5