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 16, 2025
1 parent 2b4051e commit 00a91b6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
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,58 @@
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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 00a91b6

Please sign in to comment.