我正在使用Spring进行MVC测试
这是我的测试课
@RunWith(SpringRunner.class)
@WebMvcTest
public class ITIndexController {
@Autowired
WebApplicationContext context;
MockMvc mockMvc;
@MockBean
UserRegistrationApplicationService userRegistrationApplicationService;
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders
.webAppContextSetup(context)
.apply(springSecurity())
.build();
}
@Test
public void should_render_index() throws Exception {
mockMvc.perform(get("/"))
.andExpect(status().isOk())
.andExpect(view().name("index"))
.andExpect(content().string(containsString("Login")));
}
}
Run Code Online (Sandbox Code Playgroud)
这是MVC配置
@Configuration
@EnableWebMvc
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index");
registry.addViewController("/login/form").setViewName("login");
}
}
Run Code Online (Sandbox Code Playgroud)
这是安全配置
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
@Qualifier("customUserDetailsService")
UserDetailsService userDetailsService;
@Override
protected void configure(HttpSecurity http) throws Exception …Run Code Online (Sandbox Code Playgroud) 我正在为我的应用程序编写集成测试,并希望为我的测试使用自定义 webmvc 配置
我的基本包 com.marco.nutri 中有三个类:
我的测试在 br.com.marco.nutri.integration.auth 包中:
@RunWith(SpringRunner.class)
@SpringBootTest(classes={Application.class, WebMvcTestConfiguration.class, SecurityConfig.class})
public class ITSignup {
//Test code
}
Run Code Online (Sandbox Code Playgroud)
我在包 com.marco.nutri.integration 中有一个测试配置类:
@TestConfiguration
@EnableWebMvc
public class WebMvcTestConfiguration extends WebMvcConfigurerAdapter {
//Some configuration
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行我的测试时,选择的是 MvcConfig.class 而不是 WebMvcTestConfiguration.class
我究竟做错了什么?
我有两个具有一对多关系的实体
public class Order {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String userName;
private String company;
@OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name="ORDER_ID")
private List<Item> items;
}
public class Item {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String name;
private Long quantity;
}
Run Code Online (Sandbox Code Playgroud)
两个实体都有一个@RepositoryRestResrouce,当我尝试在 /orders 集合中发布一个包含以下项目的新订单时:
{
"userName":"Marco",
"company":"MP",
"items":[
{"name":"CD","quantity":"10"},
{"name":"DVD","quantity":"5"}
]
}
Run Code Online (Sandbox Code Playgroud)
我有一个内部服务器错误:
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Failed to convert from type [java.net.URI] to type [com.example.springdatarest.domain.entity.Item] for value 'name'; nested exception is java.lang.IllegalArgumentException: Cannot resolve URI name. Is it local or remote? …Run Code Online (Sandbox Code Playgroud) 我将开始学习Vue.js并希望使用它来使用HATEOAS编译API,但没有发现任何使它更容易的
是否有一些Vue.js模块用于消耗HATEOAS编译Rest APIS?