use of ee.ria.xroad.common.metadata.RestServiceDetailsListType in project X-Road by nordic-institute.
the class RestMetadataServiceHandlerTest method shouldHandleListMethods.
@Test
public void shouldHandleListMethods() throws Exception {
RestMetadataServiceHandlerImpl handlerToTest = new RestMetadataServiceHandlerImpl();
ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, LIST_METHODS);
RestRequest mockRestRequest = mock(RestRequest.class);
when(mockRestRequest.getServiceId()).thenReturn(serviceId);
when(mockRestRequest.getVerb()).thenReturn(RestRequest.Verb.GET);
when(mockRestRequest.getClientId()).thenReturn(DEFAULT_CLIENT);
when(mockRestRequest.getHash()).thenReturn(REQUEST_HASH);
when(mockProxyMessage.getRest()).thenReturn(mockRestRequest);
ProxyMessageDecoder mockDecoder = mock(ProxyMessageDecoder.class);
ProxyMessageEncoder mockEncoder = mock(ProxyMessageEncoder.class);
handlerToTest.startHandling(mockRequest, mockProxyMessage, mockDecoder, mockEncoder, httpClientMock, httpClientMock, mock(OpMonitoringData.class));
RestResponse restResponse = handlerToTest.getRestResponse();
assertEquals(HttpStatus.SC_OK, restResponse.getResponseCode());
assertEquals("OK", restResponse.getReason());
CachingStream restResponseBody = handlerToTest.getRestResponseBody();
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
RestServiceDetailsListType restServiceDetailsList = MAPPER.readValue(restResponseBody.getCachedContents(), RestServiceDetailsListType.class);
assertEquals(3, restServiceDetailsList.getService().size());
assertEquals(1, restServiceDetailsList.getService().get(0).getEndpointList().size());
}
use of ee.ria.xroad.common.metadata.RestServiceDetailsListType in project X-Road by nordic-institute.
the class RestMetadataServiceHandlerTest method shouldHandleAllowedMethods.
@Test
public void shouldHandleAllowedMethods() throws Exception {
RestMetadataServiceHandlerImpl handlerToTest = new RestMetadataServiceHandlerImpl();
ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, ALLOWED_METHODS);
RestRequest mockRestRequest = mock(RestRequest.class);
when(mockRestRequest.getServiceId()).thenReturn(serviceId);
when(mockRestRequest.getVerb()).thenReturn(RestRequest.Verb.GET);
when(mockRestRequest.getClientId()).thenReturn(DEFAULT_CLIENT);
when(mockRestRequest.getHash()).thenReturn(REQUEST_HASH);
when(mockProxyMessage.getRest()).thenReturn(mockRestRequest);
ProxyMessageDecoder mockDecoder = mock(ProxyMessageDecoder.class);
ProxyMessageEncoder mockEncoder = mock(ProxyMessageEncoder.class);
handlerToTest.startHandling(mockRequest, mockProxyMessage, mockDecoder, mockEncoder, httpClientMock, httpClientMock, mock(OpMonitoringData.class));
RestResponse restResponse = handlerToTest.getRestResponse();
assertEquals(HttpStatus.SC_OK, restResponse.getResponseCode());
assertEquals("OK", restResponse.getReason());
CachingStream restResponseBody = handlerToTest.getRestResponseBody();
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
RestServiceDetailsListType restServiceDetailsList = MAPPER.readValue(restResponseBody.getCachedContents(), RestServiceDetailsListType.class);
assertEquals(3, restServiceDetailsList.getService().size());
assertEquals(1, restServiceDetailsList.getService().get(0).getEndpointList().size());
}
use of ee.ria.xroad.common.metadata.RestServiceDetailsListType in project X-Road by nordic-institute.
the class ServerConfImpl method getAllowedRestServices.
@Override
public RestServiceDetailsListType getAllowedRestServices(ClientId serviceProvider, ClientId client) {
return tx(session -> {
RestServiceDetailsListType restServiceDetailsList = new RestServiceDetailsListType();
serviceDao.getServicesByDescriptionType(session, serviceProvider, DescriptionType.OPENAPI3, DescriptionType.REST).forEach(serviceId -> {
final List<EndpointType> acl = getAclEndpoints(session, client, serviceId);
if (!acl.isEmpty()) {
final List<Endpoint> endpoints = getServiceEndpoints(serviceId);
XRoadRestServiceDetailsType serviceDetails = createRestServiceDetails(serviceId);
for (Endpoint e : endpoints) {
if (acl.stream().anyMatch(it -> it.matches(e.getMethod(), e.getPath()))) {
serviceDetails.getEndpointList().add(e);
}
}
restServiceDetailsList.getService().add(serviceDetails);
}
});
return restServiceDetailsList;
});
}
use of ee.ria.xroad.common.metadata.RestServiceDetailsListType in project X-Road by nordic-institute.
the class ServerConfImpl method getRestServices.
@Override
public RestServiceDetailsListType getRestServices(ClientId serviceProvider) {
return tx(session -> {
RestServiceDetailsListType restServiceDetailsList = new RestServiceDetailsListType();
serviceDao.getServicesByDescriptionType(session, serviceProvider, DescriptionType.OPENAPI3, DescriptionType.REST).forEach(serviceId -> {
XRoadRestServiceDetailsType serviceDetails = createRestServiceDetails(serviceId);
serviceDetails.getEndpointList().addAll(getServiceEndpoints(serviceId));
restServiceDetailsList.getService().add(serviceDetails);
});
return restServiceDetailsList;
});
}
use of ee.ria.xroad.common.metadata.RestServiceDetailsListType in project X-Road by nordic-institute.
the class EmptyServerConf method getRestServices.
@Override
public RestServiceDetailsListType getRestServices(ClientId serviceProvider) {
RestServiceDetailsListType restServiceDetailsList = new RestServiceDetailsListType();
ServiceId serviceId1 = ServiceId.create(DEFAULT_CLIENT, SERVICE1);
XRoadRestServiceDetailsType serviceDetails1 = createRestServiceDetails(serviceId1);
serviceDetails1.getEndpointList().addAll(getServiceEndpoints(serviceId1));
restServiceDetailsList.getService().add(serviceDetails1);
ServiceId serviceId2 = ServiceId.create(DEFAULT_CLIENT, SERVICE2);
XRoadRestServiceDetailsType serviceDetails2 = createRestServiceDetails(serviceId2);
serviceDetails2.getEndpointList().addAll(getServiceEndpoints(serviceId2));
restServiceDetailsList.getService().add(serviceDetails2);
ServiceId serviceId3 = ServiceId.create(DEFAULT_CLIENT, SERVICE3);
XRoadRestServiceDetailsType serviceDetails3 = createRestServiceDetails(serviceId3);
serviceDetails3.getEndpointList().addAll(getServiceEndpoints(serviceId3));
restServiceDetailsList.getService().add(serviceDetails3);
return restServiceDetailsList;
}
Aggregations