Search in sources :

Example 1 with Rest

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();
}
Also used : Rest(org.talend.components.jira.connection.Rest) JiraResponse(org.talend.components.jira.connection.JiraResponse) Test(org.junit.Test)

Example 2 with Rest

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;
}
Also used : Rest(org.talend.components.jira.connection.Rest) Result(org.talend.components.api.component.runtime.Result)

Example 3 with Rest

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());
}
Also used : Rest(org.talend.components.jira.connection.Rest) IOException(java.io.IOException) ValidationResult(org.talend.daikon.properties.ValidationResult)

Example 4 with Rest

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());
}
Also used : Rest(org.talend.components.jira.connection.Rest) Test(org.junit.Test)

Aggregations

Rest (org.talend.components.jira.connection.Rest)4 Test (org.junit.Test)2 IOException (java.io.IOException)1 Result (org.talend.components.api.component.runtime.Result)1 JiraResponse (org.talend.components.jira.connection.JiraResponse)1 ValidationResult (org.talend.daikon.properties.ValidationResult)1