added flyway
This commit is contained in:
parent
bb1d49cecb
commit
40ff3ca9bf
@ -1,10 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.8.RELEASE</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<groupId>org.ros</groupId>
|
||||
<artifactId>Chatto</artifactId>
|
||||
@ -12,12 +13,10 @@
|
||||
<packaging>jar</packaging>
|
||||
<name>chatto</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
<gruntArg> </gruntArg>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -27,7 +26,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
@ -49,7 +47,6 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
@ -63,46 +60,32 @@
|
||||
<artifactId>spring-security-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>com.github.ulisesbocchio</groupId>
|
||||
<artifactId>jasypt-spring-boot-starter</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||
|
||||
|
||||
</dependency> -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.modelmapper/modelmapper -->
|
||||
<dependency>
|
||||
<groupId>org.modelmapper</groupId>
|
||||
<artifactId>modelmapper</artifactId>
|
||||
<version>2.3.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.ehcache/ehcache -->
|
||||
<dependency>
|
||||
<groupId>org.ehcache</groupId>
|
||||
<artifactId>ehcache</artifactId>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/javax.cache/cache-api -->
|
||||
<dependency>
|
||||
<groupId>javax.cache</groupId>
|
||||
<artifactId>cache-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId>
|
||||
<version>2.2.11</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-core</artifactId> <version>2.2.11</version> </dependency> -->
|
||||
<!-- https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity5 -->
|
||||
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
@ -111,22 +94,16 @@
|
||||
<groupId>org.glassfish.jaxb</groupId>
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.thymeleaf.extras</groupId>
|
||||
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/net.sf.ehcache/ehcache -->
|
||||
<!-- <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId>
|
||||
</dependency> -->
|
||||
|
||||
<!-- <dependency> <groupId>javax.cache</groupId> <artifactId>cache-api</artifactId>
|
||||
<version>1.1.0</version> </dependency> -->
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-core</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@ -136,10 +113,7 @@
|
||||
<plugin>
|
||||
<groupId>com.github.eirslett</groupId>
|
||||
<artifactId>frontend-maven-plugin</artifactId>
|
||||
<!-- Use the latest released version:
|
||||
https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
|
||||
<version>1.9.1</version>
|
||||
|
||||
<configuration>
|
||||
<workingDirectory>src/main/javascript/</workingDirectory>
|
||||
</configuration>
|
||||
@ -150,19 +124,16 @@
|
||||
<goal>install-node-and-yarn</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<!-- See https://nodejs.org/en/download/ for latest node and npm (lts) versions -->
|
||||
<nodeVersion>v12.10.0</nodeVersion>
|
||||
<yarnVersion>v1.21.1</yarnVersion>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
<execution>
|
||||
<id>yarn install</id>
|
||||
<goals>
|
||||
<goal>yarn</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
|
||||
<execution>
|
||||
<id>watch</id>
|
||||
<goals>
|
||||
@ -173,9 +144,8 @@
|
||||
<arguments>run watch</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
||||
<execution>
|
||||
<id>grunt browserify</id>
|
||||
<id>grunt-browserify</id>
|
||||
<goals>
|
||||
<goal>grunt</goal>
|
||||
</goals>
|
||||
@ -188,5 +158,4 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -19,8 +19,8 @@ public class DBInitializerConfig {
|
||||
|
||||
private final String resetSessionsQuery;
|
||||
|
||||
public DBInitializerConfig(@Value("${database-name}") String dbName, @Value("${num-tables}") String numTablesQuery,
|
||||
@Value("${reset-sessions}") String resetSessionsQuery) {
|
||||
public DBInitializerConfig(@Value("${chatto.datasource.database-name}") String dbName,
|
||||
@Value("${num-tables}") String numTablesQuery, @Value("${reset-sessions}") String resetSessionsQuery) {
|
||||
this.dbName = dbName;
|
||||
this.numTablesQuery = numTablesQuery;
|
||||
this.resetSessionsQuery = resetSessionsQuery;
|
||||
|
@ -50,16 +50,16 @@ public class DBInitializerService {
|
||||
|
||||
final Session session = entityManager.unwrap(Session.class);
|
||||
|
||||
session.doWork(connection -> {
|
||||
if (getNumTables(connection) == 0) {
|
||||
log.info("Database is empty. Populating tables and roles");
|
||||
try {
|
||||
populateDB(connection);
|
||||
} catch (final IOException e) {
|
||||
log.error("IO error", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
// session.doWork(connection -> {
|
||||
// if (getNumTables(connection) == 0) {
|
||||
// log.info("Database is empty. Populating tables and roles");
|
||||
// try {
|
||||
// populateDB(connection);
|
||||
// } catch (final IOException e) {
|
||||
// log.error("IO error", e);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
session.doWork(connection -> {
|
||||
log.info("Resetting all user sessions");
|
||||
|
@ -14,7 +14,6 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDial
|
||||
spring.jpa.hibernate.ddl-auto = none
|
||||
spring.jpa.open-in-view=false
|
||||
|
||||
# spring.jpa.properties.hibernate.generate_statistics=true
|
||||
logging.level.org.hibernate.stat=debug
|
||||
logging.level.org.springframework.web=DEBUG
|
||||
logging.level.web=DEBUG
|
||||
@ -23,13 +22,9 @@ logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
|
||||
spring.http.log-request-details=true
|
||||
#spring.jackson.date-format=yyyy-MM-d
|
||||
spring.jackson.serialization.write-dates-as-timestamps=false
|
||||
#spring.mvc.static-path-pattern=/static/**
|
||||
#spring.cache.type=ehcache3
|
||||
spring.cache.jcache.config=classpath:ehcache.xml
|
||||
logging.level.org.springframework.cache = DEBUG
|
||||
|
||||
#test.bindAddress=192.168.1.106
|
||||
|
||||
chatto.token.timeout-duration=30
|
||||
|
||||
# spring.devtools.add-properties=false
|
@ -1,46 +0,0 @@
|
||||
--INSERT INTO `admins` (`admin_id`, `user_id`) VALUES
|
||||
--(1, 3);
|
||||
--INSERT INTO `chat_messages` (`m_id`, `from_user`, `to_user`, `message`, `message_time`) VALUES
|
||||
--(5, 3, 6, 3, '2019-09-28 15:42:15'),
|
||||
--(6, 8, 3, 9, '2019-09-30 10:38:18'),
|
||||
--(7, 8, 6, 10, '2019-09-30 10:40:31'),
|
||||
--(8, 8, 3, 11, '2019-09-30 10:42:54'),
|
||||
--(9, 3, 8, 4, '2019-09-30 12:40:16'),
|
||||
--(10, 8, 3, 12, '2019-09-30 13:47:41'),
|
||||
--(11, 8, 13, 13, '2019-09-30 13:47:48'),
|
||||
--(12, 8, 6, 14, '2019-09-30 13:48:00'),
|
||||
--(13, 8, 3, 15, '2019-10-01 06:34:10'),
|
||||
--(14, 8, 3, 16, '2019-10-01 06:37:19'),
|
||||
--(15, 8, 13, 17, '2019-10-01 06:56:07'),
|
||||
--(16, 8, 13, 18, '2019-10-01 20:42:32'),
|
||||
--(17, 3, 6, 19, '2019-10-01 20:44:59'),
|
||||
--(18, 3, 13, 20, '2019-10-02 04:47:23'),
|
||||
--(19, 3, 8, 21, '2019-10-02 04:56:07'),
|
||||
--(20, 3, 8, 22, '2019-10-02 04:56:19'),
|
||||
--(21, 3, 3, 23, '2019-10-02 06:42:21'),
|
||||
--(22, 8, 3, 24, '2019-10-02 07:14:02'),
|
||||
--(23, 3, 8, 25, '2019-10-02 09:07:13'),
|
||||
--(24, 8, 13, 26, '2019-10-02 09:17:28'),
|
||||
--(25, 8, 3, 27, '2019-10-02 09:18:54'),
|
||||
--(26, 8, 3, 28, '2019-10-02 09:20:49'),
|
||||
--(27, 3, 8, 29, '2019-10-02 09:47:29'),
|
||||
--(28, 3, 8, 30, '2019-10-02 09:47:58'),
|
||||
--(29, 3, 8, 31, '2019-10-02 10:14:32');
|
||||
--
|
||||
--INSERT INTO `chatmessage` (`Id`, `Message`, `userName`, `MsgTime`, `colorSelected`) VALUES
|
||||
--(400, '', 'dae', '2019/08/19 12:58:52', '333'),
|
||||
--(401, 'aegqe\n', 'dae', '2019/08/19 12:58:52', '333');
|
||||
--
|
||||
--
|
||||
--INSERT INTO `users` (`user_id`, `name`, `password`, `join_date`) VALUES
|
||||
--(3, 'user2', '$2a$10$nLhkNrGu0/2ahSlULoQ0ROvUK2sRTEZBV014BLB/W9nBSMxy0rTGy', '2019-09-23 07:44:59'),
|
||||
--(6, 'novo', '$2a$10$nLhkNrGu0/2ahSlULoQ0ROvUK2sRTEZBV014BLB/W9nBSMxy0rTGy', '2019-09-23 07:45:06'),
|
||||
--(8, 'hmm', '$2a$10$k4tASmvqJ1mPA7avuzAnSO1KmWOmNhp7K8Y5Yg.dV/VXMX2L73/Ma', '2019-09-23 07:40:56'),
|
||||
--(13, 'hmm2', '$2a$10$F.lMGPDXOguXWehMf1fvq.7XqzbFZWweLv3DYwB.1zpDEuPDcKBv6', '2019-09-23 13:46:33');
|
||||
|
||||
-- INSERT INTO `status` (`status`) values (true);
|
||||
|
||||
INSERT INTO `roles` (`role_id`, `role_name`, `description`) VALUES
|
||||
(0, 'SUPER_USER', 'Most privileged'),
|
||||
(1, 'ADMIN', 'Administrator'),
|
||||
(2, 'USER', 'Regular user');
|
98
chatto/src/main/resources/db/migration/V1__ddl.sql
Normal file
98
chatto/src/main/resources/db/migration/V1__ddl.sql
Normal file
@ -0,0 +1,98 @@
|
||||
CREATE TABLE IF NOT EXISTS `message_ciphers` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`iv` varchar(30) NOT NULL,
|
||||
`v` int(2) NOT NULL,
|
||||
`iterations` int(11) NOT NULL,
|
||||
`key_size` int(11) NOT NULL,
|
||||
`tag_size` int(11) NOT NULL,
|
||||
`mode` varchar(11) NOT NULL,
|
||||
`adata` varchar(11) NOT NULL,
|
||||
`cipher` varchar(11) NOT NULL,
|
||||
`salt` varchar(100) NOT NULL,
|
||||
`cipher_text` varchar(2000) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `roles` (
|
||||
`role_id` int(5) NOT NULL,
|
||||
`role_name` varchar(15) NOT NULL,
|
||||
`description` varchar(20) NOT NULL,
|
||||
PRIMARY KEY (`role_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `total_messages` (
|
||||
`t_id` int(101) NOT NULL AUTO_INCREMENT,
|
||||
`from_user` int(11) NOT NULL,
|
||||
`to_user` int(11) NOT NULL,
|
||||
`total_messages` int(11) NOT NULL,
|
||||
PRIMARY KEY (`t_id`),
|
||||
UNIQUE KEY `identifier` (`t_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`user_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(10) NOT NULL,
|
||||
`password` varchar(80) NOT NULL,
|
||||
`join_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`user_id`),
|
||||
UNIQUE KEY `name` (`name`),
|
||||
KEY `user_id` (`user_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `users_roles` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int(11) NOT NULL,
|
||||
`role_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `user` (`user_id`),
|
||||
KEY `role` (`role_id`),
|
||||
CONSTRAINT `FOREIGN KEY USER IN USERS-ROLES TABLE` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_roles_roleAssignments` FOREIGN KEY (`role_id`) REFERENCES `roles` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `chat_messages` (
|
||||
`m_id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`from_user` int(11) NOT NULL,
|
||||
`to_user` int(11) NOT NULL,
|
||||
`message` int(10) NOT NULL,
|
||||
`message_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`m_id`),
|
||||
UNIQUE KEY `identifier_message_number` (`m_id`),
|
||||
KEY `identifier_message_number_2` (`m_id`),
|
||||
KEY `from_user` (`from_user`,`to_user`),
|
||||
KEY `message` (`message`),
|
||||
KEY `FOREIGN KEY TO USER IN MESSAGES TABLE` (`to_user`),
|
||||
CONSTRAINT `FOREIGN KEY ENC MESSAGE TABLE` FOREIGN KEY (`message`) REFERENCES `message_ciphers` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `FOREIGN KEY FROM USER IN MESSAGES TABLE` FOREIGN KEY (`from_user`) REFERENCES `users` (`user_id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `FOREIGN KEY TO USER IN MESSAGES TABLE` FOREIGN KEY (`to_user`) REFERENCES `users` (`user_id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `status` (
|
||||
`id` int(2) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(15) NOT NULL,
|
||||
`value` tinyint(1) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name` (`name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `user_sessions` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int(15) NOT NULL,
|
||||
`online` tinyint(1) NOT NULL,
|
||||
`num_sessions` int(11) NOT NULL,
|
||||
`time_stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `user_name` (`user_id`),
|
||||
CONSTRAINT `FOREIGN KEY USER ID` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `tokens` (
|
||||
`token_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_name` varchar(15) NOT NULL,
|
||||
`token_content` varchar(256) NOT NULL,
|
||||
`role` varchar(15) NOT NULL,
|
||||
`creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`token_id`),
|
||||
UNIQUE KEY `user_name` (`user_name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4;
|
||||
|
5
chatto/src/main/resources/db/migration/V2__data.sql
Normal file
5
chatto/src/main/resources/db/migration/V2__data.sql
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
INSERT INTO `roles` (`role_id`, `role_name`, `description`) VALUES
|
||||
(0, 'SUPER_USER', 'Most privileged'),
|
||||
(1, 'ADMIN', 'Administrator'),
|
||||
(2, 'USER', 'Regular user');
|
@ -1 +0,0 @@
|
||||
#test.bindAddress=192.168.1.106
|
@ -1,374 +0,0 @@
|
||||
-- -- MySQL dump 10.15 Distrib 10.0.38-MariaDB, for debian-linux-gnu (x86_64)
|
||||
-- --
|
||||
-- -- Host: localhost Database: chatto_db
|
||||
-- -- ------------------------------------------------------
|
||||
-- -- Server version 10.0.38-MariaDB-0ubuntu0.16.04.1
|
||||
|
||||
-- /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
-- /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
-- /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
-- /*!40101 SET NAMES utf8mb4 */;
|
||||
-- /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
||||
-- /*!40103 SET TIME_ZONE='+00:00' */;
|
||||
-- /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||
-- /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
-- /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
-- /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
-- --
|
||||
-- -- Table structure for table `admins`
|
||||
-- --
|
||||
|
||||
-- --DROP TABLE IF EXISTS `admins`;
|
||||
-- /*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
-- /*!40101 SET character_set_client = utf8 */;
|
||||
-- -- CREATE TABLE IF NOT EXISTS `admins` (
|
||||
-- -- `admin_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
-- -- `user_id` int(11) NOT NULL,
|
||||
-- -- PRIMARY KEY (`admin_id`),
|
||||
-- -- UNIQUE KEY `user_id_2` (`user_id`),
|
||||
-- -- KEY `admin_id` (`admin_id`),
|
||||
-- -- KEY `user_id` (`user_id`),
|
||||
-- -- CONSTRAINT `fk_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE
|
||||
-- -- ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
|
||||
-- /*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
-- --
|
||||
-- -- Table structure for table `chat_messages`
|
||||
-- --
|
||||
|
||||
|
||||
-- /*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
-- --
|
||||
-- -- Table structure for table `chatmessage`
|
||||
-- --
|
||||
|
||||
-- --DROP TABLE IF EXISTS `chatmessage`;
|
||||
-- /*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
-- /*!40101 SET character_set_client = utf8 */;
|
||||
-- CREATE TABLE IF NOT EXISTS `chatmessage` (
|
||||
-- `Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
-- `Message` varchar(4000) NOT NULL,
|
||||
-- `userName` varchar(100) NOT NULL,
|
||||
-- `MsgTime` varchar(45) NOT NULL,
|
||||
-- `colorSelected` varchar(45) NOT NULL,
|
||||
-- PRIMARY KEY (`Id`)
|
||||
-- ) ENGINE=InnoDB AUTO_INCREMENT=402 DEFAULT CHARSET=latin1;
|
||||
-- /*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
-- --
|
||||
-- -- Table structure for table `message_ciphers`
|
||||
-- --
|
||||
|
||||
-- --DROP TABLE IF EXISTS `message_ciphers`;
|
||||
-- /*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
-- /*!40101 SET character_set_client = utf8 */;
|
||||
-- CREATE TABLE IF NOT EXISTS `message_ciphers` (
|
||||
-- `id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
-- `iv` varchar(30) NOT NULL,
|
||||
-- `v` int(2) NOT NULL,
|
||||
-- `iterations` int(11) NOT NULL,
|
||||
-- `key_size` int(11) NOT NULL,
|
||||
-- `tag_size` int(11) NOT NULL,
|
||||
-- `mode` varchar(11) NOT NULL,
|
||||
-- `adata` varchar(11) NOT NULL,
|
||||
-- `cipher` varchar(11) NOT NULL,
|
||||
-- `salt` varchar(100) NOT NULL,
|
||||
-- `cipher_text` varchar(600) NOT NULL,
|
||||
-- PRIMARY KEY (`id`)
|
||||
-- ) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8mb4;
|
||||
-- /*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
-- --
|
||||
-- -- Table structure for table `roles`
|
||||
-- --
|
||||
|
||||
-- --DROP TABLE IF EXISTS `roles`;
|
||||
-- /*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
-- /*!40101 SET character_set_client = utf8 */;
|
||||
-- CREATE TABLE IF NOT EXISTS `roles` (
|
||||
-- `role_id` int(5) NOT NULL,
|
||||
-- `role_name` varchar(15) NOT NULL,
|
||||
-- `description` varchar(20) NOT NULL,
|
||||
-- PRIMARY KEY (`role_id`)
|
||||
-- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
-- /*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
-- --
|
||||
-- -- Table structure for table `total_messages`
|
||||
-- --
|
||||
|
||||
-- --DROP TABLE IF EXISTS `total_messages`;
|
||||
-- /*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
-- /*!40101 SET character_set_client = utf8 */;
|
||||
-- CREATE TABLE IF NOT EXISTS `total_messages` (
|
||||
-- `t_id` int(101) NOT NULL AUTO_INCREMENT,
|
||||
-- `from_user` int(11) NOT NULL,
|
||||
-- `to_user` int(11) NOT NULL,
|
||||
-- `total_messages` int(11) NOT NULL,
|
||||
-- PRIMARY KEY (`t_id`),
|
||||
-- UNIQUE KEY `identifier` (`t_id`)
|
||||
-- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
-- /*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
-- --
|
||||
-- -- Table structure for table `users`
|
||||
-- --
|
||||
|
||||
-- --DROP TABLE IF EXISTS `users`;
|
||||
-- /*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
-- /*!40101 SET character_set_client = utf8 */;
|
||||
-- CREATE TABLE IF NOT EXISTS `users` (
|
||||
-- `user_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
-- `name` varchar(10) NOT NULL,
|
||||
-- `password` varchar(80) NOT NULL,
|
||||
-- `join_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
-- PRIMARY KEY (`user_id`),
|
||||
-- UNIQUE KEY `name` (`name`),
|
||||
-- KEY `user_id` (`user_id`)
|
||||
-- ) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4;
|
||||
-- /*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
-- --
|
||||
-- -- Table structure for table `users_roles`
|
||||
-- --
|
||||
|
||||
-- --DROP TABLE IF EXISTS `users_roles`;
|
||||
-- /*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
-- /*!40101 SET character_set_client = utf8 */;
|
||||
-- CREATE TABLE IF NOT EXISTS `users_roles` (
|
||||
-- `id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
-- `user_id` int(11) NOT NULL,
|
||||
-- `role_id` int(11) NOT NULL,
|
||||
-- PRIMARY KEY (`id`),
|
||||
-- KEY `user` (`user_id`),
|
||||
-- KEY `role` (`role_id`),
|
||||
-- CONSTRAINT `FOREIGN KEY USER IN USERS-ROLES TABLE` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
-- CONSTRAINT `fk_roles_roleAssignments` FOREIGN KEY (`role_id`) REFERENCES `roles` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
-- ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
|
||||
-- /*!40101 SET character_set_client = @saved_cs_client */;
|
||||
-- /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
-- /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
-- /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
-- /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
-- /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
-- /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
-- /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
-- /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- -- Dump completed on 2019-10-03 12:37:23
|
||||
-- --DROP TABLE IF EXISTS `chat_messages`;
|
||||
-- /*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
-- /*!40101 SET character_set_client = utf8 */;
|
||||
-- CREATE TABLE IF NOT EXISTS `chat_messages` (
|
||||
-- `m_id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
-- `from_user` int(11) NOT NULL,
|
||||
-- `to_user` int(11) NOT NULL,
|
||||
-- `message` int(10) NOT NULL,
|
||||
-- `message_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
-- PRIMARY KEY (`m_id`),
|
||||
-- UNIQUE KEY `identifier_message_number` (`m_id`),
|
||||
-- KEY `identifier_message_number_2` (`m_id`),
|
||||
-- KEY `from_user` (`from_user`,`to_user`),
|
||||
-- KEY `message` (`message`),
|
||||
-- KEY `FOREIGN KEY TO USER IN MESSAGES TABLE` (`to_user`),
|
||||
-- CONSTRAINT `FOREIGN KEY ENC MESSAGE TABLE` FOREIGN KEY (`message`) REFERENCES `message_ciphers` (`id`) ON UPDATE CASCADE,
|
||||
-- CONSTRAINT `FOREIGN KEY FROM USER IN MESSAGES TABLE` FOREIGN KEY (`from_user`) REFERENCES `users` (`user_id`) ON UPDATE CASCADE,
|
||||
-- CONSTRAINT `FOREIGN KEY TO USER IN MESSAGES TABLE` FOREIGN KEY (`to_user`) REFERENCES `users` (`user_id`) ON UPDATE CASCADE
|
||||
-- ) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- MySQL dump 10.15 Distrib 10.0.38-MariaDB, for debian-linux-gnu (x86_64)
|
||||
--
|
||||
-- Host: localhost Database: chatto_db
|
||||
-- ------------------------------------------------------
|
||||
-- Server version 10.0.38-MariaDB-0ubuntu0.16.04.1
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
||||
/*!40103 SET TIME_ZONE='+00:00' */;
|
||||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
--
|
||||
-- Table structure for table `chat_messages`
|
||||
--
|
||||
|
||||
--DROP TABLE IF EXISTS `chat_messages`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `chatmessage`
|
||||
--
|
||||
|
||||
--DROP TABLE IF EXISTS `chatmessage`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
-- CREATE TABLE IF NOT EXISTS `chatmessage` (
|
||||
-- `Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
-- `Message` varchar(4000) NOT NULL,
|
||||
-- `userName` varchar(100) NOT NULL,
|
||||
-- `MsgTime` varchar(45) NOT NULL,
|
||||
-- `colorSelected` varchar(45) NOT NULL,
|
||||
-- PRIMARY KEY (`Id`)
|
||||
-- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `message_ciphers`
|
||||
--
|
||||
|
||||
--DROP TABLE IF EXISTS `message_ciphers`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE IF NOT EXISTS `message_ciphers` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`iv` varchar(30) NOT NULL,
|
||||
`v` int(2) NOT NULL,
|
||||
`iterations` int(11) NOT NULL,
|
||||
`key_size` int(11) NOT NULL,
|
||||
`tag_size` int(11) NOT NULL,
|
||||
`mode` varchar(11) NOT NULL,
|
||||
`adata` varchar(11) NOT NULL,
|
||||
`cipher` varchar(11) NOT NULL,
|
||||
`salt` varchar(100) NOT NULL,
|
||||
`cipher_text` varchar(2000) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `roles`
|
||||
--
|
||||
|
||||
--DROP TABLE IF EXISTS `roles`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE IF NOT EXISTS `roles` (
|
||||
`role_id` int(5) NOT NULL,
|
||||
`role_name` varchar(15) NOT NULL,
|
||||
`description` varchar(20) NOT NULL,
|
||||
PRIMARY KEY (`role_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `total_messages`
|
||||
--
|
||||
|
||||
--DROP TABLE IF EXISTS `total_messages`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE IF NOT EXISTS `total_messages` (
|
||||
`t_id` int(101) NOT NULL AUTO_INCREMENT,
|
||||
`from_user` int(11) NOT NULL,
|
||||
`to_user` int(11) NOT NULL,
|
||||
`total_messages` int(11) NOT NULL,
|
||||
PRIMARY KEY (`t_id`),
|
||||
UNIQUE KEY `identifier` (`t_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `users`
|
||||
--
|
||||
|
||||
--DROP TABLE IF EXISTS `users`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`user_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(10) NOT NULL,
|
||||
`password` varchar(80) NOT NULL,
|
||||
`join_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`user_id`),
|
||||
UNIQUE KEY `name` (`name`),
|
||||
KEY `user_id` (`user_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `users_roles`
|
||||
--
|
||||
|
||||
--DROP TABLE IF EXISTS `users_roles`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE IF NOT EXISTS `users_roles` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int(11) NOT NULL,
|
||||
`role_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `user` (`user_id`),
|
||||
KEY `role` (`role_id`),
|
||||
CONSTRAINT `FOREIGN KEY USER IN USERS-ROLES TABLE` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_roles_roleAssignments` FOREIGN KEY (`role_id`) REFERENCES `roles` (`role_id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `chat_messages` (
|
||||
`m_id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`from_user` int(11) NOT NULL,
|
||||
`to_user` int(11) NOT NULL,
|
||||
`message` int(10) NOT NULL,
|
||||
`message_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`m_id`),
|
||||
UNIQUE KEY `identifier_message_number` (`m_id`),
|
||||
KEY `identifier_message_number_2` (`m_id`),
|
||||
KEY `from_user` (`from_user`,`to_user`),
|
||||
KEY `message` (`message`),
|
||||
KEY `FOREIGN KEY TO USER IN MESSAGES TABLE` (`to_user`),
|
||||
CONSTRAINT `FOREIGN KEY ENC MESSAGE TABLE` FOREIGN KEY (`message`) REFERENCES `message_ciphers` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `FOREIGN KEY FROM USER IN MESSAGES TABLE` FOREIGN KEY (`from_user`) REFERENCES `users` (`user_id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `FOREIGN KEY TO USER IN MESSAGES TABLE` FOREIGN KEY (`to_user`) REFERENCES `users` (`user_id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2019-10-03 12:37:23
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `status` (
|
||||
`id` int(2) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(15) NOT NULL,
|
||||
`value` tinyint(1) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name` (`name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `user_sessions` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_id` int(15) NOT NULL,
|
||||
`online` tinyint(1) NOT NULL,
|
||||
`num_sessions` int(11) NOT NULL,
|
||||
`time_stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `user_name` (`user_id`),
|
||||
CONSTRAINT `FOREIGN KEY USER ID` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `tokens` (
|
||||
`token_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`user_name` varchar(15) NOT NULL,
|
||||
`token_content` varchar(256) NOT NULL,
|
||||
`role` varchar(15) NOT NULL,
|
||||
PRIMARY KEY (`token_id`),
|
||||
UNIQUE KEY `user_name` (`user_name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4;
|
||||
|
@ -1,79 +1,79 @@
|
||||
package org.ros.chatto;
|
||||
// package org.ros.chatto;
|
||||
|
||||
import java.util.List;
|
||||
// import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.ros.chatto.repository.UserRepository;
|
||||
import org.ros.chatto.repository.UserRoleRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
// import org.junit.Test;
|
||||
// import org.junit.runner.RunWith;
|
||||
// import org.ros.chatto.repository.UserRepository;
|
||||
// import org.ros.chatto.repository.UserRoleRepository;
|
||||
// import org.slf4j.Logger;
|
||||
// import org.slf4j.LoggerFactory;
|
||||
// import org.springframework.beans.factory.annotation.Autowired;
|
||||
// import org.springframework.boot.test.context.SpringBootTest;
|
||||
// import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class ChattoApplicationTests {
|
||||
// @RunWith(SpringRunner.class)
|
||||
// @SpringBootTest
|
||||
// public class ChattoApplicationTests {
|
||||
|
||||
// @Autowired
|
||||
// ChatMessageRepository chatMessageRepository;
|
||||
//
|
||||
// @Mock
|
||||
// ChatMessageRepository mockChatMessageRepository;
|
||||
//
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
// // @Autowired
|
||||
// // ChatMessageRepository chatMessageRepository;
|
||||
// //
|
||||
// // @Mock
|
||||
// // ChatMessageRepository mockChatMessageRepository;
|
||||
// //
|
||||
// @Autowired
|
||||
// private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private UserRoleRepository userRoleRepository;
|
||||
// @Autowired
|
||||
// private UserRoleRepository userRoleRepository;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ChattoApplicationTests.class);
|
||||
//
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
//
|
||||
// @Test
|
||||
// public void testMessageRepo() {
|
||||
// chatMessageRepository.findAll().toString();
|
||||
// }
|
||||
// private final Logger logger = LoggerFactory.getLogger(ChattoApplicationTests.class);
|
||||
// //
|
||||
// @Test
|
||||
// public void contextLoads() {
|
||||
// }
|
||||
// //
|
||||
// // @Test
|
||||
// // public void testMessageRepo() {
|
||||
// // chatMessageRepository.findAll().toString();
|
||||
// // }
|
||||
|
||||
@Test
|
||||
public void testRoleRepo() {
|
||||
List<String> list = userRoleRepository.getAllRegularUser();
|
||||
logger.info("List = {} ", list);
|
||||
}
|
||||
// @Test
|
||||
// public void testRoleRepo() {
|
||||
// List<String> list = userRoleRepository.getAllRegularUser();
|
||||
// logger.info("List = {} ", list);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void findAllOtherUsers() {
|
||||
logger.info("Usernames = {}",userRepository.findAllOtherUserNames("hmm").toString());
|
||||
}
|
||||
// @Test
|
||||
// public void findAllOtherUsers() {
|
||||
// logger.info("Usernames = {}",userRepository.findAllOtherUserNames("hmm").toString());
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void testSave() {
|
||||
// ChatUser fromUser = new ChatUser();
|
||||
// fromUser = userRepository.findByUserName("hmm");
|
||||
// ChatUser toUser = new ChatUser();
|
||||
// toUser = userRepository.findByUserName("user2");
|
||||
// ChatMessage chatMessage = new ChatMessage();
|
||||
// chatMessage.setMessage("Hello!");
|
||||
// chatMessage.setFromUser(fromUser);
|
||||
// chatMessage.setToUser(toUser);
|
||||
//
|
||||
// chatMessageRepository.save(chatMessage);
|
||||
// }
|
||||
// // @Test
|
||||
// // public void testSave() {
|
||||
// // ChatUser fromUser = new ChatUser();
|
||||
// // fromUser = userRepository.findByUserName("hmm");
|
||||
// // ChatUser toUser = new ChatUser();
|
||||
// // toUser = userRepository.findByUserName("user2");
|
||||
// // ChatMessage chatMessage = new ChatMessage();
|
||||
// // chatMessage.setMessage("Hello!");
|
||||
// // chatMessage.setFromUser(fromUser);
|
||||
// // chatMessage.setToUser(toUser);
|
||||
// //
|
||||
// // chatMessageRepository.save(chatMessage);
|
||||
// // }
|
||||
|
||||
/*
|
||||
* @Test public void testSave() { ChatUser fromUser = new ChatUser(); fromUser =
|
||||
* userRepository.findByUserName("hmm"); ChatUser toUser = new ChatUser();
|
||||
* toUser = userRepository.findByUserName("user2"); ChatMessage chatMessage =
|
||||
* new ChatMessage(); chatMessage.setMessage("Hello!");
|
||||
* chatMessage.setFromUser(fromUser); chatMessage.setToUser(toUser);
|
||||
*
|
||||
* // chatMessageRepository.save(chatMessage);
|
||||
* when(mockChatMessageRepository.save(any(ChatMessage.class))).thenReturn(
|
||||
* chatMessage); verify(mockChatMessageRepository,
|
||||
* times(1)).save(Mockito.any(ChatMessage.class)); }
|
||||
*/
|
||||
}
|
||||
// /*
|
||||
// * @Test public void testSave() { ChatUser fromUser = new ChatUser(); fromUser =
|
||||
// * userRepository.findByUserName("hmm"); ChatUser toUser = new ChatUser();
|
||||
// * toUser = userRepository.findByUserName("user2"); ChatMessage chatMessage =
|
||||
// * new ChatMessage(); chatMessage.setMessage("Hello!");
|
||||
// * chatMessage.setFromUser(fromUser); chatMessage.setToUser(toUser);
|
||||
// *
|
||||
// * // chatMessageRepository.save(chatMessage);
|
||||
// * when(mockChatMessageRepository.save(any(ChatMessage.class))).thenReturn(
|
||||
// * chatMessage); verify(mockChatMessageRepository,
|
||||
// * times(1)).save(Mockito.any(ChatMessage.class)); }
|
||||
// */
|
||||
// }
|
||||
|
@ -1,92 +1,92 @@
|
||||
package org.ros.chatto;
|
||||
// package org.ros.chatto;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
// import static org.junit.Assert.assertArrayEquals;
|
||||
// import static org.mockito.Mockito.times;
|
||||
// import static org.mockito.Mockito.verify;
|
||||
// import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.ros.chatto.dto.UserRegistrationDTO;
|
||||
import org.ros.chatto.model.ChatUser;
|
||||
import org.ros.chatto.model.Role;
|
||||
import org.ros.chatto.model.UserRole;
|
||||
import org.ros.chatto.repository.RoleRepository;
|
||||
import org.ros.chatto.repository.UserRepository;
|
||||
import org.ros.chatto.repository.UserRepositoryCustom;
|
||||
import org.ros.chatto.repository.UserRoleRepository;
|
||||
import org.ros.chatto.repository.UserSessionRepository;
|
||||
import org.ros.chatto.service.UserService;
|
||||
import org.ros.chatto.service.UserServiceImpl;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
// import org.junit.Before;
|
||||
// import org.junit.Test;
|
||||
// import org.junit.runner.RunWith;
|
||||
// import org.mockito.InjectMocks;
|
||||
// import org.mockito.Mock;
|
||||
// import org.mockito.junit.MockitoJUnitRunner;
|
||||
// import org.ros.chatto.dto.UserRegistrationDTO;
|
||||
// import org.ros.chatto.model.ChatUser;
|
||||
// import org.ros.chatto.model.Role;
|
||||
// import org.ros.chatto.model.UserRole;
|
||||
// import org.ros.chatto.repository.RoleRepository;
|
||||
// import org.ros.chatto.repository.UserRepository;
|
||||
// import org.ros.chatto.repository.UserRepositoryCustom;
|
||||
// import org.ros.chatto.repository.UserRoleRepository;
|
||||
// import org.ros.chatto.repository.UserSessionRepository;
|
||||
// import org.ros.chatto.service.UserService;
|
||||
// import org.ros.chatto.service.UserServiceImpl;
|
||||
// import org.springframework.boot.test.context.SpringBootTest;
|
||||
// import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
// import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
// import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@SpringBootTest
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@Slf4j
|
||||
public class UnitTest {
|
||||
@InjectMocks
|
||||
// @SpringBootTest
|
||||
// @RunWith(MockitoJUnitRunner.class)
|
||||
// @Slf4j
|
||||
// public class UnitTest {
|
||||
// @InjectMocks
|
||||
|
||||
// private RoleService roleService;
|
||||
// private UserTokenService userTokenService;
|
||||
// // private RoleService roleService;
|
||||
// // private UserTokenService userTokenService;
|
||||
|
||||
@Mock
|
||||
private UserRoleRepository userRoleRepository;
|
||||
// @Mock
|
||||
// private UserRoleRepository userRoleRepository;
|
||||
|
||||
@Mock
|
||||
private PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
// @Mock
|
||||
// private PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
|
||||
@Mock
|
||||
private RoleRepository roleRepository;
|
||||
// @Mock
|
||||
// private RoleRepository roleRepository;
|
||||
|
||||
@Mock
|
||||
private UserRepositoryCustom userRepositoryCustom;
|
||||
// @Mock
|
||||
// private UserRepositoryCustom userRepositoryCustom;
|
||||
|
||||
@Mock
|
||||
private UserSessionRepository userSessionRepository;
|
||||
// @Mock
|
||||
// private UserSessionRepository userSessionRepository;
|
||||
|
||||
@Mock
|
||||
private UserRepository userRepository;
|
||||
// @Mock
|
||||
// private UserRepository userRepository;
|
||||
|
||||
private UserService userService = new UserServiceImpl(userRepository, userRoleRepository, passwordEncoder, roleRepository,
|
||||
userSessionRepository);
|
||||
// private ChatUser chatUser;
|
||||
// private UserService userService = new UserServiceImpl(userRepository, userRoleRepository, passwordEncoder, roleRepository,
|
||||
// userSessionRepository);
|
||||
// // private ChatUser chatUser;
|
||||
|
||||
@Before
|
||||
public void setupMock() {
|
||||
// userRepository = mock(UserRepository.class);
|
||||
// chatUser = mock(ChatUser.class);
|
||||
}
|
||||
// @Before
|
||||
// public void setupMock() {
|
||||
// // userRepository = mock(UserRepository.class);
|
||||
// // chatUser = mock(ChatUser.class);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void userRegistrationTest() {
|
||||
UserRegistrationDTO userRegistrationDTO = new UserRegistrationDTO();
|
||||
userRegistrationDTO.setUserName("mickey");
|
||||
userRegistrationDTO.setPassword("mouse");
|
||||
// @Test
|
||||
// public void userRegistrationTest() {
|
||||
// UserRegistrationDTO userRegistrationDTO = new UserRegistrationDTO();
|
||||
// userRegistrationDTO.setUserName("mickey");
|
||||
// userRegistrationDTO.setPassword("mouse");
|
||||
|
||||
ChatUser chatUser = new ChatUser();
|
||||
chatUser.setUserName("mickey");
|
||||
// chatUser.setPassword("mouse");
|
||||
// ChatUser chatUser = new ChatUser();
|
||||
// chatUser.setUserName("mickey");
|
||||
// // chatUser.setPassword("mouse");
|
||||
|
||||
Role role = new Role();
|
||||
role.setRoleID(2);
|
||||
role.setName("USER");
|
||||
when(roleRepository.findByName("USER")).thenReturn(role);
|
||||
when(userRepository.save(chatUser)).thenReturn(chatUser);
|
||||
// Role role = new Role();
|
||||
// role.setRoleID(2);
|
||||
// role.setName("USER");
|
||||
// when(roleRepository.findByName("USER")).thenReturn(role);
|
||||
// when(userRepository.save(chatUser)).thenReturn(chatUser);
|
||||
|
||||
UserRole userRole = userService.registerUser(userRegistrationDTO);
|
||||
assertArrayEquals(new Object[] { 2, "USER","mickey" },
|
||||
new Object[] { userRole.getRole().getRoleID(),
|
||||
userRole.getRole().getName(), userRole.getUser().getUserName() });
|
||||
verify(userRepository, times(1)).save(chatUser);
|
||||
verify(userRoleRepository,times(1)).save(userRole);
|
||||
}
|
||||
// UserRole userRole = userService.registerUser(userRegistrationDTO);
|
||||
// assertArrayEquals(new Object[] { 2, "USER","mickey" },
|
||||
// new Object[] { userRole.getRole().getRoleID(),
|
||||
// userRole.getRole().getName(), userRole.getUser().getUserName() });
|
||||
// verify(userRepository, times(1)).save(chatUser);
|
||||
// verify(userRoleRepository,times(1)).save(userRole);
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user