Search in sources :

Example 1 with PostPolicyV4Test

use of com.google.cloud.conformance.storage.v1.PostPolicyV4Test in project java-storage by googleapis.

the class V4PostPolicyTest method testCases.

/**
 * Loads all of the tests and return a {@code Collection<Object[]>} representing the set of tests.
 * Each entry in the returned collection is the set of parameters to the constructor of this test
 * class.
 *
 * <p>The results of this method will then be run by JUnit's Parameterized test runner
 */
@Parameters(name = "{2}")
public static Collection<Object[]> testCases() throws IOException {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    InputStream credentialsStream = cl.getResourceAsStream(SERVICE_ACCOUNT_JSON_RESOURCE);
    assertNotNull(String.format("Unable to load service account json: %s", SERVICE_ACCOUNT_JSON_RESOURCE), credentialsStream);
    InputStream dataJson = cl.getResourceAsStream(TEST_DATA_JSON_RESOURCE);
    assertNotNull(String.format("Unable to load test definition: %s", TEST_DATA_JSON_RESOURCE), dataJson);
    ServiceAccountCredentials serviceAccountCredentials = ServiceAccountCredentials.fromStream(credentialsStream);
    InputStreamReader reader = new InputStreamReader(dataJson, Charsets.UTF_8);
    TestFile.Builder testBuilder = TestFile.newBuilder();
    JsonFormat.parser().merge(reader, testBuilder);
    TestFile testFile = testBuilder.build();
    List<PostPolicyV4Test> tests = testFile.getPostPolicyV4TestsList();
    ArrayList<Object[]> data = new ArrayList<>(tests.size());
    for (PostPolicyV4Test test : tests) {
        data.add(new Object[] { test, serviceAccountCredentials, test.getDescription() });
    }
    return data;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) TestFile(com.google.cloud.conformance.storage.v1.TestFile) ArrayList(java.util.ArrayList) ServiceAccountCredentials(com.google.auth.oauth2.ServiceAccountCredentials) PostPolicyV4Test(com.google.cloud.conformance.storage.v1.PostPolicyV4Test) Parameters(org.junit.runners.Parameterized.Parameters)

Aggregations

ServiceAccountCredentials (com.google.auth.oauth2.ServiceAccountCredentials)1 PostPolicyV4Test (com.google.cloud.conformance.storage.v1.PostPolicyV4Test)1 TestFile (com.google.cloud.conformance.storage.v1.TestFile)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Parameters (org.junit.runners.Parameterized.Parameters)1