spring-boot-test

How to fix the null value response of RestTemplate.exchange in a Mockito Test?

点点圈 提交于 2021-02-08 23:38:20
问题 My Service class is below, followed by its test - @Service public class MyServiceImpl implements MyService { @Autowired private RestTemplate restTemplate; @Override public StudentInfo getStudentInfo(String name) { HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); HttpEntity entity = new HttpEntity(headers); StudentInfo student = null; URI uri = new URI("http:\\someurl.com"); ResponseEntity<String> responseEntity = restTemplate.exchange(uri,

wiremock post request json body property value is dynamic generated value how to stub

穿精又带淫゛_ 提交于 2021-02-08 10:45:18
问题 Am new to wiremock , am using wiremock in my spring boot integration test for mocking one of the external http call. My json request body contains two dynamic properties, all other fields am able to set and stub in the request only two field values am not able to set as they are dynamic values. As these are dynamic in nature, I mean value of the property is random-auto-genarated values. Is there a way to ignore these properties and remaining all properties are anyhow matching. I know that

Unsatisfied dependency during test

自古美人都是妖i 提交于 2021-02-07 07:41:49
问题 I have a spring boot 2.0.0 M2 application who run well. I use autowired on constructor @RequestMapping(value = "/rest") @RestController public class AddressRestController extends BaseController{ private final AddressService AddressService; @Autowired public AddressRestController(final AddressService AddressService) { this.AddressService = AddressService; } ... } @Service public class AddressServiceImpl extends BaseService implements AddressService { @Autowired public AddressServiceImpl(final

Spring Boot Application is starting up from a JUnit test but unable to access through URL

杀马特。学长 韩版系。学妹 提交于 2021-02-05 11:27:26
问题 I have a JUnit Test that starts my spring boot appcliation (Application.java). @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) public class AppclaitionTest { @Test public void contextLoads(){ Application.main(new String[]{}); } } If I run the JUnit test, Application is successfully starting up, but not accessible through url Application Logs: 2017-06-16 12:18:07.918 INFO 207028 --- [ main] com.chandu.test.AppclaitionTest : Started AppclaitionTest in 1.927 seconds

Spring Boot Application is starting up from a JUnit test but unable to access through URL

℡╲_俬逩灬. 提交于 2021-02-05 11:26:27
问题 I have a JUnit Test that starts my spring boot appcliation (Application.java). @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) public class AppclaitionTest { @Test public void contextLoads(){ Application.main(new String[]{}); } } If I run the JUnit test, Application is successfully starting up, but not accessible through url Application Logs: 2017-06-16 12:18:07.918 INFO 207028 --- [ main] com.chandu.test.AppclaitionTest : Started AppclaitionTest in 1.927 seconds

spring boot test junit null pointer exception

半世苍凉 提交于 2021-02-05 06:10:48
问题 im new on this of unit tests, so im trying to code the unit test for my service, right now i have this class package com.praxis.topics.service; import com.praxis.topics.exception.EntityNotFoundException; import com.praxis.topics.model.Topic; import com.praxis.topics.model.enums.Status; import com.praxis.topics.repository.TopicRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java

spring boot test junit null pointer exception

萝らか妹 提交于 2021-02-05 06:09:46
问题 im new on this of unit tests, so im trying to code the unit test for my service, right now i have this class package com.praxis.topics.service; import com.praxis.topics.exception.EntityNotFoundException; import com.praxis.topics.model.Topic; import com.praxis.topics.model.enums.Status; import com.praxis.topics.repository.TopicRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java

UriComponentsBuilder/MvcComponentsBuilder usage in a Spring Boot Test

橙三吉。 提交于 2021-01-29 09:21:38
问题 I've put a very simple sample project on GitHub to reproduce the problem. The main issue is that I have a PersonController that has a PutMapping to create a new person. In order to populate the Location header with the URL to fetch that person, I add the UriComponentsBuilder as parameter for that PutMapping , as you can see here: @PostMapping public ResponseEntity<Person> add(@RequestBody final PersonForCreate personForCreate, UriComponentsBuilder uriComponentsBuilder) { Person newPerson =

Adding custom header using Spring Kafka

人走茶凉 提交于 2021-01-27 14:00:06
问题 I am planning to use the Spring Kafka client to consume and produce messages from a kafka setup in a Spring Boot application. I see support for custom headers in Kafka 0.11 as detailed here. While it is available for native Kafka producers and consumers, I don't see support for adding/reading custom headers in Spring Kafka. I am trying to implement a DLQ for messages based on a retry count that I was hoping to store in the message header without having to parse the payload. 回答1: Well, Spring

Spring boot with WebFlux always throw 403 status in tests

不问归期 提交于 2020-12-05 11:54:10
问题 Great thx for viewing my question) I have some strange subject: my spring boot tests don't work. They start successfully but always throwing 403 HTTP status when making the requests to any controller I have some project with next dependencies: buildscript { ext.kotlin_version = '1.3.71' dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.71" classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.1.RELEASE" classpath "com.google.cloud.tools.jib:com.google.cloud