Skip to content

Commit

Permalink
Homogenize metamodel terminology and test cases fix (#121)
Browse files Browse the repository at this point in the history
* Fixed input data test case

* Updated names

* fix thingsboard sql database

* Added missing testconsistency test case

* Added Benerator files
  • Loading branch information
suarezgpablo authored Dec 17, 2024
1 parent 46a339d commit 2d5d174
Show file tree
Hide file tree
Showing 25 changed files with 335 additions and 84 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ jobs:
docker exec -i test-mysql sh -c "exec mysql -uroot -prootpassword" < ./setup/minds.sql
docker exec -i test-mysql sh -c "exec mysql -uroot -prootpassword" < ./setup/wire.sql
docker exec -i test-mysql sh -c "exec mysql -uroot -prootpassword" < ./setup/thingsboard.sql
docker exec -i test-mysql sh -c "exec mysql -uroot -prootpassword" < ./setup/thingsboard2.sql
- name: Initialize Cassandra database
run: |
docker run --name test-cassandra -d -p 9042:9042 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ public void testCustomV7SplitTable() throws IOException {
projectionAfterEvo.put("table1copied2", "SELECT DISTINCT author.id AS idauthor FROM author INNER JOIN authorbook ON author.id = authorbook.idauthor INNER JOIN book ON book.id = authorbook.idbook ORDER BY author.id DESC;");
testConsistency(name.getMethodName(), projectionAfterEvo, "custom", projectionBeforeEvo);
}
@Test
public void testCustomV8JoinColumn() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Map<String, String> projectionBeforeEvo = new HashMap<String, String>();
projectionBeforeEvo.put("table1", "SELECT author.id AS idauthor, book.id AS idbook, book.title as title, book.subtitle AS subtitle FROM author INNER JOIN authorbook ON author.id = authorbook.idauthor INNER JOIN book ON book.id = authorbook.idbook;");
projectionAfterEvo.put("table1", "SELECT author.id AS idauthor, book.id AS idbook, CONCAT(book.title, book.subtitle) AS completetitle, book.subtitle AS subtitle, book.title as title FROM author INNER JOIN authorbook ON author.id = authorbook.idauthor INNER JOIN book ON book.id = authorbook.idbook ORDER BY author.id DESC, book.id DESC;");
testConsistency(name.getMethodName(), projectionAfterEvo, "custom", projectionBeforeEvo);
}
@Test
public void testCustomV9RemovePK() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Map<String, String> projectionBeforeEvo = new HashMap<String, String>();
projectionBeforeEvo.put("table1beforechange", "SELECT author.id AS idauthor, book.id AS idbook, book.title as title FROM author INNER JOIN authorbook ON author.id = authorbook.idauthor INNER JOIN book ON book.id = authorbook.idbook;");
projectionAfterEvo.put("table1", "SELECT author.id AS idauthor, book.id AS idbook FROM author INNER JOIN authorbook ON author.id = authorbook.idauthor INNER JOIN book ON book.id = authorbook.idbook ORDER BY author.id DESC, book.id DESC;");
testConsistency(name.getMethodName(), projectionAfterEvo, "custom", projectionBeforeEvo);
}

@Test
public void testMindsV10NewTableMigrationFromOneTable() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Expand Down Expand Up @@ -154,6 +171,15 @@ public void testWireV2NewTableMigrationFromOneTable() throws IOException {
testConsistency(name.getMethodName(), projectionAfterEvo, "wire", projectionBeforeEvo);
}
@Test
public void testWireV8NewTableMigrationFromPreviousVersion() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Map<String, String> projectionBeforeEvo = new HashMap<String, String>();
projectionBeforeEvo.put("scim_user", "SELECT scim.id AS id FROM scim;");
projectionAfterEvo.put("scim_user", "SELECT scim.id AS id FROM scim ORDER BY scim.id DESC;");
projectionAfterEvo.put("scim_user_times", "SELECT scim.id AS id FROM scim ORDER BY scim.id DESC;");
testConsistency(name.getMethodName(), projectionAfterEvo, "wire", projectionBeforeEvo);
}
@Test
public void testWireV91NewTableMigrationFromOneTable() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Map<String, String> projectionBeforeEvo = new HashMap<String, String>();
Expand Down Expand Up @@ -181,26 +207,27 @@ public void testThingsBoardV11NewColumnNonKey() throws IOException {
projectionAfterEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id ORDER BY device.id DESC, tenant_id DESC, customer_ID DESC;");
projectionBeforeEvo.put("entity_view", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id);");
projectionAfterEvo.put("entity_view", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_type as dev_type, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id) ORDER BY entity.id DESC;");
testConsistency(name.getMethodName(), projectionAfterEvo, "thingsboard", projectionBeforeEvo);
testConsistency(name.getMethodName(), projectionAfterEvo, "thingsboard2", projectionBeforeEvo);
}
@Test
public void testThingsBoardV12NewColumnPK() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Map<String, String> projectionBeforeEvo = new HashMap<String, String>();
projectionBeforeEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id;");
projectionAfterEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id ORDER BY device.id DESC, tenant_id DESC, customer_ID DESC;");
projectionBeforeEvo.put("entity_view2_old", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id);");
projectionAfterEvo.put("entity_view2", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_type as dev_type, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id) ORDER BY entity.id DESC;");
projectionBeforeEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant;");
projectionAfterEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant ORDER BY device.id DESC, tenant_id DESC, customer_ID DESC;");
projectionBeforeEvo.put("entity_view2_old", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id);");
projectionAfterEvo.put("entity_view2", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_type as dev_type, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id) ORDER BY id DESC, tenant_id DESC, customer_id DESC, dev_type DESC;");
testConsistency(name.getMethodName(), projectionAfterEvo, "thingsboard", projectionBeforeEvo);
}
@Test
public void testThingsBoardV13NewColumnKeyInTable() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Map<String, String> projectionBeforeEvo = new HashMap<String, String>();
projectionBeforeEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id;");
projectionAfterEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id ORDER BY device.id DESC, tenant_id DESC, customer_ID DESC;");
projectionBeforeEvo.put("entity_view_devpk", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.id as device_id, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id);");
projectionAfterEvo.put("entity_view_devpk", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.id as device_id, device.dev_type as dev_type, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id) ORDER BY entity.id DESC;");
projectionBeforeEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant;");
projectionAfterEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant ORDER BY device.id DESC, tenant_id DESC, customer_ID DESC;");
projectionBeforeEvo.put("entity_view_devpk", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.id as device_id, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id);");
projectionAfterEvo.put("entity_view_devpk", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.id as device_id, device.dev_type as dev_type, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id) ORDER BY id DESC, tenant_id DESC, customer_id DESC, device_id DESC, dev_type DESC;");

testConsistency(name.getMethodName(), projectionAfterEvo, "thingsboard", projectionBeforeEvo);
}
/**
Expand All @@ -219,6 +246,7 @@ private void testConsistency (String testName, Map<String, String> tableQueryCom
* Sets up the Cassandra by populating it with all the data required from the SQL database using the queries specified in tableProjection
*/
private void setUpCassandraDatabase(String testName, String keyspace, Map<String, String> tableProjection) {
resetDatabaseCassandraUnitTesting (testName);
OracleCsv oc = new OracleCsv();
Map<String, List<String>> tableColumnsMap = oc.namesTablesColumnsKeyspace(testName, connection, tableProjection); //Map of the names of tables and its columns
Map <String, PreparedStatement> preparedStatementsTable = new HashMap <>();
Expand All @@ -231,6 +259,19 @@ private void setUpCassandraDatabase(String testName, String keyspace, Map<String
}
migrateSqlToCassandra (preparedStatementsTable, keyspace, tableProjection); //Migrates data from the SQL database to each Cassandra table
}
/**
* Empties the database of data
*/
private void resetDatabaseCassandraUnitTesting(String keyspace) {
String cql = "SELECT table_name FROM system_schema.tables WHERE keyspace_name = '"+keyspace+"';";
com.datastax.oss.driver.api.core.cql.ResultSet results = connection.executeStatement(cql);
for (com.datastax.oss.driver.api.core.cql.Row row : results) {
String nameTable = row.getString(0);
String delete = "";
delete = "TRUNCATE \""+keyspace+"\"."+nameTable+";";
connection.executeStatement(delete);
}
}

/**
* Builds a PreparedStatement to insert data to all columns of a Cassandra table
Expand Down
6 changes: 3 additions & 3 deletions modevo-script/dat/bmk/testMindsV3SplitColumn-script.cql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FOR $1,$2 = SELECT parent_guid, id FROM comments WHERE parent_guid>'f' ALLOW FILTERING
FOR $3,$4 = SELECT parent_guid, id FROM comments WHERE parent_guid>'p' ALLOW FILTERING
FOR $5,$6 = SELECT parent_guid, id FROM comments WHERE parent_guid<'p' ALLOW FILTERING
FOR $1,$2 = SELECT parent_guid, id FROM comments WHERE parent_guid<'F' ALLOW FILTERING
FOR $3,$4 = SELECT parent_guid, id FROM comments WHERE parent_guid<'P' ALLOW FILTERING
FOR $5,$6 = SELECT parent_guid, id FROM comments WHERE parent_guid>'P' ALLOW FILTERING
INSERT INTO comments(parent_guid_c1, id) VALUES ($1, $2);
INSERT INTO comments(parent_guid_c2, id) VALUES ($3, $4);
INSERT INTO comments(parent_guid_c3, id) VALUES ($5, $6);
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Not executable script because there are key columns that cannot be inserted
FOR $1 = SELECT id FROM scim_user
INSERT INTO scim_user_times(uid) VALUES ($1);
4 changes: 2 additions & 2 deletions modevo-script/dat/inp/creationSchema.cql
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ CREATE TABLE "testWireV8NewTableMigrationFromPreviousVersion".scim_user_times (
created_at text,
last_updated_at text,
uid text,
PRIMARY KEY (created_at, last_updated_at)
) WITH CLUSTERING ORDER BY ( last_updated_at ASC );
PRIMARY KEY (uid)
);

-- Export of keyspace testWireV91NewTableMigrationFromOneTable
CREATE KEYSPACE "testWireV91NewTableMigrationFromOneTable"
Expand Down
6 changes: 0 additions & 6 deletions modevo-transform/dat/inp/ThingsBoardCM.xmi
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@
<Attribute xmi:id="a1" name = "id" entity='e1' isUnique="true"/>
<Attribute xmi:id="a2" name = "name" entity='e1' isUnique="false"/>
<Attribute xmi:id="a3" name = "type" entity='e1' isUnique="false"/>

<Entity xmi:id="e2" name="device"/>
<Attribute xmi:id="a4" name = "dev_id" entity='e2' isUnique="true"/>
<Attribute xmi:id="a5" name = "dev_name" entity='e2' isUnique="false"/>
<Attribute xmi:id="a6" name = "dev_type" entity='e2' isUnique="false"/>

<Entity xmi:id="e3" name="tenant"/>
<Attribute xmi:id="a7" name = "ten_id" entity='e3' isUnique="true"/>

<Entity xmi:id="e4" name="customer"/>
<Attribute xmi:id="a8" name = "cus_id" entity='e4' isUnique="true"/>


<Relationship xmi:id="r2" name ="relation1" entity1="e1" entity2="e3" cardinality1="1" cardinality2="n" />
<Relationship xmi:id="r3" name ="relation2" entity1="e1" entity2="e4" cardinality1="1" cardinality2="n"/>
<Relationship xmi:id="r4" name ="relation3" entity1="e2" entity2="e3" entity3="e4" cardinality1="n" cardinality2="1" cardinality3="1"/>

</xmi:XMI>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="SchemaEvolution" xsi:schemaLocation="SchemaEvolution ../../src/main/java/giis/modevo/transformations/atl/Metamodels/SchemaEvolution.ecore">
<NewColumn xmi:id="a1" tab="a2"/>
<NewColumn xmi:id="a1" table="table2" columns="a3"/>
<Table xmi:id="a2" cols="a3" name="table2"/>
<Column xmi:id="a3" name="title" tab="a2" nameAttribute = "title" nameEntity = "Book"/>
</xmi:XMI>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="SchemaEvolution" xsi:schemaLocation="SchemaEvolution ../../src/main/java/giis/modevo/transformations/atl/Metamodels/SchemaEvolution.ecore">
<NewColumn xmi:id="a1" tab="a2"/>
<NewColumn xmi:id="a1" table="table2" columns = "a3 a4"/>
<Table xmi:id="a2" cols="a3 a4" name="table2"/>
<Column xmi:id="a3" name="title" tab="a2" nameAttribute = "title" nameEntity = "Book"/>
<Column xmi:id="a4" name="publisher" tab="a2" nameAttribute = "publisher" nameEntity = "Book"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="SchemaEvolution" xsi:schemaLocation="SchemaEvolution ../../src/main/java/giis/modevo/transformations/atl/Metamodels/SchemaEvolution.ecore">
<NewColumn xmi:id="a1" tab="a2"/>
<NewColumn xmi:id="a1" table="table2" columns="a3 a4"/>
<Table xmi:id="a2" cols="a3 a4" name="table2" NewTableName="table2New" isNew="true"/>
<Column xmi:id="a3" name="title" tab="a2" nameAttribute = "title" nameEntity = "Book"/>
<Column xmi:id="a4" name="idBook" tab="a2" nameAttribute = "id" nameEntity = "Book" key ="true"/>
Expand Down
12 changes: 6 additions & 6 deletions modevo-transform/dat/inp/testMindsV3SplitColumn-schemaChange.xmi
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
<CriteriaSplit
xmi:id="cs1"
column="c1"
value="f"
operator="g"/>
value="F"
operator="l"/>
<CriteriaSplit
xmi:id="cs2"
column="c2"
value="p"
operator="g"/>
value="P"
operator="l"/>
<CriteriaSplit
xmi:id="cs3"
column="c3"
value="p"
operator="l"/>
value="P"
operator="g"/>
</xmi:XMI>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="SchemaEvolution" xsi:schemaLocation="SchemaEvolution ../../src/main/java/giis/modevo/transformations/atl/Metamodels/SchemaEvolution.ecore">
<NewColumn xmi:id="a1" tab="a2"/>
<NewColumn xmi:id="a1" table="entity_view" columns ="a3"/>
<Table xmi:id="a2" cols="a3" name="entity_view"/>
<Column xmi:id="a3" name="dev_type" tab="a2" nameAttribute = "dev_type" nameEntity = "device"/>
</xmi:XMI>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="SchemaEvolution" xsi:schemaLocation="SchemaEvolution ../../src/main/java/giis/modevo/transformations/atl/Metamodels/SchemaEvolution.ecore">
<NewColumn xmi:id="a1"
tab="a2"/>
<NewColumn xmi:id="a1" table="entity_view2_old" columns="a3"/>
<Table xmi:id="a2"
cols="a3"
name="entity_view2_old"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="SchemaEvolution" xsi:schemaLocation="SchemaEvolution ../../src/main/java/giis/modevo/transformations/atl/Metamodels/SchemaEvolution.ecore">

<NewColumn xmi:id="a1"
tab="a2"/>
table="entity_view_devpk" columns="a3"/>
<Table xmi:id="a2"
name="entity_view_devpk" cols="a3">
</Table>
Expand Down
Loading

0 comments on commit 2d5d174

Please sign in to comment.