Skip to content
Snippets Groups Projects
Unverified Commit cd7d8ace authored by Martin Weise's avatar Martin Weise
Browse files

Fixed the tests

parent 8517a0e4
No related branches found
No related tags found
2 merge requests!163Relase 1.3.0,!160Resolve "Query alias causes mapping issue"
Showing with 278 additions and 132 deletions
......@@ -54,6 +54,7 @@ public class View {
@Column(name = "createdBy", nullable = false, columnDefinition = "VARCHAR(36)")
private UUID createdBy;
@ToString.Exclude
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumns({
@JoinColumn(name = "createdBy", referencedColumnName = "ID", insertable = false, updatable = false)
......
......@@ -5,7 +5,6 @@ import at.tuwien.entities.database.View;
import at.tuwien.entities.database.table.Table;
import at.tuwien.entities.user.User;
import lombok.*;
import lombok.extern.log4j.Log4j2;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
......@@ -17,7 +16,7 @@ import java.util.List;
@Data
@Entity
@Builder
@Builder(toBuilder=true)
@ToString
@AllArgsConstructor
@NoArgsConstructor
......@@ -148,10 +147,13 @@ public class TableColumn implements Comparable<TableColumn> {
* @return True if columns are equal, false otherwise
*/
public boolean equals(Object object) {
if (!(object instanceof TableColumn)) {
if (object == null) {
return false;
}
final TableColumn other = (TableColumn) object;
return this.getId().equals(other.getId()) && this.getTid().equals(other.getTid()) && this.getCdbid().equals(other.getCdbid());
if (!(object instanceof final TableColumn other)) {
return false;
}
return this.getId().equals(other.getId()) && this.getTid().equals(other.getTid())
&& this.getCdbid().equals(other.getCdbid());
}
}
......@@ -48,9 +48,9 @@ VALUES ('2022-12-24 17:00:00', 10.0),
CREATE VIEW junit2 AS
(
SELECT `location`, `lat`, `lng`
FROM `weather_location`
WHERE `location` = 'Albury');
select `date`, `location`, `mintemp`, `rainfall`
from `weather_aus`
where `location` = 'Albury');
CREATE VIEW `hs_weather_aus` AS
SELECT *
......
......@@ -22,6 +22,8 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
......@@ -37,11 +39,9 @@ public class ViewRepositoryIntegrationTest extends BaseUnitTest {
@MockBean
private Channel channel;
/* keep */
@MockBean
private RabbitMqListenerImpl rabbitMqListener;
/* keep */
@MockBean
private BrokerServiceGateway brokerServiceGateway;
......@@ -54,31 +54,37 @@ public class ViewRepositoryIntegrationTest extends BaseUnitTest {
@Autowired
private UserRepository userRepository;
@Autowired
private RealmRepository realmRepository;
@Autowired
private ContainerRepository containerRepository;
@Autowired
private DatabaseRepository databaseRepository;
private TableRepository tableRepository;
@Autowired
private ViewRepository viewRepository;
private TableColumnRepository tableColumnRepository;
@Autowired
private DatabaseRepository databaseRepository;
@Autowired
private H2Utils h2Utils;
private ViewRepository viewRepository;
@Rule
public Timeout globalTimeout = Timeout.seconds(60);
@BeforeEach
public void beforeEach() {
realmRepository.save(REALM_DBREPO);
userRepository.save(USER_1);
imageRepository.save(IMAGE_1);
containerRepository.save(CONTAINER_1);
DATABASE_1.setTables(List.of());
DATABASE_1.setViews(List.of());
databaseRepository.save(DATABASE_1);
containerRepository.save(CONTAINER_1_SIMPLE);
databaseRepository.save(DATABASE_1_SIMPLE);
tableRepository.saveAll(List.of(TABLE_1, TABLE_2, TABLE_3, TABLE_7));
viewRepository.save(VIEW_1);
viewRepository.save(VIEW_2);
viewRepository.save(VIEW_3);
viewRepository.save(VIEW_3);
}
......@@ -87,15 +93,7 @@ public class ViewRepositoryIntegrationTest extends BaseUnitTest {
/* test */
final List<View> response = viewRepository.findAllPublicByDatabaseId(DATABASE_1_ID);
assertEquals(2, response.size());
final View view1 = response.get(0);
assertEquals(VIEW_1_ID, view1.getId());
assertEquals(VIEW_1_CONTAINER_ID, view1.getVcid());
assertEquals(VIEW_1_DATABASE_ID, view1.getVdbid());
final View view2 = response.get(1);
assertEquals(VIEW_2_ID, view2.getId());
assertEquals(VIEW_2_CONTAINER_ID, view2.getVcid());
assertEquals(VIEW_2_DATABASE_ID, view2.getVdbid());
assertEquals(0, response.size());
}
@Test
......@@ -103,19 +101,11 @@ public class ViewRepositoryIntegrationTest extends BaseUnitTest {
/* test */
final List<View> response = viewRepository.findAllPublicOrMineByDatabaseId(DATABASE_1_ID, USER_1_USERNAME);
assertEquals(3, response.size());
assertEquals(1, response.size());
final View view1 = response.get(0);
assertEquals(VIEW_1_ID, view1.getId());
assertEquals(VIEW_1_CONTAINER_ID, view1.getVcid());
assertEquals(VIEW_1_DATABASE_ID, view1.getVdbid());
final View view2 = response.get(1);
assertEquals(VIEW_2_ID, view2.getId());
assertEquals(VIEW_2_CONTAINER_ID, view2.getVcid());
assertEquals(VIEW_2_DATABASE_ID, view2.getVdbid());
final View view3 = response.get(2);
assertEquals(VIEW_3_ID, view3.getId());
assertEquals(VIEW_3_CONTAINER_ID, view3.getVcid());
assertEquals(VIEW_3_DATABASE_ID, view3.getVdbid());
assertEquals(VIEW_3_ID, view1.getId());
assertEquals(VIEW_3_CONTAINER_ID, view1.getVcid());
assertEquals(VIEW_3_DATABASE_ID, view1.getVdbid());
}
}
......@@ -10,7 +10,6 @@ import at.tuwien.config.MariaDbConfig;
import at.tuwien.config.ReadyConfig;
import at.tuwien.exception.*;
import at.tuwien.gateway.BrokerServiceGateway;
import at.tuwien.listener.MessageQueueListener;
import at.tuwien.listener.impl.RabbitMqListenerImpl;
import at.tuwien.querystore.Query;
import at.tuwien.repository.jpa.*;
......@@ -86,19 +85,6 @@ public class QueryServiceIntegrationTest extends BaseUnitTest {
private final static String BIND_ZOO = new File("../../dbrepo-metadata-db/test/src/test/resources/zoo").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d";
@BeforeAll
public static void beforeAll() {
afterAll();
/* create network */
DockerConfig.createAllNetworks();
}
@AfterAll
public static void afterAll() {
DockerConfig.removeAllContainers();
DockerConfig.removeAllNetworks();
}
@BeforeEach
public void beforeEach() {
afterEach();
......@@ -106,17 +92,9 @@ public class QueryServiceIntegrationTest extends BaseUnitTest {
DockerConfig.createAllNetworks();
/* metadata database */
DATABASE_1.setTables(List.of(TABLE_1, TABLE_2, TABLE_3, TABLE_7));
TABLE_1.setDatabase(DATABASE_1);
TABLE_1.setColumns(TABLE_1_COLUMNS);
TABLE_2.setDatabase(DATABASE_1);
TABLE_3.setDatabase(DATABASE_1);
TABLE_7.setDatabase(DATABASE_1);
DATABASE_1.setViews(List.of(VIEW_2, VIEW_3));
DATABASE_2.setTables(List.of(TABLE_4, TABLE_5, TABLE_6));
DATABASE_2.setViews(List.of(VIEW_4));
TABLE_4.setDatabase(DATABASE_2);
TABLE_5.setDatabase(DATABASE_2);
TABLE_6.setDatabase(DATABASE_2);
VIEW_4.setDatabase(DATABASE_2);
}
@AfterEach
......
......@@ -129,22 +129,20 @@ public class ViewServiceIntegrationTest extends BaseUnitTest {
assertEquals(VIEW_3_INTERNAL_NAME, response.getInternalName());
assertEquals(VIEW_3_QUERY, response.getQuery());
final List<Map<String, String>> resultSet = MariaDbConfig.selectQuery(CONTAINER_1_INTERNALNAME, DATABASE_1_INTERNALNAME,
"SELECT j.* FROM `debug` j", "mintemp", "rainfall", "location", "lat", "lng");
"SELECT j.* FROM `debug` j", "mintemp", "rainfall", "date", "location");
assertEquals("13.4", resultSet.get(0).get("mintemp"));
assertEquals("0.6", resultSet.get(0).get("rainfall"));
assertEquals("Albury", resultSet.get(0).get("location"));
assertEquals("-36.0653583", resultSet.get(0).get("lat"));
assertEquals("146.9112214", resultSet.get(0).get("lng"));
assertEquals("2008-12-01", resultSet.get(0).get("date"));
assertEquals("7.4", resultSet.get(1).get("mintemp"));
assertEquals("0", resultSet.get(1).get("rainfall"));
assertEquals("Albury", resultSet.get(1).get("location"));
assertEquals("-36.0653583", resultSet.get(1).get("lat"));
assertEquals("146.9112214", resultSet.get(1).get("lng"));
assertEquals("2008-12-01", resultSet.get(1).get("date"));
assertEquals("12.9", resultSet.get(2).get("mintemp"));
assertEquals("0", resultSet.get(2).get("rainfall"));
assertEquals("Albury", resultSet.get(2).get("location"));
assertEquals("-36.0653583", resultSet.get(2).get("lat"));
assertEquals("146.9112214", resultSet.get(2).get("lng"));
assertEquals("2008-12-01", resultSet.get(2).get("date"));
/* more result checks omitted */
}
@Test
......
......@@ -44,7 +44,6 @@ import java.time.Instant;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
......@@ -477,30 +476,29 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService
log.trace("columns referenced in the from-clause and join-clause(s): {}", clauses);
/* Checking if all tables or views exist */
final List<TableColumn> allColumns = new ArrayList<>();
for (FromItem fromItem : tablesOrViews) {
database.getTables()
.stream()
.filter(table -> table.equals(fromItem))
.forEach(table -> {
table.getColumns()
.forEach(column -> {
column.setTable(table);
final TableColumn tmp = column.toBuilder() /* copy constructor */
.table(table)
.build();
allColumns.add(tmp);
});
allColumns.addAll(table.getColumns());
});
database.getViews()
.stream()
.filter(view -> view.equals(fromItem))
.forEach(view -> {
view.getColumns()
.forEach(column -> {
column.setView(view);
final TableColumn tmp = column.toBuilder() /* copy constructor */
.view(view)
.build();
allColumns.add(tmp);
});
allColumns.addAll(view.getColumns());
});
}
final List<TableColumn> col = allColumns.stream().filter(c -> c.getInternalName().equals("date")).toList();
log.trace("");
log.trace("table(s) or view(s) referenced in the statement: {}", tablesOrViews.stream().map(t -> ((net.sf.jsqlparser.schema.Table) t).getName()).collect(Collectors.toList()));
log.trace("column(s) referenced in the statement: {}", allColumns.stream().map(c -> (c.getTable() == null ? c.getView().getInternalName() : c.getTable().getInternalName()) + "." + c.getInternalName()).collect(Collectors.toList()));
/* Checking if all columns exist */
for (SelectItem clause : clauses) {
final SelectExpressionItem item = (SelectExpressionItem) clause;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment