use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class SyncManagerTest method test_twiceWithTwoApis_apiToRemove.
@Test
public void test_twiceWithTwoApis_apiToRemove() throws Exception {
io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test").updatedAt(new Date()).definition("test").build();
final Api mockApi = mockApi(api);
final Event mockEvent = mockEvent(api, EventType.PUBLISH_API);
when(eventRepository.search(any(EventCriteria.class), any(Pageable.class))).thenReturn(new Page<>(Collections.singletonList(mockEvent), 0, 0, 1));
when(apiRepository.findAll()).thenReturn(Collections.singleton(api));
syncManager.refresh();
io.gravitee.repository.management.model.Api api2 = new RepositoryApiBuilder().id("api-test-2").updatedAt(new Date()).definition("test2").build();
final Api mockApi2 = mockApi(api2);
final Event mockEvent2 = mockEvent(api2, EventType.PUBLISH_API);
when(apiRepository.findAll()).thenReturn(Collections.singleton(api2));
when(apiManager.apis()).thenReturn(Collections.singleton(mockApi));
syncManager.refresh();
verify(apiManager, times(2)).deploy(argThat(new ArgumentMatcher<Api>() {
@Override
public boolean matches(Object argument) {
final Api api = (Api) argument;
return api.getId().equals(mockApi.getId()) || api2.getId().equals(mockApi2.getId());
}
}));
verify(apiManager, never()).update(any(Api.class));
verify(apiManager, never()).undeploy(api.getId());
verify(apiManager, never()).undeploy(api2.getId());
}
use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class SyncManagerTest method test_not_deployApiWithoutTag.
@Test
public void test_not_deployApiWithoutTag() throws Exception {
io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test").updatedAt(new Date()).definition("test").build();
final Api mockApi = mockApi(api);
when(gatewayConfiguration.shardingTags()).thenReturn(Optional.of(Arrays.asList("test", "toto")));
when(apiRepository.findAll()).thenReturn(Collections.singleton(api));
final Event mockEvent = mockEvent(api, EventType.PUBLISH_API);
when(eventRepository.search(any(EventCriteria.class), any(Pageable.class))).thenReturn(new Page<>(Collections.singletonList(mockEvent), 0, 0, 1));
syncManager.refresh();
verify(apiManager, never()).deploy(mockApi);
verify(apiManager, never()).update(any(Api.class));
}
use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class SyncManagerTest method test_deployOnlyOneApiWithTwoApisAndOneEvent.
@Test
public void test_deployOnlyOneApiWithTwoApisAndOneEvent() throws Exception {
io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test").updatedAt(new Date()).definition("test").build();
io.gravitee.repository.management.model.Api api2 = new RepositoryApiBuilder().id("api-test-2").updatedAt(new Date()).definition("test2").build();
final Api mockApi = mockApi(api);
Set<io.gravitee.repository.management.model.Api> apis = new HashSet<>();
apis.add(api);
apis.add(api2);
final Event mockEvent = mockEvent(api, EventType.PUBLISH_API);
when(eventRepository.search(any(EventCriteria.class), any(Pageable.class))).thenReturn(new Page<>(Collections.emptyList(), 0, 0, 0), new Page<>(Collections.singletonList(mockEvent), 0, 0, 1));
when(apiRepository.findAll()).thenReturn(apis);
syncManager.refresh();
verify(apiManager).deploy(argThat(new ArgumentMatcher<Api>() {
@Override
public boolean matches(Object argument) {
final Api api = (Api) argument;
return api.getId().equals(mockApi.getId());
}
}));
verify(apiManager, never()).update(any(Api.class));
verify(apiManager, never()).undeploy(any(String.class));
}
use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class SyncManagerTest method test_deployApiWithTagInclusionExclusion.
@Test
public void test_deployApiWithTagInclusionExclusion() throws Exception {
io.gravitee.repository.management.model.Api api = new RepositoryApiBuilder().id("api-test").updatedAt(new Date()).definition("test").build();
// api.setTags(new HashSet<>(Arrays.asList(new String[]{"test", "toto"})));
final Api mockApi = mockApi(api);
when(gatewayConfiguration.shardingTags()).thenReturn(Optional.of(Arrays.asList("!test", "toto")));
when(apiRepository.findAll()).thenReturn(Collections.singleton(api));
when(apiManager.apis()).thenReturn(Collections.singleton(mockApi));
final Event mockEvent = mockEvent(api, EventType.PUBLISH_API);
when(eventRepository.search(any(EventCriteria.class), any(Pageable.class))).thenReturn(new Page<>(Collections.singletonList(mockEvent), 0, 0, 1));
syncManager.refresh();
verify(apiManager).deploy(mockApi);
verify(apiManager, never()).update(any(Api.class));
verify(apiManager, never()).undeploy(any(String.class));
}
use of io.gravitee.gateway.handlers.api.definition.Api in project gravitee-gateway by gravitee-io.
the class ApiHandler method handle.
@Override
public void handle(RoutingContext ctx) {
HttpServerResponse response = ctx.response();
try {
String sApi = ctx.request().getParam("apiId");
Api api = apiManager.get(sApi);
if (api == null) {
response.setStatusCode(HttpStatusCode.NOT_FOUND_404);
} else {
response.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
response.setStatusCode(HttpStatusCode.OK_200);
response.setChunked(true);
Json.prettyMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
response.write(Json.prettyMapper.writeValueAsString(api));
}
} catch (JsonProcessingException jpe) {
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR_500);
LOGGER.error("Unable to transform data object to JSON", jpe);
}
response.end();
}
Aggregations