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:
13
src/test/java/com/release11/klaus/KlausApplicationTests.java
Normal file
13
src/test/java/com/release11/klaus/KlausApplicationTests.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.release11.klaus;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class KlausApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.release11.klaus.config;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.core.env.Environment;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
class RedisConfigTest {
|
||||
|
||||
@Test
|
||||
void jedisPool() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.release11.klaus.controller;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class KlausControllerTest {
|
||||
|
||||
@Test
|
||||
void getMockedResponse() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void setMockedResponse() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.release11.klaus.controller;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class KlausMvcControllerTest {
|
||||
|
||||
@Test
|
||||
void showHome() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.release11.klaus.repository;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class MockedResponseRedisRepositoryTest {
|
||||
|
||||
@Test
|
||||
void getMockedResponse() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void setMockedResponse() {
|
||||
}
|
||||
}
|
||||
@@ -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