Skip to content

Commit 74a537f

Browse files
修改ut,使用spy的方式 review by songyumeng
1 parent d069cd4 commit 74a537f

14 files changed

+229
-90
lines changed

test/leaflet/services/AddressMatchServiceSpec.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {addressMatchService} from '../../../src/leaflet/services/AddressMatchService';
22
import {GeoCodingParameter} from '../../../src/common/iServer/GeoCodingParameter';
33
import {GeoDecodingParameter} from '../../../src/common/iServer/GeoDecodingParameter';
4+
import { FetchRequest } from '../../../src/common/util/FetchRequest';
5+
46

57
var addressMatchURL = GlobeParameter.addressMatchURL;
68
var options = {
@@ -29,7 +31,15 @@ describe('leaflet_AddressMatchService', () => {
2931
maxReturn: -1
3032
});
3133
var geoCodingService = addressMatchService(addressMatchURL, options);
32-
geoCodingService.code(geoCodingParams, (result) => {
34+
35+
spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => {
36+
expect(testUrl).toBe(addressMatchURL + "/geocoding");
37+
expect(params).not.toBeNull();
38+
expect(options).not.toBeNull();
39+
return Promise.resolve(new Response(codeSuccessEscapedJson));
40+
});
41+
42+
geoCodingService.code(geoCodingParams, (result) => {
3343
serviceResult = result
3444
});
3545
setTimeout(() => {
@@ -69,6 +79,14 @@ describe('leaflet_AddressMatchService', () => {
6979
geoDecodingRadius: 500
7080
});
7181
var GeoDecodingService = addressMatchService(addressMatchURL, options);
82+
83+
spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => {
84+
expect(testUrl).toBe(addressMatchURL + "/geodecoding");
85+
expect(params).not.toBeNull();
86+
expect(options).not.toBeNull();
87+
return Promise.resolve(new Response(decodeSuccessEscapedJson));
88+
});
89+
7290
GeoDecodingService.decode(GeoDecodingParams, (result) => {
7391
serviceResult = result
7492
});
@@ -107,6 +125,13 @@ describe('leaflet_AddressMatchService', () => {
107125
maxReturn: -1
108126
});
109127
var geoCodingService = addressMatchService(addressMatchURL, options);
128+
129+
spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => {
130+
expect(testUrl).toBe(addressMatchURL + "/geocoding");
131+
expect(options).not.toBeNull();
132+
return Promise.resolve(new Response(codeFailEscapedJson));
133+
});
134+
110135
geoCodingService.code(geoCodingParams, (result) => {
111136
serviceResult = result
112137
});
@@ -141,6 +166,13 @@ describe('leaflet_AddressMatchService', () => {
141166
geoDecodingRadius: 500
142167
});
143168
var geoDecodingService = addressMatchService(addressMatchURL, options);
169+
170+
spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => {
171+
expect(testUrl).toBe(addressMatchURL + "/geodecoding");
172+
expect(options).not.toBeNull();
173+
return Promise.resolve(new Response(decodeFailEscapedJson));
174+
});
175+
144176
geoDecodingService.decode(GeoDecodingParams, (result) => {
145177
serviceResult = result
146178
});

test/leaflet/services/BufferAnalysisSpec.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {DataReturnOption} from '../../../src/common/iServer/DataReturnOption';
88
import {BufferEndType} from '../../../src/common/REST';
99
import {DataReturnMode} from '../../../src/common/REST';
1010
import request from 'request';
11+
import { FetchRequest } from '../../../src/common/util/FetchRequest';
1112

1213
var spatialAnalystURL = GlobeParameter.spatialAnalystURL_Changchun;
1314
var options = {
@@ -73,6 +74,15 @@ describe('leaflet_SpatialAnalystService_bufferAnalysis', () => {
7374
})
7475
});
7576
var bufferAnalystService = spatialAnalystService(spatialAnalystURL, options);
77+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
78+
expect(method).toBe("POST");
79+
expect(testUrl).toBe(spatialAnalystURL + "/geometry/buffer.json?returnContent=true");
80+
var expectParams = "{'analystParameter':{'endType':\"ROUND\",'leftDistance':{'exp':null,'value':250},'rightDistance':{'exp':null,'value':250},'semicircleLineSegment':10,'radiusUnit':\"METER\"},'sourceGeometry':{'id':0,'style':null,'parts':[33],'points':[{'id':\"SuperMap.Geometry_38\",'bounds':null,'SRID':null,'x':2823.94,'y':-4690,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_39\",'bounds':null,'SRID':null,'x':3448.94,'y':-4690.301,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_40\",'bounds':null,'SRID':null,'x':3816.561,'y':-3810.125,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_41\",'bounds':null,'SRID':null,'x':3917.383,'y':-3609.158,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_42\",'bounds':null,'SRID':null,'x':3976.983,'y':-3490.291,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_43\",'bounds':null,'SRID':null,'x':4020.004,'y':-4377.027,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_44\",'bounds':null,'SRID':null,'x':4076.265,'y':-4382.939,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_45\",'bounds':null,'SRID':null,'x':4215.049,'y':-4382.333,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_46\",'bounds':null,'SRID':null,'x':4428.156,'y':-4382.285,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_47\",'bounds':null,'SRID':null,'x':4647.579,'y':-4383.017,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_48\",'bounds':null,'SRID':null,'x':4679.707,'y':-4382.898,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_49\",'bounds':null,'SRID':null,'x':4917.462,'y':-4382.635,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_50\",'bounds':null,'SRID':null,'x':5074.019,'y':-4381.833,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_51\",'bounds':null,'SRID':null,'x':5257.042,'y':-4381.031,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_52\",'bounds':null,'SRID':null,'x':5363.785,'y':-4380.717,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_53\",'bounds':null,'SRID':null,'x':5671.717,'y':-4378.794,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_54\",'bounds':null,'SRID':null,'x':5847.521,'y':-4377.97,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_55\",'bounds':null,'SRID':null,'x':5990.637,'y':-4303.528,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_56\",'bounds':null,'SRID':null,'x':6055.343,'y':-4270.072,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_57\",'bounds':null,'SRID':null,'x':6168.913,'y':-4382.389,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_58\",'bounds':null,'SRID':null,'x':6214.183,'y':-4209.927,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_59\",'bounds':null,'SRID':null,'x':6377.789,'y':-4209.142,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_60\",'bounds':null,'SRID':null,'x':6393.692,'y':-4210.142,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_61\",'bounds':null,'SRID':null,'x':6693.989,'y':-4207.45,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_62\",'bounds':null,'SRID':null,'x':6788.392,'y':-4208.45,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_63\",'bounds':null,'SRID':null,'x':6984.304,'y':-4207.21,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_64\",'bounds':null,'SRID':null,'x':7189.183,'y':-4208.296,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_65\",'bounds':null,'SRID':null,'x':7300.505,'y':-4208.296,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_66\",'bounds':null,'SRID':null,'x':7573.056,'y':-4208.803,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_67\",'bounds':null,'SRID':null,'x':7680.977,'y':-4208.804,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_68\",'bounds':null,'SRID':null,'x':7850.593,'y':-4208.393,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_69\",'bounds':null,'SRID':null,'x':8182.656,'y':-4210.533,'tag':null,'type':\"Point\"},{'id':\"SuperMap.Geometry_70\",'bounds':null,'SRID':null,'x':8554.893,'y':-4261.485,'tag':null,'type':\"Point\"}],'type':\"LINE\",'prjCoordSys':{'epsgCode':null}},'sourceGeometrySRID':null}";
81+
expect(params).toBe(expectParams);
82+
expect(options).not.toBeNull();
83+
return Promise.resolve(new Response(bufferAnalysisByGeometryLEscapedJson));
84+
});
85+
7686
bufferAnalystService.bufferAnalysis(geoBufferAnalystParams, (result) => {
7787
serviceResult = result;
7888
});
@@ -125,6 +135,16 @@ describe('leaflet_SpatialAnalystService_bufferAnalysis', () => {
125135
})
126136
});
127137
var bufferAnalystService = spatialAnalystService(spatialAnalystURL);
138+
139+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
140+
expect(method).toBe("POST");
141+
expect(testUrl).toBe(spatialAnalystURL + "/datasets/RoadLine2@Changchun/buffer.json?returnContent=true");
142+
var expectParams = "{'bufferAnalystParameter':{'endType':\"ROUND\",'leftDistance':{'value':10},'rightDistance':{'value':10},'semicircleLineSegment':10,'radiusUnit':\"METER\"},'filterQueryParameter':{'attributeFilter':\"NAME='团结路'\",'name':null,'joinItems':null,'linkItems':null,'ids':null,'orderBy':null,'groupBy':null,'fields':null},'dataReturnOption':{'expectCount':2000,'dataset':\"bufferAnalystByDatasets_leafletTest\",'dataReturnMode':\"DATASET_ONLY\",'deleteExistResultDataset':true},'isAttributeRetained':true,'isUnion':false}";
143+
expect(params).toBe(expectParams);
144+
expect(options).not.toBeNull();
145+
return Promise.resolve(new Response(bufferAnalysisByDatasetLEscapedJson));
146+
});
147+
128148
bufferAnalystService.bufferAnalysis(dsBufferAnalystParameters, (result) => {
129149
serviceResult = result;
130150
});
@@ -137,10 +157,4 @@ describe('leaflet_SpatialAnalystService_bufferAnalysis', () => {
137157
}, 5000);
138158
});
139159

140-
// 删除测试过程中产生的测试数据集
141-
it('delete test resources', (done) => {
142-
var testResult = GlobeParameter.datachangchunURL + resultDataset;
143-
request.delete(testResult);
144-
done();
145-
});
146160
});

test/leaflet/services/GridCellInfosServiceSpec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {gridCellInfosService} from '../../../src/leaflet/services/GridCellInfosService';
22
import {GetGridCellInfosParameters} from '../../../src/common/iServer/GetGridCellInfosParameters';
3+
import { FetchRequest } from '../../../src/common/util/FetchRequest';
34

45
var url = GlobeParameter.dataServiceURL;
56
describe('leaflet_GridCellInfosService', () => {
@@ -17,13 +18,27 @@ describe('leaflet_GridCellInfosService', () => {
1718
expect(gridCellInfoService.url).toEqual(url);
1819
});
1920

21+
22+
2023
it('getGridCellInfos', () => {
2124
var params = new GetGridCellInfosParameters({
2225
dataSourceName: "World",
2326
datasetName: "WorldEarth",
2427
X: 4,
2528
Y: 20
2629
});
30+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
31+
expect(method).toBe("GET");
32+
expect(options).not.toBeNull();
33+
if (testUrl.indexOf("WorldEarth.json") > 0) {
34+
return Promise.resolve(new Response(getDatasetInfoEcapedJson));
35+
} else {
36+
if (testUrl.indexOf("imageValue.json") > 0) {
37+
return Promise.resolve(new Response(getGridCellInfosEcapedJson));
38+
}
39+
};
40+
return null;
41+
});
2742
gridCellInfosService(url).getGridCellInfos(params, (serviceResult) => {
2843
expect(serviceResult).not.toBeNull();
2944
expect(serviceResult.type).toBe("processCompleted");
@@ -39,6 +54,7 @@ describe('leaflet_GridCellInfosService', () => {
3954
expect(serviceResult.object.dataSourceName).toBe("World");
4055
expect(serviceResult.object.datasetName).toBe("WorldEarth");
4156
expect(serviceResult.object.datasetType).toBe("IMAGE");
57+
expect(FetchRequest.commit.calls.count()).toEqual(2);
4258
params.destroy();
4359
});
4460
});

test/leaflet/services/InterpolationAnalysisSpec.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {spatialAnalystService} from '../../../src/leaflet/services/SpatialAnalys
22
import {InterpolationKrigingAnalystParameters} from '../../../src/common/iServer/InterpolationKrigingAnalystParameters';
33
import {PixelFormat} from '../../../src/common/REST';
44
import request from 'request';
5+
import {FetchRequest} from '../../../src/common/util/FetchRequest';
56

67
var spatialAnalystURL = GlobeParameter.spatialAnalystURL;
78
var options = {
@@ -53,6 +54,14 @@ describe('leaflet_SpatialAnalystService_interpolationAnalysis', () => {
5354
bounds: L.bounds([-2640403.63, 1873792.1], [3247669.39, 5921501.4])
5455
});
5556
var interpolationAnalystService = spatialAnalystService(spatialAnalystURL, options);
57+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
58+
expect(method).toBe("POST");
59+
expect(testUrl).toBe(spatialAnalystURL + "/datasets/SamplesP@Interpolation/interpolation/kriging.json?returnContent=true");
60+
var expectParams = "{'bounds':{'left':-2640403.63,'bottom':1873792.1,'right':3247669.39,'top':5921501.4,'centerLonLat':null},'searchRadius':\"0\",'zValueFieldName':\"AVG_TMP\",'zValueScale':1,'resolution':null,'filterQueryParameter':{'attributeFilter':\"\"},'outputDatasetName':\"Interpolation_UnvsKriging_lfTest\",'outputDatasourceName':\"Interpolation\",'pixelFormat':\"DOUBLE\",'dataset':\"SamplesP@Interpolation\",'inputPoints':null,'InterpolationAnalystType':\"dataset\",'clipParam':null,'type':\"UniversalKriging\",'angle':0,'nugget':0,'range':0,'sill':0,'variogramMode':\"SPHERICAL\",'searchMode':\"KDTREE_FIXED_COUNT\",'mean':null,'exponent':\"EXP1\",'expectedCount':12,'maxPointCountForInterpolation':200,'maxPointCountInNode':50}";
61+
expect(params).toBe(expectParams);
62+
expect(options).not.toBeNull();
63+
return Promise.resolve(new Response(interpolationUnvsKrigingEscapedJson));
64+
});
5665
interpolationAnalystService.interpolationAnalysis(interpolationAnalystParameters, (result) => {
5766
serviceResult = result;
5867
try {
@@ -62,7 +71,7 @@ describe('leaflet_SpatialAnalystService_interpolationAnalysis', () => {
6271
expect(serviceResult.result).not.toBeNull();
6372
expect(serviceResult.result.dataset).toContain(resultDataset);
6473
expect(serviceResult.result.dataset).toContain("@Interpolation");
65-
expect(serviceResult.result.succeed).toBe(true);
74+
expect(serviceResult.result.succeed).toBe(true);
6675
interpolationAnalystService.destroy();
6776
} catch (exception) {
6877
console.log("'leaflet_interpolationAnalystService_Kriging_Universal'案例失败" + exception.name + ":" + exception.message);
@@ -71,11 +80,4 @@ describe('leaflet_SpatialAnalystService_interpolationAnalysis', () => {
7180
}
7281
});
7382
});
74-
75-
// 删除测试过程中产生的测试数据集
76-
it('delete test resources', (done) => {
77-
var testResult = GlobeParameter.dataspatialAnalystURL + resultDataset;
78-
request.delete(testResult);
79-
done();
80-
});
8183
});

test/mapboxgl/services/AddressMatchServiceSpec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {AddressMatchService} from '../../../src/mapboxgl/services/AddressMatchService';
22
import {GeoCodingParameter} from '../../../src/common/iServer/GeoCodingParameter';
33
import {GeoDecodingParameter} from '../../../src/common/iServer/GeoDecodingParameter';
4+
import { FetchRequest } from '../../../src/common/util/FetchRequest';
45

56
var addressMatchURL = GlobeParameter.addressMatchURL;
67
describe('mapboxgl_AddressMatchService', () => {
@@ -26,6 +27,15 @@ describe('mapboxgl_AddressMatchService', () => {
2627
maxReturn: -1
2728
});
2829
var service = new AddressMatchService(addressMatchURL);
30+
31+
spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => {
32+
// expect(testUrl).toBe(addressMatchURL + "/geocoding.json?address=公司&fromIndex=0&toIndex=10&filters=[\"北京市\",\"海淀区\"]&prjCoordSys={epsgcode:4326}&maxReturn=-1");
33+
expect(testUrl).toBe(addressMatchURL + "/geocoding");
34+
expect(params).not.toBeNull();
35+
expect(options).not.toBeNull();
36+
return Promise.resolve(new Response(codeSuccessEscapedJson));
37+
});
38+
2939
service.code(geoCodingParams, (result) => {
3040
serviceResult = result;
3141
});
@@ -64,6 +74,14 @@ describe('mapboxgl_AddressMatchService', () => {
6474
geoDecodingRadius: 500
6575
});
6676
var service = new AddressMatchService(addressMatchURL);
77+
spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => {
78+
// expect(testUrl).toBe(addressMatchURL + "/geodecoding.json?x=116.31740122415627&y=39.92311315752059&fromIndex=0&toIndex=5&filters=[\"北京市\",\"海淀区\"]&prjCoordSys={epsgcode:4326}&maxReturn=-1&geoDecodingRadius=500");
79+
expect(testUrl).toBe(addressMatchURL + "/geodecoding");
80+
expect(params).not.toBeNull();
81+
expect(options).not.toBeNull();
82+
return Promise.resolve(new Response(decodeSuccessEscapedJson));
83+
});
84+
6785
service.decode(geoDecodingParams, (result) => {
6886
serviceResult = result;
6987
});
@@ -100,6 +118,12 @@ describe('mapboxgl_AddressMatchService', () => {
100118
maxReturn: -1
101119
});
102120
var service = new AddressMatchService(addressMatchURL);
121+
spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => {
122+
// expect(testUrl).toBe(addressMatchURL + "/geocoding.json?fromIndex=0&toIndex=10&filters=[\"北京市\",\"海淀区\"]&prjCoordSys={epsgcode:4326}&maxReturn=-1");
123+
expect(testUrl).toBe(addressMatchURL + "/geocoding");
124+
expect(options).not.toBeNull();
125+
return Promise.resolve(new Response(codeFailEscapedJson));
126+
});
103127
service.code(geoCodingParams, (result) => {
104128
serviceResult = result;
105129
});
@@ -132,6 +156,14 @@ describe('mapboxgl_AddressMatchService', () => {
132156
geoDecodingRadius: 500
133157
});
134158
var service = new AddressMatchService(addressMatchURL);
159+
160+
spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => {
161+
// expect(testUrl).toBe(addressMatchURL + "/geodecoding.json?fromIndex=0&toIndex=5&filters=[\"北京市\",\"海淀区\"]&prjCoordSys={epsgcode:4326}&maxReturn=-1&geoDecodingRadius=500");
162+
expect(testUrl).toBe(addressMatchURL + "/geodecoding");
163+
expect(options).not.toBeNull();
164+
return Promise.resolve(new Response(decodeFailEscapedJson));
165+
});
166+
135167
service.decode(geoDecodingParams, (result) => {
136168
serviceResult = result;
137169
});

test/mapboxgl/services/GridCellInfosServiceSpec.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import {GridCellInfosService} from '../../../src/mapboxgl/services/GridCellInfosService';
2-
import {GetGridCellInfosParameters} from '../../../src/common/iServer/GetGridCellInfosParameters';
1+
import { GridCellInfosService } from '../../../src/mapboxgl/services/GridCellInfosService';
2+
import { GetGridCellInfosParameters } from '../../../src/common/iServer/GetGridCellInfosParameters';
3+
import { FetchRequest } from '../../../src/common/util/FetchRequest';
34

45
var url = GlobeParameter.dataServiceURL;
56

@@ -24,6 +25,19 @@ describe('mapboxgl_GridCellInfosService', () => {
2425
Y: 20
2526
});
2627
var service = new GridCellInfosService(url);
28+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
29+
expect(method).toBe("GET");
30+
expect(options).not.toBeNull();
31+
if (testUrl.indexOf("WorldEarth.json") > 0) {
32+
return Promise.resolve(new Response(getDatasetInfoEcapedJson));
33+
} else {
34+
if (testUrl.indexOf("imageValue.json") > 0) {
35+
return Promise.resolve(new Response(getGridCellInfosEcapedJson));
36+
}
37+
};
38+
return null;
39+
});
40+
2741
service.getGridCellInfos(getGridCellInfosParam, (result) => {
2842
serviceResult = result
2943
});
@@ -42,6 +56,7 @@ describe('mapboxgl_GridCellInfosService', () => {
4256
expect(serviceResult.result.column).toEqual(1046);
4357
expect(serviceResult.result.row).toEqual(398);
4458
expect(serviceResult.result.value).toEqual(12295026);
59+
expect(FetchRequest.commit.calls.count()).toEqual(2);
4560
done();
4661
} catch (e) {
4762
console.log("'getGridCellInfos'案例失败" + e.name + ":" + e.message);

0 commit comments

Comments
 (0)