Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .codegenignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/src/test/java/com/akoya/ddp/sandboxproducts/auth_tests/**
/src/test/java/com/akoya/ddp/sandboxproducts/endpoint_tests/**
.gitignore
.github/**
51 changes: 51 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Endpoints Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
run-tests:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "17"
- name: Create .env file
run: |
echo "OAUTH_CLIENT_ID=${{ secrets.OAUTH_CLIENT_ID }}" >> .env
echo "OAUTH_CLIENT_SECRET=${{ secrets.OAUTH_CLIENT_SECRET }}" >> .env
echo "OAUTH_REDIRECT_URI=${{ secrets.OAUTH_REDIRECT_URI }}" >> .env
echo "ENVIRONMENT=${{ secrets.ENVIRONMENT }}" >> .env
echo "TEST_USERNAME=${{ secrets.TEST_USERNAME }}" >> .env
echo "TEST_PASSWORD=${{ secrets.TEST_PASSWORD }}" >> .env
echo "TAX_USERNAME=${{ secrets.TAX_USERNAME }}" >> .env
echo "TAX_PASSWORD=${{ secrets.TAX_PASSWORD }}" >> .env
echo "CONNECTOR=${{ secrets.CONNECTOR }}" >> .env
echo "STATE=${{ secrets.STATE }}" >> .env
echo "RETURN_URL=${{ secrets.RETURN_URL }}" >> .env
echo "AKOYA_PROVIDER_ID=${{ secrets.AKOYA_PROVIDER_ID }}" >> .env
echo "AKOYA_API_VERSION=${{ secrets.AKOYA_API_VERSION }}" >> .env
echo "STATEMENT_ACCOUNT_ID=${{ secrets.STATEMENT_ACCOUNT_ID }}" >> .env
echo "TAXLOT_ACCOUNT_ID=${{ secrets.TAXLOT_ACCOUNT_ID }}" >> .env
echo "HOLDING_ID=${{ secrets.HOLDING_ID }}" >> .env
echo "STATEMENT_ID=${{ secrets.STATEMENT_ID }}" >> .env
- name: Add test dependencies to pom.xml
run: |
sed -i '/<dependencies>/a <dependency><groupId>io.github.cdimascio</groupId><artifactId>dotenv-java</artifactId><version>3.0.0</version></dependency>' pom.xml
sed -i '/<dependencies>/a <dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>test</scope></dependency>' pom.xml
sed -i '/<dependencies>/a <dependency><groupId>com.microsoft.playwright</groupId><artifactId>playwright</artifactId><version>1.53.0</version></dependency>' pom.xml
sed -i '/<plugins>/a <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.10.1</version><!-- References to interface static methods are allowed only at source level 1.8 or above --><configuration><source>1.8</source><target>1.8</target></configuration></plugin>' pom.xml
sed -i '/<plugins>/a <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.3.1</version> <configuration> <!-- Add any specific configuration for Surefire here --> </configuration> </plugin>' pom.xml
- name: Build & Install
run: mvn -B install -D skipTests --no-transfer-progress
- name: Install Playwright
run: mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install --with-deps"
- name: Run Auth tests
run: mvn test -Dtest=**/com/akoya/ddp/sandboxproducts/auth_tests/**/*
- name: Run Endpoints tests
run: mvn test -Dtest=**/com/akoya/ddp/sandboxproducts/endpoint_tests/**/*
91 changes: 91 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
##############################
## Java
##############################
.mtj.tmp/
*.class
*.jar
*.war
*.ear
*.nar
hs_err_pid*
replay_pid*

##############################
## Maven
##############################
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
pom.xml.bak
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

##############################
## Gradle
##############################
bin/
build/
.gradle
.gradletasknamecache
gradle-app.setting
!gradle-wrapper.jar

##############################
## IntelliJ
##############################
out/
.idea/
.idea_modules/
*.iml
*.ipr
*.iws

##############################
## Eclipse
##############################
.settings/
bin/
tmp/
.metadata
.classpath
.project
*.tmp
*.bak
*.swp
*~.nib
local.properties
.loadpath
.factorypath

##############################
## NetBeans
##############################
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml

##############################
## Visual Studio Code
##############################
.vscode/
.code-workspace

##############################
## OS X
##############################
.DS_Store

##############################
## Miscellaneous
##############################
*.log
.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
package com.akoya.ddp.sandboxproducts.auth_tests;

import com.akoya.ddp.sandboxproducts.AkoyaApIsV240Client;
import com.akoya.ddp.sandboxproducts.apis.AccountinformationApi;
import com.akoya.ddp.sandboxproducts.exceptions.ApiException;
import com.akoya.ddp.sandboxproducts.exceptions.ErrorErrorException;
import com.akoya.ddp.sandboxproducts.endpoint_tests.ControllerTestBase;
import org.junit.Test;
import static org.junit.Assert.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.microsoft.playwright.*;
import org.junit.Before;
import org.junit.After;
import com.akoya.ddp.sandboxproducts.models.OauthToken;

public class TestErrorScenarios extends ControllerTestBase {
private Playwright playwright;
private Browser browser;
private BrowserContext context;
private Page page;

@Before
public void setUp() throws Exception {
// Load properties from environment (for things like apiVersion, providerId, etc.)
// But do NOT run consent flow with env credentials
java.lang.reflect.Method loadProperties = ControllerTestBase.class.getDeclaredMethod("loadProperties");
loadProperties.setAccessible(true);
loadProperties.invoke(this);

// Initialize Playwright
playwright = Playwright.create();
browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(true));
context = browser.newContext();
page = context.newPage();
// Do NOT initialize client here
}

@After
public void tearDown() {
if (page != null) page.close();
if (context != null) context.close();
if (browser != null) browser.close();
if (playwright != null) playwright.close();
}

@Override
public AkoyaApIsV240Client getAkoyaClientWithConsent(String username, String password) throws Exception {
// Use the Playwright/page instance from this class
AkoyaApIsV240Client tempClient = new AkoyaApIsV240Client.Builder()
.loggingConfig(builder -> builder
.level(org.slf4j.event.Level.DEBUG)
.requestConfig(logConfigBuilder -> logConfigBuilder.body(true))
.responseConfig(logConfigBuilder -> logConfigBuilder.headers(true)))
.httpClientConfig(configBuilder -> configBuilder.timeout(0))
.authorizationCodeAuth(new com.akoya.ddp.sandboxproducts.authentication.AuthorizationCodeAuthModel.Builder(
oauthClientId,
oauthClientSecret,
oauthRedirectUri
)
.build())
.environment(com.akoya.ddp.sandboxproducts.Environment.SANDBOX)
.build();

String authUrl = tempClient.getAuthorizationCodeAuth().buildAuthorizationUrl(connector, state);
try {
page.navigate(authUrl);
page.locator("input[type=\"text\"]").fill(username);
page.locator("input[type=\"password\"]").fill(password);
page.getByRole(com.microsoft.playwright.options.AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Sign in →")).click();
page.getByRole(com.microsoft.playwright.options.AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Next")).click();
Locator checkboxes = page.locator("input[type=\"checkbox\"][name=\"account\"]");
int count = checkboxes.count();
for (int i = 0; i < count; i++) {
checkboxes.nth(i).check(new Locator.CheckOptions().setForce(true));
}
page.getByRole(com.microsoft.playwright.options.AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Approve")).click();
page.waitForURL(url -> url.startsWith(returnUrl));
String currentUrl = page.url();
String code = currentUrl.split("code=")[1].split("&")[0];
OauthToken token = tempClient.getAuthorizationCodeAuth().fetchToken(code);
if (token == null) {
throw new RuntimeException("Failed to obtain OAuth token");
}
token = token.toBuilder().tokenType("SandboxToken").build();
return tempClient.newBuilder()
.authorizationCodeAuth(tempClient.getAuthorizationCodeAuthModel().toBuilder()
.oauthToken(token)
.build())
.build();
} catch (Exception e) {
page.screenshot(new Page.ScreenshotOptions().setPath(java.nio.file.Paths.get("consent_flow_failure.png")));
throw new RuntimeException("Consent flow failed: " + e.getMessage(), e);
}
}

private AccountinformationApi getApiWithUser(String username, String password) throws Exception {
// Use the consent flow in ControllerTestBase to get a client for the given user
return getAkoyaClientWithConsent(username, password).getAccountinformationApi();
}

@Test
public void testMikomo500InternalServerError() throws Exception {
try {
AccountinformationApi api = getApiWithUser("mikomo_500", "mikomo_500");
api.getAccountsInfo(apiVersion, providerId, null, null);
fail("ApiException was not raised");
} catch (ErrorErrorException e) {
assertEquals(Integer.valueOf(e.getCode()), Integer.valueOf(500));
}
}

@Test
public void testMikomo501SubsystemUnavailable() throws Exception {
try {
AccountinformationApi api = getApiWithUser("mikomo_501", "mikomo_501");
api.getAccountsInfo(apiVersion, providerId, null, null);
fail("ApiException was not raised");
} catch (ErrorErrorException e) {
assertEquals(Integer.valueOf(e.getCode()), Integer.valueOf(501));
}
}

@Test
public void testMikomo601CustomerNotFound() throws Exception {
try {
AccountinformationApi api = getApiWithUser("mikomo_601", "mikomo_601");
api.getAccountsInfo(apiVersion, providerId, null, null);
fail("ApiException was not raised");
} catch (ErrorErrorException e) {
assertEquals(Integer.valueOf(e.getCode()), Integer.valueOf(601));
}
}

@Test
public void testMikomo602CustomerNotAuthorized() throws Exception {
try {
AccountinformationApi api = getApiWithUser("mikomo_602", "mikomo_602");
api.getAccountsInfo(apiVersion, providerId, null, null);
fail("ApiException was not raised");
} catch (ErrorErrorException e) {
assertEquals(Integer.valueOf(e.getCode()), Integer.valueOf(602));
}
}

@Test
public void testMikomo701AccountNotFound() throws Exception {
try {
AccountinformationApi api = getApiWithUser("mikomo_701", "mikomo_701");
api.getAccountsInfo(apiVersion, providerId, null, null);
fail("ApiException was not raised");
} catch (ErrorErrorException e) {
assertEquals(Integer.valueOf(e.getCode()), Integer.valueOf(701));
}
}

@Test
public void testMikomo702InvalidStartOrEndDate() throws Exception {
try {
AccountinformationApi api = getApiWithUser("mikomo_702", "mikomo_702");
api.getAccountsInfo(apiVersion, providerId, null, null);
fail("ApiException was not raised");
} catch (ErrorErrorException e) {
assertEquals(Integer.valueOf(e.getCode()), Integer.valueOf(702));
}
}

@Test
public void testMikomo703InvalidDateRange() throws Exception {
try {
AccountinformationApi api = getApiWithUser("mikomo_703", "mikomo_703");
api.getAccountsInfo(apiVersion, providerId, null, null);
fail("ApiException was not raised");
} catch (ErrorErrorException e) {
assertEquals(Integer.valueOf(e.getCode()), Integer.valueOf(703));
}
}

@Test
public void testMikomo704AccountTypeNotSupported() throws Exception {
try {
AccountinformationApi api = getApiWithUser("mikomo_704", "mikomo_704");
api.getAccountsInfo(apiVersion, providerId, null, null);
fail("ApiException was not raised");
} catch (ApiException e) {
System.out.println("Expected ApiException for 704: " + e.toString());
}
}
}
Loading
Loading