Skip to content

Commit

Permalink
Insert method test added
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlomorozov committed Feb 8, 2018
1 parent f917094 commit 80b2130
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
8 changes: 4 additions & 4 deletions AtomikosTestDump20180205.sql → AtomikosTestDump20180208.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ DROP TABLE IF EXISTS `first`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `first` (
`id` int(11) NOT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -75,7 +75,7 @@ CREATE TABLE `first` (

LOCK TABLES `first` WRITE;
/*!40000 ALTER TABLE `first` DISABLE KEYS */;
INSERT INTO `first` VALUES (1,'first name');
INSERT INTO `first` VALUES (1,'first');
/*!40000 ALTER TABLE `first` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
Expand All @@ -88,4 +88,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2018-02-05 17:49:11
-- Dump completed on 2018-02-08 11:44:18
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.demo.persistence.mapper.first;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
Expand All @@ -19,4 +21,8 @@ public interface FirstMapper {
})
FirstModel selectById(@Param("id") long id);


@Insert("INSERT into first (id, name) VALUES(#{id}, #{name})")
@Options(useGeneratedKeys = true, keyProperty = "id")
long insert(FirstModel first);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.example.demo.persistence.mapper.first;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import javax.sql.DataSource;
import javax.transaction.Transactional;

import org.junit.After;
import org.junit.Test;
Expand All @@ -14,7 +16,9 @@
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.jta.atomikos.AtomikosDataSourceBean;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;

import com.example.demo.model.first.FirstModel;
Expand All @@ -26,7 +30,7 @@
DataSourceTransactionManagerAutoConfiguration.class,
MybatisAutoConfiguration.class
})

@AutoConfigureMockMvc
public class FirstMapperTest {
@Autowired
FirstMapper firstMapper;
Expand All @@ -45,8 +49,21 @@ public void selectByIdTest() {
assertEquals("first name", first.getName());
}

@Test
@Transactional
public void insertTest() {
FirstModel firstModel = new FirstModel();
firstModel.setName("new enty");
firstMapper.insert(firstModel);

assertTrue(firstModel.getId()>0);
}

@After
public void afterTest() {

System.out.println("Close data sources");

((AtomikosDataSourceBean)firstDataSource).close();
((AtomikosDataSourceBean)secondDataSource).close();
}
Expand Down

0 comments on commit 80b2130

Please sign in to comment.