Search in sources :

Example 1 with JsonClient

use of net.nemerosa.ontrack.client.JsonClient in project ontrack by nemerosa.

the class DefaultJenkinsClientTest method before.

@Before
public void before() {
    OTHttpClient httpClient = mock(OTHttpClient.class);
    when(httpClient.getUrl(anyString(), any(String[].class))).thenAnswer(invocation -> {
        String path = (String) invocation.getArguments()[0];
        String parameters = (String) invocation.getArguments()[1];
        return String.format("http://jenkins/%s", String.format(path, parameters));
    });
    JsonClient jsonClient = new JsonClientImpl(httpClient);
    jenkinsClient = new DefaultJenkinsClient(jsonClient);
}
Also used : JsonClient(net.nemerosa.ontrack.client.JsonClient) JsonClientImpl(net.nemerosa.ontrack.client.JsonClientImpl) OTHttpClient(net.nemerosa.ontrack.client.OTHttpClient) Matchers.anyString(org.mockito.Matchers.anyString) Before(org.junit.Before)

Example 2 with JsonClient

use of net.nemerosa.ontrack.client.JsonClient in project ontrack by nemerosa.

the class JIRASessionFactoryImpl method create.

@Override
public JIRASession create(JIRAConfiguration configuration) {
    // Creates a HTTP JSON client
    JsonClient jsonClient = clientFactory.getJsonClient(new ClientConnection(configuration.getUrl(), configuration.getUser(), configuration.getPassword()));
    // Creates the client
    JIRAClient client = new JIRAClientImpl(jsonClient);
    // Creates the session
    return new JIRASession() {

        @Override
        public JIRAClient getClient() {
            return client;
        }

        @Override
        public void close() {
            client.close();
        }
    };
}
Also used : JIRAClient(net.nemerosa.ontrack.extension.jira.client.JIRAClient) JsonClient(net.nemerosa.ontrack.client.JsonClient) ClientConnection(net.nemerosa.ontrack.extension.support.client.ClientConnection) JIRAClientImpl(net.nemerosa.ontrack.extension.jira.client.JIRAClientImpl)

Example 3 with JsonClient

use of net.nemerosa.ontrack.client.JsonClient in project ontrack by nemerosa.

the class ArtifactoryClientImplTest method buildNumbersEmptyForBuildNotFound.

@Test
public void buildNumbersEmptyForBuildNotFound() {
    JsonClient jsonClient = mock(JsonClient.class);
    when(jsonClient.get("/api/build/%s", "PROJECT")).thenThrow(new ClientNotFoundException("Not found"));
    ArtifactoryClientImpl client = new ArtifactoryClientImpl(jsonClient);
    assertEquals(Collections.<String>emptyList(), client.getBuildNumbers("PROJECT"));
}
Also used : JsonClient(net.nemerosa.ontrack.client.JsonClient) ClientNotFoundException(net.nemerosa.ontrack.client.ClientNotFoundException) ArtifactoryClientImpl(net.nemerosa.ontrack.extension.artifactory.client.ArtifactoryClientImpl) Test(org.junit.Test)

Example 4 with JsonClient

use of net.nemerosa.ontrack.client.JsonClient in project ontrack by nemerosa.

the class ArtifactoryClientImplTest method buildNumbers.

@Test
public void buildNumbers() {
    JsonClient jsonClient = mock(JsonClient.class);
    when(jsonClient.get("/api/build/%s", "PROJECT")).thenReturn(object().with("buildsNumbers", array().with(object().with("uri", "/1").end()).with(object().with("uri", "/2").end()).end()).end());
    ArtifactoryClientImpl client = new ArtifactoryClientImpl(jsonClient);
    assertEquals(Arrays.asList("1", "2"), client.getBuildNumbers("PROJECT"));
}
Also used : JsonClient(net.nemerosa.ontrack.client.JsonClient) ArtifactoryClientImpl(net.nemerosa.ontrack.extension.artifactory.client.ArtifactoryClientImpl) Test(org.junit.Test)

Aggregations

JsonClient (net.nemerosa.ontrack.client.JsonClient)4 ArtifactoryClientImpl (net.nemerosa.ontrack.extension.artifactory.client.ArtifactoryClientImpl)2 Test (org.junit.Test)2 ClientNotFoundException (net.nemerosa.ontrack.client.ClientNotFoundException)1 JsonClientImpl (net.nemerosa.ontrack.client.JsonClientImpl)1 OTHttpClient (net.nemerosa.ontrack.client.OTHttpClient)1 JIRAClient (net.nemerosa.ontrack.extension.jira.client.JIRAClient)1 JIRAClientImpl (net.nemerosa.ontrack.extension.jira.client.JIRAClientImpl)1 ClientConnection (net.nemerosa.ontrack.extension.support.client.ClientConnection)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1