Home > Mobile >  How do I test with Postman a Controller's method which has one (or multiple) objects as paramet
How do I test with Postman a Controller's method which has one (or multiple) objects as paramet

Time:03-18

I an a novice with Spring framework. I have to create a simple application that searches for jobs in a database based on certain criteria, criteria which are sent to the controller's method via a parameter of an entity class specially designed for this scope. I attach the prototype of the method:

@Slf4j
@Service
@RequiredArgsConstructor
@Transactional
public class JobServiceImpl implements JobService {
    private final JobRepository jobRepository;
    private final JobTypeRepository jobTypeRepository;
    private final EntityManagerFactory entityManagerFactory;
    private final UserService userService;
    private final JobContactRepository jobContactRepository;

    @Override
    **public List<JobEntity> searchJobs(JobSearchEntity searchCriteria)** 
    { ...}

Does anyone know how does a method of this type (having parameters a special designed object) can be tested (called) in Postman? Is there any possibility to declare the "parameters of the parameters" of a method, such as is the case here...? Or is it possible to construct the object taken as parameter by the method in the Postman's graphical interface? Does anyone know how to do this task? Thanks in advance.

CodePudding user response:

This isn't a controller, and so you can't talk to it with Postman. Find the controller where this service is used and inspect it there.

(Note that if you're using Spring, you'll often want to use Spring Data to simplify data access; manually using EntityManager is usually unnecessary, and you almost never want to use EntityManagerFactory directly.)

CodePudding user response:

The JobServiceImpl you attached isn't a controller class. For Spring-MVC to recognize the class as a Controller you need to annotate the class with @Controller or @RestController annotation. Also, the method which will handle the URL mapping within the controller class needs to be annotated with @GetMapping or @PostMapping or @DeleteMapping, or so on.

@Contoller // or @RestController
public class JobServiceImpl {
    
    @GetMapping // @PostMapping or @DeleteMapping, etc
    public ResponseEntity mappingMethod() {
        // your code to handle request goes here
    }
}
  • Related