blob: 45ccd821dd2713af6d6e0a09478d03fb764970a5 [file] [log] [blame]
library googleapis.iap.v1.test;
import "dart:core" as core;
import "dart:async" as async;
import "dart:convert" as convert;
import 'package:http/http.dart' as http;
import 'package:test/test.dart' as unittest;
import 'package:googleapis/iap/v1.dart' as api;
class HttpServerMock extends http.BaseClient {
core.Function _callback;
core.bool _expectJson;
void register(core.Function callback, core.bool expectJson) {
_callback = callback;
_expectJson = expectJson;
}
async.Future<http.StreamedResponse> send(http.BaseRequest request) {
if (_expectJson) {
return request
.finalize()
.transform(convert.utf8.decoder)
.join('')
.then((core.String jsonString) {
if (jsonString.isEmpty) {
return _callback(request, null);
} else {
return _callback(request, convert.json.decode(jsonString));
}
});
} else {
var stream = request.finalize();
if (stream == null) {
return _callback(request, []);
} else {
return stream.toBytes().then((data) {
return _callback(request, data);
});
}
}
}
}
http.StreamedResponse stringResponse(core.int status,
core.Map<core.String, core.String> headers, core.String body) {
var stream = new async.Stream.fromIterable([convert.utf8.encode(body)]);
return new http.StreamedResponse(stream, status, headers: headers);
}
buildUnnamed3692() {
var o = new core.List<core.String>();
o.add("foo");
o.add("foo");
return o;
}
checkUnnamed3692(core.List<core.String> o) {
unittest.expect(o, unittest.hasLength(2));
unittest.expect(o[0], unittest.equals('foo'));
unittest.expect(o[1], unittest.equals('foo'));
}
core.int buildCounterBinding = 0;
buildBinding() {
var o = new api.Binding();
buildCounterBinding++;
if (buildCounterBinding < 3) {
o.condition = buildExpr();
o.members = buildUnnamed3692();
o.role = "foo";
}
buildCounterBinding--;
return o;
}
checkBinding(api.Binding o) {
buildCounterBinding++;
if (buildCounterBinding < 3) {
checkExpr(o.condition);
checkUnnamed3692(o.members);
unittest.expect(o.role, unittest.equals('foo'));
}
buildCounterBinding--;
}
core.int buildCounterExpr = 0;
buildExpr() {
var o = new api.Expr();
buildCounterExpr++;
if (buildCounterExpr < 3) {
o.description = "foo";
o.expression = "foo";
o.location = "foo";
o.title = "foo";
}
buildCounterExpr--;
return o;
}
checkExpr(api.Expr o) {
buildCounterExpr++;
if (buildCounterExpr < 3) {
unittest.expect(o.description, unittest.equals('foo'));
unittest.expect(o.expression, unittest.equals('foo'));
unittest.expect(o.location, unittest.equals('foo'));
unittest.expect(o.title, unittest.equals('foo'));
}
buildCounterExpr--;
}
core.int buildCounterGetIamPolicyRequest = 0;
buildGetIamPolicyRequest() {
var o = new api.GetIamPolicyRequest();
buildCounterGetIamPolicyRequest++;
if (buildCounterGetIamPolicyRequest < 3) {}
buildCounterGetIamPolicyRequest--;
return o;
}
checkGetIamPolicyRequest(api.GetIamPolicyRequest o) {
buildCounterGetIamPolicyRequest++;
if (buildCounterGetIamPolicyRequest < 3) {}
buildCounterGetIamPolicyRequest--;
}
buildUnnamed3693() {
var o = new core.List<api.Binding>();
o.add(buildBinding());
o.add(buildBinding());
return o;
}
checkUnnamed3693(core.List<api.Binding> o) {
unittest.expect(o, unittest.hasLength(2));
checkBinding(o[0]);
checkBinding(o[1]);
}
core.int buildCounterPolicy = 0;
buildPolicy() {
var o = new api.Policy();
buildCounterPolicy++;
if (buildCounterPolicy < 3) {
o.bindings = buildUnnamed3693();
o.etag = "foo";
o.version = 42;
}
buildCounterPolicy--;
return o;
}
checkPolicy(api.Policy o) {
buildCounterPolicy++;
if (buildCounterPolicy < 3) {
checkUnnamed3693(o.bindings);
unittest.expect(o.etag, unittest.equals('foo'));
unittest.expect(o.version, unittest.equals(42));
}
buildCounterPolicy--;
}
core.int buildCounterSetIamPolicyRequest = 0;
buildSetIamPolicyRequest() {
var o = new api.SetIamPolicyRequest();
buildCounterSetIamPolicyRequest++;
if (buildCounterSetIamPolicyRequest < 3) {
o.policy = buildPolicy();
}
buildCounterSetIamPolicyRequest--;
return o;
}
checkSetIamPolicyRequest(api.SetIamPolicyRequest o) {
buildCounterSetIamPolicyRequest++;
if (buildCounterSetIamPolicyRequest < 3) {
checkPolicy(o.policy);
}
buildCounterSetIamPolicyRequest--;
}
buildUnnamed3694() {
var o = new core.List<core.String>();
o.add("foo");
o.add("foo");
return o;
}
checkUnnamed3694(core.List<core.String> o) {
unittest.expect(o, unittest.hasLength(2));
unittest.expect(o[0], unittest.equals('foo'));
unittest.expect(o[1], unittest.equals('foo'));
}
core.int buildCounterTestIamPermissionsRequest = 0;
buildTestIamPermissionsRequest() {
var o = new api.TestIamPermissionsRequest();
buildCounterTestIamPermissionsRequest++;
if (buildCounterTestIamPermissionsRequest < 3) {
o.permissions = buildUnnamed3694();
}
buildCounterTestIamPermissionsRequest--;
return o;
}
checkTestIamPermissionsRequest(api.TestIamPermissionsRequest o) {
buildCounterTestIamPermissionsRequest++;
if (buildCounterTestIamPermissionsRequest < 3) {
checkUnnamed3694(o.permissions);
}
buildCounterTestIamPermissionsRequest--;
}
buildUnnamed3695() {
var o = new core.List<core.String>();
o.add("foo");
o.add("foo");
return o;
}
checkUnnamed3695(core.List<core.String> o) {
unittest.expect(o, unittest.hasLength(2));
unittest.expect(o[0], unittest.equals('foo'));
unittest.expect(o[1], unittest.equals('foo'));
}
core.int buildCounterTestIamPermissionsResponse = 0;
buildTestIamPermissionsResponse() {
var o = new api.TestIamPermissionsResponse();
buildCounterTestIamPermissionsResponse++;
if (buildCounterTestIamPermissionsResponse < 3) {
o.permissions = buildUnnamed3695();
}
buildCounterTestIamPermissionsResponse--;
return o;
}
checkTestIamPermissionsResponse(api.TestIamPermissionsResponse o) {
buildCounterTestIamPermissionsResponse++;
if (buildCounterTestIamPermissionsResponse < 3) {
checkUnnamed3695(o.permissions);
}
buildCounterTestIamPermissionsResponse--;
}
main() {
unittest.group("obj-schema-Binding", () {
unittest.test("to-json--from-json", () {
var o = buildBinding();
var od = new api.Binding.fromJson(o.toJson());
checkBinding(od);
});
});
unittest.group("obj-schema-Expr", () {
unittest.test("to-json--from-json", () {
var o = buildExpr();
var od = new api.Expr.fromJson(o.toJson());
checkExpr(od);
});
});
unittest.group("obj-schema-GetIamPolicyRequest", () {
unittest.test("to-json--from-json", () {
var o = buildGetIamPolicyRequest();
var od = new api.GetIamPolicyRequest.fromJson(o.toJson());
checkGetIamPolicyRequest(od);
});
});
unittest.group("obj-schema-Policy", () {
unittest.test("to-json--from-json", () {
var o = buildPolicy();
var od = new api.Policy.fromJson(o.toJson());
checkPolicy(od);
});
});
unittest.group("obj-schema-SetIamPolicyRequest", () {
unittest.test("to-json--from-json", () {
var o = buildSetIamPolicyRequest();
var od = new api.SetIamPolicyRequest.fromJson(o.toJson());
checkSetIamPolicyRequest(od);
});
});
unittest.group("obj-schema-TestIamPermissionsRequest", () {
unittest.test("to-json--from-json", () {
var o = buildTestIamPermissionsRequest();
var od = new api.TestIamPermissionsRequest.fromJson(o.toJson());
checkTestIamPermissionsRequest(od);
});
});
unittest.group("obj-schema-TestIamPermissionsResponse", () {
unittest.test("to-json--from-json", () {
var o = buildTestIamPermissionsResponse();
var od = new api.TestIamPermissionsResponse.fromJson(o.toJson());
checkTestIamPermissionsResponse(od);
});
});
unittest.group("resource-V1ResourceApi", () {
unittest.test("method--getIamPolicy", () {
var mock = new HttpServerMock();
api.V1ResourceApi res = new api.IapApi(mock).v1;
var arg_request = buildGetIamPolicyRequest();
var arg_resource = "foo";
var arg_$fields = "foo";
mock.register(unittest.expectAsync2((http.BaseRequest req, json) {
var obj = new api.GetIamPolicyRequest.fromJson(json);
checkGetIamPolicyRequest(obj);
var path = (req.url).path;
var pathOffset = 0;
var index;
var subPart;
unittest.expect(
path.substring(pathOffset, pathOffset + 1), unittest.equals("/"));
pathOffset += 1;
unittest.expect(
path.substring(pathOffset, pathOffset + 3), unittest.equals("v1/"));
pathOffset += 3;
// NOTE: We cannot test reserved expansions due to the inability to reverse the operation;
var query = (req.url).query;
var queryOffset = 0;
var queryMap = <core.String, core.List<core.String>>{};
addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
parseBool(n) {
if (n == "true") return true;
if (n == "false") return false;
if (n == null) return null;
throw new core.ArgumentError("Invalid boolean: $n");
}
if (query.length > 0) {
for (var part in query.split("&")) {
var keyvalue = part.split("=");
addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]),
core.Uri.decodeQueryComponent(keyvalue[1]));
}
}
unittest.expect(queryMap["fields"].first, unittest.equals(arg_$fields));
var h = {
"content-type": "application/json; charset=utf-8",
};
var resp = convert.json.encode(buildPolicy());
return new async.Future.value(stringResponse(200, h, resp));
}), true);
res
.getIamPolicy(arg_request, arg_resource, $fields: arg_$fields)
.then(unittest.expectAsync1(((response) {
checkPolicy(response);
})));
});
unittest.test("method--setIamPolicy", () {
var mock = new HttpServerMock();
api.V1ResourceApi res = new api.IapApi(mock).v1;
var arg_request = buildSetIamPolicyRequest();
var arg_resource = "foo";
var arg_$fields = "foo";
mock.register(unittest.expectAsync2((http.BaseRequest req, json) {
var obj = new api.SetIamPolicyRequest.fromJson(json);
checkSetIamPolicyRequest(obj);
var path = (req.url).path;
var pathOffset = 0;
var index;
var subPart;
unittest.expect(
path.substring(pathOffset, pathOffset + 1), unittest.equals("/"));
pathOffset += 1;
unittest.expect(
path.substring(pathOffset, pathOffset + 3), unittest.equals("v1/"));
pathOffset += 3;
// NOTE: We cannot test reserved expansions due to the inability to reverse the operation;
var query = (req.url).query;
var queryOffset = 0;
var queryMap = <core.String, core.List<core.String>>{};
addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
parseBool(n) {
if (n == "true") return true;
if (n == "false") return false;
if (n == null) return null;
throw new core.ArgumentError("Invalid boolean: $n");
}
if (query.length > 0) {
for (var part in query.split("&")) {
var keyvalue = part.split("=");
addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]),
core.Uri.decodeQueryComponent(keyvalue[1]));
}
}
unittest.expect(queryMap["fields"].first, unittest.equals(arg_$fields));
var h = {
"content-type": "application/json; charset=utf-8",
};
var resp = convert.json.encode(buildPolicy());
return new async.Future.value(stringResponse(200, h, resp));
}), true);
res
.setIamPolicy(arg_request, arg_resource, $fields: arg_$fields)
.then(unittest.expectAsync1(((response) {
checkPolicy(response);
})));
});
unittest.test("method--testIamPermissions", () {
var mock = new HttpServerMock();
api.V1ResourceApi res = new api.IapApi(mock).v1;
var arg_request = buildTestIamPermissionsRequest();
var arg_resource = "foo";
var arg_$fields = "foo";
mock.register(unittest.expectAsync2((http.BaseRequest req, json) {
var obj = new api.TestIamPermissionsRequest.fromJson(json);
checkTestIamPermissionsRequest(obj);
var path = (req.url).path;
var pathOffset = 0;
var index;
var subPart;
unittest.expect(
path.substring(pathOffset, pathOffset + 1), unittest.equals("/"));
pathOffset += 1;
unittest.expect(
path.substring(pathOffset, pathOffset + 3), unittest.equals("v1/"));
pathOffset += 3;
// NOTE: We cannot test reserved expansions due to the inability to reverse the operation;
var query = (req.url).query;
var queryOffset = 0;
var queryMap = <core.String, core.List<core.String>>{};
addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
parseBool(n) {
if (n == "true") return true;
if (n == "false") return false;
if (n == null) return null;
throw new core.ArgumentError("Invalid boolean: $n");
}
if (query.length > 0) {
for (var part in query.split("&")) {
var keyvalue = part.split("=");
addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]),
core.Uri.decodeQueryComponent(keyvalue[1]));
}
}
unittest.expect(queryMap["fields"].first, unittest.equals(arg_$fields));
var h = {
"content-type": "application/json; charset=utf-8",
};
var resp = convert.json.encode(buildTestIamPermissionsResponse());
return new async.Future.value(stringResponse(200, h, resp));
}), true);
res
.testIamPermissions(arg_request, arg_resource, $fields: arg_$fields)
.then(unittest.expectAsync1(((response) {
checkTestIamPermissionsResponse(response);
})));
});
});
}