Skip to content
Permalink
Browse files

Improve code coverage

  • Loading branch information...
gquerret committed Jun 21, 2019
1 parent d357f90 commit ce37e5f26a30621825bf30584d1d1e63bf73773e
@@ -39,7 +39,7 @@
private File dbDir = null;
private String dbName = null;
private File outputLog = null;
private List<Index> indexes = new ArrayList<>();
private List<IndexNode> indexes = new ArrayList<>();
private String cpInternal = null;
private List<PCTRunOption> options = new ArrayList<>();

@@ -77,7 +77,7 @@ public void setCpInternal(String cpInternal) {
this.cpInternal = cpInternal;
}

public void addConfiguredIndex(Index index) {
public void addConfiguredIndex(IndexNode index) {
if ((index.table == null) || index.table.isEmpty())
throw new BuildException("Invalid index");
if ((index.index == null) || index.index.isEmpty())
@@ -87,7 +87,6 @@ public void addConfiguredIndex(Index index) {

public void addOption(PCTRunOption option) {
options.add(option);

}


@@ -107,7 +106,7 @@ public void execute() {
if (indexes.isEmpty())
throw new BuildException("Index list can't be empty");

// Update destDir if not defined
// Update dbDir if not defined
if (dbDir == null) {
dbDir = getProject().getBaseDir();
}
@@ -126,7 +125,7 @@ protected void cleanup() {
deleteFile(tmpFile);
}

public static class Index {
public static class IndexNode {
private String table;
private String index;

@@ -145,7 +144,7 @@ private void generateIndexFile() throws IOException {
BufferedWriter bw = new BufferedWriter(w)) {
bw.write("some");
bw.newLine();
for (Index idx : indexes) {
for (IndexNode idx : indexes) {
bw.write(idx.table);
bw.newLine();
bw.write(idx.index);
@@ -48,4 +48,20 @@ public void test2() {
assertTrue(log.exists());
expectBuildException("test3", "Invalid cpinternal");
}

@Test(groups = {"v10"})
public void test3() {
configureProject("IndexRebuild/test3/build.xml");
executeTarget("init");
expectBuildException("test1", "Invalid index node");
expectBuildException("test2", "Invalid index node");
}

@Test(groups = {"v10"})
public void test4() {
configureProject("IndexRebuild/test4/build.xml");
executeTarget("init");
executeTarget("test1");
expectBuildException("test2", "Invalid option value");
}
}
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<project name="IndexRebuild-test3">
<taskdef resource="PCT.properties" />

<target name="init">
<mkdir dir="db" />
<sports2000 destDir="db" dbName="sp2k" dlcHome="${DLC}" />
<PCTLoadSchema dlcHome="${DLC}" srcFile="index.df">
<DBConnection dbName="sp2k" dbDir="db" singleUser="true" />
</PCTLoadSchema>
</target>

<target name="test1">
<IndexRebuild dbDir="db" dbName="sp2k" dlcHome="${DLC}">
<Index index="CustomerNew1" />
</IndexRebuild>
</target>

<target name="test2">
<IndexRebuild dbDir="db" dbName="sp2k" dlcHome="${DLC}">
<Index table="customer" />
</IndexRebuild>
</target>

</project>
@@ -0,0 +1,10 @@
ADD INDEX "CustomerNew1" ON "customer"
INACTIVE
DESCRIPTION "XXX"
INDEX-FIELD "name" ASCENDING

ADD INDEX "EmployeeNew1" ON "employee"
INACTIVE
DESCRIPTION "XXX"
INDEX-FIELD "lastname" ASCENDING

@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<project name="IndexRebuild-test4">
<taskdef resource="PCT.properties" />

<target name="init">
<mkdir dir="db" />
<sports2000 destDir="db" dbName="sp2k" dlcHome="${DLC}" />
<PCTLoadSchema dlcHome="${DLC}" srcFile="index.df">
<DBConnection dbName="sp2k" dbDir="db" singleUser="true" />
</PCTLoadSchema>
</target>

<target name="test1">
<IndexRebuild dbDir="db" dbName="sp2k" dlcHome="${DLC}">
<Index table="customer" index="CustomerNew1" />
<Index table="employee" index="EmployeeNew1" />
<Option name="-thread" value="1" />
</IndexRebuild>
</target>

<target name="test2">
<IndexRebuild dbDir="db" dbName="sp2k" dlcHome="${DLC}">
<Index table="customer" index="CustomerNew1" />
<Index table="employee" index="EmployeeNew1" />
<Option name="-thread" value="-1" />
</IndexRebuild>
</target>

</project>
@@ -0,0 +1,10 @@
ADD INDEX "CustomerNew1" ON "customer"
INACTIVE
DESCRIPTION "XXX"
INDEX-FIELD "name" ASCENDING

ADD INDEX "EmployeeNew1" ON "employee"
INACTIVE
DESCRIPTION "XXX"
INDEX-FIELD "lastname" ASCENDING

0 comments on commit ce37e5f

Please sign in to comment.
You can’t perform that action at this time.