-
Notifications
You must be signed in to change notification settings - Fork 976
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,88 +20,92 @@ | |
import static org.apache.beam.it.truthmatchers.PipelineAsserts.assertThatPipeline; | ||
import static org.apache.beam.it.truthmatchers.PipelineAsserts.assertThatResult; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.apache.beam.it.common.PipelineLauncher.LaunchConfig; | ||
import org.apache.beam.it.common.PipelineLauncher.LaunchInfo; | ||
import org.apache.beam.it.common.PipelineOperator; | ||
import org.apache.beam.it.common.TestProperties; | ||
import org.apache.beam.it.common.utils.ResourceManagerUtils; | ||
import org.apache.beam.it.gcp.TemplateTestBase; | ||
import org.apache.beam.it.neo4j.Neo4jResourceManager; | ||
import org.apache.beam.it.common.PipelineLauncher.LaunchConfig; | ||
import org.apache.beam.it.common.PipelineLauncher.LaunchInfo; | ||
import org.apache.beam.it.neo4j.conditions.Neo4jQueryCheck; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Category(Neo4jCustomTestCategory.class) | ||
public class MinimalServiceAccountIT extends TemplateTestBase { | ||
|
||
private final String MINIMAL_SERVICE_ACCOUNT = "[email protected]"; | ||
private final String MINIMAL_SERVICE_ACCOUNT = | ||
"[email protected]"; | ||
|
||
private Neo4jResourceManager neo4jClient; | ||
private Neo4jResourceManager neo4jClient; | ||
|
||
@Before | ||
public void setup() { | ||
neo4jClient = Neo4jResourceManager.builder(testName) | ||
.setAdminPassword("letmein!") | ||
.setHost(TestProperties.hostIp()) | ||
.build(); | ||
} | ||
@Before | ||
public void setup() { | ||
neo4jClient = | ||
Neo4jResourceManager.builder(testName) | ||
.setAdminPassword("letmein!") | ||
.setHost(TestProperties.hostIp()) | ||
.build(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
ResourceManagerUtils.cleanResources(neo4jClient); | ||
} | ||
@After | ||
public void tearDown() { | ||
ResourceManagerUtils.cleanResources(neo4jClient); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
assertThat(2).isEqualTo(1 + 2); | ||
} | ||
@Test | ||
public void test() { | ||
assertThat(2).isEqualTo(1 + 2); | ||
} | ||
|
||
@Test | ||
public void runsWithProjectAndDataset() throws IOException { | ||
gcsClient.createArtifact( | ||
"project-and-dataset.json", | ||
contentOf("/testing-specs/minimal-service-account/project-and-dataset.json")); | ||
gcsClient.createArtifact( | ||
"neo4j.json", | ||
String.format( | ||
"{\n" | ||
+ " \"server_url\": \"%s\",\n" | ||
+ " \"database\": \"%s\",\n" | ||
+ " \"auth_type\": \"basic\",\n" | ||
+ " \"username\": \"neo4j\",\n" | ||
+ " \"pwd\": \"%s\"\n" | ||
+ "}", | ||
neo4jClient.getUri(), neo4jClient.getDatabaseName(), neo4jClient.getAdminPassword())); | ||
@Test | ||
public void runsWithProjectAndDataset() throws IOException { | ||
gcsClient.createArtifact( | ||
"project-and-dataset.json", | ||
contentOf("/testing-specs/minimal-service-account/project-and-dataset.json")); | ||
gcsClient.createArtifact( | ||
"neo4j.json", | ||
String.format( | ||
"{\n" | ||
+ " \"server_url\": \"%s\",\n" | ||
+ " \"database\": \"%s\",\n" | ||
+ " \"auth_type\": \"basic\",\n" | ||
+ " \"username\": \"neo4j\",\n" | ||
+ " \"pwd\": \"%s\"\n" | ||
+ "}", | ||
neo4jClient.getUri(), neo4jClient.getDatabaseName(), neo4jClient.getAdminPassword())); | ||
|
||
LaunchConfig.Builder options = LaunchConfig.builder(testName, specPath) | ||
.addParameter("jobSpecUri", getGcsPath("spec.json")) | ||
.addParameter("neo4jConnectionUri", getGcsPath("neo4j.json")) | ||
.addParameter("serviceAccount", MINIMAL_SERVICE_ACCOUNT); | ||
LaunchConfig.Builder options = | ||
LaunchConfig.builder(testName, specPath) | ||
.addParameter("jobSpecUri", getGcsPath("spec.json")) | ||
.addParameter("neo4jConnectionUri", getGcsPath("neo4j.json")) | ||
.addParameter("serviceAccount", MINIMAL_SERVICE_ACCOUNT); | ||
|
||
LaunchInfo info = launchTemplate(options); | ||
assertThatPipeline(info).isRunning(); | ||
PipelineOperator.Result result = pipelineOperator() | ||
.waitForCondition( | ||
createConfig(info), | ||
Neo4jQueryCheck.builder(neo4jClient) | ||
.setQuery("RETURN EXISTS {\n" + | ||
" MATCH (p:Person)\n" + | ||
" RETURN p\n" + | ||
"} AS personExists") | ||
.setExpectedResult(List.of(Map.of("personExists", true))) | ||
.build()); | ||
assertThatResult(result).meetsConditions(); | ||
} | ||
LaunchInfo info = launchTemplate(options); | ||
assertThatPipeline(info).isRunning(); | ||
PipelineOperator.Result result = | ||
pipelineOperator() | ||
.waitForCondition( | ||
createConfig(info), | ||
Neo4jQueryCheck.builder(neo4jClient) | ||
.setQuery( | ||
"RETURN EXISTS {\n" | ||
+ " MATCH (p:Person)\n" | ||
+ " RETURN p\n" | ||
+ "} AS personExists") | ||
.setExpectedResult(List.of(Map.of("personExists", true))) | ||
.build()); | ||
assertThatResult(result).meetsConditions(); | ||
} | ||
|
||
@Test | ||
public void runsWithOnlyDataset() {} | ||
@Test | ||
public void runsWithOnlyDataset() {} | ||
|
||
@Test | ||
public void failsWithoutProjectAndDataset() {} | ||
@Test | ||
public void failsWithoutProjectAndDataset() {} | ||
} |