Spring Boot Microservices JWT JUnit Test Issue

I have a problem about solving JwtGrantedAuthoritiesConverter in order service after defining preauthorize annotation in some methods of Order Controller. After I wrote the test shown below, I tried to run it but I got this issue shown below as well. I also shared my repo as a link. How can I fix it? Here is the test method shown below
@Test
public void test_WhenPlaceOrder_DoPayment_Success() throws Exception {
OrderRequest orderRequest = getMockOrderRequest();
MvcResult mvcResult
= mockMvc.perform(MockMvcRequestBuilders.post("/order/placeOrder")
.with(jwt().authorities(new SimpleGrantedAuthority("USER")))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(orderRequest))
).andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();

String orderId = mvcResult.getResponse().getContentAsString();

Optional<Order> order = orderRepository.findById(Long.valueOf(orderId));
assertTrue(order.isPresent());

Order o = order.get();
assertEquals(Long.parseLong(orderId), o.getId());
assertEquals("PLACED", o.getOrderStatus());
assertEquals(orderRequest.getTotalAmount(), o.getAmount());
assertEquals(orderRequest.getQuantity(), o.getQuantity());

}
@Test
public void test_WhenPlaceOrder_DoPayment_Success() throws Exception {
OrderRequest orderRequest = getMockOrderRequest();
MvcResult mvcResult
= mockMvc.perform(MockMvcRequestBuilders.post("/order/placeOrder")
.with(jwt().authorities(new SimpleGrantedAuthority("USER")))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(orderRequest))
).andExpect(MockMvcResultMatchers.status().isOk())
.andReturn();

String orderId = mvcResult.getResponse().getContentAsString();

Optional<Order> order = orderRepository.findById(Long.valueOf(orderId));
assertTrue(order.isPresent());

Order o = order.get();
assertEquals(Long.parseLong(orderId), o.getId());
assertEquals("PLACED", o.getOrderStatus());
assertEquals(orderRequest.getTotalAmount(), o.getAmount());
assertEquals(orderRequest.getQuantity(), o.getQuantity());

}
Here is the error shown below.
java.lang.NoClassDefFoundError: org/springframework/security/oauth2/server/resource/authentication/JwtGrantedAuthoritiesConverter
Caused by: java.lang.ClassNotFoundException: org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter
java.lang.NoClassDefFoundError: org/springframework/security/oauth2/server/resource/authentication/JwtGrantedAuthoritiesConverter
Caused by: java.lang.ClassNotFoundException: org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter
Here is the repo link : https://github.com/Rapter1990/microservicecoursedailybuffer
GitHub
GitHub - Rapter1990/microservicecoursedailybuffer: Spring Boot Micr...
Spring Boot Microservice Example. Contribute to Rapter1990/microservicecoursedailybuffer development by creating an account on GitHub.
3 Replies
JavaBot
JavaBot3y ago
Hey, @direct_x_34! Please remember to /close this post once your question has been answered!
direct_x_34
direct_x_34OP3y ago
I have a problem regarding JWT in JUnit Controller Test in Spring Boot Microservices. Here is the link : https://stackoverflow.com/questions/74378611/spring-boot-microservices-junit-controller-test-jwt-issue
Stack Overflow
Spring Boot Microservices - JUnit Controller Test JWT Issue
I have a problem about solving JWT Issue in order service after defining preauthorize annotation in some methods of Order Controller. After I wrote the test shown below, I tried to run it but I got...
direct_x_34
direct_x_34OP3y ago
@everyone
Want results from more Discord servers?
Add your server