Skip to content

Commit

Permalink
module renamed to dbconstraint / package renamed to org.evomaster.dbc…
Browse files Browse the repository at this point in the history
…onstraint
  • Loading branch information
jgaleotti committed May 9, 2019
1 parent 715af79 commit fd71335
Show file tree
Hide file tree
Showing 58 changed files with 97 additions and 99 deletions.
Expand Up @@ -92,7 +92,7 @@ is empty or not, and only way is to call next()


/**
* Adds a unique constraint to the correspondinding ColumnDTO for the selected table.column pair.
* Adds a unique dbconstraint to the correspondinding ColumnDTO for the selected table.column pair.
* Requires the ColumnDTO to be contained in the TableDTO.
* If the column DTO is not contained, a IllegalArgumentException is thrown.
**/
Expand Down Expand Up @@ -161,7 +161,7 @@ private static void addConstraints(DbSchemaDto schemaDto, List<DbTableConstraint
addUniqueConstraintToColumn(tableName, tableDto, columnName);
}
} else {
throw new RuntimeException("Unknown constraint type " + constraint.getClass().getName());
throw new RuntimeException("Unknown dbconstraint type " + constraint.getClass().getName());
}

}
Expand Down
Expand Up @@ -9,7 +9,7 @@
import org.evomaster.client.java.controller.db.DataRow;
import org.evomaster.client.java.controller.db.QueryResult;

import java.util.*;
import java.util.List;

import static org.evomaster.client.java.controller.internal.db.ParserUtils.getWhere;

Expand Down Expand Up @@ -139,7 +139,7 @@ public static double computeDistance(String select, QueryResult data) {

Expression where = getWhere(stmt);
if (where == null) {
//no constraint, and at least one data point
//no dbconstraint, and at least one data point
return 0;
}

Expand Down
Expand Up @@ -70,13 +70,13 @@ private List<DbTableConstraint> extractTableConstraints(Connection connectionToH

} else if (constraintType.equals("REFERENTIAL")) {
/**
* This type of constraint is already handled by
* This type of dbconstraint is already handled by
* JDBC Metadata
**/
continue;
} else if (constraintType.equals("PRIMARY KEY") || constraintType.equals("PRIMARY_KEY")) {
/**
* This type of constraint is already handled by
* This type of dbconstraint is already handled by
* JDBC Metadata
**/
continue;
Expand All @@ -87,7 +87,7 @@ private List<DbTableConstraint> extractTableConstraints(Connection connectionToH
tableCheckExpressions.add(constraint);

} else {
throw new RuntimeException("Unknown constraint type : " + constraintType);
throw new RuntimeException("Unknown dbconstraint type : " + constraintType);
}

}
Expand Down
Expand Up @@ -6,7 +6,8 @@
import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* Created by arcuri82 on 25-Mar-19.
Expand Down Expand Up @@ -55,7 +56,7 @@ public void testFKs() throws Exception{

SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Foo(x int, primary key (x));");
SqlScriptRunner.execCommand(getConnection(), "CREATE TABLE Bar(y int, primary key (y));");
SqlScriptRunner.execCommand(getConnection(), "alter table Bar add constraint FK foreign key (y) references Foo;");
SqlScriptRunner.execCommand(getConnection(), "alter table Bar add dbconstraint FK foreign key (y) references Foo;");

//can't insert before Foo
assertThrows(Exception.class, () ->
Expand Down
Expand Up @@ -10,9 +10,9 @@
import java.util.List;

import static io.restassured.RestAssured.given;
import static org.evomaster.client.java.controller.db.dsl.SqlDsl.sql;
import static org.evomaster.client.java.controller.api.ControllerConstants.BASE_PATH;
import static org.evomaster.client.java.controller.api.ControllerConstants.DATABASE_COMMAND;
import static org.evomaster.client.java.controller.db.dsl.SqlDsl.sql;
import static org.junit.jupiter.api.Assertions.*;

public class SqlScriptRunnerTest extends DatabaseTestTemplate {
Expand Down Expand Up @@ -90,7 +90,7 @@ public void testInsertWhenForeignKey() throws Exception {
", barId bigint not null " +
");" +
" CREATE TABLE Bar(id bigint generated by default as identity);" +
" ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;\n"
" ALTER TABLE Foo add dbconstraint barIdKey foreign key (barId) references Bar;\n"
);

QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");
Expand Down Expand Up @@ -125,7 +125,7 @@ public void testIdentityExtractGeneratedKey() throws Exception {
" id bigint generated by default as identity " +
", x integer " +
", primary key (id));" +
" ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;\n"
" ALTER TABLE Foo add dbconstraint barIdKey foreign key (barId) references Bar;\n"
);

QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");
Expand Down Expand Up @@ -161,7 +161,7 @@ public void testInsertionListWithGeneratedKeys() throws Exception {
" id bigint generated by default as identity " +
", x integer " +
", primary key (id));" +
" ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;\n"
" ALTER TABLE Foo add dbconstraint barIdKey foreign key (barId) references Bar;\n"
);

QueryResult res = SqlScriptRunner.execCommand(getConnection(), "SELECT * FROM Bar;");
Expand Down Expand Up @@ -281,10 +281,10 @@ public void testDoubleIndirectForeignKey() throws Exception {
");"
+
"alter table Table2 " +
" add constraint FKTable2 foreign key (id) references Table1;"
" add dbconstraint FKTable2 foreign key (id) references Table1;"
+
"alter table Table3 " +
" add constraint FKTable3 foreign key (id) references Table2;"
" add dbconstraint FKTable3 foreign key (id) references Table2;"
);

List<InsertionDto> insertions = sql()
Expand Down
Expand Up @@ -117,7 +117,7 @@ public void testBasicForeignKey() throws Exception {
", barId bigint not null " +
");" +
" CREATE TABLE Bar(id bigint generated by default as identity);" +
" ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;\n"
" ALTER TABLE Foo add dbconstraint barIdKey foreign key (barId) references Bar;\n"
);

DbSchemaDto schema = SchemaExtractor.extract(getConnection());
Expand Down Expand Up @@ -179,7 +179,7 @@ public void testColumnUpperBoundConstraint() throws Exception {
assertTrue(fooTable.columns.stream().anyMatch(c -> c.name.equalsIgnoreCase("fooId")));
assertTrue(fooTable.columns.stream().anyMatch(c -> c.name.equalsIgnoreCase("age_max")));

// TODO check that the column constraint is actually extracted
// TODO check that the column dbconstraint is actually extracted
ColumnDto columnDto = fooTable.columns.stream().filter(c -> c.name.equalsIgnoreCase("age_max")).findFirst().orElse(null);

assertEquals("INTEGER", columnDto.type);
Expand Down
7 changes: 2 additions & 5 deletions core/pom.xml
Expand Up @@ -126,13 +126,10 @@
</dependency>
<dependency>
<groupId>org.evomaster</groupId>
<artifactId>evomaster-db-constraints</artifactId>
</dependency>
<dependency>
<groupId>org.evomaster</groupId>
<artifactId>evomaster-db-constraints</artifactId>
<artifactId>evomaster-dbconstraint</artifactId>
</dependency>


</dependencies>

<build>
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/kotlin/org/evomaster/core/EMConfig.kt
Expand Up @@ -162,7 +162,7 @@ class EMConfig {
* chosen on the command line
*
*
* @throws IllegalArgumentException if there are constraint violations
* @throws IllegalArgumentException if there are dbconstraint violations
*/
fun updateProperties(options: OptionSet) {

Expand Down Expand Up @@ -213,15 +213,15 @@ class EMConfig {
m.annotations.find { it is Min }?.also {
it as Min
if(parameterValue.toDouble() < it.min){
throw IllegalArgumentException("Failed to handle Min ${it.min} constraint for" +
throw IllegalArgumentException("Failed to handle Min ${it.min} dbconstraint for" +
" parameter '${m.name}' with value $parameterValue")
}
}

m.annotations.find { it is Max }?.also {
it as Max
if(parameterValue.toDouble() > it.max){
throw IllegalArgumentException("Failed to handle Max ${it.max} constraint for" +
throw IllegalArgumentException("Failed to handle Max ${it.max} dbconstraint for" +
" parameter '${m.name}' with value $parameterValue")
}
}
Expand Down
Expand Up @@ -235,7 +235,7 @@ class DbAction(
*/
/*
This is a nasty case, as it is a blob of binary data.
Could be any format, and likely no constraint in the DB schema,
Could be any format, and likely no dbconstraint in the DB schema,
where the actual constraints are in the SUT code.
This is also what for example can be used by Hibernate to represent
a ZoneDataTime before Java 8 support.
Expand Down
@@ -1,11 +1,11 @@
package org.evomaster.core.database

import org.evomaster.core.Lazy
import org.evomaster.core.search.Action
import org.evomaster.core.search.gene.Gene
import org.evomaster.core.search.gene.SqlForeignKeyGene
import org.evomaster.core.search.gene.SqlPrimaryKeyGene
import org.evomaster.core.search.service.Randomness
import org.evomaster.core.Lazy

object DbActionUtils {

Expand Down Expand Up @@ -189,13 +189,13 @@ object DbActionUtils {

val tableName = action.table.name

//handle unique constraint
//handle unique dbconstraint
action.seeGenes().forEach { g ->
val columnName = g.name

/*
Is the current gene representing a column in database for which we need
to enforce a unique constraint?
to enforce a unique dbconstraint?
*/
val isUnique = action.table.columns.any {
it.name == columnName && !it.autoIncrement && it.unique
Expand Down
Expand Up @@ -5,14 +5,14 @@ import org.evomaster.client.java.controller.api.dto.database.operations.QueryRes
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType
import org.evomaster.client.java.controller.api.dto.database.schema.DbSchemaDto
import org.evomaster.client.java.controller.api.dto.database.schema.TableDto
import org.evomaster.constraint.*
import org.evomaster.core.database.schema.Column
import org.evomaster.core.database.schema.ColumnDataType
import org.evomaster.core.database.schema.ForeignKey
import org.evomaster.core.database.schema.Table
import org.evomaster.core.search.gene.Gene
import org.evomaster.core.search.gene.ImmutableDataHolderGene
import org.evomaster.core.search.gene.SqlPrimaryKeyGene
import org.evomaster.dbconstraint.*


class SqlInsertBuilder(
Expand Down
Expand Up @@ -147,7 +147,7 @@ class SqlInsertBuilderTest {
id bigint generated by default as identity,
primary key (id)
);
ALTER TABLE Foo add constraint barIdKey foreign key (barId) references Bar;
ALTER TABLE Foo add dbconstraint barIdKey foreign key (barId) references Bar;
""")

val dto = SchemaExtractor.extract(connection)
Expand Down
@@ -1,7 +1,7 @@
package org.evomaster.core.database.extract

import org.evomaster.client.java.controller.internal.db.SchemaExtractor
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType
import org.evomaster.client.java.controller.internal.db.SchemaExtractor
import org.evomaster.core.database.DbActionTransformer
import org.evomaster.core.database.DbActionUtils
import org.evomaster.core.database.SqlInsertBuilder
Expand Down Expand Up @@ -46,7 +46,7 @@ class ProxyPrintSqlExtractTest : ExtractTestBaseH2() {
/**
* The schema includes an alter table command that specifies that
* table USERS has a unique column USERNAME:
* alter table users add constraint UK_r43af9ap4edm43mmtq01oddj6 unique (username);
* alter table users add dbconstraint UK_r43af9ap4edm43mmtq01oddj6 unique (username);
*/
assertEquals(true, schema.tables.find { it.name == "USERS" }!!.columns.find { it.name == "USERNAME" }!!.unique)

Expand Down
2 changes: 1 addition & 1 deletion db-constraints/pom.xml → dbconstraint/pom.xml
Expand Up @@ -21,7 +21,7 @@
</parent>

<groupId>org.evomaster</groupId>
<artifactId>evomaster-db-constraints</artifactId>
<artifactId>evomaster-dbconstraint</artifactId>
<packaging>jar</packaging>


Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint;
package org.evomaster.dbconstraint;

import java.util.Objects;

Expand Down
@@ -1,11 +1,11 @@
package org.evomaster.constraint;
package org.evomaster.dbconstraint;

import org.evomaster.constraint.ast.SqlCondition;
import org.evomaster.constraint.extract.SqlConditionTranslator;
import org.evomaster.constraint.extract.TranslationContext;
import org.evomaster.constraint.parser.SqlConditionParser;
import org.evomaster.constraint.parser.SqlConditionParserException;
import org.evomaster.constraint.parser.SqlConditionParserFactory;
import org.evomaster.dbconstraint.ast.SqlCondition;
import org.evomaster.dbconstraint.extract.SqlConditionTranslator;
import org.evomaster.dbconstraint.extract.TranslationContext;
import org.evomaster.dbconstraint.parser.SqlConditionParser;
import org.evomaster.dbconstraint.parser.SqlConditionParserException;
import org.evomaster.dbconstraint.parser.SqlConditionParserFactory;

public class ConstraintBuilder {

Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint;
package org.evomaster.dbconstraint;

import java.util.List;
import java.util.Objects;
Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint;
package org.evomaster.dbconstraint;

import java.util.Objects;

Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint;
package org.evomaster.dbconstraint;

import java.util.Objects;

Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint;
package org.evomaster.dbconstraint;


import java.util.Arrays;
Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint;
package org.evomaster.dbconstraint;

import java.util.Objects;

Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint;
package org.evomaster.dbconstraint;

import java.util.Objects;

Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint;
package org.evomaster.dbconstraint;

import java.util.Objects;

Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint;
package org.evomaster.dbconstraint;

import java.util.List;
import java.util.Objects;
Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint;
package org.evomaster.dbconstraint;

import java.util.Objects;

Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint;
package org.evomaster.dbconstraint;

import java.util.Objects;

Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint.ast;
package org.evomaster.dbconstraint.ast;

import java.util.Objects;

Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint.ast;
package org.evomaster.dbconstraint.ast;

import java.math.BigDecimal;
import java.util.Objects;
Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint.ast;
package org.evomaster.dbconstraint.ast;

import java.math.BigInteger;
import java.util.Objects;
Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint.ast;
package org.evomaster.dbconstraint.ast;

public class SqlBinaryDataLiteralValue extends SqlLiteralValue {

Expand Down
@@ -1,4 +1,4 @@
package org.evomaster.constraint.ast;
package org.evomaster.dbconstraint.ast;

import java.util.Objects;

Expand Down

0 comments on commit fd71335

Please sign in to comment.