Create an initial web service
Create a maven project structure. One mock webservice should be included. Both Json and XML payload accepted. Configuration of this webservice (response body, response headers, http status code) should be fully configured in a configuration file. Invoication details (headers, payload) should be logged. Closes #T124
This commit is contained in:
		| @@ -0,0 +1,61 @@ | ||||
| package com.release11.klaus.service; | ||||
|  | ||||
| import com.release11.klaus.repository.MockedResponseRedisRepository; | ||||
| import org.junit.jupiter.api.BeforeAll; | ||||
| import org.junit.jupiter.api.Test; | ||||
| import org.mockito.InjectMocks; | ||||
| import org.mockito.Mock; | ||||
| import org.springframework.boot.test.context.SpringBootTest; | ||||
| import org.springframework.http.*; | ||||
|  | ||||
| import java.net.URI; | ||||
| import java.util.UUID; | ||||
|  | ||||
| import static org.mockito.ArgumentMatchers.any; | ||||
| import static org.mockito.ArgumentMatchers.anyInt; | ||||
| import static org.assertj.core.api.Assertions.*; | ||||
| import static org.mockito.Mockito.*; | ||||
|  | ||||
| @SpringBootTest | ||||
| class KlausServiceImplTest { | ||||
|  | ||||
|     @Mock | ||||
|     MockedResponseRedisRepository mockedResponseRedisRepository; | ||||
|  | ||||
|     @InjectMocks | ||||
|     KlausServiceImpl klausServiceImpl; | ||||
|  | ||||
|     private final static UUID uuid = UUID.fromString("e4248095-100e-4f1f-8226-e722014ae29f"); | ||||
|     private final static URI uri = URI.create("http//:localhost:8080"); | ||||
|     private static ResponseEntity<String> mockedResponseEntity; | ||||
|     private static RequestEntity<String> mockedRequestEntity; | ||||
|  | ||||
|     @BeforeAll | ||||
|     public static void initializeMockEntities(){ | ||||
|         HttpHeaders httpHeaders = new HttpHeaders(); | ||||
|         mockedResponseEntity = new ResponseEntity<String>("body", httpHeaders, HttpStatus.ACCEPTED); | ||||
|         mockedRequestEntity = new RequestEntity<String>(HttpMethod.POST, uri); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     void getMockedResponse() { | ||||
|         when(mockedResponseRedisRepository.getMockedResponse(any(), anyInt())) | ||||
|                 .thenReturn(mockedResponseEntity); | ||||
|  | ||||
|         ResponseEntity<String> responseEntity = klausServiceImpl.getMockedResponse(uuid, 1); | ||||
|         assertThat(responseEntity).isNotNull(); | ||||
|         verify(mockedResponseRedisRepository).getMockedResponse(any(), anyInt()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     void setMockedResponse() { | ||||
|         when(mockedResponseRedisRepository.setMockedResponse(any(), anyInt(), any(), any())) | ||||
|                 .thenReturn(mockedResponseEntity); | ||||
|  | ||||
|         ResponseEntity<String> responseEntity = klausServiceImpl.setMockedResponse(uuid, 1, | ||||
|                 HttpStatus.ACCEPTED, mockedRequestEntity); | ||||
|         assertThat(responseEntity).isNotNull(); | ||||
|         verify(mockedResponseRedisRepository).setMockedResponse(any(), anyInt(), any(), any()); | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Szakalakamaka
					Szakalakamaka