Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/e2e integration tests #31

Merged
merged 34 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
09f4cff
Merge pull request #17 from jpmorganchase/main
knighto82 Apr 4, 2023
5582e23
Incremented version to 0.03-SNAPSHOT
knighto82 Apr 4, 2023
2f944fe
feature/update usage examples (#30)
knighto82 Apr 6, 2023
205848b
Initial play with pact for contract testing
knighto82 Apr 6, 2023
e46eef3
Added PACT consumer tests
knighto82 Apr 20, 2023
c95755d
Update build-on-push.yml
knighto82 Apr 20, 2023
c43fffa
Update build-on-push.yml
knighto82 Apr 20, 2023
24037b1
Changed home of PACT tests
knighto82 Apr 20, 2023
43a8b5b
Merge branch 'feature/e2e-integration-tests' of github.com:jpmorganch…
knighto82 Apr 20, 2023
5c067d8
Additional Logging
knighto82 Apr 20, 2023
65b2cb2
Updated logging
knighto82 Apr 20, 2023
9d3d27c
Updated Logging
knighto82 Apr 20, 2023
3755079
spotless
knighto82 Apr 20, 2023
549f652
Log level to DEBUG
knighto82 Apr 20, 2023
cf3de6e
Remove verification of User-Agent header in PACT
knighto82 Apr 20, 2023
bee3e1c
spotless
knighto82 Apr 20, 2023
f1224b3
Tidy up following github failing build
knighto82 Apr 24, 2023
9213ffc
Update Consumer Tests for FusionApi
knighto82 Apr 24, 2023
a50fe63
Updating PACT tests to align to provider
knighto82 May 1, 2023
3d1e11c
Updating PACT tests to align to provider
knighto82 May 1, 2023
8f55772
spotless corrections
knighto82 May 1, 2023
e43543d
Updated provider and consumer ids
knighto82 May 1, 2023
2e6f00f
Updated PACT Samples
knighto82 May 1, 2023
ee3e2f6
Added some negative test cases for PACT
knighto82 May 1, 2023
61d0d83
spotless adjustments
knighto82 May 1, 2023
0f0a0f5
Update 110274-fusionsdk-consumer-110274-fusionapi-provider.json
knighto82 May 1, 2023
4173923
Further PACT tweaks
knighto82 May 1, 2023
b79ea5b
Tweaks as per provider integration of PACT
knighto82 May 2, 2023
f67e36e
Corrected failing test
knighto82 May 2, 2023
27f7c56
Update 110274-fusionsdk-consumer-110274-fusionapi-provider.json
knighto82 May 2, 2023
028e099
Removing redundant e2e tests
knighto82 May 2, 2023
2b62dad
simplified the provision of dataset tokens at construction
knighto82 May 4, 2023
2e32d12
changes as per pr review
knighto82 May 4, 2023
4fb2319
spotless ....
knighto82 May 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
architecture: x64
cache: maven
- name: Build with Maven
run: mvn --batch-mode --update-snapshots package
run: mvn --batch-mode --update-snapshots package
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
**/localAuthCredential.json
**/client_credentials.json
.vscode
.DS_Store
50 changes: 41 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The Fusion SDK is published to Maven Central and can be retrieved from there usi
<dependency>
<groupId>io.github.jpmorganchase.fusion</groupId>
<artifactId>fusion-sdk</artifactId>
<version>0.0.2</version>
<version>0.0.3</version>
</dependency>
```

Expand All @@ -38,8 +38,11 @@ Once you have the dependency added to your project and imports configured, you w

##### With an OAUth client ID and secret


https://github.com/jpmorganchase/fusion-java-sdk/blob/3300f986bb55bf70ed0e36953c9834b8caa9960d/src/test/java/io/github/jpmorganchase/fusion/example/FusionInstanceCreationExamples.java#L35-L37
```java
Fusion fusion = Fusion.builder()
.secretBasedCredentials(CLIENT_ID, CLIENT_SECRET, RESOURCE, AUTH_SERVER_URL)
.build();
```

This will configure the SDK to retrieve a bearer token from an OAuth server using the supplied parameters:

Expand All @@ -52,7 +55,9 @@ When configured in this way, the SDK will retrieve the token from the OAuth serv

##### Loading the OAuth configuration from a file

https://github.com/jpmorganchase/fusion-java-sdk/blob/3300f986bb55bf70ed0e36953c9834b8caa9960d/src/test/java/io/github/jpmorganchase/fusion/example/FusionInstanceCreationExamples.java#L43-L45
```java
Fusion fusion = Fusion.builder().credentialFile(CREDENTIAL_FILE_PATH).build();
```

This will configure the SDK to retrieve a bearer token from an OAuth server using configuration details stored in a file at the supplied path _CREDENTIAL_FILE_PATH_

Expand All @@ -79,7 +84,9 @@ Similar to the above option, this will configure the SDK to manage the tokens on

##### With a pre-existing bearer token

https://github.com/jpmorganchase/fusion-java-sdk/blob/3300f986bb55bf70ed0e36953c9834b8caa9960d/src/test/java/io/github/jpmorganchase/fusion/example/FusionInstanceCreationExamples.java#L28-L30
```java
Fusion fusion = Fusion.builder().bearerToken(BEARER_TOKEN).build();
```

Here _BEARER_TOKEN_ is the String value of a bearer token you have retrieved which provides access to the Fusion API. You can use this mechanism in cases where you already have a means to retrieve the token and would prefer to manage that within your application than having the SDK manage that on your behalf.

Expand All @@ -89,11 +96,36 @@ Note than when your token has expired, you will need to pass a new token to the

Once you have initialised the Fusion object, you can interact with it to retrieve metadata or download distribution files for any datasets that you need.

Examples (to follow):
##### Examples:

1. Download some metadata
2. Download as a file
3. Download as a stream
1. List catalogs
```java
Map<String, Catalog> catalogs = fusion.listCatalogs();
```
2. List datasets
```java
Map<String, Dataset> datasets = fusion.listDatasets("my-catalog");
```
3. Download some dataset metadata
```java
Map<String, Attribute> attributes = fusion.listAttributes("my-catalog", "my-dataset");
```
4. List the series members available in the dataset
```java
Map<String, DatasetSeries> members = fusion.listDatasetMembers("my-catalog", "my-dataset");
```
5. List the distributions available in the dataset member
```java
Map<String, Distribution> distributions = fusion.listDistributions("my-catalog", "my-dataset", "my-series-member");
```
6. Download as a file
```java
fusion.download("my-catalog", "my-dataset", "my-series-member", "csv", "/downloads/distributions");
```
7. Download as a stream
```java
InputStream is = fusion.downloadStream("my-catalog", "my-dataset", "my-series-member", "csv");
```

#### Logging

Expand Down
24 changes: 23 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>io.github.jpmorganchase.fusion</groupId>
<artifactId>fusion-sdk</artifactId>
<packaging>jar</packaging>
<version>0.0.2</version>
<version>0.0.3-SNAPSHOT</version>

<name>fusion-sdk</name>
<description>A Java SDK for the Fusion platform API</description>
Expand Down Expand Up @@ -121,6 +121,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>au.com.dius.pact.consumer</groupId>
<artifactId>junit5</artifactId>
<version>4.1.41</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -289,6 +296,21 @@
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>pact</classifier>
<classesDirectory>${project.build.directory}/pacts</classesDirectory>
<includes>
<include>**/*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down

This file was deleted.

30 changes: 0 additions & 30 deletions src/it/resources/e2e-responses/catalog-success-response.json

This file was deleted.

20 changes: 18 additions & 2 deletions src/main/java/io/github/jpmorganchase/fusion/Fusion.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
import io.github.jpmorganchase.fusion.model.*;
import io.github.jpmorganchase.fusion.oauth.credential.*;
import io.github.jpmorganchase.fusion.oauth.exception.OAuthException;
import io.github.jpmorganchase.fusion.oauth.model.BearerToken;
import io.github.jpmorganchase.fusion.oauth.provider.DatasetTokenProvider;
import io.github.jpmorganchase.fusion.oauth.provider.OAuthDatasetTokenProvider;
import io.github.jpmorganchase.fusion.oauth.provider.OAuthSessionTokenProvider;
import io.github.jpmorganchase.fusion.oauth.provider.SimpleDatasetTokenProvider;
import io.github.jpmorganchase.fusion.parsing.APIResponseParser;
import io.github.jpmorganchase.fusion.parsing.GsonAPIResponseParser;
import io.github.jpmorganchase.fusion.parsing.ParsingException;
Expand All @@ -29,6 +32,7 @@
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.AccessLevel;
Expand Down Expand Up @@ -566,6 +570,9 @@ public static class FusionBuilder {
protected String credentialFile;
protected String rootURL;
protected APIManager api;
protected Map<String, BearerToken> datasetBearerTokens = new HashMap<>();

protected DatasetTokenProvider datasetTokenProvider;

public FusionBuilder bearerToken(String token) {
this.credentials = new BearerTokenCredentials(token);
Expand Down Expand Up @@ -603,6 +610,11 @@ public FusionBuilder rootURL(String rootURL) {
this.rootURL = rootURL;
return this;
}

public FusionBuilder datasetBearerToken(String catalog, String dataset, String token) {
knighto82 marked this conversation as resolved.
Show resolved Hide resolved
datasetBearerTokens.put(String.format("%s_%s", catalog, dataset), BearerToken.of(token));
return this;
}
}

private static class CustomFusionBuilder extends FusionBuilder {
Expand Down Expand Up @@ -646,8 +658,12 @@ public Fusion build() {

// TODO : Make this part of the builder journey
OAuthSessionTokenProvider sessionTokenProvider = new OAuthSessionTokenProvider(credentials, client);
OAuthDatasetTokenProvider datasetTokenProvider =
new OAuthDatasetTokenProvider(rootURL, sessionTokenProvider, client);
if (datasetBearerTokens.isEmpty()) {
datasetTokenProvider = new OAuthDatasetTokenProvider(rootURL, sessionTokenProvider, client);
} else {
datasetTokenProvider = new SimpleDatasetTokenProvider(datasetBearerTokens);
}

DigestProducer digestProducer =
AlgoSpecificDigestProducer.builder().sha256().build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ public class OAuthException extends RuntimeException {

private final String response;

public OAuthException(String message) {
super(message);
this.response = message;
}

public OAuthException(String message, String response) {
super(message);
this.response = response;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.jpmorganchase.fusion.oauth.provider;

import io.github.jpmorganchase.fusion.oauth.exception.OAuthException;
import io.github.jpmorganchase.fusion.oauth.model.BearerToken;
import java.util.Map;

public class SimpleDatasetTokenProvider implements DatasetTokenProvider {

private static final String BEARER_TOKEN_NOT_FOUND_ERROR = "Bearer token not found for catalog %s and dataset %s";

private final Map<String, BearerToken> datasetTokens;

public SimpleDatasetTokenProvider(Map<String, BearerToken> datasetTokens) {
this.datasetTokens = datasetTokens;
}

@Override
public String getDatasetBearerToken(String catalog, String dataset) {

String tokenKey = String.format("%s_%s", catalog, dataset);
if (datasetTokens.containsKey(tokenKey)) {
return datasetTokens.get(tokenKey).getToken();
}

throw new OAuthException(String.format(BEARER_TOKEN_NOT_FOUND_ERROR, catalog, dataset));
}
}

This file was deleted.

Loading