Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 getUsers() {

return repository.findAll();

}

@GetMapping("/Users/{id}")

public Optional getUsers(@PathVariable String id) {

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

fscanf retums a special value EOF that stands for...

Answered: 1 week ago