Bael 5296: Added Http Request Header using the Feign Client (#12201)
* Implemented cassandra batch query * Added netty version param * Reformatted correctly * Reformatted correctly * Reformatted correctly * Formatting fix resolved * Formatting fix resolved * Removed unused method * Refactored method for better readability * tab spaces corrected * Added http headers in feign * Updated code * Updated code * Removed unused code * Removed unused logger code * Implemented Interceptor and logging related code review * Added AuthService Code * Removed toString method * Removed unnecessary declaration * Removed new line * Added feign headers log as well * Moved to Authorisation package for better naming * spaces removed * @Override included Co-authored-by: saikat chakraborty <saikat.chakraborty@tesco.com>
This commit is contained in:
committed by
GitHub
parent
4abe624ea6
commit
4b36bbf0b7
+38
@@ -0,0 +1,38 @@
|
||||
package com.baeldung.feign.clients.header.dynamicheader;
|
||||
|
||||
import com.baeldung.feign.clients.builder.BookFeignClientBuilder;
|
||||
import com.baeldung.feign.models.Book;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Consumes https://github.com/Baeldung/spring-hypermedia-api
|
||||
*/
|
||||
public class BookClientLiveTest {
|
||||
|
||||
private BookClient bookClient;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
bookClient = BookFeignClientBuilder.createClient(BookClient.class, "http://localhost:8081/api/books");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBookClient_shouldPostBook() throws Exception {
|
||||
String isbn = UUID.randomUUID()
|
||||
.toString();
|
||||
|
||||
Book book = new Book(isbn, "Me", "It's me!", null, null);
|
||||
|
||||
Map<String,Object> headerMap = new HashMap<>();
|
||||
|
||||
headerMap.put("metadata-key1", "metadata-value1");
|
||||
headerMap.put("metadata-key2", "metadata-value2");
|
||||
|
||||
bookClient.create(headerMap, book);
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package com.baeldung.feign.clients.header.interceptor;
|
||||
|
||||
import com.baeldung.feign.clients.builder.BookFeignClientBuilder;
|
||||
import com.baeldung.feign.clients.header.staticheader.BookClient;
|
||||
import com.baeldung.feign.models.Book;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Consumes https://github.com/Baeldung/spring-hypermedia-api
|
||||
*/
|
||||
public class BookClientLiveTest {
|
||||
|
||||
private BookClient bookClient;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
bookClient = BookFeignClientBuilder.createClientWithInterceptor(BookClient.class, "http://localhost:8081/api/books");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBookClient_shouldFindOneBook() throws Exception {
|
||||
Book book = bookClient.findByIsbn("0151072558")
|
||||
.getBook();
|
||||
assertThat(book.getAuthor(), containsString("Orwell"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBookClient2_shouldFindOneBook() throws Exception {
|
||||
Book book = bookClient.findByIsbn("0151072558")
|
||||
.getBook();
|
||||
assertThat(book.getAuthor(), containsString("Orwell"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBookClient_shouldPostBook() throws Exception {
|
||||
String isbn = UUID.randomUUID()
|
||||
.toString();
|
||||
Book book = new Book(isbn, "Me", "It's me!", null, null);
|
||||
bookClient.create(book);
|
||||
|
||||
book = bookClient.findByIsbn(isbn)
|
||||
.getBook();
|
||||
assertThat(book.getAuthor(), is("Me"));
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.baeldung.feign.clients.header.staticheader;
|
||||
|
||||
import com.baeldung.feign.clients.builder.BookFeignClientBuilder;
|
||||
import com.baeldung.feign.models.Book;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Consumes https://github.com/Baeldung/spring-hypermedia-api
|
||||
*/
|
||||
public class BookClientLiveTest {
|
||||
|
||||
private BookClient bookClient;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
bookClient = BookFeignClientBuilder.createClient(BookClient.class, "http://localhost:8081/api/books");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBookClient_shouldFindOneBook() throws Exception {
|
||||
Book book = bookClient.findByIsbn("0151072558")
|
||||
.getBook();
|
||||
assertThat(book.getAuthor(), containsString("Orwell"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBookClient_shouldPostBook() throws Exception {
|
||||
String isbn = UUID.randomUUID()
|
||||
.toString();
|
||||
Book book = new Book(isbn, "Me", "It's me!", null, null);
|
||||
|
||||
bookClient.create(book);
|
||||
|
||||
book = bookClient.findByIsbn(isbn)
|
||||
.getBook();
|
||||
assertThat(book.getAuthor(), is("Me"));
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.feign.clients.header.staticheader.parameterized;
|
||||
|
||||
import com.baeldung.feign.clients.builder.BookFeignClientBuilder;
|
||||
import com.baeldung.feign.models.Book;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Consumes https://github.com/Baeldung/spring-hypermedia-api
|
||||
*/
|
||||
public class BookClientLiveTest {
|
||||
|
||||
private BookClient bookClient;
|
||||
|
||||
private String requester = "test";
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
bookClient = BookFeignClientBuilder.createClient(BookClient.class, "http://localhost:8081/api/books");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBookClient_shouldFindOneBook() throws Exception {
|
||||
Book book = bookClient.findByIsbn(requester, "0151072558")
|
||||
.getBook();
|
||||
assertThat(book.getAuthor(), containsString("Orwell"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user