Skip to content

Commit

Permalink
Test override JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
duckAsteroid committed Dec 10, 2018
1 parent 36a165f commit 9f2c06a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
46 changes: 46 additions & 0 deletions src/test/java/com/asteroid/duck/velociwraptor/MainTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.asteroid.duck.velociwraptor;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -9,8 +10,12 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

import static com.asteroid.duck.velociwraptor.AssertFile.assertStandardTemplateApplied;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class MainTest {
@Rule
Expand All @@ -20,6 +25,47 @@ public void runMain(String ... args) {
Main.main(args);
}

@Test
public void localOverride() throws IOException {
String userDir = System.getProperty("user.dir");
File template = temporaryFolder.newFolder("template");
OverrideJsonSessionTest.createBasicTemplate(template);

File json = temporaryFolder.newFolder("json");
System.setProperty("user.dir", json.getAbsolutePath());

File oneJson = new File(json, "1.json");
FileUtils.write(oneJson, "{ \"Name\": \"Override-1\" }", StandardCharsets.UTF_8);
File twoJson = new File(json, "2.json");
FileUtils.write(twoJson, "{ \"Name\": \"Override-2\" }", StandardCharsets.UTF_8);

File output = temporaryFolder.newFolder("local");

runMain("-q",
"-d", template.getAbsolutePath(),
"-j", oneJson.getAbsolutePath() + ";"+twoJson.getAbsolutePath(),
"-o", output.getAbsolutePath());

File expectedFile = new File(output, "test.txt");
assertTrue(expectedFile.exists());
assertTrue(expectedFile.isFile());
String content = FileUtils.readFileToString(expectedFile, StandardCharsets.UTF_8);
assertEquals("Override-1", content);

output = temporaryFolder.newFolder("local2");

runMain("-q",
"-d", template.getAbsolutePath(),
"-j", twoJson.getAbsolutePath() + ";"+oneJson.getAbsolutePath(),
"-o", output.getAbsolutePath());

expectedFile = new File(output, "test.txt");
assertTrue(expectedFile.exists());
assertTrue(expectedFile.isFile());
content = FileUtils.readFileToString(expectedFile, StandardCharsets.UTF_8);
assertEquals("Override-2", content);
}

@Test
public void remoteZipTest() throws IOException {
File output = temporaryFolder.newFolder("remote-zip-test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ public class OverrideJsonSessionTest {
public void setUp() throws Exception {
target = temporaryFolder.newFolder("session-test");
File template = temporaryFolder.newFolder("template-test");
FileUtils.write(new File(template, "default.json"), "{ \"Name\": \"Default\" }", StandardCharsets.UTF_8);
File sub = new File(template, "template");
sub.mkdirs();
FileUtils.write(new File(sub, "test.txt"), "${Name}", StandardCharsets.UTF_8);

createBasicTemplate(template);

UserInteractive interactive = UserInteractive.nullInteractive();

Expand All @@ -55,6 +53,13 @@ public void setUp() throws Exception {
subject = new Session(templateRoot.rootDirectory(), data, target);
}

public static void createBasicTemplate(File template) throws IOException {
FileUtils.write(new File(template, "default.json"), "{ \"Name\": \"Default\" }", StandardCharsets.UTF_8);
File sub = new File(template, "template");
sub.mkdirs();
FileUtils.write(new File(sub, "test.txt"), "${Name}", StandardCharsets.UTF_8);
}

@After
public void tearDown() throws Exception {
//FileUtils.forceDelete(target);
Expand Down

0 comments on commit 9f2c06a

Please sign in to comment.