Procházet zdrojové kódy

去掉 framework 部分测试代码

jobob před 9 roky
rodič
revize
c9c68f0c9e

+ 6 - 26
mybatis-plus/pom.xml

@@ -43,8 +43,6 @@
 		<mybatis-ehcache.version>1.0.3</mybatis-ehcache.version>
 		<junit.version>4.12</junit.version>
 		<contiperf.version>2.3.4</contiperf.version>
-		<hamcrest.version>1.3</hamcrest.version>
-		<mockito.version>2.1.0-RC.1</mockito.version>
 	</properties>
 
 	<dependencies>
@@ -115,33 +113,15 @@
 			<scope>test</scope>
 		</dependency>
 		<dependency>
-			<groupId>org.springframework</groupId>
-			<artifactId>spring-test</artifactId>
-			<version>${spring.version}</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
-			<version>${junit.version}</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>org.databene</groupId>
-			<artifactId>contiperf</artifactId>
-			<version>${contiperf.version}</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>org.hamcrest</groupId>
-			<artifactId>hamcrest-all</artifactId>
-			<version>${hamcrest.version}</version>
+		    <groupId>junit</groupId>
+		    <artifactId>junit</artifactId>
+		    <version>${junit.version}</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>
-			<groupId>org.mockito</groupId>
-			<artifactId>mockito-core</artifactId>
-			<version>${mockito.version}</version>
+		    <groupId>org.databene</groupId>
+		    <artifactId>contiperf</artifactId>
+		    <version>${contiperf.version}</version>
 			<scope>test</scope>
 		</dependency>
 		<!-- test end -->

+ 0 - 39
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/framework/RestResponse.java

@@ -1,39 +0,0 @@
-package com.baomidou.mybatisplus.test.framework;
-
-public class RestResponse<T> {
-
-	private boolean success;
-	private String message;
-	private T data;
-
-	public RestResponse(boolean success, String message, T data) {
-		this.success = success;
-		this.message = message;
-		this.data = data;
-	}
-
-	public boolean getSuccess() {
-		return success;
-	}
-
-	public void setSuccess(boolean success) {
-		this.success = success;
-	}
-
-	public String getMessage() {
-		return message;
-	}
-
-	public void setMessage(String message) {
-		this.message = message;
-	}
-
-	public T getData() {
-		return data;
-	}
-
-	public void setData(T data) {
-		this.data = data;
-	}
-
-}

+ 0 - 64
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/framework/UserController.java

@@ -1,64 +0,0 @@
-package com.baomidou.mybatisplus.test.framework;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-import com.baomidou.mybatisplus.test.framework.service.IUserService;
-import com.baomidou.mybatisplus.test.mysql.entity.User;
-
-@Controller
-@RequestMapping("/user")
-public class UserController {
-
-	@Autowired
-	private IUserService userService;
-
-	@ResponseBody
-	@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json")
-	public RestResponse<User> getUser(@PathVariable("id") Long id) {
-		User user = userService.selectById(id);
-		return retRestResponse(user);
-	}
-
-	//
-	// @ResponseBody
-	// @RequestMapping(method = RequestMethod.POST, produces =
-	// "application/json")
-	// public RestResponse saveUser(@RequestBody User user) {
-	// userService.saveUser(user);
-	// return new RestResponse<String>(true, "", null);
-	// }
-	//
-	// @ResponseBody
-	// @RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces
-	// = "application/json")
-	// public RestResponse deleteUser(@PathVariable("id") int id) {
-	// userService.deleteUser(id);
-	// return new RestResponse<String>(true, "", null);
-	// }
-	//
-	// @ResponseBody
-	// @RequestMapping(method = RequestMethod.PUT, produces =
-	// "application/json")
-	// public RestResponse updateUser(@RequestBody User user) {
-	// userService.updateUser(user);
-	// return new RestResponse<String>(true, "", null);
-	// }
-
-	public RestResponse<User> retRestResponse() {
-		return retRestResponse(null);
-	}
-
-	public RestResponse<User> retRestResponse(User user) {
-		return retRestResponse("", user);
-	}
-
-	public RestResponse<User> retRestResponse(String message, User user) {
-		return new RestResponse<User>(true, message, user);
-	}
-
-}

+ 0 - 103
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/framework/UserControllerTest.java

@@ -1,103 +0,0 @@
-package com.baomidou.mybatisplus.test.framework;
-
-import static org.hamcrest.Matchers.is;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
-
-import java.nio.charset.Charset;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.MockitoAnnotations;
-import org.mockito.Spy;
-import org.springframework.http.MediaType;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.TestExecutionListeners;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
-import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
-import org.springframework.test.web.servlet.MockMvc;
-import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
-import org.springframework.test.web.servlet.setup.MockMvcBuilders;
-
-import com.baomidou.mybatisplus.test.framework.service.IUserService;
-import com.baomidou.mybatisplus.test.mysql.entity.User;
-
-/*
- * Retrieve user with ID=3: GET http://localhost:8080/user/3
- * Save a new User: POST http://localhost:8080/user
- * Update User: PUT http://localhost:8080/user
- * Delete use with ID=3: DELETE http://localhost:8080/user/3
- */
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { "classpath:mysql/spring-test-context.xml" })
-
-/*
- * 事务配置<br>
- * DependencyInjectionTestExecutionListener 监听测试类中的依赖注入是否正确<br>
- * TransactionalTestExecutionListener 监听测试类中的事务<br>
- */
-@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class,
-		TransactionalTestExecutionListener.class })
-//@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
-public class UserControllerTest {
-
-	public static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
-			MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
-
-	@InjectMocks
-	private UserController userController;
-
-	private MockMvc mockMvc;
-
-	@Spy
-	private IUserService userService;
-
-	@Before
-	public void setup() {
-		MockitoAnnotations.initMocks(this);
-		mockMvc = MockMvcBuilders.standaloneSetup(userController).build();
-	}
-
-	@Test
-	public void testSave() throws Exception {
-		mockMvc.perform(post("/user").contentType(APPLICATION_JSON_UTF8).content(new User().toString()))
-				.andExpect(MockMvcResultMatchers.status().isOk())
-				.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(jsonPath("success", is(true)));
-	}
-
-	@Test
-	public void testGet() throws Exception {
-
-		int userId = 3;
-
-		mockMvc.perform(get("/user/" + userId)).andExpect(MockMvcResultMatchers.status().isOk())
-				.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andExpect(jsonPath("data.age", is(15)))
-				.andExpect(jsonPath("data.firstName", is("bob"))).andExpect(jsonPath("data.id", is(userId)))
-				.andExpect(jsonPath("success", is(true)));
-	}
-
-	// @Test
-	// public void testUpdate() throws Exception {
-	// mockMvc.perform(
-	// put("/user")
-	// .contentType(TestUtil.APPLICATION_JSON_UTF8)
-	// .content(TestUtil.convertObjectToJsonBytes(new User())))
-	// .andExpect(MockMvcResultMatchers.status().isOk())
-	// .andExpect(jsonPath("success", is(true)));
-	// }
-	//
-	// @Test
-	// public void testDelete() throws Exception {
-	// mockMvc.perform(
-	// delete("/user/3"))
-	// .andExpect(MockMvcResultMatchers.status().isOk())
-	// .andExpect(content().contentType(MediaType.APPLICATION_JSON))
-	// .andExpect(jsonPath("success", is(true)));
-	// }
-
-}

+ 0 - 8
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/framework/service/IUserService.java

@@ -1,8 +0,0 @@
-package com.baomidou.mybatisplus.test.framework.service;
-
-import com.baomidou.framework.service.ISuperService;
-import com.baomidou.mybatisplus.test.mysql.entity.User;
-
-public interface IUserService extends ISuperService<User> {
-	
-}

+ 0 - 22
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/framework/service/UserServiceImpl.java

@@ -1,22 +0,0 @@
-package com.baomidou.mybatisplus.test.framework.service;
-
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import com.baomidou.framework.service.impl.SuperServiceImpl;
-import com.baomidou.mybatisplus.test.mysql.UserMapper;
-import com.baomidou.mybatisplus.test.mysql.entity.User;
-
-@Service
-public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implements IUserService {
-	
-	/**
-	 * 测试事务
-	 */
-	@Transactional
-	@Override
-	public boolean insert(User entity) {
-		return super.insert(entity);
-	}
-	
-}

+ 0 - 49
mybatis-plus/src/test/resources/mysql/spring-test-context.xml

@@ -1,49 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
-	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
-	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
-	xsi:schemaLocation="
-     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
-     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
-     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
-     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
-
-	<context:component-scan
-		base-package="com.baomidou.mybatisplus.test.framework.service" />
-
-	<!-- 配置DataSource数据源 -->
-	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
-		destroy-method="close">
-		<property name="driverClassName" value="${driverClass}" />
-		<property name="url" value="${jdbcUrl}" />
-		<property name="username" value="${user}" />
-		<property name="password" value="${password}" />
-		<property name="maxActive" value="50" />
-		<property name="maxIdle" value="3" />
-		<property name="maxWait" value="1000" />
-		<property name="defaultAutoCommit" value="true" />
-		<property name="removeAbandoned" value="true" />
-		<property name="removeAbandonedTimeout" value="60" />
-	</bean>
-
-	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
-		<property name="dataSource" ref="dataSource" />
-		<property name="mapperLocations" value="classpath:mysql/*Mapper.xml" />
-	</bean>
-
-	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
-		p:basePackage="com.baomidou.mybatisplus.test.mysql"
-		p:sqlSessionFactoryBeanName="sqlSessionFactory" />
-
-	<!-- 对dataSource 数据源进行事务管理 -->
-	<bean id="transactionManager"
-		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
-		<property name="dataSource" ref="dataSource" />
-	</bean>
-
-	<!-- 开启事务注解驱动 -->
-	<tx:annotation-driven transaction-manager="transactionManager" />
-
-</beans>