}
private String getAuthtenticationToken() {
String token = null;
AbiquoContext context = ContextBuilder.newBuilder(new AbiquoApiMetadata()) //
.endpoint(endpoint) //
.credentials(identity, credential) //
.modules(ImmutableSet.<Module> of(new SLF4JLoggingModule())) //
.build(AbiquoContext.class);
try {
// Create a request to authenticate to the API and generate the token
HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create(endpoint)).build();
request = request.toBuilder().replaceHeader(HttpHeaders.AUTHORIZATION, basic(identity, credential)).build();
// Execute the request and read the generated token
HttpResponse response = context.utils().http().invoke(request);
assertEquals(response.getStatusCode(), 200);
token = readAuthenticationToken(response);
assertNotNull(token);
releasePayload(response);
} finally {
if (context != null) {
context.close();
}
}
return token;
}