use of org.talend.components.jira.connection.Rest in project components by Talend.
the class JiraReaderTest method testThrowComponentExceptionWhenErrorOccurred.
@Test
public void testThrowComponentExceptionWhenErrorOccurred() throws IOException {
thrown.expect(ComponentException.class);
thrown.expectMessage("Can't get response from server, error code is 400\nSome error message");
JiraSearchReader jiraReader = new JiraSearchReader(source);
Rest rest = mock(Rest.class);
JiraResponse jr = new JiraResponse(400, "Some error message");
when(rest.get(anyString(), anyMap())).thenReturn(jr);
jiraReader.setRest(rest);
jiraReader.makeHttpRequest();
}
use of org.talend.components.jira.connection.Rest in project components by Talend.
the class JiraWriter method open.
/**
* Initializes connection of this {@link Writer}
*
* @param uId Unique ID of this {@link Writer}
*/
@Override
public void open(String uId) {
if (opened) {
LOG.debug("Writer is already opened");
return;
}
result = new Result(uId);
String hostPort = writeOperation.getSink().getHostPort();
String userId = writeOperation.getSink().getUserId();
String userPassword = writeOperation.getSink().getUserPassword();
rest = new Rest(hostPort);
rest.setCredentials(userId, userPassword);
opened = true;
}
use of org.talend.components.jira.connection.Rest in project components by Talend.
the class JiraSourceOrSink method validateConnection.
/**
* Validate connection to JIRA server.
*
* @return {@link Result#OK} if connection is valid, {@link Result#ERROR} otherwise
*/
protected ValidationResult validateConnection() {
Rest rest = new Rest(hostPort);
String errorMessage;
try {
int statusCode = rest.checkConnection();
if (statusCode == SC_OK) {
return ValidationResult.OK;
} else {
errorMessage = messages.getMessage("error.wrongStatusCode", statusCode);
LOG.debug(errorMessage);
}
} catch (IOException e) {
errorMessage = messages.getMessage("error.connectionException", e);
LOG.debug(errorMessage);
}
String validationFailed = messages.getMessage("error.hostNotValidated", hostPort);
StringBuilder sb = new StringBuilder(validationFailed);
sb.append(System.lineSeparator());
sb.append(errorMessage);
return new ValidationResult(Result.ERROR, sb.toString());
}
use of org.talend.components.jira.connection.Rest in project components by Talend.
the class JiraWriterTest method testOpen.
/**
* Checks {@link JiraWriter#open(String)} initializes connection instance
*/
@Test
public void testOpen() {
JiraWriter writer = new JiraWriter(writeOperation);
writer.open("uId");
Rest connection = writer.getConnection();
assertThat(connection, notNullValue());
}
Aggregations