Question
Maven Project I am trying to understand and type a JUnit test for each of these methods. Below I have sent in my methods that
Maven Project
I am trying to understand and type a JUnit test for each of these methods. Below I have sent in my methods that I have currently. Please send back the code to do JUnit testing with the methods below.
package com.userserver.mongo1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RestController
@CrossOrigin(origins = "http://localhost:4200")
public class UserController {
@Autowired
UserRepository repository;
@Autowired
AuthService authService;
@Autowired
SaveUserService saveUserService;
@PostMapping("/Users")
public Boolean saveUser(@RequestBody User user) {
Boolean saved = saveUserService.saveUser(user);
return saved;
}
@PostMapping("/authentication")
public void authenticateUser(@RequestBody User user)
{ authService.authenticateUser(user);
}
@PostMapping("/userRole")
public String returnUserRole(@RequestBody User user)
{
String userEmail = user.getUserEmail();
System.out.println(userEmail);
User userInfo = repository.findByUserEmail(userEmail);
System.out.println(userInfo);
String role = userInfo.getUserRole();
return role;
}
@GetMapping("/Users")
public List
return repository.findAll();
}
@GetMapping("/Users/{id}")
public Optional
return repository.findById(id);
}
@DeleteMapping("/Users/{id}")
public String deleteUser(@PathVariable String id) {
repository.deleteById(id);
return "user deleted with id : " + id;
}
//Deletes all users
@DeleteMapping("/Users")
public String deleteAllUsers() {
repository.deleteAll();
return "All users delete.";
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started