Skip to content

Commit

Permalink
Merge #7 'en7-force-dry-run'
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLeoni committed Feb 3, 2017
2 parents cd29877 + d0f5041 commit 682abef
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public class ImportXmlCommand implements DiverCliCommand {
@Parameter(names = { "--skip-augment", "-s" }, description = "Skips augmenting the db graph to speed up "
+ " operations requiring the transitive closure.")
boolean skipAugment = false;

@Parameter(names = { "--dry-run", "-r" }, description = "A dry run simulates the import without writing anything into the database.")
boolean dryRun = false;

@Parameter(names = { "--force", "-f" }, description = "Forces import even on warnings (in particular, missing external references).")
boolean force = false;

@Parameter(required = true, variableArity = true, description = "a space separated list of XML files in UBY-LMF format."
+ " Lexical resources must have a 'name' attribute. If there are already present resources with the"
Expand Down Expand Up @@ -74,10 +80,12 @@ public void configure() {
checkNotBlank(author, "Tried to import files without '--author' parameter! ");

checkNotBlank(description, "Tried to import files without '--description' parameter! ");
importConfig = new ImportConfig();
importConfig.setAuthor(author);
importConfig.setDescription(description);
importConfig.setSkipAugment(skipAugment);
importConfig = new ImportConfig()
.setAuthor(author)
.setDescription(description)
.setSkipAugment(skipAugment)
.setForce(force)
.setDryRun(dryRun);

for (String fileUrl : importXmlPaths) {
importConfig.addLexResFileUrl(fileUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@ public void run(){
System.setOut(new PrintStream(
new OutputStream() { @Override public void write(int b) { }}
));
Diversicons.dropCreateTables(dbCfg);
} catch (Exception ex){
///LOG.setLevel(savedLevel);
Diversicons.dropCreateTables(dbCfg);
} finally {
System.setOut(savedOut);
throw ex;
}
}

Expand Down
104 changes: 95 additions & 9 deletions src/test/java/eu/kidf/diversicon/cli/test/DiverCliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.ini4j.InvalidFileFormatException;
import org.ini4j.Wini;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -40,12 +39,12 @@
import eu.kidf.diversicon.core.Diversicon;
import eu.kidf.diversicon.core.Diversicons;
import eu.kidf.diversicon.core.ImportJob;
import eu.kidf.diversicon.core.exceptions.InvalidImportException;
import eu.kidf.diversicon.core.exceptions.InvalidXmlException;
import eu.kidf.diversicon.core.internal.Internals;
import eu.kidf.diversicon.core.test.DivTester;
import eu.kidf.diversicon.data.DivUpper;
import eu.kidf.diversicon.data.DivWn31;
import eu.kidf.diversicon.data.Examplicon;

import static eu.kidf.diversicon.cli.MainCommand.PRJ_OPTION;
import static eu.kidf.diversicon.cli.test.CliTester.initEmpty;
Expand Down Expand Up @@ -319,44 +318,44 @@ public void testIni() throws InvalidFileFormatException, IOException {
*/
@Test
public void testImportXmlBadParams() {
DiverCli.of(PRJ_OPTION, "db", InitCommand.CMD).run();
DiverCli.of(PRJ_OPTION, "db", InitCommand.CMD).run();

File xmlFile = DivTester.writeXml(DivTester.GRAPH_1_HYPERNYM);

try {
DiverCli.of("--import ", xmlFile.getAbsolutePath())
DiverCli.of(ImportXmlCommand.CMD, xmlFile.getAbsolutePath())
.run();
Assert.fail("Should need author!");
} catch (Exception ex) {
LOG.debug("Expected exception:", ex);
}

try {
DiverCli.of("--import ", xmlFile.getAbsolutePath(), "--author", " ")
DiverCli.of(ImportXmlCommand.CMD, xmlFile.getAbsolutePath(), "--author", " ")
.run();
Assert.fail("Should need author!");
} catch (Exception ex) {
LOG.debug("Expected exception:", ex);
}

try {
DiverCli.of("--import ", xmlFile.getAbsolutePath(), "--author", "")
DiverCli.of(ImportXmlCommand.CMD, xmlFile.getAbsolutePath(), "--author", "")
.run();
Assert.fail("Should need author!");
} catch (Exception ex) {
LOG.debug("Expected exception:", ex);
}

try {
DiverCli.of("--import ", xmlFile.getAbsolutePath(), "--author", "a")
DiverCli.of(ImportXmlCommand.CMD, xmlFile.getAbsolutePath(), "--author", "a")
.run();
Assert.fail("Need description!");
} catch (Exception ex) {
LOG.debug("Expected exception:", ex);
}

try {
DiverCli.of("--import ", xmlFile.getAbsolutePath(), "--author", "a", "--description", "")
DiverCli.of(ImportXmlCommand.CMD, xmlFile.getAbsolutePath(), "--author", "a", "--description", "")
.run();
Assert.fail("Need description!");
} catch (Exception ex) {
Expand All @@ -372,6 +371,40 @@ public void testImportXmlBadParams() {
}

}

/**
* @since 0.1.0
*/
@Test
public void testImportXmlWarning(){
initEmpty();

File xml = DivTester.writeXml(DivTester.GRAPH_WARNING,
DivTester.createLexResPackage(DivTester.GRAPH_WARNING, DivTester.TOO_LONG_PREFIX));
DiverCli cli = DiverCli.of(ImportXmlCommand.CMD, "-a", "a", "-d","d", xml.getAbsolutePath());
try {
cli.run();
Assert.fail("Shouldn't arrive here!");
} catch (InvalidImportException ex){
LOG.debug("Caught expected exception: ", ex);
}
}

/**
* @since 0.1.0
*/
@Test
public void testImportXmlWarningForce(){
initEmpty();

File xml = DivTester.writeXml(DivTester.GRAPH_WARNING,
DivTester.createLexResPackage(DivTester.GRAPH_WARNING, DivTester.TOO_LONG_PREFIX));
DiverCli cli = DiverCli.of(ImportXmlCommand.CMD, "-a", "a", "-d","d", "--force", xml.getAbsolutePath());

cli.run();

}


/**
* This also tests MainCommand is working
Expand All @@ -384,6 +417,9 @@ public void testDebug() {
cli.run();
}

/**
* @since 0.1.0
*/
@Test
public void testImportXml() {

Expand All @@ -404,6 +440,29 @@ public void testImportXml() {
.close();
}

/**
* @since 0.1.0
*/
@Test
public void testImportXmlDry() {
initEmpty();

File xmlFile = DivTester.writeXml(DivTester.GRAPH_1_HYPERNYM);

DiverCli cli = DiverCli.of(ImportXmlCommand.CMD,
"--author", "a",
"--description", "d",
"--dry-run",
xmlFile.getAbsolutePath());

cli.run();

Diversicon div = Diversicon.connectToDb(cli.divConfig());
assertEquals(null, div.getLexicalResource(DivTester.GRAPH_1_HYPERNYM.getName()));
div.getSession()
.close();

}


/**
Expand Down Expand Up @@ -478,6 +537,9 @@ public void testDbAugment() {
cli2.disconnect();
}

/**
* @since 0.1.0
*/
@Test
public void testExportXmlMissingXmlPath() {
initEmpty();
Expand All @@ -490,6 +552,9 @@ public void testExportXmlMissingXmlPath() {
}
}

/**
* @since 0.1.0
*/
@Test
public void testExportXmlMissingLexicalResourceName() throws IOException {

Expand All @@ -506,6 +571,9 @@ public void testExportXmlMissingLexicalResourceName() throws IOException {
}
}

/**
* @since 0.1.0
*/
@Test
public void testExportXmlWrongLexicalResource() throws IOException {

Expand All @@ -522,6 +590,9 @@ public void testExportXmlWrongLexicalResource() throws IOException {
}
}

/**
* @since 0.1.0
*/
@Test
public void testExportXmlExistingXml() throws IOException {

Expand All @@ -542,6 +613,9 @@ public void testExportXmlExistingXml() throws IOException {
}
}

/**
* @since 0.1.0
*/
@Test
public void testExportXml() throws IOException {

Expand All @@ -561,6 +635,9 @@ public void testExportXml() throws IOException {

}

/**
* @since 0.1.0
*/
@Test
public void testExportXmlCompressed() throws IOException {
initEmpty();
Expand All @@ -582,6 +659,9 @@ public void testExportXmlCompressed() throws IOException {

}

/**
* @since 0.1.0
*/
@Test
public void testExportSqlMissingSqlPath() {
initEmpty();
Expand All @@ -595,6 +675,9 @@ public void testExportSqlMissingSqlPath() {
}
}

/**
* @since 0.1.0
*/
@Test
public void testExportSqlExistingSql() throws IOException {
initEmpty();
Expand All @@ -614,6 +697,9 @@ public void testExportSqlExistingSql() throws IOException {
}
}

/**
* @since 0.1.0
*/
@Test
public void testExportSql() throws IOException {
initEmpty();
Expand Down Expand Up @@ -856,6 +942,6 @@ public void testDiversiconBuildInfo(){
LOG.debug(bfWn31.getScmUrl());
assertTrue(bfWn31.getScmUrl().toLowerCase().contains("diversicon-wordnet-3.1"));
}


}

0 comments on commit 682abef

Please sign in to comment.