Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wegener committed Jul 7, 2017
2 parents a42d4c9 + c842329 commit eab7420
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gdk-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>com.github.libgraviton</groupId>
<artifactId>gdk</artifactId>
<version>0.3.4</version>
<version>0.4.0</version>
</parent>
<artifactId>gdk-core</artifactId>
<name>gdk-core</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public String getBaseUrl() {
*/
public Request.Builder request() {
return new Request.Builder(executor)
.setHeaders(getDefaultHeaders());
.setHeaders(getDefaultHeaders().build());
}

public Request.Builder head(String url) {
Expand Down Expand Up @@ -233,10 +233,9 @@ public ObjectMapper getObjectMapper() {
}

// TODO make it configurable
protected HeaderBag getDefaultHeaders() {
protected HeaderBag.Builder getDefaultHeaders() {
return new HeaderBag.Builder()
.set("Content-Type", "application/json")
.set("Accept", "application/json")
.build();
.set("Accept", "application/json");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ public Request.Builder getFile(String url) {
LOG.debug("Requesting file");

// without the 'Accept' - 'application/json' header, we get the file instead of the metadata
HeaderBag headers = new HeaderBag.Builder()
.set("Content-Type", "application/json")
.build();
HeaderBag.Builder headers = gravitonApi.getDefaultHeaders()
.unset("Accept");

return gravitonApi.request()
.setUrl(url)
.setHeaders(headers)
.setHeaders(headers.build())
.get();
}

Expand Down Expand Up @@ -68,20 +67,28 @@ public Request.Builder post(byte[] data, GravitonBase resource) throws Serializa
Part dataPart = new Part(data, "upload");
Part metadataPart = new Part(gravitonApi.serializeResource(resource), "metadata");

HeaderBag.Builder headers = gravitonApi.getDefaultHeaders()
.unset("Accept")
.unset("Content-Type");

return gravitonApi.request()
.setUrl(gravitonApi.getEndpointManager().getEndpoint(resource.getClass().getName()).getUrl())
.setHeaders(new HeaderBag.Builder().build())
.setHeaders(headers.build())
.post(dataPart, metadataPart);
}

public Request.Builder put(byte[] data, GravitonBase resource) throws SerializationException {
Part dataPart = new Part(data, "upload");
Part metadataPart = new Part(gravitonApi.serializeResource(resource), "metadata");

HeaderBag.Builder headers = gravitonApi.getDefaultHeaders()
.unset("Accept")
.unset("Content-Type");

return gravitonApi.request()
.setUrl(gravitonApi.getEndpointManager().getEndpoint(resource.getClass().getName()).getItemUrl())
.addParam("id", gravitonApi.extractId(resource))
.setHeaders(new HeaderBag.Builder().build())
.setHeaders(headers.build())
.put(dataPart, metadataPart);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;

/**
* This is the base class used for Graviton API calls.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.Iterator;
import java.util.Map;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public void setupService() throws Exception {
when(gravitonApi.getEndpointManager()).thenReturn(endpointManager);
when(gravitonApi.extractId(any(GravitonBase.class))).thenCallRealMethod();
when(gravitonApi.serializeResource(any(SimpleClass.class))).thenReturn("{ \"id\":\"111\"}");
HeaderBag headers = new HeaderBag.Builder()
HeaderBag.Builder headers = new HeaderBag.Builder()
.set("whatever", "something")
.build();
.set("Accept", "almost-everything");

when(gravitonApi.getDefaultHeaders()).thenReturn(headers);
resource = new SimpleClass();
Expand All @@ -56,7 +56,7 @@ public void setupService() throws Exception {
public void testGetFile() throws Exception {
Request request = gravitonFileEndpoint.getFile(url).build();
assertEquals(0, request.getHeaders().get("Accept").all().size());
assertEquals(1, request.getHeaders().get("Content-Type").all().size());
assertEquals(1, request.getHeaders().get("whatever").all().size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;

public class NoopResponseTest {
Expand Down
4 changes: 2 additions & 2 deletions gdk-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.github.libgraviton</groupId>
<artifactId>gdk</artifactId>
<version>0.3.4</version>
<version>0.4.0</version>
</parent>
<artifactId>gdk-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
Expand Down Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>com.github.libgraviton</groupId>
<artifactId>gdk-core</artifactId>
<version>0.3.4</version>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>org.jsonschema2pojo</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.libgraviton</groupId>
<artifactId>gdk</artifactId>
<version>0.3.4</version>
<version>0.4.0</version>
<packaging>pom</packaging>
<name>gdk</name>
<description>Graviton Development Kit</description>
Expand Down

0 comments on commit eab7420

Please sign in to comment.