简体   繁体   English

java.lang.AssertionError:预期状态:<200> 但原为:<404> Spring 引导页面未找到

[英]java.lang.AssertionError: Status expected:<200> but was:<404> Spring Boot Page Not found

CheckoutController结帐控制器

@Controller
@Profile("!test")
public class CheckoutController {

  private MonetaryAmount total = Money.of(0, EURO);
  private final UniqueInventory<UniqueInventoryItem> inventory;
  private final Katalog catalogue;

  private List<UniqueInventoryItem> history = new ArrayList();
  
  @Autowired
  public CheckoutController(UniqueInventory<UniqueInventoryItem> _inventory, Katalog _catalogue){
    inventory = _inventory;
    catalogue = _catalogue;
  }
  
  //!  Get Mappings

  //@GetMapping("/checkout")
  @RequestMapping("/checkout")
  @PreAuthorize("hasRole('WORKER')")
  public String checkout(Model model){
    model.addAttribute("total", this.total);
    model.addAttribute("history", this.history);
    model.addAttribute("controller", this);

    return "checkout"; // thymleafe located in proper path, visible when logged in 
  }
}

TestingController测试控制器

@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("test")
public class CheckoutControllerTests {

  @Autowired
  MockMvc mockMvc;

  @BeforeEach
  public void pre() {
    // code
  }

  @Test
  public void checkout() throws Exception {
    // TODO Error msg: status expected:<200> but was:<404>
        mockMvc.perform(get("/checkout").with(user("paul").roles("WORKER")))
      .andExpect(status().isOk());


  }
}

Where it says "/checkout" above, I could put all other available routes which are accepted, but not this one and I do not know why.在上面写着“/checkout”的地方,我可以放上所有其他被接受的可用路线,但不是这个,我不知道为什么。 Again, it's visible to my once logged in running the project.同样,一旦登录运行该项目,我就可以看到它。

I tried using RequestMapping instead of GetMapping but that didnt work either.我尝试使用 RequestMapping 而不是 GetMapping,但这也不起作用。 I googled with no success, in most cases people did not actually point to the right html file but thats not the case here either.我用谷歌搜索没有成功,在大多数情况下,人们实际上并没有指向正确的 html 文件,但这里也不是这种情况。 I am lost at this point, asked my friends and colleagues with no success.我在这一点上迷失了,问我的朋友和同事没有成功。

If you have any clue what it could be, improper mvc setup, yadada, please let me know!如果您有任何线索可能是什么,不正确的 mvc 设置,yadada,请告诉我!

You have conflicting profiles.您有冲突的个人资料。 Your controller is annotated with @Profile("!test") while your test is executing with @ActiveProfiles("test") .您的 controller 使用@Profile("!test")注释,而您的测试使用@ActiveProfiles("test")执行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.AssertionError:预期状态:<200> 但为:<404> 对于 Spring 启动 Rest Controller - java.lang.AssertionError: Status expected:<200> but was:<404> for Spring Boot Rest Controller java.lang.AssertionError:预期状态:&lt;200&gt;但原为:&lt;404&gt; - java.lang.AssertionError: Status expected:<200> but was:<404> java.lang.AssertionError:预期状态:&lt;200&gt;,但在静态服务中为:&lt;404&gt; - java.lang.AssertionError: Status expected:<200> but was:<404> in restful services @RequestMapping java.lang.AssertionError:预期状态:200 实际:404 - @RequestMapping java.lang.AssertionError: Status Expected :200 Actual :404 java.lang.AssertionError: Status expected:&lt;200&gt; but was:&lt;404&gt; in Junit test - java.lang.AssertionError: Status expected:<200> but was:<404> in Junit test java.lang.AssertionError: Status expected:&lt;200&gt; but was:&lt;404&gt; with test case failed - java.lang.AssertionError: Status expected:<200> but was:<404> with test cases failing java.lang.AssertionError: 预期状态:&lt;200&gt; 但为:&lt;400&gt; - java.lang.AssertionError: Status expected:<200> but was:<400> java.lang.AssertionError:预期状态:&lt;200&gt;但原为:&lt;201&gt; - java.lang.AssertionError: Status expected:<200> but was:<201> java.lang.AssertionError:预期状态:&lt;200&gt;但原为:&lt;405&gt; - java.lang.AssertionError: Status expected:<200> but was:<405> java.lang.AssertionError:预期状态:&lt;200&gt;但原为:&lt;302&gt; itShouldAllowAccessToSecuredPageForPermittedUser - java.lang.AssertionError: Status expected:<200> but was:<302> itShouldAllowAccessToSecuredPageForPermittedUser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM