-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor external_source_event_type to a view
- Loading branch information
psubram3
committed
Jul 30, 2024
1 parent
060d2c3
commit 0649272
Showing
6 changed files
with
136 additions
and
88 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
db-tests/src/test/java/gov/nasa/jpl/aerie/database/ExternalEventTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package gov.nasa.jpl.aerie.database; | ||
|
||
import gov.nasa.jpl.aerie.database.PlanCollaborationTests.Activity; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.postgresql.util.PGInterval; | ||
import org.postgresql.util.PGobject; | ||
|
||
import javax.swing.plaf.basic.BasicInternalFrameTitlePane; | ||
import java.io.IOException; | ||
import java.sql.Connection; | ||
import java.sql.Date; | ||
import java.sql.SQLException; | ||
import java.time.Duration; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
@SuppressWarnings("SqlSourceToSinkFlow") | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
public class ExternalEventTests { | ||
private DatabaseTestHelper helper; | ||
private MerlinDatabaseTestHelper merlinHelper; | ||
private Connection connection; | ||
private int planId; | ||
|
||
@BeforeEach | ||
void beforeEach() throws SQLException { | ||
int fileId = merlinHelper.insertFileUpload(); | ||
int missionModelId = merlinHelper.insertMissionModel(fileId); | ||
planId = merlinHelper.insertPlan(missionModelId); | ||
} | ||
|
||
@AfterEach | ||
void afterEach() throws SQLException { | ||
helper.clearSchema("merlin"); | ||
} | ||
|
||
@BeforeAll | ||
void beforeAll() throws SQLException, IOException, InterruptedException { | ||
helper = new DatabaseTestHelper("external_event", "Activity Directive Changelog Tests"); | ||
connection = helper.connection(); | ||
merlinHelper = new MerlinDatabaseTestHelper(connection); | ||
} | ||
|
||
@AfterAll | ||
void afterAll() throws SQLException, IOException, InterruptedException { | ||
helper.close(); | ||
connection = null; | ||
helper = null; | ||
} | ||
|
||
private record ExternalEvent(int id, String key, int event_type_id, int source_id, Date start_time, PGInterval duration, String properties){} | ||
private record ExternalSource(int id, String key, int file_id, int source_type_id, int derivation_group_id, Date valid_at, Date start_time, Date end_time, Date created_at, String metadata){} | ||
private record ExternalEventType(int id, String name){} | ||
private record ExternalSourceType(int id, String name){} | ||
private record DerivationGroup(int id, String name, int source_type_id){} | ||
private record DerivedExternalEvent(int source_id, int file_id, int event_id, String event_key, int event_type_id, int derivation_group_id, Date start_time, String source_range, String valid_at){} | ||
|
||
// to test: | ||
// - upload file - creates source, creates dg, creates events, creates source type, creates event types | ||
// - delete file - should auto clear everything. add two sources, check everything still there after first deletion, then it disappears after second deletion | ||
// - derived events cases: | ||
// + rule 1 | ||
// + rule 2 | ||
// + rule 3 | ||
// + rule 4 | ||
// - test duplicate events by constraint | ||
@Test | ||
void uploadFile() throws SQLException { | ||
try (final var statement = connection.createStatement()) { | ||
final var res = statement.executeQuery( | ||
// language=sql | ||
""" | ||
SELECT * FROM merlin.external_event; | ||
""" | ||
); | ||
res.next(); | ||
System.out.println(res.getInt("id")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
deployment/postgres-init-db/sql/merlin/tables/external_event.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
create table external_event( | ||
id integer generated always as identity check ( id > 0 ), | ||
name text not null | ||
|
||
); |