use of uk.gov.justice.services.clients.core.EndpointDefinition in project microservice_framework by CJSCommonPlatform.
the class ContextMatcherTest method shouldReturnFalseIfTheCurrentServiceAndTheRemoteServiceAreNotTheSameContext.
@Test
public void shouldReturnFalseIfTheCurrentServiceAndTheRemoteServiceAreNotTheSameContext() throws Exception {
final String localServiceContextName = "usersgroups-command-api";
final String baseUri = "http://localhost:8080/notification-command-api/command/api/rest/notification";
final EndpointDefinition endpointDefinition = mock(EndpointDefinition.class);
when(contextNameProvider.getServiceContextName()).thenReturn(localServiceContextName);
when(endpointDefinition.getBaseUri()).thenReturn(baseUri);
assertThat(contextMatcher.isSameContext(endpointDefinition), is(false));
}
use of uk.gov.justice.services.clients.core.EndpointDefinition in project microservice_framework by CJSCommonPlatform.
the class BaseUriFactoryTest method shouldCreateABaseUriWithADefaultPortIfNoMockServerPortIsSet.
@Test
public void shouldCreateABaseUriWithADefaultPortIfNoMockServerPortIsSet() {
final String defaultPort = "9090";
final String baseUri = "http://localhost:8080/anyUrl";
final String resultUri = "http://localhost:9090/anyUrl";
final EndpointDefinition endpointDefinition = mock(EndpointDefinition.class);
when(endpointDefinition.getBaseUri()).thenReturn(baseUri);
when(mockServerPortProvider.getMockServerPort(endpointDefinition)).thenReturn(empty());
when(defaultServerPortProvider.getDefaultPort()).thenReturn(defaultPort);
assertThat(baseUriFactory.createBaseUri(endpointDefinition), is(resultUri));
}
use of uk.gov.justice.services.clients.core.EndpointDefinition in project microservice_framework by CJSCommonPlatform.
the class MockServerPortProviderTest method shouldReturnEmptyIfSystemPropertyIsSetButIsTheSameService.
@Test
public void shouldReturnEmptyIfSystemPropertyIsSetButIsTheSameService() throws Exception {
final String port = "1234";
System.setProperty(MOCK_SERVER_PORT, port);
final EndpointDefinition endpointDefinition = mock(EndpointDefinition.class);
when(contextMatcher.isSameContext(endpointDefinition)).thenReturn(true);
final Optional<String> mockServerPort = mockServerPortProvider.getMockServerPort(endpointDefinition);
assertThat(mockServerPort.isPresent(), is(false));
}
use of uk.gov.justice.services.clients.core.EndpointDefinition in project microservice_framework by CJSCommonPlatform.
the class MockServerPortProviderTest method shouldReturnEmptyIfSystemPropertyIsNotSet.
@Test
public void shouldReturnEmptyIfSystemPropertyIsNotSet() throws Exception {
assertThat(System.getProperty(MOCK_SERVER_PORT), is(nullValue()));
final EndpointDefinition endpointDefinition = mock(EndpointDefinition.class);
final Optional<String> mockServerPort = mockServerPortProvider.getMockServerPort(endpointDefinition);
assertThat(mockServerPort.isPresent(), is(false));
}
use of uk.gov.justice.services.clients.core.EndpointDefinition in project microservice_framework by CJSCommonPlatform.
the class RestClientGenerator_MethodBodyTest method shouldCallRestClientWithEndpointDefinitionContainingQueryParams.
@Test
@SuppressWarnings("unchecked")
public void shouldCallRestClientWithEndpointDefinitionContainingQueryParams() throws Exception {
generator.run(restRamlWithQueryApiDefaults().with(defaultGetResource().with(defaultGetAction().with(queryParam("qparam1").required(true), queryParam("qparam2").required(false), queryParam("qparam3").required(false).withType(INTEGER), queryParam("qparam4").required(false).withType(BOOLEAN)))).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties().withServiceComponentOf("SOME_COMPONENT")));
final Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "RemoteSomeComponent2ServiceQueryApi");
invokeFirstMethod(clazz);
final EndpointDefinition endpointDefinition = capturedGetEndpointDefinition();
assertThat(endpointDefinition.getQueryParams(), hasSize(4));
assertThat(endpointDefinition.getQueryParams(), hasItems(allOf(hasProperty("name", is("qparam1")), hasProperty("required", is(true)), hasProperty("type", is(ParameterType.STRING))), allOf(hasProperty("name", is("qparam2")), hasProperty("required", is(false)), hasProperty("type", is(ParameterType.STRING))), allOf(hasProperty("name", is("qparam3")), hasProperty("required", is(false)), hasProperty("type", is(ParameterType.NUMERIC))), allOf(hasProperty("name", is("qparam4")), hasProperty("required", is(false)), hasProperty("type", is(ParameterType.BOOLEAN)))));
}
Aggregations