Skip to content

Commit

Permalink
fix: export should set the type
Browse files Browse the repository at this point in the history
**Issue** [APIM-8360](https://gravitee.atlassian.net/browse/APIM-8360)

## Description

I made the minimal change because this code is fully reworked for 4.7
  • Loading branch information
michel-barret committed Jan 15, 2025
1 parent b7fe402 commit c447a6f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gravitee-apim-console-webui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23385,7 +23385,7 @@ __metadata:

"typescript@patch:typescript@npm%3A5.5.4#optional!builtin<compat/typescript>":
version: 5.5.4
resolution: "typescript@patch:typescript@npm%3A5.5.4#optional!builtin<compat/typescript>::version=5.5.4&hash=5adc0c"
resolution: "typescript@patch:typescript@npm%3A5.5.4#optional!builtin<compat/typescript>::version=5.5.4&hash=b45daf"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.gravitee.apim.infra.adapter;

import io.gravitee.apim.core.api.model.import_definition.GraviteeDefinition;
import io.gravitee.apim.core.api.model.import_definition.ImportDefinition;
import io.gravitee.rest.api.model.v4.api.ExportApiEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.gravitee.apim.core.api.model.import_definition.GraviteeDefinition;
import io.gravitee.apim.core.audit.model.AuditInfo;
import io.gravitee.apim.infra.adapter.GraviteeDefinitionAdapter;
import io.gravitee.rest.api.model.v4.api.ApiEntity;
import io.gravitee.rest.api.service.common.ExecutionContext;
import io.gravitee.rest.api.service.v4.ApiImportExportService;
import java.util.Set;
Expand All @@ -35,6 +36,10 @@ public class ApiExportDomainServiceImpl implements ApiExportDomainService {
public GraviteeDefinition export(String apiId, AuditInfo auditInfo) {
var executionContext = new ExecutionContext(auditInfo.organizationId(), auditInfo.environmentId());
var exportEntity = exportService.exportApi(executionContext, apiId, null, Set.of());
return GraviteeDefinitionAdapter.INSTANCE.map(exportEntity);
var graviteeDefinition = GraviteeDefinitionAdapter.INSTANCE.map(exportEntity);
if (exportEntity.getApiEntity() instanceof ApiEntity v4) {
graviteeDefinition.getApi().setType(v4.getType());
}
return graviteeDefinition;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.gravitee.apim.infra.domain_service.api;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import io.gravitee.apim.core.api.model.import_definition.GraviteeDefinition;
import io.gravitee.apim.core.audit.model.AuditInfo;
import io.gravitee.definition.model.v4.ApiType;
import io.gravitee.rest.api.model.v4.api.ApiEntity;
import io.gravitee.rest.api.model.v4.api.ExportApiEntity;
import io.gravitee.rest.api.service.v4.ApiImportExportService;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class ApiExportDomainServiceImplTest {

@Mock
ApiImportExportService exportService;

@InjectMocks
ApiExportDomainServiceImpl sut;

@Test
void exportServiceMustMapTypeWhenExportV4() {
// Given
String apiId = UUID.randomUUID().toString();
ApiEntity api = new ApiEntity();
api.setType(ApiType.PROXY);
when(exportService.exportApi(any(), any(), any(), any())).thenReturn(new ExportApiEntity(api, null, null, null, null, null));

// When
GraviteeDefinition export = sut.export(apiId, AuditInfo.builder().build());

// Then
assertThat(export.getApi().getType()).isEqualTo(ApiType.PROXY);
}
}

0 comments on commit c447a6f

Please sign in to comment.