Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
incubator-dubbo-admin
提交
3adac8a5
I
incubator-dubbo-admin
项目概览
爱吃血肠
/
incubator-dubbo-admin
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
incubator-dubbo-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3adac8a5
编写于
1月 23, 2019
作者:
孙
孙不服
提交者:
min
1月 23, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
unit test (#268)
* unit test * add Apache license & remove *
上级
2d40e623
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
175 addition
and
0 deletion
+175
-0
dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/common/util/CoderUtilTest.java
...ava/org/apache/dubbo/admin/common/util/CoderUtilTest.java
+69
-0
dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/service/RegistryServerSyncTest.java
...rg/apache/dubbo/admin/service/RegistryServerSyncTest.java
+106
-0
未找到文件。
dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/common/util/CoderUtilTest.java
0 → 100644
浏览文件 @
3adac8a5
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.dubbo.admin.common.util
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Java6Assertions
.
fail
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
public
class
CoderUtilTest
{
@Test
public
void
MD5_16bit
()
{
assertNull
(
CoderUtil
.
MD5_16bit
(
null
));
String
input
=
"dubbo"
;
String
output
=
"2CC9DEED96FE012E"
;
assertEquals
(
output
,
CoderUtil
.
MD5_16bit
(
input
));
}
@Test
public
void
MD5_32bit
()
{
String
input
=
null
;
assertNull
(
CoderUtil
.
MD5_32bit
(
input
));
input
=
"dubbo"
;
String
output
=
"AA4E1B8C2CC9DEED96FE012EF2E0752A"
;
assertEquals
(
output
,
CoderUtil
.
MD5_32bit
(
input
));
}
@Test
public
void
MD5_32bit1
()
{
byte
[]
input
=
null
;
assertNull
(
CoderUtil
.
MD5_32bit
(
input
));
input
=
"dubbo"
.
getBytes
();
String
output
=
"AA4E1B8C2CC9DEED96FE012EF2E0752A"
;
assertEquals
(
output
,
CoderUtil
.
MD5_32bit
(
input
));
}
@Test
public
void
decodeBase64
()
{
try
{
CoderUtil
.
decodeBase64
(
null
);
fail
(
"when param is null, this should throw exception"
);
}
catch
(
Exception
e
)
{
}
String
input
=
"ZHViYm8="
;
String
output
=
"dubbo"
;
assertEquals
(
output
,
CoderUtil
.
decodeBase64
(
input
));
}
}
\ No newline at end of file
dubbo-admin-backend/src/test/java/org/apache/dubbo/admin/service/RegistryServerSyncTest.java
0 → 100644
浏览文件 @
3adac8a5
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.dubbo.admin.service
;
import
org.apache.dubbo.admin.common.util.Constants
;
import
org.apache.dubbo.common.URL
;
import
org.apache.dubbo.registry.Registry
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentMap
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
public
class
RegistryServerSyncTest
{
@Mock
private
Registry
registry
;
@InjectMocks
private
RegistryServerSync
registryServerSync
;
@Test
public
void
testGetRegistryCache
()
{
registryServerSync
.
getRegistryCache
();
}
@Test
public
void
testAfterPropertiesSet
()
throws
Exception
{
registryServerSync
.
afterPropertiesSet
();
verify
(
registry
).
subscribe
(
any
(
URL
.
class
),
any
(
RegistryServerSync
.
class
));
}
@Test
public
void
testDestroy
()
throws
Exception
{
registryServerSync
.
destroy
();
verify
(
registry
).
unsubscribe
(
any
(
URL
.
class
),
any
(
RegistryServerSync
.
class
));
}
@Test
public
void
testNotify
()
{
registryServerSync
.
notify
(
null
);
registryServerSync
.
notify
(
Collections
.
emptyList
());
// when url.getProtocol is not empty protocol
URL
consumerUrl
=
mock
(
URL
.
class
);
URL
providerUrl
=
mock
(
URL
.
class
);
when
(
consumerUrl
.
getParameter
(
Constants
.
CATEGORY_KEY
,
Constants
.
PROVIDERS_CATEGORY
)).
thenReturn
(
org
.
apache
.
dubbo
.
common
.
Constants
.
CONSUMER_PROTOCOL
);
when
(
consumerUrl
.
getServiceInterface
()).
thenReturn
(
"org.apache.dubbo.consumer"
);
when
(
consumerUrl
.
getServiceKey
()).
thenReturn
(
"org.apache.dubbo.consumer"
);
when
(
consumerUrl
.
toFullString
()).
thenReturn
(
"consumer://192.168.1.10/sunbufu.dubbo.consumer?application=dubbo&category=consumer&check=false&dubbo=2.7.0&interface=sunbufu.dubbo.consumer&loadbalabce=roundrobin&mehods=sayHi,sayGoodBye&owner=sunbufu&pid=18&protocol=dubbo&side=consumer&timeout=3000×tamp=1548127407769"
);
when
(
providerUrl
.
getParameter
(
Constants
.
CATEGORY_KEY
,
Constants
.
PROVIDERS_CATEGORY
)).
thenReturn
(
org
.
apache
.
dubbo
.
common
.
Constants
.
PROVIDER_PROTOCOL
);
when
(
providerUrl
.
getServiceInterface
()).
thenReturn
(
"org.apache.dubbo.provider"
);
when
(
providerUrl
.
getServiceKey
()).
thenReturn
(
"org.apache.dubbo.provider"
);
when
(
providerUrl
.
toFullString
()).
thenReturn
(
"consumer://192.168.1.10/sunbufu.dubbo.consumer?application=dubbo&category=consumer&check=false&dubbo=2.6.2&interface=sunbufu.dubbo.consumer&loadbalabce=roundrobin&mehods=sayHi,sayGoodBye&owner=sunbufu&pid=18&protocol=dubbo&side=consumer&timeout=3000×tamp=1548127407769"
);
registryServerSync
.
notify
(
Arrays
.
asList
(
consumerUrl
,
consumerUrl
,
providerUrl
));
ConcurrentMap
<
String
,
Map
<
String
,
URL
>>
consumerMap
=
registryServerSync
.
getRegistryCache
().
get
(
org
.
apache
.
dubbo
.
common
.
Constants
.
CONSUMER_PROTOCOL
);
assertTrue
(
consumerMap
.
keySet
().
contains
(
"org.apache.dubbo.consumer"
));
ConcurrentMap
<
String
,
Map
<
String
,
URL
>>
providerMap
=
registryServerSync
.
getRegistryCache
().
get
(
org
.
apache
.
dubbo
.
common
.
Constants
.
PROVIDER_PROTOCOL
);
assertTrue
(
providerMap
.
keySet
().
contains
(
"org.apache.dubbo.provider"
));
// when url.getProtocol is empty protocol
when
(
consumerUrl
.
getProtocol
()).
thenReturn
(
org
.
apache
.
dubbo
.
common
.
Constants
.
EMPTY_PROTOCOL
);
when
(
consumerUrl
.
getParameter
(
Constants
.
GROUP_KEY
)).
thenReturn
(
"dubbo"
);
when
(
consumerUrl
.
getParameter
(
Constants
.
VERSION_KEY
)).
thenReturn
(
"2.7.0"
);
registryServerSync
.
notify
(
Collections
.
singletonList
(
consumerUrl
));
assertTrue
(!
consumerMap
.
keySet
().
contains
(
"org.apache.dubbo.consumer"
));
// when url's group or version is ANY_VALUE (*)
when
(
providerUrl
.
getProtocol
()).
thenReturn
(
org
.
apache
.
dubbo
.
common
.
Constants
.
EMPTY_PROTOCOL
);
when
(
providerUrl
.
getParameter
(
Constants
.
GROUP_KEY
)).
thenReturn
(
Constants
.
ANY_VALUE
);
registryServerSync
.
notify
(
Collections
.
singletonList
(
providerUrl
));
assertTrue
(!
providerMap
.
keySet
().
contains
(
"org.apache.dubbo.provider"
));
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录