Skip to content

Commit 1755f2b

Browse files
author
codezhang
committed
增加GetUAICensorAvailResourceType
1 parent 97c954c commit 1755f2b

8 files changed

Lines changed: 302 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cn.ucloud.censor.client;
2+
3+
import cn.ucloud.censor.model.GetUAICensorAvailResourceTypeParam;
4+
import cn.ucloud.censor.model.GetUAICensorAvailResourceTypeResult;
5+
import cn.ucloud.common.client.UcloudClient;
6+
import cn.ucloud.common.handler.UcloudHandler;
7+
8+
/**
9+
* @Description : censor 客户端接口
10+
* @Author : codezhang
11+
* @Date : 2019-04-17 10:47
12+
**/
13+
public interface CensorClient extends UcloudClient {
14+
15+
16+
/**
17+
* 获取可用的UAI安全审查资源类型
18+
*
19+
* @param param 参数对象
20+
* @return 结果对象
21+
* @throws Exception
22+
*/
23+
GetUAICensorAvailResourceTypeResult getUAICensorAvailResourceType(
24+
GetUAICensorAvailResourceTypeParam param) throws Exception;
25+
26+
/**
27+
* 获取可用的UAI安全审查资源类型 (回调)
28+
*
29+
* @param param 参数对象
30+
* @param handler 回调接口
31+
* @param asyncFlag 是否异步
32+
*/
33+
void getUAICensorAvailResourceType(GetUAICensorAvailResourceTypeParam param,
34+
UcloudHandler<GetUAICensorAvailResourceTypeResult> handler,
35+
Boolean... asyncFlag);
36+
37+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cn.ucloud.censor.client;
2+
3+
import cn.ucloud.censor.model.GetUAICensorAvailResourceTypeParam;
4+
import cn.ucloud.censor.model.GetUAICensorAvailResourceTypeResult;
5+
import cn.ucloud.common.client.DefaultUcloudClient;
6+
import cn.ucloud.common.handler.UcloudHandler;
7+
import cn.ucloud.common.http.UcloudHttp;
8+
import cn.ucloud.common.http.UcloudHttpImpl;
9+
import cn.ucloud.common.pojo.UcloudConfig;
10+
11+
/**
12+
* @Description :
13+
* @Author : codezhang
14+
* @Date : 2019-04-17 10:49
15+
**/
16+
public class DefaultCensorClient extends DefaultUcloudClient implements CensorClient {
17+
18+
public DefaultCensorClient(UcloudConfig config) {
19+
super(config);
20+
}
21+
22+
@Override
23+
public GetUAICensorAvailResourceTypeResult
24+
getUAICensorAvailResourceType(GetUAICensorAvailResourceTypeParam param) throws Exception {
25+
UcloudHttp http = new UcloudHttpImpl(GetUAICensorAvailResourceTypeResult.class);
26+
return (GetUAICensorAvailResourceTypeResult) http.doGet(param, config, null);
27+
}
28+
29+
@Override
30+
public void getUAICensorAvailResourceType(GetUAICensorAvailResourceTypeParam param,
31+
UcloudHandler<GetUAICensorAvailResourceTypeResult> handler,
32+
Boolean... asyncFlag) {
33+
UcloudHttp http = new UcloudHttpImpl(GetUAICensorAvailResourceTypeResult.class);
34+
try {
35+
http.doGet(param, config, handler, asyncFlag);
36+
} catch (Exception e) {
37+
}
38+
}
39+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package cn.ucloud.censor.model;
2+
3+
import cn.ucloud.common.annotation.UcloudParam;
4+
import cn.ucloud.common.pojo.BaseRequestParam;
5+
6+
import javax.validation.constraints.NotEmpty;
7+
8+
/**
9+
* @Description : 获取可用的UAI安全审查资源类型
10+
* @Author : codezhang
11+
* @Date : 2019-04-17 10:41
12+
**/
13+
public class GetUAICensorAvailResourceTypeParam extends BaseRequestParam {
14+
15+
/**
16+
* 地域。 参见 [地域和可用区列表]
17+
*/
18+
@NotEmpty(message = "region can not be empty")
19+
@UcloudParam("Region")
20+
private String region;
21+
22+
/**
23+
* 可用区。参见 [可用区列表]
24+
*/
25+
@NotEmpty(message = "zone can not be empty")
26+
@UcloudParam("Zone")
27+
private String zone;
28+
29+
public GetUAICensorAvailResourceTypeParam(@NotEmpty(message = "region can not be empty") String region,
30+
@NotEmpty(message = "zone can not be empty") String zone) {
31+
super("GetUAICensorAvailResourceType");
32+
this.region = region;
33+
this.zone = zone;
34+
}
35+
36+
public String getRegion() {
37+
return region;
38+
}
39+
40+
public void setRegion(String region) {
41+
this.region = region;
42+
}
43+
44+
public String getZone() {
45+
return zone;
46+
}
47+
48+
public void setZone(String zone) {
49+
this.zone = zone;
50+
}
51+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package cn.ucloud.censor.model;
2+
3+
import cn.ucloud.common.pojo.BaseResponseResult;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
import java.util.List;
7+
8+
/**
9+
* @Description : 获取可用的UAI安全审查资源类型
10+
* @Author : codezhang
11+
* @Date : 2019-04-17 10:43
12+
**/
13+
public class GetUAICensorAvailResourceTypeResult extends BaseResponseResult {
14+
15+
/**
16+
* 支持的资源类型总数
17+
*/
18+
@SerializedName("TotalCount")
19+
private Integer totalCount;
20+
21+
/**
22+
* 支持资源类型的具体信息
23+
*/
24+
@SerializedName("DataSet")
25+
private List<UAICensorResourceTypeInfo> typeInfos;
26+
27+
28+
public Integer getTotalCount() {
29+
return totalCount;
30+
}
31+
32+
public void setTotalCount(Integer totalCount) {
33+
this.totalCount = totalCount;
34+
}
35+
36+
public List<UAICensorResourceTypeInfo> getTypeInfos() {
37+
return typeInfos;
38+
}
39+
40+
public void setTypeInfos(List<UAICensorResourceTypeInfo> typeInfos) {
41+
this.typeInfos = typeInfos;
42+
}
43+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cn.ucloud.censor.model;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
/**
6+
* @Description : UAI安全审查资源类型信息
7+
* @Author : codezhang
8+
* @Date : 2019-04-17 10:44
9+
**/
10+
public class UAICensorResourceTypeInfo {
11+
12+
13+
/**
14+
* 资源类型ID
15+
*/
16+
@SerializedName("ResourceTypeId")
17+
private Integer resourceTypeId;
18+
19+
/**
20+
* 资源类型名称
21+
*/
22+
@SerializedName("ResourceTypeName")
23+
private String resourceTypeName;
24+
25+
public Integer getResourceTypeId() {
26+
return resourceTypeId;
27+
}
28+
29+
public void setResourceTypeId(Integer resourceTypeId) {
30+
this.resourceTypeId = resourceTypeId;
31+
}
32+
33+
public String getResourceTypeName() {
34+
return resourceTypeName;
35+
}
36+
37+
public void setResourceTypeName(String resourceTypeName) {
38+
this.resourceTypeName = resourceTypeName;
39+
}
40+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cn.ucloud.censor.pojo;
2+
3+
import cn.ucloud.common.pojo.Account;
4+
import cn.ucloud.common.pojo.UcloudConfig;
5+
6+
/**
7+
* @Description : censor 配置类
8+
* @Author : codezhang
9+
* @Date : 2019-04-17 10:39
10+
**/
11+
public class CensorConfig extends UcloudConfig {
12+
public CensorConfig(Account account) {
13+
super(account);
14+
}
15+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package cn.ucloud.censor.client;
2+
3+
import cn.ucloud.censor.model.GetUAICensorAvailResourceTypeParam;
4+
import cn.ucloud.censor.model.GetUAICensorAvailResourceTypeResult;
5+
import cn.ucloud.censor.pojo.CensorConfig;
6+
import cn.ucloud.common.pojo.Account;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
10+
import static org.junit.Assert.assertNull;
11+
12+
/**
13+
* @Description :
14+
* @Author : codezhang
15+
* @Date : 2019-04-17 10:52
16+
**/
17+
public class GetUAICensorAvailResourceTypeTest {
18+
19+
private CensorClient client;
20+
21+
private GetUAICensorAvailResourceTypeParam param;
22+
23+
@Before
24+
public void setUp() throws Exception {
25+
client = new DefaultCensorClient(new CensorConfig(
26+
new Account(System.getenv("UCloudPrivateKey"),
27+
System.getenv("UCloudPublicKey"))));
28+
String projectId = System.getenv("ProjectId");
29+
String region = "cn-bj2";
30+
String zone = "cn-bj2-04";
31+
param = new GetUAICensorAvailResourceTypeParam(region,zone);
32+
param.setProjectId(projectId);
33+
}
34+
35+
@Test
36+
public void getUAICensorAvailResourceType() {
37+
try {
38+
GetUAICensorAvailResourceTypeResult result =
39+
client.getUAICensorAvailResourceType(param);
40+
JSONComparator.jsonComparator(result);
41+
} catch (Exception e) {
42+
assertNull(e);
43+
}
44+
}
45+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cn.ucloud.censor.client;
2+
3+
import cn.ucloud.common.pojo.BaseResponseResult;
4+
import com.google.gson.Gson;
5+
import com.google.gson.GsonBuilder;
6+
import org.skyscreamer.jsonassert.JSONAssert;
7+
import org.skyscreamer.jsonassert.JSONCompareMode;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
11+
import static org.junit.Assert.assertNull;
12+
13+
/**
14+
* @Description :
15+
* @Author : codezhang
16+
* @Date : 2019-03-05 21:32
17+
**/
18+
public class JSONComparator {
19+
20+
private static final Logger logger = LoggerFactory.getLogger(JSONComparator.class.getName());
21+
22+
public static void jsonComparator(BaseResponseResult result) {
23+
try {
24+
Gson gson = new GsonBuilder().serializeNulls().create();
25+
logger.info("result 2 json:{}", gson.toJson(result));
26+
JSONAssert.assertEquals(result.getResponseContent(), gson.toJson(result), JSONCompareMode.LENIENT);
27+
} catch (Exception e) {
28+
assertNull(e);
29+
}
30+
}
31+
32+
}

0 commit comments

Comments
 (0)