⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlmapclienttests.java

📁 struts+spring 源码 希望能给大家带来帮助
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		template.executorControl.setReturnValue(result, 1);
		template.executorControl.replay();
		assertEquals(result, template.queryForList("myStatement", 10, 20));
		template.executorControl.verify();
	}

	public void testQueryForListParameterAndWithResultSize() throws SQLException {
		List result = new ArrayList();
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.queryForList("myStatement", "myParameter", 10, 20);
		template.executorControl.setReturnValue(result, 1);
		template.executorControl.replay();
		assertEquals(result, template.queryForList("myStatement", "myParameter", 10, 20));
		template.executorControl.verify();
	}

	public void testQueryWithRowHandler() throws SQLException {
		RowHandler rowHandler = new TestRowHandler();
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.queryWithRowHandler("myStatement", null, rowHandler);
		template.executorControl.setVoidCallable(1);
		template.executorControl.replay();
		template.queryWithRowHandler("myStatement", rowHandler);
		template.executorControl.verify();
	}

	public void testQueryWithRowHandlerWithParameter() throws SQLException {
		RowHandler rowHandler = new TestRowHandler();
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.queryWithRowHandler("myStatement", "myParameter", rowHandler);
		template.executorControl.setVoidCallable(1);
		template.executorControl.replay();
		template.queryWithRowHandler("myStatement", "myParameter", rowHandler);
		template.executorControl.verify();
	}

	public void testQueryForPaginatedList() throws SQLException {
		PaginatedList result = new PaginatedArrayList(10);
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.queryForPaginatedList("myStatement", null, 10);
		template.executorControl.setReturnValue(result, 1);
		template.executorControl.replay();
		assertEquals(result, template.queryForPaginatedList("myStatement", 10));
		template.executorControl.verify();
	}

	public void testQueryForPaginatedListWithParameter() throws SQLException {
		PaginatedList result = new PaginatedArrayList(10);
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.queryForPaginatedList("myStatement", "myParameter", 10);
		template.executorControl.setReturnValue(result, 1);
		template.executorControl.replay();
		assertEquals(result, template.queryForPaginatedList("myStatement", "myParameter", 10));
		template.executorControl.verify();
	}

	public void testQueryForMap() throws SQLException {
		Map result = new HashMap();
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.queryForMap("myStatement", "myParameter", "myKey");
		template.executorControl.setReturnValue(result, 1);
		template.executorControl.replay();
		assertEquals(result, template.queryForMap("myStatement", "myParameter", "myKey"));
		template.executorControl.verify();
	}

	public void testQueryForMapWithValueProperty() throws SQLException {
		Map result = new HashMap();
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.queryForMap("myStatement", "myParameter", "myKey", "myValue");
		template.executorControl.setReturnValue(result, 1);
		template.executorControl.replay();
		assertEquals(result, template.queryForMap("myStatement", "myParameter", "myKey", "myValue"));
		template.executorControl.verify();
	}

	public void testInsert() throws SQLException {
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.insert("myStatement", null);
		template.executorControl.setReturnValue("myResult", 1);
		template.executorControl.replay();
		assertEquals("myResult", template.insert("myStatement"));
		template.executorControl.verify();
	}

	public void testInsertWithParameter() throws SQLException {
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.insert("myStatement", "myParameter");
		template.executorControl.setReturnValue("myResult", 1);
		template.executorControl.replay();
		assertEquals("myResult", template.insert("myStatement", "myParameter"));
		template.executorControl.verify();
	}

	public void testUpdate() throws SQLException {
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.update("myStatement", null);
		template.executorControl.setReturnValue(10, 1);
		template.executorControl.replay();
		assertEquals(10, template.update("myStatement"));
		template.executorControl.verify();
	}

	public void testUpdateWithParameter() throws SQLException {
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.update("myStatement", "myParameter");
		template.executorControl.setReturnValue(10, 1);
		template.executorControl.replay();
		assertEquals(10, template.update("myStatement", "myParameter"));
		template.executorControl.verify();
	}

	public void testUpdateWithRequiredRowsAffected() throws SQLException {
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.update("myStatement", "myParameter");
		template.executorControl.setReturnValue(10, 1);
		template.executorControl.replay();
		template.update("myStatement", "myParameter", 10);
		template.executorControl.verify();
	}

	public void testUpdateWithRequiredRowsAffectedAndInvalidRowCount() throws SQLException {
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.update("myStatement", "myParameter");
		template.executorControl.setReturnValue(20, 1);
		template.executorControl.replay();
		try {
			template.update("myStatement", "myParameter", 10);
			fail("Should have thrown JdbcUpdateAffectedIncorrectNumberOfRowsException");
		}
		catch (JdbcUpdateAffectedIncorrectNumberOfRowsException ex) {
			// expected
			assertEquals(10, ex.getExpectedRowsAffected());
			assertEquals(20, ex.getActualRowsAffected());
		}
		template.executorControl.verify();
	}

	public void testDelete() throws SQLException {
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.delete("myStatement", null);
		template.executorControl.setReturnValue(10, 1);
		template.executorControl.replay();
		assertEquals(10, template.delete("myStatement"));
		template.executorControl.verify();
	}

	public void testDeleteWithParameter() throws SQLException {
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.delete("myStatement", "myParameter");
		template.executorControl.setReturnValue(10, 1);
		template.executorControl.replay();
		assertEquals(10, template.delete("myStatement", "myParameter"));
		template.executorControl.verify();
	}

	public void testDeleteWithRequiredRowsAffected() throws SQLException {
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.delete("myStatement", "myParameter");
		template.executorControl.setReturnValue(10, 1);
		template.executorControl.replay();
		template.delete("myStatement", "myParameter", 10);
		template.executorControl.verify();
	}

	public void testDeleteWithRequiredRowsAffectedAndInvalidRowCount() throws SQLException {
		TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
		template.executor.delete("myStatement", "myParameter");
		template.executorControl.setReturnValue(20, 1);
		template.executorControl.replay();
		try {
			template.delete("myStatement", "myParameter", 10);
			fail("Should have thrown JdbcUpdateAffectedIncorrectNumberOfRowsException");
		}
		catch (JdbcUpdateAffectedIncorrectNumberOfRowsException ex) {
			// expected
			assertEquals(10, ex.getExpectedRowsAffected());
			assertEquals(20, ex.getActualRowsAffected());
		}
		template.executorControl.verify();
	}

	public void testSqlMapClientDaoSupport() throws Exception {
		MockControl dsControl = MockControl.createControl(DataSource.class);
		DataSource ds = (DataSource) dsControl.getMock();
		SqlMapClientDaoSupport testDao = new SqlMapClientDaoSupport() {
		};
		testDao.setDataSource(ds);
		assertEquals(ds, testDao.getDataSource());

		MockControl clientControl = MockControl.createControl(SqlMapClient.class);
		SqlMapClient client = (SqlMapClient) clientControl.getMock();
		clientControl.replay();

		testDao.setSqlMapClient(client);
		assertEquals(client, testDao.getSqlMapClient());

		SqlMapClientTemplate template = new SqlMapClientTemplate();
		template.setDataSource(ds);
		template.setSqlMapClient(client);
		testDao.setSqlMapClientTemplate(template);
		assertEquals(template, testDao.getSqlMapClientTemplate());

		testDao.afterPropertiesSet();
	}


	private static class TestSqlMapClientTemplate extends SqlMapClientTemplate {

		public MockControl executorControl = MockControl.createControl(SqlMapExecutor.class);
		public SqlMapExecutor executor = (SqlMapExecutor) executorControl.getMock();

		public Object execute(SqlMapClientCallback action) throws DataAccessException {
			try {
				return action.doInSqlMapClient(executor);
			}
			catch (SQLException ex) {
				throw getExceptionTranslator().translate("SqlMapClient operation", null, ex);
			}
		}
	}


	private static class TestRowHandler implements RowHandler {

		public void handleRow(Object row) {
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -