| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file |  | 
| 2 // for details. All rights reserved. Use of this source code is governed by a |  | 
| 3 // BSD-style license that can be found in the LICENSE file. |  | 
| 4 |  | 
| 5 library shelf.pipeline_test; |  | 
| 6 |  | 
| 7 import 'package:shelf/shelf.dart'; |  | 
| 8 import 'package:unittest/unittest.dart'; |  | 
| 9 |  | 
| 10 import 'test_util.dart'; |  | 
| 11 |  | 
| 12 void main() { |  | 
| 13   test('compose middleware with Pipeline', () { |  | 
| 14     int accessLocation = 0; |  | 
| 15 |  | 
| 16     var middlewareA = createMiddleware(requestHandler: (request) { |  | 
| 17       expect(accessLocation, 0); |  | 
| 18       accessLocation = 1; |  | 
| 19       return null; |  | 
| 20     }, responseHandler: (response) { |  | 
| 21       expect(accessLocation, 4); |  | 
| 22       accessLocation = 5; |  | 
| 23       return response; |  | 
| 24     }); |  | 
| 25 |  | 
| 26     var middlewareB = createMiddleware(requestHandler: (request) { |  | 
| 27       expect(accessLocation, 1); |  | 
| 28       accessLocation = 2; |  | 
| 29       return null; |  | 
| 30     }, responseHandler: (response) { |  | 
| 31       expect(accessLocation, 3); |  | 
| 32       accessLocation = 4; |  | 
| 33       return response; |  | 
| 34     }); |  | 
| 35 |  | 
| 36     var handler = const Pipeline() |  | 
| 37         .addMiddleware(middlewareA) |  | 
| 38         .addMiddleware(middlewareB) |  | 
| 39         .addHandler((request) { |  | 
| 40       expect(accessLocation, 2); |  | 
| 41       accessLocation = 3; |  | 
| 42       return syncHandler(request); |  | 
| 43     }); |  | 
| 44 |  | 
| 45     return makeSimpleRequest(handler).then((response) { |  | 
| 46       expect(response, isNotNull); |  | 
| 47       expect(accessLocation, 5); |  | 
| 48     }); |  | 
| 49   }); |  | 
| 50 |  | 
| 51   test('Pipeline can be used as middleware', () { |  | 
| 52     int accessLocation = 0; |  | 
| 53 |  | 
| 54     var middlewareA = createMiddleware(requestHandler: (request) { |  | 
| 55       expect(accessLocation, 0); |  | 
| 56       accessLocation = 1; |  | 
| 57       return null; |  | 
| 58     }, responseHandler: (response) { |  | 
| 59       expect(accessLocation, 4); |  | 
| 60       accessLocation = 5; |  | 
| 61       return response; |  | 
| 62     }); |  | 
| 63 |  | 
| 64     var middlewareB = createMiddleware(requestHandler: (request) { |  | 
| 65       expect(accessLocation, 1); |  | 
| 66       accessLocation = 2; |  | 
| 67       return null; |  | 
| 68     }, responseHandler: (response) { |  | 
| 69       expect(accessLocation, 3); |  | 
| 70       accessLocation = 4; |  | 
| 71       return response; |  | 
| 72     }); |  | 
| 73 |  | 
| 74     var innerPipeline = const Pipeline() |  | 
| 75         .addMiddleware(middlewareA) |  | 
| 76         .addMiddleware(middlewareB); |  | 
| 77 |  | 
| 78     var handler = const Pipeline() |  | 
| 79         .addMiddleware(innerPipeline.middleware) |  | 
| 80         .addHandler((request) { |  | 
| 81       expect(accessLocation, 2); |  | 
| 82       accessLocation = 3; |  | 
| 83       return syncHandler(request); |  | 
| 84     }); |  | 
| 85 |  | 
| 86     return makeSimpleRequest(handler).then((response) { |  | 
| 87       expect(response, isNotNull); |  | 
| 88       expect(accessLocation, 5); |  | 
| 89     }); |  | 
| 90   }); |  | 
| 91 } |  | 
| OLD | NEW | 
|---|