Skip to content

Commit

Permalink
fix evil tab indents
Browse files Browse the repository at this point in the history
  • Loading branch information
tringuyen-yw committed Jul 28, 2020
1 parent f3822a6 commit d8f13bb
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ public UUID create(String spacecraft, String journeySummary) {
* Check result with
* select journey_id, spacecraft_name,summary,start,end,active from killrvideo.spacecraft_journey_catalog;
*/
public void takeoff(UUID journeyId, String spacecraft) {
cqlSession.execute(SimpleStatement.builder(SOLUTION_TAKEOFF)
.addPositionalValue(Instant.now())
.addPositionalValue(spacecraft)
.addPositionalValue(journeyId)
.build());
}
public void takeoff(UUID journeyId, String spacecraft) {
cqlSession.execute(SimpleStatement.builder(SOLUTION_TAKEOFF)
.addPositionalValue(Instant.now())
.addPositionalValue(spacecraft)
.addPositionalValue(journeyId)
.build());
}

/**
* Save a few readings
Expand Down Expand Up @@ -157,13 +157,13 @@ public void log(UUID journeyId, String spacecraft, double speed,
cqlSession.execute(bb.build());
}

public void landing(UUID journeyId, String spacecraft) {
cqlSession.execute(SimpleStatement.builder(SOLUTION_LANDING)
.addPositionalValue(Instant.now())
.addPositionalValue(spacecraft)
.addPositionalValue(journeyId)
.build());
}
public void landing(UUID journeyId, String spacecraft) {
cqlSession.execute(SimpleStatement.builder(SOLUTION_LANDING)
.addPositionalValue(Instant.now())
.addPositionalValue(spacecraft)
.addPositionalValue(journeyId)
.build());
}

public void delete(String spacecraft, UUID journeyId) {
BatchStatementBuilder bb = new BatchStatementBuilder(BatchType.LOGGED);
Expand Down Expand Up @@ -262,20 +262,20 @@ private SimpleStatement deleteLocationsStmt(String spacecraft, UUID journeyId) {
// == SOLUTIONS ==

private static final String SOLUTION_INSERT =
"INSERT INTO spacecraft_journey_catalog (spacecraft_name, journey_id, active, summary) "
+ "VALUES(?,?,?,?)";
"INSERT INTO spacecraft_journey_catalog (spacecraft_name, journey_id, active, summary) "
+ "VALUES(?,?,?,?)";

private static final String SOLUTION_TAKEOFF =
"UPDATE spacecraft_journey_catalog "
+ "SET active=true, start=? "
+ "WHERE spacecraft_name=? AND journey_id=?";
private static final String SOLUTION_TAKEOFF =
"UPDATE spacecraft_journey_catalog "
+ "SET active=true, start=? "
+ "WHERE spacecraft_name=? AND journey_id=?";

private static final String SOLUTION_LANDING =
"UPDATE spacecraft_journey_catalog "
+ "SET active=false, end=? "
+ "WHERE spacecraft_name=? AND journey_id=?";
private static final String SOLUTION_LANDING =
"UPDATE spacecraft_journey_catalog "
+ "SET active=false, end=? "
+ "WHERE spacecraft_name=? AND journey_id=?";

private static final String SOLUTION_READ_JOURNEY =
"SELECT * FROM spacecraft_journey_catalog "
+ "WHERE spacecraft_name=? AND journey_id=?";
"SELECT * FROM spacecraft_journey_catalog "
+ "WHERE spacecraft_name=? AND journey_id=?";
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ public void should_connect_to_Astra() {
.build()) {

// Then
Optional<CqlIdentifier> connectedKeyspace = cqlSession.getKeyspace();
Optional<CqlIdentifier> connectedKeyspace = cqlSession.getKeyspace();

Assertions.assertTrue(connectedKeyspace.isPresent(), "cqlSession must connect to a valid Keyspace");
Assertions.assertTrue(
connectedKeyspace.isPresent(),
"cqlSession should connect to a valid Keyspace"
);

Assertions.assertEquals(
connectedKeyspace.get().toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,43 @@
@RunWith(JUnitPlatform.class)
public class Ex04_Query5b_TakeOff extends TestFixtures implements DataModelConstants {

/**
* CHECK on Astra CQL Console:
* Must see: active=true, 'start' has valid timestamp
* SELECT * FROM killrvideo.spacecraft_journey_catalog WHERE spacecraft_name='Crew Dragon Endeavour,SpaceX' AND journey_id=8dfd0a30-c73b-11ea-b87b-1325d5aaa06b;
*/
@Test
public void takeoff_the_spacecraft() {
// When
LOGGER.info("9..8..7..6..5..4..3..2..1 Ignition");
journeyRepo.takeoff(
UUID.fromString(this.TEST_JOURNEYID),
this.TEST_SPACECRAFT
);
LOGGER.info("Journey {} has now taken off", this.TEST_JOURNEYID);

// Then
Optional<Journey> journey = this.findTestJourney();

Assertions.assertTrue(journey.isPresent(),
String.format(
"spacecraft_journey_catalog should have a row with\n" +
"spacecraft_name = '%s'" +
"journey_id = %s",
this.TEST_SPACECRAFT,
this.TEST_JOURNEYID)
);

Assertions.assertTrue(
journey.get().isActive(),
"Journey takeoff should set active = true"
);

Assertions.assertTrue(
journey.get().getStart().compareTo(Instant.now()) <= 0,
"Journey start timestamp should be <= now()"
);

LOGGER.info("SUCCESS");
}
/**
* CHECK on Astra CQL Console:
* Must see: active=true, 'start' has valid timestamp
* SELECT * FROM killrvideo.spacecraft_journey_catalog WHERE spacecraft_name='Crew Dragon Endeavour,SpaceX' AND journey_id=8dfd0a30-c73b-11ea-b87b-1325d5aaa06b;
*/
@Test
public void takeoff_the_spacecraft() {
// When
LOGGER.info("9..8..7..6..5..4..3..2..1 Ignition");
journeyRepo.takeoff(
UUID.fromString(this.TEST_JOURNEYID),
this.TEST_SPACECRAFT
);
LOGGER.info("Journey {} has now taken off", this.TEST_JOURNEYID);

// Then
Optional<Journey> journey = this.findTestJourney();

Assertions.assertTrue(journey.isPresent(),
String.format(
"spacecraft_journey_catalog should have a row with\n" +
"spacecraft_name = '%s'" +
"journey_id = %s",
this.TEST_SPACECRAFT,
this.TEST_JOURNEYID)
);

Assertions.assertTrue(
journey.get().isActive(),
"Journey takeoff should set active = true"
);

Assertions.assertTrue(
journey.get().getStart().compareTo(Instant.now()) <= 0,
"Journey start timestamp should be <= now()"
);

LOGGER.info("SUCCESS");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,53 @@
@RunWith(JUnitPlatform.class)
public class Ex06_Query5d_Landing extends TestFixtures implements DataModelConstants {

@Test
/**
* CHECK on Astra CQL Console:
* Must see: active=false, 'end' has valid timestamp
* SELECT * FROM killrvideo.spacecraft_journey_catalog WHERE spacecraft_name='Crew Dragon Endeavour,SpaceX' AND journey_id=8dfd0a30-c73b-11ea-b87b-1325d5aaa06b;
*/
public void landing_journey() {
// When
journeyRepo.landing(
UUID.fromString(this.TEST_JOURNEYID),
this.TEST_SPACECRAFT
);
LOGGER.info("Journey {} has now landed", this.TEST_JOURNEYID);
@Test
/**
* CHECK on Astra CQL Console:
* Must see: active=false, 'end' has valid timestamp
* SELECT * FROM killrvideo.spacecraft_journey_catalog WHERE spacecraft_name='Crew Dragon Endeavour,SpaceX' AND journey_id=8dfd0a30-c73b-11ea-b87b-1325d5aaa06b;
*/
public void landing_journey() {
// When
journeyRepo.landing(
UUID.fromString(this.TEST_JOURNEYID),
this.TEST_SPACECRAFT
);
LOGGER.info("Journey {} has now landed", this.TEST_JOURNEYID);

// Then
Optional<Journey> journey = this.findTestJourney();
// Then
Optional<Journey> journey = this.findTestJourney();

Assertions.assertTrue(journey.isPresent(),
String.format(
"spacecraft_journey_catalog should have a row with\n" +
"spacecraft_name = '%s'" +
"journey_id = %s",
this.TEST_SPACECRAFT,
this.TEST_JOURNEYID)
);
Assertions.assertTrue(journey.isPresent(),
String.format(
"spacecraft_journey_catalog should have a row with\n" +
"spacecraft_name = '%s'" +
"journey_id = %s",
this.TEST_SPACECRAFT,
this.TEST_JOURNEYID)
);

Assertions.assertFalse(
journey.get().isActive(),
"Journey takeoff should set active = false"
);
Assertions.assertFalse(
journey.get().isActive(),
"Journey takeoff should set active = false"
);

Instant startTimestamp = journey.get().getStart();
Instant endTimestamp = journey.get().getEnd();
Instant startTimestamp = journey.get().getStart();
Instant endTimestamp = journey.get().getEnd();

Assertions.assertTrue(
endTimestamp.compareTo(Instant.now()) <= 0,
"Journey end timestamp should be <= now()"
);
Assertions.assertTrue(
endTimestamp.compareTo(Instant.now()) <= 0,
"Journey end timestamp should be <= now()"
);

Assertions.assertTrue(
endTimestamp.isAfter(startTimestamp),
String.format(
"Journey end timestamp (%s) should be < start timestamp (%s)",
endTimestamp.toString(),
startTimestamp.toString())
);
Assertions.assertTrue(
endTimestamp.isAfter(startTimestamp),
String.format(
"Journey end timestamp (%s) should be < start timestamp (%s)",
endTimestamp.toString(),
startTimestamp.toString())
);

LOGGER.info("SUCCESS");
}
LOGGER.info("SUCCESS");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,58 @@
* Common setup for all tests
*/
public class TestFixtures {
/** Logger for the class. */
protected static Logger STATICLOGGER = LoggerFactory.getLogger(TestFixtures.class);
/** Logger for the class. */
protected static Logger STATICLOGGER = LoggerFactory.getLogger(TestFixtures.class);

/** Connect once for all tests. */
protected static CqlSession cqlSession;
/** Connect once for all tests. */
protected static CqlSession cqlSession;

/** Use the Repository Pattern. */
protected static JourneyRepository journeyRepo;
/** Use the Repository Pattern. */
protected static JourneyRepository journeyRepo;

// common logger used by test class instance
protected Logger LOGGER = LoggerFactory.getLogger(this.getClass());
// common logger used by test class instance
protected Logger LOGGER = LoggerFactory.getLogger(this.getClass());

// Common journey data for all tests
protected String TEST_SPACECRAFT = "Crew Dragon Endeavour,SpaceX";
protected String TEST_JOURNEYID = "8dfd0a30-c73b-11ea-b87b-1325d5aaa06b";
protected String TEST_JOURNEYSUMMARY = "Bring Astronauts to ISS";
// Common journey data for all tests
protected String TEST_SPACECRAFT = "Crew Dragon Endeavour,SpaceX";
protected String TEST_JOURNEYID = "8dfd0a30-c73b-11ea-b87b-1325d5aaa06b";
protected String TEST_JOURNEYSUMMARY = "Bring Astronauts to ISS";


@BeforeAll
public static void initConnection() {
STATICLOGGER.info("========================================");
STATICLOGGER.info("Init CqlSession");
//TestUtils.getInstance().createKeyspaceForLocalInstance();
@BeforeAll
public static void initConnection() {
STATICLOGGER.info("========================================");
STATICLOGGER.info("Init CqlSession");
//TestUtils.getInstance().createKeyspaceForLocalInstance();

AstraConnectionInfo conn = TestUtils.getInstance().getAstraDBConnectInfo();
AstraConnectionInfo conn = TestUtils.getInstance().getAstraDBConnectInfo();

cqlSession = CqlSession.builder()
.withCloudSecureConnectBundle(Paths.get(conn.getSecureBundleFilename()))
.withAuthCredentials(conn.getUserName(), conn.getPassword())
.withKeyspace(conn.getKeyspace())
.build();
STATICLOGGER.info("Init JourneyRepository");
journeyRepo = new JourneyRepository(cqlSession);
cqlSession = CqlSession.builder()
.withCloudSecureConnectBundle(Paths.get(conn.getSecureBundleFilename()))
.withAuthCredentials(conn.getUserName(), conn.getPassword())
.withKeyspace(conn.getKeyspace())
.build();
STATICLOGGER.info("Init JourneyRepository");
journeyRepo = new JourneyRepository(cqlSession);
}

@AfterAll
public static void closeConnectionToCassandra() {
if (null != cqlSession) {
STATICLOGGER.info("Closing CqlSession");
STATICLOGGER.info("========================================");
cqlSession.close();
}
}
@AfterAll
public static void closeConnectionToCassandra() {
if (null != cqlSession) {
STATICLOGGER.info("Closing CqlSession");
STATICLOGGER.info("========================================");
cqlSession.close();
}
}

/**
* Retrieve the single row of the "Test" Journey
* in the killrvideo.spacecraft_journey_catalog tableß
*/
protected Optional<Journey> findTestJourney() {
return journeyRepo.find(
UUID.fromString(this.TEST_JOURNEYID),
this.TEST_SPACECRAFT
);
}
/**
* Retrieve the single row of the "Test" Journey
* in the killrvideo.spacecraft_journey_catalog tableß
*/
protected Optional<Journey> findTestJourney() {
return journeyRepo.find(
UUID.fromString(this.TEST_JOURNEYID),
this.TEST_SPACECRAFT
);
}
}
Loading

0 comments on commit d8f13bb

Please sign in to comment.