Commit 23ea0734 authored by vikram singh's avatar vikram singh

segregated integration and component test cases

parent 942fa67b
......@@ -2,12 +2,14 @@ package com.nisum.webflux.controller;
import com.nisum.webflux.model.Employee;
import com.nisum.webflux.service.IEmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@RestController
@Slf4j
public class EmployeeController {
@Autowired
......@@ -17,7 +19,7 @@ public class EmployeeController {
@PostMapping("/employee")
public Mono<Employee> save(@RequestBody
Employee employee) {
System.out.println("employee obj ##################################################"+employee);
log.info("employee obj ##################################################"+employee);
return employeeService.save(employee);
}
......
......@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@Slf4j
//basic kafka
public class SampleController {
@Autowired
KafkaServer kafkaServer;
......
......@@ -30,17 +30,12 @@ import static org.mockito.Mockito.when;
@SpringBootTest
@RunWith(SpringRunner.class)
@AutoConfigureWebTestClient
public class EmployeeControllerTest {
public class EmployeeControllerIntegrationTest {
@Autowired
WebTestClient webTestClient;
//// @MockBean
// @Autowired
// EmployeeRepo empRepo;
@InjectMocks
EmployeeController employeeController;
......
package com.nisum.webflux.controller;
import com.nisum.webflux.model.Fruit;
import com.nisum.webflux.repository.FruitRepository;
import com.nisum.webflux.service.impl.TestConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.function.BodyInserters;
import reactor.core.publisher.Mono;
import static org.mockito.Mockito.when;
@SpringBootTest
@RunWith(SpringRunner.class)
@AutoConfigureWebTestClient
//@ContextConfiguration(classes = TestConfig.class)
@ContextConfiguration(classes = TestConfig.class)
public class FruitControllerComponentTest {
@Autowired
@Autowired
WebTestClient webTestClient;
@Test
public void save_UsingWebTestClient() {
Fruit fruit=new Fruit("1","apple","300");
webTestClient.post().uri("/fruit").contentType(MediaType.APPLICATION_JSON_UTF8).body(BodyInserters.fromObject(fruit))
.exchange()
.expectStatus().isOk().expectBody().jsonPath("$.id").isEqualTo("1");
}
@Autowired
FruitRepository fruitRepo;
Please register or sign in to reply
@Test
public void save() {
ArgumentCaptor<Fruit> requestCaptor = ArgumentCaptor.forClass(
Fruit.class);
when(fruitRepo.save(requestCaptor.capture())).thenReturn(Mono.error(new RuntimeException()));
Fruit fruit=new Fruit("1","apple","300");
webTestClient.post().uri("/fruit").contentType(MediaType.APPLICATION_JSON_UTF8).body(BodyInserters.fromObject(fruit))
.exchange()
.expectStatus().isOk().expectBody().jsonPath("$.id").isEqualTo("1");
}
}
package com.nisum.webflux.controller;
import com.nisum.webflux.model.Fruit;
import com.nisum.webflux.repository.FruitRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.function.BodyInserters;
import reactor.core.publisher.Mono;
import static org.mockito.Mockito.when;
@SpringBootTest
@RunWith(SpringRunner.class)
@AutoConfigureWebTestClient
public class FruitControllerIntegrationTest {
@Autowired
WebTestClient webTestClient;
Please register or sign in to reply
@Test
public void save() {
Fruit fruit= new Fruit("1","apple","300");
webTestClient.post().uri("/fruit").contentType(MediaType.APPLICATION_JSON_UTF8).body(BodyInserters.fromObject(fruit))
.exchange()
.expectStatus().isOk().expectBody().jsonPath("$.id").isEqualTo("1");
}
}
package com.nisum.webflux.service.impl;
import com.nisum.webflux.repository.EmployeeRepo;
import com.nisum.webflux.repository.FruitRepository;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
......@@ -9,5 +10,7 @@ public class TestConfig {
@MockBean
EmployeeRepo empRepo;
@MockBean
FruitRepository fruitRepo;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment