我正在尝试测试我的上传我正在使用 Junit、Mockmvc 和 Spring
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:app-context.xml")
@WebAppConfiguration
public class UploadTest {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
Application app;
String session;
@Before
public void setup() throws Exception {
Users.init();
Graphs.init();
Sessions.init();
this.mockMvc = MockMvcBuilders.standaloneSetup(new Controller()).build();
Users.setConfig("dani.pass", "81dc9bdb52d04dc20036dbd8313ed055");
MvcResult m = mockMvc.perform(get("/logIn?name=dani&encrypted=81dc9bdb52d04dc20036dbd8313ed055"))
.andExpect(content().contentType(TestUtil.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.status", is(1)))
.andExpect(jsonPath("$.error", is("")))
.andReturn();
String content = m.getResponse().getContentAsString();
JSONObject jsonObject = new JSONObject(content);
session=jsonObject.get("data").toString();
}
@Test
public void uploadTest1() throws Exception {
String filePath = (new File(".")).getCanonicalFile().getCanonicalFile().getCanonicalPath()
+ "/books.ttl";
FileInputStream fis = new FileInputStream(filePath);
MockMultipartFile multipartFile = new MockMultipartFile("file", fis);
HashMap<String, String> contentTypeParams = new HashMap<String, String>();
contentTypeParams.put("name", "http://exampleTest.com/ng"+Long.toString(System.currentTimeMillis()));
contentTypeParams.put("session", session);
MediaType mediaType = new MediaType("multipart", "form-data", contentTypeParams);
mockMvc.perform(MockMvcRequestBuilders.fileUpload("/upload")
.file(multipartFile)
.param("name", "http://exampleTest.com/ng"+Long.toString(System.currentTimeMillis()))
.param("session", session))
.andExpect(content().contentType(TestUtil.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.status", is(1)))
.andReturn();
}
}
你可以帮帮我吗?
错误堆栈跟踪:
[org.springframework.test.context.support.DependencyInjectionTestExecutionListener@361cb7a1] 准备测试实例 [endpoint.security.tests.UploadTest@6f7918f0] org.springframework.beans.factory.BeanCreationException:创建名为“endpoint.security. tests.UploadTest':自动装配依赖注入失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法自动装配字段:私有 com.sun.jersey.server.impl.application.WebApplicationContext endpoint.security.tests.UploadTest.wac;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type of [com.sun.jersey.server.impl.application.WebApplicationContext] found for dependency: 预期至少有 1 个 bean 有资格作为此依赖项的自动装配候选者. 依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)} at [.cp/:na] 原因:org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private com .sun.jersey.server.impl.application.WebApplicationContext 端点.security.tests.UploadTest.wac;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type of [com.sun.jersey.server.impl.application.WebApplicationContext] found for dependency: 预期至少有 1 个 bean 有资格作为此依赖项的自动装配候选者. 依赖注解:私有 com.sun.jersey.server.impl.application.WebApplicationContext 端点.security.tests.UploadTest.wac;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type of [com.sun.jersey.server.impl.application.WebApplicationContext] found for dependency: 预期至少有 1 个 bean 有资格作为此依赖项的自动装配候选者. 依赖注解:私有 com.sun.jersey.server.impl.application.WebApplicationContext 端点.security.tests.UploadTest.wac;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type of [com.sun.jersey.server.impl.application.WebApplicationContext] found for dependency: 预期至少有 1 个 bean 有资格作为此依赖项的自动装配候选者. 依赖注解: