Skip to content

Commit

Permalink
issues/216 - Change json resource path
Browse files Browse the repository at this point in the history
  • Loading branch information
meywood committed Sep 22, 2023
1 parent 62c47f7 commit d8d648a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.casper.sdk.e2e.steps;

import com.casper.sdk.e2e.utils.AssetUtils;
import com.casper.sdk.e2e.utils.CasperClientProvider;
import com.casper.sdk.e2e.utils.ContextMap;
import com.casper.sdk.model.clvalue.AbstractCLValue;
Expand All @@ -22,6 +23,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.net.URL;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -48,7 +50,8 @@ public void thatTheJSONDeployIsLoaded(final String jsonFilename) throws IOExcept

logger.info("Given that the {} JSON deploy is loaded", jsonFilename);

final InputStream jsonIn = Objects.requireNonNull(getClass().getResource("/json/" + jsonFilename)).openStream();
final URL jsonUrl = AssetUtils.getStandardTestResourceURL("/json/" + jsonFilename);
final InputStream jsonIn = Objects.requireNonNull(jsonUrl.openStream());
assertThat(jsonIn, is(notNullValue()));

final Deploy transfer = new ObjectMapper().readValue(jsonIn, Deploy.class);
Expand Down
11 changes: 4 additions & 7 deletions src/test/java/com/casper/sdk/e2e/steps/WasmStepDefinitions.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,17 @@ public class WasmStepDefinitions {
public void thatASmartContractIsInTheFolder(String wasmFileName, String contractsFolder) throws IOException {
logger.info("Give that a smart contract {string} is in the {string} folder");

final String wasmPath = "/" + contractsFolder + "/" + wasmFileName;
contextMap.put(StepConstants.WASM_PATH, wasmPath);
final URL resource = getClass().getResource(wasmPath);
//noinspection DataFlowIssue
assertThat(resource.openStream(), is(notNullValue()));
final URL wasmUrl = AssetUtils.getStandardTestResourceURL("/" + contractsFolder + "/" + wasmFileName);
contextMap.put(StepConstants.WASM_PATH, wasmUrl);
assertThat(wasmUrl.openStream(), is(notNullValue()));
}

@When("the wasm is loaded as from the file system")
public void whenTheWasmIsLoadedAsFromTheFileSystem() throws IOException, ValueSerializationException, NoSuchTypeException, GeneralSecurityException {
logger.info("Then when the wasm is loaded as from the file system");

final URL resource = getClass().getResource(contextMap.get(StepConstants.WASM_PATH));
final URL resource = contextMap.get(StepConstants.WASM_PATH);

//noinspection DataFlowIssue
final byte[] bytes = IOUtils.readBytesFromStream(resource.openStream());
assertThat(bytes.length, is(189336));

Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/casper/sdk/e2e/utils/AssetUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.casper.sdk.e2e.utils;

import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

/**
Expand All @@ -19,4 +22,10 @@ public static URL getFaucetAsset(final int networkId, final String keyFilename)
String path = String.format("/net-%d/faucet/%s", networkId, keyFilename);
return Objects.requireNonNull(AssetUtils.class.getResource(path), "missing resource " + path);
}

public static URL getStandardTestResourceURL(String jsonFilename) throws MalformedURLException {
final Path currentRelativePath = Paths.get("");
final String jsonPath = "file://" + currentRelativePath.toAbsolutePath() + "/sdk-std-test-resources" + jsonFilename;
return new URL(jsonPath);
}
}

0 comments on commit d8d648a

Please sign in to comment.