-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1703 from Xylus/testfix/mybatis-spring-1.3.0
Fix integration tests to support mybatis-spring v1.3.x test fix - no review required
- Loading branch information
Showing
4 changed files
with
287 additions
and
120 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
agent/src/test/java/com/navercorp/pinpoint/plugin/mybatis/SqlSessionTemplateITBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.navercorp.pinpoint.plugin.mybatis; | ||
|
||
/** | ||
* @author HyunGil Jeong | ||
*/ | ||
public class SqlSessionTemplateITBase { | ||
} |
241 changes: 121 additions & 120 deletions
241
.../plugin/mybatis/SqlSessionTemplateIT.java → .../mybatis/SqlSessionTemplate_1_1_x_IT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,121 @@ | ||
/* | ||
* Copyright 2015 NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.pinpoint.plugin.mybatis; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.apache.ibatis.mapping.Environment; | ||
import org.apache.ibatis.session.Configuration; | ||
import org.apache.ibatis.session.ExecutorType; | ||
import org.apache.ibatis.session.SqlSession; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.apache.ibatis.transaction.TransactionFactory; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.mybatis.spring.SqlSessionTemplate; | ||
|
||
import com.navercorp.pinpoint.common.Version; | ||
import com.navercorp.pinpoint.test.plugin.Dependency; | ||
import com.navercorp.pinpoint.test.plugin.PinpointAgent; | ||
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; | ||
|
||
/** | ||
* Tests against mybatis-spring 1.1.0+. Prior versions do not handle mocked SqlSession proxies well. | ||
* | ||
* @author HyunGil Jeong | ||
*/ | ||
@RunWith(PinpointPluginTestSuite.class) | ||
@PinpointAgent("agent/target/pinpoint-agent-" + Version.VERSION) | ||
@Dependency({ "org.mybatis:mybatis-spring:[1.1.0,)", "org.mybatis:mybatis:3.2.7", | ||
"org.springframework:spring-jdbc:[4.1.7.RELEASE]", "org.mockito:mockito-all:1.8.4" }) | ||
public class SqlSessionTemplateIT extends SqlSessionTestBase { | ||
|
||
private static final ExecutorType EXECUTOR_TYPE = ExecutorType.SIMPLE; | ||
|
||
@Mock | ||
private SqlSessionFactory sqlSessionFactory; | ||
|
||
@Mock | ||
private SqlSession sqlSessionProxy; | ||
|
||
private SqlSessionTemplate sqlSessionTemplate; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
MockitoAnnotations.initMocks(this); | ||
Configuration configuration = mock(Configuration.class); | ||
TransactionFactory transactionFactory = mock(TransactionFactory.class); | ||
DataSource dataSource = mock(DataSource.class); | ||
Environment environment = new Environment("test", transactionFactory, dataSource); | ||
when(configuration.getEnvironment()).thenReturn(environment); | ||
when(this.sqlSessionFactory.getConfiguration()).thenReturn(configuration); | ||
when(this.sqlSessionFactory.openSession(EXECUTOR_TYPE)).thenReturn(this.sqlSessionProxy); | ||
this.sqlSessionTemplate = new SqlSessionTemplate(this.sqlSessionFactory, EXECUTOR_TYPE); | ||
} | ||
|
||
@Override | ||
protected SqlSession getSqlSession() { | ||
return this.sqlSessionTemplate; | ||
} | ||
|
||
@Test | ||
public void methodCallWithNullSqlIdShouldOnlyTraceMethodName() throws Exception { | ||
super.testAndVerifyInsertWithNullParameter(); | ||
} | ||
|
||
@Test | ||
public void selectShouldBeTraced() throws Exception { | ||
super.testAndVerifySelect(); | ||
} | ||
|
||
@Test | ||
public void selectOneShouldBeTraced() throws Exception { | ||
super.testAndVerifySelectOne(); | ||
} | ||
|
||
@Test | ||
public void selectListShouldBeTraced() throws Exception { | ||
super.testAndVerifySelectList(); | ||
} | ||
|
||
@Test | ||
public void selectMapShouldBeTraced() throws Exception { | ||
super.testAndVerifySelectMap(); | ||
} | ||
|
||
@Test | ||
public void insertShouldBeTraced() throws Exception { | ||
super.testAndVerifyInsert(); | ||
} | ||
|
||
@Test | ||
public void updateShouldBeTraced() throws Exception { | ||
super.testAndVerifyUpdate(); | ||
} | ||
|
||
@Test | ||
public void deleteShouldBeTraced() throws Exception { | ||
super.testAndVerifyDelete(); | ||
} | ||
|
||
} | ||
/* | ||
* Copyright 2015 NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.pinpoint.plugin.mybatis; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.apache.ibatis.mapping.Environment; | ||
import org.apache.ibatis.session.Configuration; | ||
import org.apache.ibatis.session.ExecutorType; | ||
import org.apache.ibatis.session.SqlSession; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.apache.ibatis.transaction.TransactionFactory; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.mybatis.spring.SqlSessionTemplate; | ||
|
||
import com.navercorp.pinpoint.common.Version; | ||
import com.navercorp.pinpoint.test.plugin.Dependency; | ||
import com.navercorp.pinpoint.test.plugin.PinpointAgent; | ||
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; | ||
|
||
/** | ||
* Tests against mybatis-spring 1.1.0 ~ 1.2.x (1.3.0+ requires mybatis 3.4.0 or higher) | ||
* Prior versions do not handle mocked SqlSession proxies well. | ||
* | ||
* @author HyunGil Jeong | ||
*/ | ||
@RunWith(PinpointPluginTestSuite.class) | ||
@PinpointAgent("agent/target/pinpoint-agent-" + Version.VERSION) | ||
@Dependency({ "org.mybatis:mybatis-spring:[1.1.0,)", "org.mybatis:mybatis:3.2.7", | ||
"org.springframework:spring-jdbc:[4.1.7.RELEASE]", "org.mockito:mockito-all:1.8.4" }) | ||
public class SqlSessionTemplate_1_1_x_IT extends SqlSessionTestBase { | ||
|
||
private static final ExecutorType EXECUTOR_TYPE = ExecutorType.SIMPLE; | ||
|
||
@Mock | ||
private SqlSessionFactory sqlSessionFactory; | ||
|
||
@Mock | ||
private SqlSession sqlSessionProxy; | ||
|
||
private SqlSessionTemplate sqlSessionTemplate; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
MockitoAnnotations.initMocks(this); | ||
Configuration configuration = mock(Configuration.class); | ||
TransactionFactory transactionFactory = mock(TransactionFactory.class); | ||
DataSource dataSource = mock(DataSource.class); | ||
Environment environment = new Environment("test", transactionFactory, dataSource); | ||
when(configuration.getEnvironment()).thenReturn(environment); | ||
when(this.sqlSessionFactory.getConfiguration()).thenReturn(configuration); | ||
when(this.sqlSessionFactory.openSession(EXECUTOR_TYPE)).thenReturn(this.sqlSessionProxy); | ||
this.sqlSessionTemplate = new SqlSessionTemplate(this.sqlSessionFactory, EXECUTOR_TYPE); | ||
} | ||
|
||
@Override | ||
protected SqlSession getSqlSession() { | ||
return this.sqlSessionTemplate; | ||
} | ||
|
||
@Test | ||
public void methodCallWithNullSqlIdShouldOnlyTraceMethodName() throws Exception { | ||
super.testAndVerifyInsertWithNullParameter(); | ||
} | ||
|
||
@Test | ||
public void selectShouldBeTraced() throws Exception { | ||
super.testAndVerifySelect(); | ||
} | ||
|
||
@Test | ||
public void selectOneShouldBeTraced() throws Exception { | ||
super.testAndVerifySelectOne(); | ||
} | ||
|
||
@Test | ||
public void selectListShouldBeTraced() throws Exception { | ||
super.testAndVerifySelectList(); | ||
} | ||
|
||
@Test | ||
public void selectMapShouldBeTraced() throws Exception { | ||
super.testAndVerifySelectMap(); | ||
} | ||
|
||
@Test | ||
public void insertShouldBeTraced() throws Exception { | ||
super.testAndVerifyInsert(); | ||
} | ||
|
||
@Test | ||
public void updateShouldBeTraced() throws Exception { | ||
super.testAndVerifyUpdate(); | ||
} | ||
|
||
@Test | ||
public void deleteShouldBeTraced() throws Exception { | ||
super.testAndVerifyDelete(); | ||
} | ||
|
||
} |
121 changes: 121 additions & 0 deletions
121
agent/src/test/java/com/navercorp/pinpoint/plugin/mybatis/SqlSessionTemplate_1_2_x_IT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright 2015 NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.pinpoint.plugin.mybatis; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.apache.ibatis.mapping.Environment; | ||
import org.apache.ibatis.session.Configuration; | ||
import org.apache.ibatis.session.ExecutorType; | ||
import org.apache.ibatis.session.SqlSession; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.apache.ibatis.transaction.TransactionFactory; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.mybatis.spring.SqlSessionTemplate; | ||
|
||
import com.navercorp.pinpoint.common.Version; | ||
import com.navercorp.pinpoint.test.plugin.Dependency; | ||
import com.navercorp.pinpoint.test.plugin.PinpointAgent; | ||
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite; | ||
|
||
/** | ||
* Tests against mybatis-spring 1.1.0 ~ 1.2.x (1.3.0+ requires mybatis 3.4.0 or higher) | ||
* Prior versions do not handle mocked SqlSession proxies well. | ||
* | ||
* @author HyunGil Jeong | ||
*/ | ||
@RunWith(PinpointPluginTestSuite.class) | ||
@PinpointAgent("agent/target/pinpoint-agent-" + Version.VERSION) | ||
@Dependency({ "org.mybatis:mybatis-spring:[1.1.0,1.1.max)", "org.mybatis:mybatis:3.2.7", | ||
"org.springframework:spring-jdbc:[4.1.7.RELEASE]", "org.mockito:mockito-all:1.8.4" }) | ||
public class SqlSessionTemplate_1_2_x_IT extends SqlSessionTestBase { | ||
|
||
private static final ExecutorType EXECUTOR_TYPE = ExecutorType.SIMPLE; | ||
|
||
@Mock | ||
private SqlSessionFactory sqlSessionFactory; | ||
|
||
@Mock | ||
private SqlSession sqlSessionProxy; | ||
|
||
private SqlSessionTemplate sqlSessionTemplate; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
MockitoAnnotations.initMocks(this); | ||
Configuration configuration = mock(Configuration.class); | ||
TransactionFactory transactionFactory = mock(TransactionFactory.class); | ||
DataSource dataSource = mock(DataSource.class); | ||
Environment environment = new Environment("test", transactionFactory, dataSource); | ||
when(configuration.getEnvironment()).thenReturn(environment); | ||
when(this.sqlSessionFactory.getConfiguration()).thenReturn(configuration); | ||
when(this.sqlSessionFactory.openSession(EXECUTOR_TYPE)).thenReturn(this.sqlSessionProxy); | ||
this.sqlSessionTemplate = new SqlSessionTemplate(this.sqlSessionFactory, EXECUTOR_TYPE); | ||
} | ||
|
||
@Override | ||
protected SqlSession getSqlSession() { | ||
return this.sqlSessionTemplate; | ||
} | ||
|
||
@Test | ||
public void methodCallWithNullSqlIdShouldOnlyTraceMethodName() throws Exception { | ||
super.testAndVerifyInsertWithNullParameter(); | ||
} | ||
|
||
@Test | ||
public void selectShouldBeTraced() throws Exception { | ||
super.testAndVerifySelect(); | ||
} | ||
|
||
@Test | ||
public void selectOneShouldBeTraced() throws Exception { | ||
super.testAndVerifySelectOne(); | ||
} | ||
|
||
@Test | ||
public void selectListShouldBeTraced() throws Exception { | ||
super.testAndVerifySelectList(); | ||
} | ||
|
||
@Test | ||
public void selectMapShouldBeTraced() throws Exception { | ||
super.testAndVerifySelectMap(); | ||
} | ||
|
||
@Test | ||
public void insertShouldBeTraced() throws Exception { | ||
super.testAndVerifyInsert(); | ||
} | ||
|
||
@Test | ||
public void updateShouldBeTraced() throws Exception { | ||
super.testAndVerifyUpdate(); | ||
} | ||
|
||
@Test | ||
public void deleteShouldBeTraced() throws Exception { | ||
super.testAndVerifyDelete(); | ||
} | ||
|
||
} |
Oops, something went wrong.