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.24.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wegener committed Jul 4, 2017
2 parents 513cebe + 3dda442 commit eb34d12
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.github.libgraviton</groupId>
<artifactId>worker-base</artifactId>
<packaging>jar</packaging>
<version>0.23.4</version>
<version>0.24.0</version>
<name>Graviton Worker Base Library</name>
<url>https://github.com/libgraviton/graviton-worker-base-java</url>
<inceptionYear>2015</inceptionYear>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.libgraviton.workerbase;

import com.github.libgraviton.gdk.GravitonApi;
import com.github.libgraviton.gdk.api.header.HeaderBag;
import com.github.libgraviton.gdk.util.PropertiesLoader;

import java.io.IOException;
import java.util.Properties;

/**
* Public base class for workers api calls with auth headers
*
* @author List of contributors {@literal <https://github.com/libgraviton/graviton-worker-base-java/graphs/contributors>}
* @see <a href="http://swisscom.ch">http://swisscom.ch</a>
* @version $Id: $Id
*/
public class GravitonAuthApi extends GravitonApi {

protected Properties properties;

@Override
protected HeaderBag getDefaultHeaders() {
String authHeaderValue = properties.getProperty("graviton.authentication.prefix.username")
.concat(properties.getProperty("graviton.workerId"));
String authHeaderName = properties.getProperty("graviton.authentication.header.name");

return new HeaderBag.Builder()
.set("Content-Type", "application/json")
.set("Accept", "application/json")
.set(authHeaderName, authHeaderValue)
.build();
}


// TODO remove the setup override as soon as properties is no longer private in GravitonApi
@Override
protected void setup() {
try {
this.properties = PropertiesLoader.load();
} catch (IOException e) {
throw new IllegalStateException("Unable to load properties files.", e);
}
super.setup();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,6 @@ public QueueManager getQueueManager() {
}

protected GravitonApi initGravitonApi() {
return new GravitonApi();
return new GravitonAuthApi();
}
}
6 changes: 5 additions & 1 deletion src/main/resources/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ graviton.workerId=java-test
graviton.subscription=document.core.app.*

application.version=${project.version}
application.name=${project.name}
application.name=${project.name}

# Graviton Api Subnet authentication
graviton.authentication.prefix.username=subnet-
graviton.authentication.header.name=x-graviton-authentication
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.libgraviton.workerbase;

import com.github.libgraviton.gdk.api.header.Header;
import com.github.libgraviton.gdk.api.header.HeaderBag;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class GravitonAuthApiTest {

@Test
public void testGetDefaultHeader() {
GravitonAuthApi gravitonApi = new GravitonAuthApi();
HeaderBag headers = gravitonApi.getDefaultHeaders();
assertEquals(3, headers.all().size());

Header header = headers.get("x-graviton-authentication");
assertEquals("subnet-java-test", header.get(0));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class WorkerBaseTestCase {
protected Worker worker;
protected WorkerConsumer workerConsumer;
protected Channel queueChannel;
protected GravitonApi gravitonApi;
protected GravitonAuthApi gravitonApi;
protected Response response;
protected ObjectMapper objectMapper;

Expand All @@ -42,7 +42,7 @@ public void baseMock() throws Exception {
objectMapper = new GravitonObjectMapper(properties);

response = mock(Response.class);
gravitonApi = mock(GravitonApi.class, RETURNS_DEEP_STUBS);
gravitonApi = mock(GravitonAuthApi.class, RETURNS_DEEP_STUBS);

// PUT mock
when(gravitonApi.put(any(GravitonBase.class)).execute()).thenReturn(response);
Expand Down
7 changes: 6 additions & 1 deletion src/test/resources/app.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
addition=dude
graviton.base.url=http://gravitonApi-base-url
graviton.base.url=http://gravitonApi-base-url
graviton.workerId=java-test

# Graviton Api Subnet authentication
graviton.authentication.prefix.username=subnet-
graviton.authentication.header.name=x-graviton-authentication
14 changes: 0 additions & 14 deletions src/test/resources/default.properties

This file was deleted.

0 comments on commit eb34d12

Please sign in to comment.