From d8f13bb92bfea149c059229b2a462933db9273c6 Mon Sep 17 00:00:00 2001 From: TriNguyen Date: Mon, 27 Jul 2020 17:59:07 -0400 Subject: [PATCH] fix evil tab indents --- .../datastax/workshop/JourneyRepository.java | 52 +++++------ .../workshop/Ex02_Connect_to_Cassandra.java | 7 +- .../workshop/Ex04_Query5b_TakeOff.java | 78 ++++++++--------- .../workshop/Ex06_Query5d_Landing.java | 84 +++++++++--------- .../com/datastax/workshop/TestFixtures.java | 86 +++++++++---------- .../java/com/datastax/workshop/TestUtils.java | 42 ++++----- 6 files changed, 176 insertions(+), 173 deletions(-) diff --git a/week3-AppDev-crud/crud-java/src/main/java/com/datastax/workshop/JourneyRepository.java b/week3-AppDev-crud/crud-java/src/main/java/com/datastax/workshop/JourneyRepository.java index 75b47ac0..44862b67 100644 --- a/week3-AppDev-crud/crud-java/src/main/java/com/datastax/workshop/JourneyRepository.java +++ b/week3-AppDev-crud/crud-java/src/main/java/com/datastax/workshop/JourneyRepository.java @@ -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 @@ -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); @@ -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=?"; } diff --git a/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/Ex02_Connect_to_Cassandra.java b/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/Ex02_Connect_to_Cassandra.java index 1daf164f..951f6cc8 100644 --- a/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/Ex02_Connect_to_Cassandra.java +++ b/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/Ex02_Connect_to_Cassandra.java @@ -62,9 +62,12 @@ public void should_connect_to_Astra() { .build()) { // Then - Optional connectedKeyspace = cqlSession.getKeyspace(); + Optional 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(), diff --git a/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/Ex04_Query5b_TakeOff.java b/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/Ex04_Query5b_TakeOff.java index 4d9222b4..d8f63d5d 100644 --- a/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/Ex04_Query5b_TakeOff.java +++ b/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/Ex04_Query5b_TakeOff.java @@ -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 = 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 = 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"); + } } diff --git a/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/Ex06_Query5d_Landing.java b/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/Ex06_Query5d_Landing.java index af1fc4c9..9224ae76 100644 --- a/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/Ex06_Query5d_Landing.java +++ b/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/Ex06_Query5d_Landing.java @@ -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 = this.findTestJourney(); + // Then + Optional 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"); + } } diff --git a/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/TestFixtures.java b/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/TestFixtures.java index 21941f05..9b616fef 100644 --- a/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/TestFixtures.java +++ b/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/TestFixtures.java @@ -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 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 findTestJourney() { + return journeyRepo.find( + UUID.fromString(this.TEST_JOURNEYID), + this.TEST_SPACECRAFT + ); + } } \ No newline at end of file diff --git a/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/TestUtils.java b/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/TestUtils.java index 078b5163..6d8a1dea 100644 --- a/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/TestUtils.java +++ b/week3-AppDev-crud/crud-java/src/test/java/com/datastax/workshop/TestUtils.java @@ -40,37 +40,37 @@ public void createKeyspaceForLocalInstance() { } } - /** - * Read Astra Connection config values from src/main/resources/application.conf - * These configs are unrelated to Cassandra driver config. - * We just leverage the HOCON config format of the Typesafe Config framework - * which is implemented in the DataStax driver to allow us to read the custom config - * https://docs.datastax.com/en/developer/java-driver/4.6/manual/core/configuration/ - */ - public AstraConnectionInfo getAstraDBConnectInfo() { - final String configSection = "AstraConnectionAuth"; + /** + * Read Astra Connection config values from src/main/resources/application.conf + * These configs are unrelated to Cassandra driver config. + * We just leverage the HOCON config format of the Typesafe Config framework + * which is implemented in the DataStax driver to allow us to read the custom config + * https://docs.datastax.com/en/developer/java-driver/4.6/manual/core/configuration/ + */ + public AstraConnectionInfo getAstraDBConnectInfo() { + final String configSection = "AstraConnectionAuth"; AstraConnectionInfo connectInfo = null; try { - // Make sure we see the changes when reloading: - ConfigFactory.invalidateCaches(); + // Make sure we see the changes when reloading: + ConfigFactory.invalidateCaches(); - // Every config file in the classpath, without stripping the prefixes - Config rootConfig = ConfigFactory.load(); + // Every config file in the classpath, without stripping the prefixes + Config rootConfig = ConfigFactory.load(); - // The Custom config section added in resources/application.conf: - Config astraConnCfg = rootConfig.getConfig(configSection); + // The Custom config section added in resources/application.conf: + Config astraConnCfg = rootConfig.getConfig(configSection); - String secureBundleFilename = astraConnCfg.getString("SECURE_CONNECT_BUNDLE_FILE"); - String userName = astraConnCfg.getString("USERNAME"); - String clearPwd = astraConnCfg.getString("PASSWORD"); - String keyspaceName = astraConnCfg.getString("KEYSPACE"); + String secureBundleFilename = astraConnCfg.getString("SECURE_CONNECT_BUNDLE_FILE"); + String userName = astraConnCfg.getString("USERNAME"); + String clearPwd = astraConnCfg.getString("PASSWORD"); + String keyspaceName = astraConnCfg.getString("KEYSPACE"); connectInfo = new AstraConnectionInfo(secureBundleFilename, userName, clearPwd, keyspaceName); } catch (ConfigException ex) { - String errMsg = String.format("Missing section %s in src/main/resources/application.conf", configSection); - LOGGER.error(errMsg); + String errMsg = String.format("Missing section %s in src/main/resources/application.conf", configSection); + LOGGER.error(errMsg); ex.printStackTrace(); }