Skip to content

Commit

Permalink
Convert champion and hi pri tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-zhu committed Jun 11, 2019
1 parent 464b857 commit 13e380b
Show file tree
Hide file tree
Showing 3 changed files with 439 additions and 86 deletions.
200 changes: 116 additions & 84 deletions storage/client/src/test/java/com/azure/storage/blob/APISpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ class APISpec extends Specification {
/*
URLs to various kinds of accounts.
*/
@Shared
static BlobServiceClient primaryServiceURL
BlobServiceClient primaryServiceURL

@Shared
static BlobServiceClient alternateServiceURL
Expand Down Expand Up @@ -199,7 +198,7 @@ class APISpec extends Specification {
return HttpClient.createDefault().proxy(new Supplier<ProxyOptions>() {
@Override
ProxyOptions get() {
return new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("localhost", 8888))
return new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("localhost", 57865))
}
})
} else return HttpClient.createDefault()
Expand All @@ -226,7 +225,7 @@ class APISpec extends Specification {
new ListContainersOptions().withPrefix(containerPrefix))) {
ContainerClient containerURL = serviceURL.createContainerClient(c.name())
if (c.properties().leaseState().equals(LeaseStateType.LEASED)) {
containerURL.breakLease(0, null, null).blockingGet()
containerURL.breakLease(0, null, null)
}
containerURL.delete()
}
Expand Down Expand Up @@ -263,7 +262,6 @@ class APISpec extends Specification {
We'll let primary creds throw and crash if there are no credentials specified because everything else will fail.
*/
primaryCreds = getGenericCreds("PRIMARY_STORAGE_")
primaryServiceURL = getGenericServiceURL(primaryCreds)

/*
It's feasible someone wants to test a specific subset of tests, so we'll still attempt to create each of the
Expand Down Expand Up @@ -296,7 +294,10 @@ class APISpec extends Specification {

def setup() {
Assume.assumeTrue("The test only runs in Live mode.", getTestMode().equalsIgnoreCase(RECORD_MODE))
cu = primaryServiceURL.createContainerClient(generateContainerName())
String containerName = generateContainerName()

primaryServiceURL = getGenericServiceURL(primaryCreds)
cu = primaryServiceURL.createContainerClient(containerName)
cu.create()
}

Expand Down Expand Up @@ -452,90 +453,121 @@ class APISpec extends Specification {
to play too nicely with mocked objects and the complex reflection stuff on both ends made it more difficult to work
with than was worth it.
*/
def getStubResponse(int code, Class responseHeadersType) {
return new HttpResponse() {

@Override
int statusCode() {
return code
}

@Override
String headerValue(String s) {
return null
}

@Override
HttpHeaders headers() {
return new HttpHeaders()
}

@Override
Flux<ByteBuffer> body() {
return Flowable.empty()
}

@Override
Mono<byte[]> bodyAsByteArray() {
return null
}

@Override
Mono<String> bodyAsString() {
return null
}

@Override
Mono<String> bodyAsString(Charset charset) {
return null
}
}
}
// def getStubResponse(int code, Class responseHeadersType) {
// return new HttpResponse() {
//
// @Override
// int statusCode() {
// return code
// }
//
// @Override
// String headerValue(String s) {
// return null
// }
//
// @Override
// HttpHeaders headers() {
// return new HttpHeaders()
// }
//
// @Override
// Flux<ByteBuffer> body() {
// return Flowable.empty()
// }
//
// @Override
// Mono<byte[]> bodyAsByteArray() {
// return null
// }
//
// @Override
// Mono<String> bodyAsString() {
// return null
// }
//
// @Override
// Mono<String> bodyAsString(Charset charset) {
// return null
// }
//
// @Override
// Object deserializedHeaders() {
// def headers = responseHeadersType.getConstructor().newInstance()
//
// // If the headers have an etag method, we need to set it to prevent postProcessResponse from breaking.
// try {
// headers.getClass().getMethod("withETag", String.class).invoke(headers, "etag");
// }
// catch (NoSuchMethodException e) {
// // No op
// }
// return headers
// }
//
// @Override
// boolean isDecoded() {
// return true
// }
// }
// }

/*
This is for stubbing responses that will actually go through the pipeline and autorest code. Autorest does not seem
to play too nicely with mocked objects and the complex reflection stuff on both ends made it more difficult to work
with than was worth it. Because this type is just for BlobDownload, we don't need to accept a header type.
*/
def getStubResponseForBlobDownload(int code, Flux<ByteBuffer> body, String etag) {
return new HttpResponse() {

@Override
int statusCode() {
return code
}

@Override
String headerValue(String s) {
return null
}

@Override
HttpHeaders headers() {
return new HttpHeaders()
}

@Override
Flux<ByteBuffer> body() {
return body
}

@Override
Mono<byte[]> bodyAsByteArray() {
return null
}

@Override
Mono<String> bodyAsString() {
return null
}

@Override
Mono<String> bodyAsString(Charset charset) {
return null
}
}
}
// def getStubResponseForBlobDownload(int code, Flux<ByteBuffer> body, String etag) {
// return new HttpResponse() {
//
// @Override
// int statusCode() {
// return code
// }
//
// @Override
// String headerValue(String s) {
// return null
// }
//
// @Override
// HttpHeaders headers() {
// return new HttpHeaders()
// }
//
// @Override
// Flux<ByteBuffer> body() {
// return body
// }
//
// @Override
// Mono<byte[]> bodyAsByteArray() {
// return null
// }
//
// @Override
// Mono<String> bodyAsString() {
// return null
// }
//
// @Override
// Mono<String> bodyAsString(Charset charset) {
// return null
// }
//
// @Override
// Object deserializedHeaders() {
// def headers = new BlobDownloadHeaders()
// headers.withETag(etag)
// return headers
// }
//
// @Override
// boolean isDecoded() {
// return true
// }
// }
// }

def getContextStubPolicy(int successCode, Class responseHeadersType) {
return Mock(HttpPipelinePolicy) {
Expand Down
Loading

0 comments on commit 13e380b

Please sign in to comment.