BAEL-1931 rename SampleService to SampleClient (#6682)

* BAEL-1931 rename SampleService to SampleClient

* remove not null assertion

* remove fixed method order

* disable usage of local kerberos ticket cache
This commit is contained in:
Denis 2019-04-14 08:24:03 +02:00 committed by Grzegorz Piwowarek
parent 7fc7e61674
commit ce09990056
3 changed files with 11 additions and 13 deletions

View File

@ -12,6 +12,8 @@ class KerberosClientApp {
System.setProperty("java.security.krb5.conf", System.setProperty("java.security.krb5.conf",
Paths.get(".\\krb-test-workdir\\krb5.conf").normalize().toAbsolutePath().toString()); Paths.get(".\\krb-test-workdir\\krb5.conf").normalize().toAbsolutePath().toString());
System.setProperty("sun.security.krb5.debug", "true"); System.setProperty("sun.security.krb5.debug", "true");
// disable usage of local kerberos ticket cache
System.setProperty("http.use.global.creds", "false");
} }
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -5,14 +5,14 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@Service @Service
class SampleService { class SampleClient {
@Value("${app.access-url}") @Value("${app.access-url}")
private String endpoint; private String endpoint;
private RestTemplate restTemplate; private RestTemplate restTemplate;
public SampleService(RestTemplate restTemplate) { public SampleClient(RestTemplate restTemplate) {
this.restTemplate = restTemplate; this.restTemplate = restTemplate;
} }

View File

@ -1,6 +1,5 @@
package kerberos.client; package kerberos.client;
import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -10,7 +9,6 @@ import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
@ -23,21 +21,19 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@FixMethodOrder public class SampleClientManualTest {
public class SampleServiceManualTest {
@Autowired @Autowired
private SampleService sampleService; private SampleClient sampleClient;
@Test @Test
public void a_givenKerberizedRestTemplate_whenServiceCall_thenSuccess() { public void givenKerberizedRestTemplate_whenServiceCall_thenSuccess() {
assertNotNull(sampleService); assertEquals("data from kerberized server", sampleClient.getData());
assertEquals("data from kerberized server", sampleService.getData());
} }
@Test @Test
public void b_givenRestTemplate_whenServiceCall_thenFail() { public void givenRestTemplate_whenServiceCall_thenFail() {
sampleService.setRestTemplate(new RestTemplate()); sampleClient.setRestTemplate(new RestTemplate());
assertThrows(RestClientException.class, sampleService::getData); assertThrows(RestClientException.class, sampleClient::getData);
} }
} }