use of com.openshift.restclient.IClient in project jbosstools-openshift by jbosstools.
the class OpenShiftConnectionRequirement method createConnectionWithCredentials.
private Connection createConnectionWithCredentials(String server, String username, String password) {
IClient client = createClient(server);
Connection connection = new Connection(client, null);
connection.setAuthScheme(IAuthorizationContext.AUTHSCHEME_BASIC);
connection.setUsername(username);
connection.setPassword(password);
return connection;
}
use of com.openshift.restclient.IClient in project jbosstools-openshift by jbosstools.
the class OpenShiftConnectionRequirement method createConnectionWithToken.
private Connection createConnectionWithToken(String server, String token) {
IClient client = createClient(server);
Connection connection = new Connection(client, null);
connection.setAuthScheme(IAuthorizationContext.AUTHSCHEME_OAUTH);
connection.setUsername(connection.getUsername());
connection.setToken(token);
connection.refresh();
return connection;
}
use of com.openshift.restclient.IClient in project jbosstools-openshift by jbosstools.
the class ConnectionTest method should_prompt_when_connecting_while_being_unauthorized.
@Test
public void should_prompt_when_connecting_while_being_unauthorized() throws Exception {
// given no or outdated token
IClient client = createClient("username", "token", "https://ahost");
IAuthorizationContext authorizationContext = mock(IAuthorizationContext.class);
when(client.getAuthorizationContext()).thenReturn(authorizationContext);
doThrow(UnauthorizedException.class).when(authorizationContext).isAuthorized();
testableConnection = createTestableConnection("token", client, prompter);
testableConnection.enablePromptCredentials(true);
// when
testableConnection.connect();
// then
verify(prompter).promptAndAuthenticate(eq(testableConnection), any(IAuthorizationContext.class));
}
use of com.openshift.restclient.IClient in project jbosstools-openshift by jbosstools.
the class Connection method clone.
@Override
public IConnection clone() {
IClient clone = client.clone();
Connection connection = new Connection(clone, credentialsPrompter);
connection.passwordLoaded = this.passwordLoaded;
connection.tokenLoaded = this.tokenLoaded;
connection.rememberPassword = this.rememberPassword;
connection.rememberToken = this.rememberToken;
connection.promptCredentialsEnabled = promptCredentialsEnabled;
return connection;
}
use of com.openshift.restclient.IClient in project jbosstools-openshift by jbosstools.
the class ConnectionTest method givenAResourceThatAcceptsAVisitorForIClientCapability.
@SuppressWarnings("unchecked")
private Map<String, Object> givenAResourceThatAcceptsAVisitorForIClientCapability(IClient client) {
final IClientCapability capability = mock(IClientCapability.class);
when(capability.getClient()).thenReturn(client);
IResource resource = mock(IResource.class);
when(resource.accept(any(CapabilityVisitor.class), any())).thenAnswer(new Answer<IClient>() {
@Override
public IClient answer(InvocationOnMock invocation) throws Throwable {
CapabilityVisitor<IClientCapability, IClient> visitor = (CapabilityVisitor<IClientCapability, IClient>) invocation.getArguments()[0];
return visitor.visit(capability);
}
});
Map<String, Object> mocks = new HashMap<>();
mocks.put("capability", capability);
mocks.put("resource", resource);
return mocks;
}
Aggregations