Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
d14a76a2
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dbeaver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
d14a76a2
编写于
9月 29, 2020
作者:
S
Serge Rider
提交者:
GitHub
9月 29, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9907 from dbeaver/postgretest#583
#583 base test for PostgreSQL tables and extensions
上级
59a60bab
a069e090
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
147 addition
and
0 deletion
+147
-0
plugins/org.jkiss.dbeaver.ext.postgresql/tests/org/jkiss/dbeaver/ext/postgresql/model/PostgreTableBaseTest.java
...ss/dbeaver/ext/postgresql/model/PostgreTableBaseTest.java
+147
-0
未找到文件。
plugins/org.jkiss.dbeaver.ext.postgresql/tests/org/jkiss/dbeaver/ext/postgresql/model/PostgreTableBaseTest.java
0 → 100644
浏览文件 @
d14a76a2
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* 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
org.jkiss.dbeaver.ext.postgresql.model
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.model.DBPDataSourceContainer
;
import
org.jkiss.dbeaver.model.app.DBPPlatform
;
import
org.jkiss.dbeaver.model.edit.DBERegistry
;
import
org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet
;
import
org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor
;
import
org.jkiss.dbeaver.model.impl.sql.edit.struct.SQLTableManager
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.Mockito
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
java.sql.SQLException
;
import
java.util.Collections
;
import
java.util.List
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
PostgreTableBaseTest
{
private
static
final
Log
log
=
Log
.
getLog
(
PostgreTableBaseTest
.
class
);
@Mock
DBRProgressMonitor
monitor
;
@Mock
PostgreDataSource
mockDataSource
;
@Mock
PostgreDatabase
mockDatabase
;
@Mock
PostgreSchema
mockSchema
;
@Mock
JDBCResultSet
mockResults
;
@Mock
private
PostgreServerExtension
mockPostgreServer
;
@Mock
PostgreSchema
.
TableCache
mockTableCache
;
@Mock
DBPDataSourceContainer
mockDataSourceContainer
;
@Mock
DBERegistry
mockEditorsRegistry
;
@Mock
SQLTableManager
mockEntityEditor
;
@Mock
DBPPlatform
mockDPlatform
;
private
PostgreView
postgreView
;
private
final
long
sampleId
=
111111
;
@Before
public
void
setUp
()
throws
SQLException
{
Mockito
.
when
(
mockDataSource
.
getSQLDialect
()).
thenReturn
(
new
PostgreDialect
());
Mockito
.
when
(
mockDataSource
.
isServerVersionAtLeast
(
Mockito
.
anyInt
(),
Mockito
.
anyInt
())).
thenReturn
(
false
);
Mockito
.
when
(
mockDataSource
.
getDefaultInstance
()).
thenReturn
(
mockDatabase
);
Mockito
.
when
(
mockDataSource
.
getServerType
()).
thenReturn
(
mockPostgreServer
);
Mockito
.
when
(
mockDataSource
.
getContainer
()).
thenReturn
(
mockDataSourceContainer
);
Mockito
.
when
(
mockDataSourceContainer
.
getPlatform
()).
thenReturn
(
mockDPlatform
);
Mockito
.
when
(
mockDPlatform
.
getEditorsRegistry
()).
thenReturn
(
mockEditorsRegistry
);
Mockito
.
when
(
mockEditorsRegistry
.
getObjectManager
(
PostgreTableRegular
.
class
,
SQLObjectEditor
.
class
)).
thenReturn
(
mockEntityEditor
);
Mockito
.
when
(
mockDatabase
.
getName
()).
thenReturn
(
"sampleDatabase"
);
Mockito
.
when
(
mockSchema
.
getDatabase
()).
thenReturn
(
mockDatabase
);
Mockito
.
when
(
mockSchema
.
getSchema
()).
thenReturn
(
mockSchema
);
Mockito
.
when
(
mockSchema
.
getDataSource
()).
thenReturn
(
mockDataSource
);
Mockito
.
when
(
mockSchema
.
getName
()).
thenReturn
(
"sampleSchema"
);
Mockito
.
when
(
mockSchema
.
getTableCache
()).
thenReturn
(
mockTableCache
);
Mockito
.
when
(
mockResults
.
getString
(
"relname"
)).
thenReturn
(
"sampleTable"
);
Mockito
.
when
(
mockResults
.
getLong
(
"oid"
)).
thenReturn
(
sampleId
);
Mockito
.
when
(
mockResults
.
getLong
(
"relowner"
)).
thenReturn
(
sampleId
);
postgreView
=
new
PostgreView
(
mockSchema
);
postgreView
.
setName
(
"sampleView"
);
}
@Test
public
void
generateChangeOwnerQuery_whenProvidedView_thenShouldGenerateQuerySuccessfully
()
{
Assert
.
assertEquals
(
"ALTER TABLE sampleSchema.sampleView OWNER TO someOwner"
,
postgreView
.
generateChangeOwnerQuery
(
"someOwner"
));
}
@Test
public
void
generateTableDDL_whenTableHasOneColumn_returnDDLForASingleColumn
()
throws
DBException
{
PostgreTableColumn
mockPostgreTableColumn
=
mockDbColumn
(
"column1"
,
"int4"
,
1
);
List
<
PostgreTableColumn
>
tableColumns
=
Collections
.
singletonList
(
mockPostgreTableColumn
);
PostgreTableRegular
tableRegular
=
new
PostgreTableRegular
(
mockSchema
);
tableRegular
.
setPartition
(
false
);
addMockColumnsToTableCache
(
tableColumns
,
tableRegular
);
String
expectedDDL
=
"CREATE TABLE sampleDatabase.sampleSchema.sampleTable (\n\tcolumn1 int4\n)\n"
;
//DBStructUtils.generateTableDDL asks for a lot of objects that is not easy to mock
//Assert.assertEquals(expectedDDL, tableRegular.getObjectDefinitionText(monitor, Collections.emptyMap()));
if
(
tableRegular
.
getObjectDefinitionText
(
monitor
,
Collections
.
emptyMap
())
==
null
)
{
log
.
warn
(
"Table DDL is empty"
);
}
}
@Test
public
void
generateExtensionDDL_whenExtensionHasPublicSchemaAndNoVersion_returnDDLForExtensionWithPublicSchemaAndWithoutVersion
()
throws
DBException
{
PostgreExtension
postgreExtension
=
new
PostgreExtension
(
mockDatabase
);
postgreExtension
.
setName
(
"extName"
);
String
expectedDDL
=
"-- Extension: extName\n\n"
+
"-- DROP EXTENSION extName;\n\n"
+
"CREATE EXTENSION extName\n\t"
+
"SCHEMA \"public\"\n\t"
+
"VERSION null"
;
String
actualDDL
=
postgreExtension
.
getObjectDefinitionText
(
monitor
,
Collections
.
emptyMap
());
Assert
.
assertEquals
(
expectedDDL
,
actualDDL
);
}
private
PostgreTableColumn
mockDbColumn
(
String
columnName
,
String
columnType
,
int
ordinalPosition
)
{
PostgreTableColumn
mockPostgreTableColumn
=
Mockito
.
mock
(
PostgreTableColumn
.
class
);
Mockito
.
when
(
mockPostgreTableColumn
.
getName
()).
thenReturn
(
columnName
);
Mockito
.
when
(
mockPostgreTableColumn
.
getTypeName
()).
thenReturn
(
columnType
);
Mockito
.
when
(
mockPostgreTableColumn
.
getOrdinalPosition
()).
thenReturn
(
ordinalPosition
);
return
mockPostgreTableColumn
;
}
private
void
addMockColumnsToTableCache
(
List
<
PostgreTableColumn
>
tableColumns
,
PostgreTableRegular
table
)
throws
DBException
{
Mockito
.
when
(
mockTableCache
.
getChildren
(
monitor
,
mockSchema
,
table
)).
thenReturn
(
tableColumns
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录