use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class SwaggerService_TransformTest method shouldTransformAPIWithServerUrlAndContextPath.
@Test
public void shouldTransformAPIWithServerUrlAndContextPath() throws IOException {
PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.json", MediaType.APPLICATION_JSON);
Map<String, String> pageConfigurationEntity = new HashMap<>();
pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINTS_AS_SERVERS, "true");
pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINT_AS_BASEPATH, "true");
pageEntity.setConfiguration(pageConfigurationEntity);
OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent(), false);
final ApiEntity apiEntity = getApiEntity();
swaggerService.transform(descriptor, Arrays.asList(new PageConfigurationOAITransformer(pageEntity), new EntrypointsOAITransformer(pageEntity, apiEntity)));
assertNotNull(descriptor.toJson());
final JsonNode node = Json.mapper().readTree(descriptor.toJson());
assertEquals("https://apis.gravitee.io/test", node.get("servers").get(0).get("url").asText());
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class SwaggerService_TransformTest method shouldTransformAPIWithOriginalServer.
@Test
public void shouldTransformAPIWithOriginalServer() throws IOException {
PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.json", MediaType.APPLICATION_JSON);
Map<String, String> pageConfigurationEntity = new HashMap<>();
pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINTS_AS_SERVERS, "false");
pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINT_AS_BASEPATH, "false");
pageEntity.setConfiguration(pageConfigurationEntity);
OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent(), false);
final ApiEntity apiEntity = getApiEntity();
swaggerService.transform(descriptor, Arrays.asList(new PageConfigurationOAITransformer(pageEntity), new EntrypointsOAITransformer(pageEntity, apiEntity)));
assertNotNull(descriptor.toJson());
final JsonNode node = Json.mapper().readTree(descriptor.toJson());
assertEquals("https://demo.gravitee.io/gateway/echo", node.get("servers").get(0).get("url").asText());
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class SwaggerService_TransformTest method shouldTransformAPIWithServerUrl.
@Test
public void shouldTransformAPIWithServerUrl() throws IOException {
PageEntity pageEntity = getPage("io/gravitee/rest/api/management/service/openapi.json", MediaType.APPLICATION_JSON);
Map<String, String> pageConfigurationEntity = new HashMap<>();
pageConfigurationEntity.put(SwaggerProperties.ENTRYPOINTS_AS_SERVERS, "true");
pageEntity.setConfiguration(pageConfigurationEntity);
OAIDescriptor descriptor = (OAIDescriptor) swaggerService.parse(pageEntity.getContent(), false);
final ApiEntity apiEntity = getApiEntity();
swaggerService.transform(descriptor, Arrays.asList(new PageConfigurationOAITransformer(pageEntity), new EntrypointsOAITransformer(pageEntity, apiEntity)));
assertNotNull(descriptor.toJson());
final JsonNode node = Json.mapper().readTree(descriptor.toJson());
assertEquals("https://apis.gravitee.io", node.get("servers").get(0).get("url").asText());
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class TopApiServiceTest method shouldDelete.
@Test
public void shouldDelete() {
final ApiEntity api1 = new ApiEntity();
api1.setId("1");
api1.setName("name");
api1.setVersion("version");
api1.setDescription("description");
final ApiEntity api2 = new ApiEntity();
api2.setId("2");
when(parameterService.findAll(eq(PORTAL_TOP_APIS), any(Function.class), any(Predicate.class), any(ParameterReferenceType.class))).thenReturn(asList(api1, api2));
topApiService.delete("1");
verify(parameterService).save(PORTAL_TOP_APIS, singletonList("2"), ParameterReferenceType.ENVIRONMENT);
}
use of io.gravitee.rest.api.model.api.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class UserServiceTest method shouldNotDeleteIfAPIPO.
@Test
public void shouldNotDeleteIfAPIPO() throws TechnicalException {
ApiEntity apiEntity = mock(ApiEntity.class);
PrimaryOwnerEntity primaryOwnerEntity = mock(PrimaryOwnerEntity.class);
when(apiEntity.getPrimaryOwner()).thenReturn(primaryOwnerEntity);
when(primaryOwnerEntity.getId()).thenReturn(USER_NAME);
when(apiService.findByUser(USER_NAME, null, false)).thenReturn(Collections.singleton(apiEntity));
try {
userService.delete(USER_NAME);
fail("should throw StillPrimaryOwnerException");
} catch (StillPrimaryOwnerException e) {
// success
verify(membershipService, never()).removeMemberMemberships(MembershipMemberType.USER, USER_NAME);
verify(userRepository, never()).update(any());
verify(searchEngineService, never()).delete(any(), eq(false));
}
}
Aggregations