Skip to content

Commit 11a17ed

Browse files
committed
fix: export should set the type
**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 (cherry picked from commit 00a91b6)
1 parent d6e891b commit 11a17ed

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

gravitee-apim-rest-api/gravitee-apim-rest-api-service/src/main/java/io/gravitee/apim/infra/adapter/GraviteeDefinitionAdapter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package io.gravitee.apim.infra.adapter;
1717

1818
import io.gravitee.apim.core.api.model.import_definition.GraviteeDefinition;
19-
import io.gravitee.apim.core.api.model.import_definition.ImportDefinition;
2019
import io.gravitee.rest.api.model.v4.api.ExportApiEntity;
2120
import org.mapstruct.Mapper;
2221
import org.mapstruct.Mapping;

gravitee-apim-rest-api/gravitee-apim-rest-api-service/src/main/java/io/gravitee/apim/infra/domain_service/api/ApiExportDomainServiceImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.gravitee.apim.core.api.model.import_definition.GraviteeDefinition;
2020
import io.gravitee.apim.core.audit.model.AuditInfo;
2121
import io.gravitee.apim.infra.adapter.GraviteeDefinitionAdapter;
22+
import io.gravitee.rest.api.model.v4.api.ApiEntity;
2223
import io.gravitee.rest.api.service.common.ExecutionContext;
2324
import io.gravitee.rest.api.service.v4.ApiImportExportService;
2425
import java.util.Set;
@@ -35,6 +36,10 @@ public class ApiExportDomainServiceImpl implements ApiExportDomainService {
3536
public GraviteeDefinition export(String apiId, AuditInfo auditInfo) {
3637
var executionContext = new ExecutionContext(auditInfo.organizationId(), auditInfo.environmentId());
3738
var exportEntity = exportService.exportApi(executionContext, apiId, null, Set.of());
38-
return GraviteeDefinitionAdapter.INSTANCE.map(exportEntity);
39+
var graviteeDefinition = GraviteeDefinitionAdapter.INSTANCE.map(exportEntity);
40+
if (exportEntity.getApiEntity() instanceof ApiEntity v4) {
41+
graviteeDefinition.getApi().setType(v4.getType());
42+
}
43+
return graviteeDefinition;
3944
}
4045
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright © 2015 The Gravitee team (http://gravitee.io)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.gravitee.apim.infra.domain_service.api;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.mockito.ArgumentMatchers.any;
20+
import static org.mockito.Mockito.when;
21+
22+
import io.gravitee.apim.core.api.model.import_definition.GraviteeDefinition;
23+
import io.gravitee.apim.core.audit.model.AuditInfo;
24+
import io.gravitee.definition.model.v4.ApiType;
25+
import io.gravitee.rest.api.model.v4.api.ApiEntity;
26+
import io.gravitee.rest.api.model.v4.api.ExportApiEntity;
27+
import io.gravitee.rest.api.service.v4.ApiImportExportService;
28+
import java.util.UUID;
29+
import org.junit.jupiter.api.Test;
30+
import org.junit.jupiter.api.extension.ExtendWith;
31+
import org.mockito.InjectMocks;
32+
import org.mockito.Mock;
33+
import org.mockito.junit.jupiter.MockitoExtension;
34+
35+
@ExtendWith(MockitoExtension.class)
36+
class ApiExportDomainServiceImplTest {
37+
38+
@Mock
39+
ApiImportExportService exportService;
40+
41+
@InjectMocks
42+
ApiExportDomainServiceImpl sut;
43+
44+
@Test
45+
void exportServiceMustMapTypeWhenExportV4() {
46+
// Given
47+
String apiId = UUID.randomUUID().toString();
48+
ApiEntity api = new ApiEntity();
49+
api.setType(ApiType.PROXY);
50+
when(exportService.exportApi(any(), any(), any(), any())).thenReturn(new ExportApiEntity(api, null, null, null, null, null));
51+
52+
// When
53+
GraviteeDefinition export = sut.export(apiId, AuditInfo.builder().build());
54+
55+
// Then
56+
assertThat(export.getApi().getType()).isEqualTo(ApiType.PROXY);
57+
}
58+
}

0 commit comments

Comments
 (0)