diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dbba32..ea6f5fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ # Blockchain API Unreleased -*v0.0.15* +*v0.0.17* + +**11/7/23** + +- [ADD Nodes Health Check Service and Endpoint](#54) **10/31/23** diff --git a/README.md b/README.md index f36e872..b5b1b4a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Blockchain API -**Last Updated:** 10/31/23 +**Last Updated:** 11/2/23 This is the API and backend code for the blockchain project. @@ -29,44 +29,60 @@ mvn javadoc:javadoc ## Endpoints The current serviceable endpoints are as follows: -### Verify Blockchain +### GET http://localhost:8080/api/v1/blockchain/verifyBlockchain -### Get Blockchain +### GET http://localhost:8080/api/v1/blockchain/getBlockchain -### Get Block By Id +### GET http://localhost:8080/api/v1/blockchain/getBlockById -### Add Block to Blockchain +### POST http://localhost:8080/api/v1/block/addBlockToBlockchain +Content-Type: application/x-www-form-urlencoded -### Update Production -GET http://localhost:8080/api/v1/healthMetric/updateProduction +### +GET http://localhost:8080/api/v1/healthMetric/updateProductionHealth -### Get Production +### GET http://localhost:8080/api/v1/healthMetric/getProductionHealth -### Get Health -GET http://localhost:8080/api/v1/healthMetric/health +### +GET http://localhost:8080/api/v1/healthMetric/getExceptionHealth -### Get Readiness +### GET http://localhost:8080/api/v1/readiness -### Get Liveness +### GET http://localhost:8080/api/v1/liveness -### Get Version +### GET http://localhost:8080/api/v1/version -### Verify Blockchain -GET http://localhost:8080/api/v1/verifyBlockchain +### +GET http://localhost:8080/api/v1/node/getNodeStatus -### Submit Transaction +### +POST http://localhost:8080/api/v1/nodeManager/registerNode +Content-Type: application/json + +{} + +### +GET http://localhost:8080/api/v1/nodeManager/getNodeNetworkStatus + +### +GET http://localhost:8080/api/v1/nodeManager/nodeNetworkRollCall + +### POST http://localhost:8080/api/v1/transaction/submitTransaction +Content-Type: application/json + +{} -### Get Transaction Pool -GET /api/v1/transaction/getTransactionPool +### +GET http://localhost:8080/api/v1/transaction/getTransactionPool --- diff --git a/SCRATCH.md b/SCRATCH.md index ec02cba..e69de29 100644 --- a/SCRATCH.md +++ b/SCRATCH.md @@ -1,11 +0,0 @@ -### Get Production Payload - -```json - -{ - "data": { - "dataset1": [5, 13, 23, 24, 12, 8, 5, 0, 0, 0, 0, 0], - "dataset2": [1, 1, 3, 2, 1, 1, 1, 0, 0, 0, 0, 0 ] - } -} -``` \ No newline at end of file diff --git a/VERSION.txt b/VERSION.txt index e484aaf..927734f 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.0.16 \ No newline at end of file +0.0.17 \ No newline at end of file diff --git a/src/main/java/com/hunteryavitz/blockchainapi/constants/AppConstants.java b/src/main/java/com/hunteryavitz/blockchainapi/constants/AppConstants.java new file mode 100644 index 0000000..f9d1955 --- /dev/null +++ b/src/main/java/com/hunteryavitz/blockchainapi/constants/AppConstants.java @@ -0,0 +1,31 @@ +package com.hunteryavitz.blockchainapi.constants; + +import lombok.Getter; +import org.springframework.beans.factory.annotation.Value; + +/** + * Constants for the application. + */ +public class AppConstants { + + /** + * The node manager registry address. + */ + @Value("${REGISTRY_ADDRESS}") + @Getter + private static String registryAddress; + + /** + * The node certificate. + */ + @Value("${CERTIFICATE}") + @Getter + private static String certificate; + + /** + * The node port. + */ + @Value("${PORT}") + @Getter + private static int port; +} diff --git a/src/main/java/com/hunteryavitz/blockchainapi/constants/NodeStatus.java b/src/main/java/com/hunteryavitz/blockchainapi/constants/NodeStatus.java new file mode 100644 index 0000000..babe8e2 --- /dev/null +++ b/src/main/java/com/hunteryavitz/blockchainapi/constants/NodeStatus.java @@ -0,0 +1,32 @@ +package com.hunteryavitz.blockchainapi.constants; + +/** + * The NodeStatus enum represents the status of a node. + */ +public enum NodeStatus { + + /** + * The node is inactive. + */ + INACTIVE, + + /** + * The node is active. + */ + ACTIVE, + + /** + * The node is unresponsive. + */ + UNRESPONSIVE, + + /** + * The node is unregistered. + */ + UNREGISTERED, + + /** + * The node failed registration. + */ + FAILED_REGISTRATION +} diff --git a/src/main/java/com/hunteryavitz/blockchainapi/constants/Status.java b/src/main/java/com/hunteryavitz/blockchainapi/constants/TransactionStatus.java similarity index 96% rename from src/main/java/com/hunteryavitz/blockchainapi/constants/Status.java rename to src/main/java/com/hunteryavitz/blockchainapi/constants/TransactionStatus.java index 4fdcaea..4cab638 100644 --- a/src/main/java/com/hunteryavitz/blockchainapi/constants/Status.java +++ b/src/main/java/com/hunteryavitz/blockchainapi/constants/TransactionStatus.java @@ -3,11 +3,13 @@ /** * The Status enum represents the status of an order. */ -public enum Status { +public enum TransactionStatus { + /** * The order has been created. */ CREATED, + /** * The order is pending. */ diff --git a/src/main/java/com/hunteryavitz/blockchainapi/controllers/BlockController.java b/src/main/java/com/hunteryavitz/blockchainapi/controllers/BlockController.java index ee64cc8..e80b1ca 100644 --- a/src/main/java/com/hunteryavitz/blockchainapi/controllers/BlockController.java +++ b/src/main/java/com/hunteryavitz/blockchainapi/controllers/BlockController.java @@ -3,6 +3,7 @@ import com.hunteryavitz.blockchainapi.constants.ContaminationLevel; import com.hunteryavitz.blockchainapi.services.BlockchainService; import com.hunteryavitz.blockchainapi.services.HealthMetricService; +import jakarta.websocket.server.PathParam; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PostMapping; @@ -28,39 +29,41 @@ public class BlockController { private final HealthMetricService healthMetricService; /** - * The BlockController constructor is responsible for initializing the + * The BlockController constructor is responsible for initializing the controller. * @param blockchainService The blockchain service. * @param healthMetricService The health metric service. */ public BlockController(BlockchainService blockchainService, HealthMetricService healthMetricService) { this.blockchainService = blockchainService; this.healthMetricService = healthMetricService; + try { if (blockchainService.getBlockchain() == null) { blockchainService.createInitialBlockchain(); } - if (healthMetricService.getProduction() == null) { - healthMetricService.createHealthMetricService(); - } } catch (Exception exception) { - assert healthMetricService != null; healthMetricService.updateHealth(ContaminationLevel.CRITICAL, exception); } } /** * The addBlockToBlockchain method is responsible for adding a block to the blockchain. + * @param test The test query parameter. * @return A ResponseEntity containing a boolean indicating whether the block was added to the blockchain. */ @PostMapping("/addBlockToBlockchain") - public ResponseEntity addBlockToBlockchain() { + public ResponseEntity addBlockToBlockchain(@PathParam("test") boolean test) { try { blockchainService.addBlockToBlockchain(); + if (test) { + throw new Exception("Test exception"); + } + + return ResponseEntity.ok(true); } catch (Exception exception) { healthMetricService.updateHealth(ContaminationLevel.WARNING, exception); - return ResponseEntity.ok(false); } - return ResponseEntity.ok(true); + return ResponseEntity.ok(false); } } diff --git a/src/main/java/com/hunteryavitz/blockchainapi/controllers/BlockchainController.java b/src/main/java/com/hunteryavitz/blockchainapi/controllers/BlockchainController.java index 750d78c..27cb918 100644 --- a/src/main/java/com/hunteryavitz/blockchainapi/controllers/BlockchainController.java +++ b/src/main/java/com/hunteryavitz/blockchainapi/controllers/BlockchainController.java @@ -4,7 +4,7 @@ import com.hunteryavitz.blockchainapi.entities.Block; import com.hunteryavitz.blockchainapi.services.BlockchainService; import com.hunteryavitz.blockchainapi.services.HealthMetricService; -import org.springframework.beans.factory.annotation.Autowired; +import jakarta.websocket.server.PathParam; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -57,37 +57,50 @@ public ResponseEntity verifyBlockchain() { } catch (Exception exception) { healthMetricService.updateHealth(ContaminationLevel.CRITICAL, exception); } + return ResponseEntity.ok(false); } /** * The getBlockchain method is the endpoint for getting the blockchain. + * @param test The test query parameter. * @return A ResponseEntity containing the blockchain. */ @GetMapping("/getBlockchain") - public ResponseEntity getBlockchain() { + public ResponseEntity getBlockchain(@PathParam("test") boolean test) { try { Block[] blockchain = blockchainService.getBlockchain(); + if (test) { + throw new Exception("Empty blockchain"); + } + return ResponseEntity.ok(blockchain); } catch (Exception exception) { healthMetricService.updateHealth(ContaminationLevel.WARNING, exception); } - return ResponseEntity.ok(null); + + return ResponseEntity.ok(new Block[0]); } /** * The getBlockById method is the endpoint for getting a block by its id. * @param id The id of the block. + * @param test The test query parameter. * @return A ResponseEntity containing the block. */ @GetMapping("/getBlockById") - public ResponseEntity getBlockById(@RequestParam int id) { + public ResponseEntity getBlockById(@RequestParam int id, @PathParam("test") boolean test) { try { Block block = blockchainService.getBlockById(id); + if (test) { + throw new Exception("Empty block"); + } + return ResponseEntity.ok(block); } catch (Exception exception) { healthMetricService.updateHealth(ContaminationLevel.WARNING, exception); } - return ResponseEntity.ok(null); + + return ResponseEntity.ok(new Block()); } } diff --git a/src/main/java/com/hunteryavitz/blockchainapi/controllers/HealthMetricController.java b/src/main/java/com/hunteryavitz/blockchainapi/controllers/HealthMetricController.java index 5250fa3..8ff3c77 100644 --- a/src/main/java/com/hunteryavitz/blockchainapi/controllers/HealthMetricController.java +++ b/src/main/java/com/hunteryavitz/blockchainapi/controllers/HealthMetricController.java @@ -3,6 +3,7 @@ import com.hunteryavitz.blockchainapi.constants.ContaminationLevel; import com.hunteryavitz.blockchainapi.services.HealthMetricService; import com.hunteryavitz.blockchainapi.utils.structures.SlidingWindow; +import jakarta.websocket.server.PathParam; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; @@ -28,25 +29,21 @@ public class HealthMetricController { */ public HealthMetricController(HealthMetricService healthMetricService) { this.healthMetricService = healthMetricService; - - try { - if (healthMetricService.getProduction() == null) { - healthMetricService.createHealthMetricService(); - } - } catch (Exception exception) { - assert healthMetricService != null; - healthMetricService.updateHealth(ContaminationLevel.CRITICAL, exception); - } } /** * Updates the health metric. + * @param test The test query parameter. * @return A ResponseEntity containing a boolean indicating whether the health metric was updated. */ - @GetMapping("/updateProduction") - public ResponseEntity updateProduction() { + @GetMapping("/updateProductionHealth") + public ResponseEntity updateProductionHealth(@PathParam("test") boolean test) { try { healthMetricService.updateBlockchainProduction(); + if (test) { + throw new Exception("Test exception"); + } + return ResponseEntity.ok(true); } catch (Exception exception) { healthMetricService.updateHealth(ContaminationLevel.INFO, exception); @@ -57,12 +54,17 @@ public ResponseEntity updateProduction() { /** * Gets the production health. + * @param test The test query parameter. * @return The production health. */ @GetMapping("/getProductionHealth") - public ResponseEntity getProductionHealth() { + public ResponseEntity getProductionHealth(@PathParam("test") boolean test) { try { SlidingWindow slidingWindow = healthMetricService.getProduction(); + if (test) { + throw new Exception("Test exception"); + } + return ResponseEntity.ok(slidingWindow.asJson()); } catch (Exception exception) { healthMetricService.updateHealth(ContaminationLevel.INFO, exception); @@ -73,11 +75,16 @@ public ResponseEntity getProductionHealth() { /** * Gets the production health. + * @param test The test query parameter. * @return The production health. */ - @GetMapping("/health") - public ResponseEntity getHealth() { + @GetMapping("/getExceptionHealth") + public ResponseEntity getExceptionHealth(@PathParam("test") boolean test) { try { + if (test) { + throw new Exception("Test exception"); + } + return ResponseEntity.ok(HealthMetricService.getHealth()); } catch (Exception exception) { healthMetricService.updateHealth(ContaminationLevel.INFO, exception); diff --git a/src/main/java/com/hunteryavitz/blockchainapi/controllers/MainController.java b/src/main/java/com/hunteryavitz/blockchainapi/controllers/MainController.java index 8ce949d..67832fa 100644 --- a/src/main/java/com/hunteryavitz/blockchainapi/controllers/MainController.java +++ b/src/main/java/com/hunteryavitz/blockchainapi/controllers/MainController.java @@ -4,6 +4,7 @@ import com.hunteryavitz.blockchainapi.services.BlockchainService; import com.hunteryavitz.blockchainapi.services.HealthMetricService; import com.hunteryavitz.blockchainapi.utils.Utils; +import jakarta.websocket.server.PathParam; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; @@ -34,7 +35,6 @@ public class MainController { * @param healthMetricService The health metric service. */ public MainController(BlockchainService blockchainService, HealthMetricService healthMetricService) { - this.blockchainService = blockchainService; this.healthMetricService = healthMetricService; @@ -42,90 +42,70 @@ public MainController(BlockchainService blockchainService, HealthMetricService h if (blockchainService.getBlockchain() == null) { blockchainService.createInitialBlockchain(); } - if (healthMetricService.getProduction() == null) { - healthMetricService.createHealthMetricService(); - } } catch (Exception exception) { - assert healthMetricService != null; healthMetricService.updateHealth(ContaminationLevel.CRITICAL, exception); } } /** - * Returns a 200 response to indicate that the API is ready to accept requests. - * @return 200 response + * Returns a 200 response and true to indicate that the API is ready to accept requests. + * @param test The test query parameter. + * @return 200 response and true */ @GetMapping("/readiness") - public ResponseEntity isReady() { - - // application is running - // service passes checks - // blockchain is valid - // files - // database - // web services - + public ResponseEntity isReady(@PathParam("test") boolean test) { try { blockchainService.checkReadiness(); + if (test) { + throw new Exception("Test exception"); + } + + return ResponseEntity.ok(true); } catch (Exception exception) { healthMetricService.updateHealth(ContaminationLevel.WARNING, exception); - return ResponseEntity.ok(false); } - return ResponseEntity.ok(true); + return ResponseEntity.ok(false); } /** * Returns a 200 response to indicate that the API is alive. + * @param test The test query parameter. * @return 200 response */ @GetMapping("/liveness") - public ResponseEntity isAlive() { - int isAlive; - + public ResponseEntity isAlive(@PathParam("test") boolean test) { try { - isAlive = blockchainService.isAlive(); + if (test) { + throw new Exception("Test exception"); + } + + return ResponseEntity.ok(blockchainService.isAlive()); } catch (Exception exception) { healthMetricService.updateHealth(ContaminationLevel.ERROR, exception); - return ResponseEntity.ok(-1); } - return ResponseEntity.ok(isAlive); + return ResponseEntity.ok(-1); } /** * Returns the version of the API. + * @param test The test query parameter. * @return 200 response with the version of the API */ @GetMapping("/version") - public ResponseEntity getVersion() { - String version; - + public ResponseEntity getVersion(@PathParam("test") boolean test) { try { String filePath = "VERSION.txt"; - version = Utils.readFileToString(filePath); - } catch (Exception exception) { - healthMetricService.updateHealth(ContaminationLevel.WARNING, exception); - return ResponseEntity.ok(null); - } - - return ResponseEntity.ok(version); - } - - /** - * Returns the blockchain. - * @return 200 response with the blockchain - */ - @GetMapping("/verifyBlockchain") - public ResponseEntity verifyBlockchain() { - try { - if (blockchainService.verifyBlockchain()) { - return ResponseEntity.ok(true); + if (test) { + throw new Exception("Test exception"); } + + return ResponseEntity.ok(Utils.readFileToString(filePath).trim()); } catch (Exception exception) { - healthMetricService.updateHealth(ContaminationLevel.CRITICAL, exception); + healthMetricService.updateHealth(ContaminationLevel.WARNING, exception); } - return ResponseEntity.ok(false); + return ResponseEntity.ok(""); } } diff --git a/src/main/java/com/hunteryavitz/blockchainapi/controllers/NodeController.java b/src/main/java/com/hunteryavitz/blockchainapi/controllers/NodeController.java new file mode 100644 index 0000000..6fbf687 --- /dev/null +++ b/src/main/java/com/hunteryavitz/blockchainapi/controllers/NodeController.java @@ -0,0 +1,55 @@ +package com.hunteryavitz.blockchainapi.controllers; + +import com.hunteryavitz.blockchainapi.constants.ContaminationLevel; +import com.hunteryavitz.blockchainapi.constants.NodeStatus; +import com.hunteryavitz.blockchainapi.services.HealthMetricService; +import com.hunteryavitz.blockchainapi.services.NodeService; +import jakarta.websocket.server.PathParam; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * The node for the node network. + */ +@RestController +@CrossOrigin +@RequestMapping("/api/v1/node") +public class NodeController { + + /** + * The health metric service. + */ + private final HealthMetricService healthMetricService; + + /** + * The node controller constructor. + * @param healthMetricService the health metric service + */ + public NodeController(HealthMetricService healthMetricService) { + this.healthMetricService = healthMetricService; + NodeService.initializeNodeService(); + } + + /** + * Gets the node status. + * @param test the test query parameter + * @return the node status + */ + @GetMapping("/getNodeStatus") + public ResponseEntity getNodeStatus(@PathParam("test") boolean test) { + try { + if (test) { + throw new Exception("Test exception"); + } + + return ResponseEntity.ok(NodeService.self.toString()); + } catch (Exception exception) { + healthMetricService.updateHealth(ContaminationLevel.WARNING, exception); + } + + return ResponseEntity.ok(NodeStatus.UNRESPONSIVE.toString()); + } +} diff --git a/src/main/java/com/hunteryavitz/blockchainapi/controllers/NodeManagerController.java b/src/main/java/com/hunteryavitz/blockchainapi/controllers/NodeManagerController.java new file mode 100644 index 0000000..0112f33 --- /dev/null +++ b/src/main/java/com/hunteryavitz/blockchainapi/controllers/NodeManagerController.java @@ -0,0 +1,93 @@ +package com.hunteryavitz.blockchainapi.controllers; + +import com.hunteryavitz.blockchainapi.constants.ContaminationLevel; +import com.hunteryavitz.blockchainapi.constants.NodeStatus; +import com.hunteryavitz.blockchainapi.entities.healthmetric.NodeRegistryRequest; +import com.hunteryavitz.blockchainapi.entities.healthmetric.NodeStatusResponse; +import com.hunteryavitz.blockchainapi.services.HealthMetricService; +import com.hunteryavitz.blockchainapi.services.NodeManagerService; +import jakarta.websocket.server.PathParam; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +/** + * NodeManagerController is the controller for the NodeManagerService. + */ +@RestController +@CrossOrigin +@RequestMapping("/api/v1/nodeManager") +public class NodeManagerController { + + /** + * The Health metric service. + */ + private final HealthMetricService healthMetricService; + + /** + * Instantiates a new Node manager controller. + * @param healthMetricService the health metric service + */ + public NodeManagerController( HealthMetricService healthMetricService) { + this.healthMetricService = healthMetricService; + NodeManagerService.initializeNodeManagerService(); + } + + /** + * Register node response entity. + * @param nodeRegistryRequest the node registry request + * @param test the test query parameter + * @return the node status + */ + @PostMapping("/registerNode") + public ResponseEntity registerNode(@RequestBody NodeRegistryRequest nodeRegistryRequest, + @PathParam("test") boolean test) { + try { + if (test) { + throw new Exception("Test exception"); + } + return ResponseEntity.ok(NodeManagerService.registerNode(nodeRegistryRequest)); + } catch (Exception exception) { + healthMetricService.updateHealth(ContaminationLevel.WARNING, exception); + } + return ResponseEntity.ok(NodeStatus.FAILED_REGISTRATION); + } + + /** + * Gets node network status. + * @param test test query param + * @return the node network status + */ + @GetMapping("/getNodeNetworkStatus") + public ResponseEntity getNodeNetworkStatus(@PathParam("test") boolean test) { + try { + if (test) { + throw new Exception("test exception"); + } + return ResponseEntity.ok(NodeManagerService.getNodeNetworkStatus()); + } catch (Exception exception) { + healthMetricService.updateHealth(ContaminationLevel.WARNING, exception); + } + + return ResponseEntity.ok(new NodeStatusResponse[]{}); + } + + /** + * Gets the node network status. + * @param test test query param + * @return Boolean indicating whether the node network status was updated. + * Call this from a cronjob every x/time period. + */ + @GetMapping("/nodeNetworkRollCall") + public ResponseEntity nodeNetworkRollCall(@PathParam("test") boolean test) { + try { + if (test) { + throw new Exception("test exception"); + } + return ResponseEntity.ok(NodeManagerService.getRollCall()); + } catch (Exception exception) { + healthMetricService.updateHealth(ContaminationLevel.INFO, exception); + } + + return ResponseEntity.ok(Boolean.FALSE); + } +} diff --git a/src/main/java/com/hunteryavitz/blockchainapi/controllers/TransactionController.java b/src/main/java/com/hunteryavitz/blockchainapi/controllers/TransactionController.java index 717b1e2..0a95474 100644 --- a/src/main/java/com/hunteryavitz/blockchainapi/controllers/TransactionController.java +++ b/src/main/java/com/hunteryavitz/blockchainapi/controllers/TransactionController.java @@ -4,6 +4,7 @@ import com.hunteryavitz.blockchainapi.entities.Transaction; import com.hunteryavitz.blockchainapi.services.HealthMetricService; import com.hunteryavitz.blockchainapi.services.TransactionService; +import jakarta.websocket.server.PathParam; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -35,7 +36,7 @@ public TransactionController(TransactionService transactionService, HealthMetric this.healthMetricService = healthMetricService; try { - if (transactionService.getTransactionPool() == null) { + if (TransactionService.getTransactionPool() == null) { transactionService.createInitialTransactionPool(); } if (healthMetricService.getProduction() == null) { @@ -50,11 +51,16 @@ public TransactionController(TransactionService transactionService, HealthMetric /** * The getTransactionPool method is responsible for returning the transaction pool. * @param transaction The transaction to be added to the transaction pool. + * @param test test query param. * @return The transaction pool. */ @PostMapping(value = "/submitTransaction", consumes = "application/json", produces = "application/json") - public ResponseEntity submitTransaction(@RequestBody Transaction transaction) { + public ResponseEntity submitTransaction(@RequestBody Transaction transaction, + @PathParam("test") boolean test) { try { + if (test) { + throw new Exception("Test exception"); + } transactionService.submitTransaction(transaction); return ResponseEntity.ok(true); } catch (Exception exception) { @@ -66,12 +72,16 @@ public ResponseEntity submitTransaction(@RequestBody Transaction transa /** * The getTransactionPool method is responsible for returning the transaction pool. + * @param test test query param. * @return The transaction pool. */ @GetMapping(value = "/getTransactionPool", produces = "application/json") - public ResponseEntity getTransactionPool() { + public ResponseEntity getTransactionPool(@PathParam("test") boolean test) { try { - return ResponseEntity.ok(transactionService.getTransactionPool()); + if (test) { + throw new Exception("Test exception"); + } + return ResponseEntity.ok(TransactionService.getTransactionPool()); } catch (Exception exception) { healthMetricService.updateHealth(ContaminationLevel.WARNING, exception); } diff --git a/src/main/java/com/hunteryavitz/blockchainapi/entities/Block.java b/src/main/java/com/hunteryavitz/blockchainapi/entities/Block.java index 96b3443..c1b84d6 100644 --- a/src/main/java/com/hunteryavitz/blockchainapi/entities/Block.java +++ b/src/main/java/com/hunteryavitz/blockchainapi/entities/Block.java @@ -33,6 +33,11 @@ public class Block { */ private String hash; + /** + * The constructor for the Block class. + */ + public Block() {} + /** * The constructor for the Block class. * @param index The index of the block in the blockchain. diff --git a/src/main/java/com/hunteryavitz/blockchainapi/entities/Transaction.java b/src/main/java/com/hunteryavitz/blockchainapi/entities/Transaction.java index bd5e0f8..f3d7d91 100644 --- a/src/main/java/com/hunteryavitz/blockchainapi/entities/Transaction.java +++ b/src/main/java/com/hunteryavitz/blockchainapi/entities/Transaction.java @@ -1,6 +1,6 @@ package com.hunteryavitz.blockchainapi.entities; -import com.hunteryavitz.blockchainapi.constants.Status; +import com.hunteryavitz.blockchainapi.constants.TransactionStatus; import lombok.Data; /** @@ -27,19 +27,19 @@ public class Transaction { /** * The status of the transaction. */ - private Status status; + private TransactionStatus transactionStatus; /** * The constructor for the Transaction class. * @param id The id of the transaction. * @param timestamp The timestamp of the transaction. * @param source The source of the transaction. - * @param status The status of the transaction. + * @param transactionStatus The status of the transaction. */ - public Transaction(long id, String timestamp, String source, String status) { + public Transaction(long id, String timestamp, String source, String transactionStatus) { this.id = id; this.timestamp = timestamp; this.source = source; - this.status = Enum.valueOf(Status.class, status); + this.transactionStatus = Enum.valueOf(TransactionStatus.class, transactionStatus); } } diff --git a/src/main/java/com/hunteryavitz/blockchainapi/entities/healthmetric/Node.java b/src/main/java/com/hunteryavitz/blockchainapi/entities/healthmetric/Node.java new file mode 100644 index 0000000..eae864f --- /dev/null +++ b/src/main/java/com/hunteryavitz/blockchainapi/entities/healthmetric/Node.java @@ -0,0 +1,55 @@ +package com.hunteryavitz.blockchainapi.entities.healthmetric; + +import com.hunteryavitz.blockchainapi.constants.NodeStatus; +import lombok.Data; + +/** + * The node of the network. + */ +@Data +public class Node { + + /** + * The id of the node. + */ + private long id; + + /** + * The address of the node. + */ + private String address; + + /** + * The status of the node. + */ + private NodeStatus nodeStatus; + + /** + * The traffic of the node. + */ + private int traffic; + + /** + * The default constructor. + */ + public Node() { + id = -1; + address = "-1"; + nodeStatus = NodeStatus.INACTIVE; + traffic = -1; + } + + /** + * The overloaded constructor. + * @param id the id of the node + * @param address the address of the node + * @param nodeStatus the status of the node + * @param traffic the traffic of the node + */ + public Node(int id, String address, NodeStatus nodeStatus, int traffic) { + this.id = id; + this.address = address; + this.nodeStatus = nodeStatus; + this.traffic = traffic; + } +} diff --git a/src/main/java/com/hunteryavitz/blockchainapi/entities/healthmetric/NodeRegistryRequest.java b/src/main/java/com/hunteryavitz/blockchainapi/entities/healthmetric/NodeRegistryRequest.java new file mode 100644 index 0000000..031e969 --- /dev/null +++ b/src/main/java/com/hunteryavitz/blockchainapi/entities/healthmetric/NodeRegistryRequest.java @@ -0,0 +1,20 @@ +package com.hunteryavitz.blockchainapi.entities.healthmetric; + +import lombok.Data; + +/** + * NodeRegistryRequest is a request object for registering a node. + */ +@Data +public class NodeRegistryRequest { + + /** + * The port of the node. + */ + private int port; + + /** + * The certificate of the node. + */ + private String certificate; +} diff --git a/src/main/java/com/hunteryavitz/blockchainapi/entities/healthmetric/NodeStatusResponse.java b/src/main/java/com/hunteryavitz/blockchainapi/entities/healthmetric/NodeStatusResponse.java new file mode 100644 index 0000000..4c380c9 --- /dev/null +++ b/src/main/java/com/hunteryavitz/blockchainapi/entities/healthmetric/NodeStatusResponse.java @@ -0,0 +1,20 @@ +package com.hunteryavitz.blockchainapi.entities.healthmetric; + +import lombok.Data; + +/** + * NodeRegistryRequest is a request object for registering a node. + */ +@Data +public class NodeStatusResponse { + + /** + * The id of the node. + */ + private long x; + + /** + * The port of the node. + */ + private int y; +} diff --git a/src/main/java/com/hunteryavitz/blockchainapi/services/BlockchainService.java b/src/main/java/com/hunteryavitz/blockchainapi/services/BlockchainService.java index 72e5fb8..b56831a 100644 --- a/src/main/java/com/hunteryavitz/blockchainapi/services/BlockchainService.java +++ b/src/main/java/com/hunteryavitz/blockchainapi/services/BlockchainService.java @@ -89,6 +89,24 @@ public void addBlockToBlockchain() { blockchain[nextBlockIndex] = block; } + /** + * The addMungedBlockToBlockchain method is responsible for adding a munged block to the blockchain. + * This is here for unit testing purposes. + */ + public void addMungedBlockToBlockchain() { + + int nextBlockIndex = getNextBlockIndexFromBlockchain(); + + Block previousBlock = blockchain[nextBlockIndex - 1]; + Block block; + + block = new Block(nextBlockIndex, previousBlock.getHash(), + System.currentTimeMillis(), "Block " + nextBlockIndex, + "munged hash"); + + blockchain[nextBlockIndex] = block; + } + /** * The addBlockToBlockchain method is responsible for adding a block to the blockchain. * @param transactionPool The transaction pool. diff --git a/src/main/java/com/hunteryavitz/blockchainapi/services/NodeManagerService.java b/src/main/java/com/hunteryavitz/blockchainapi/services/NodeManagerService.java new file mode 100644 index 0000000..843b9dd --- /dev/null +++ b/src/main/java/com/hunteryavitz/blockchainapi/services/NodeManagerService.java @@ -0,0 +1,118 @@ +package com.hunteryavitz.blockchainapi.services; + +import com.hunteryavitz.blockchainapi.constants.ContaminationLevel; +import com.hunteryavitz.blockchainapi.constants.NodeStatus; +import com.hunteryavitz.blockchainapi.entities.healthmetric.Node; +import com.hunteryavitz.blockchainapi.entities.healthmetric.NodeRegistryRequest; +import com.hunteryavitz.blockchainapi.entities.healthmetric.NodeStatusResponse; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import java.util.HashSet; +import java.util.Set; + +/** + * NodeManagerService is responsible for managing the network of nodes. + */ +@Service +public class NodeManagerService { + + /** + * nodeNetwork is a set of nodes that are currently registered with the network. + */ + private static Set nodeNetwork = new HashSet<>(); + + /** + * healthMetricService is a service that is responsible for managing the health of the network. + */ + private static HealthMetricService healthMetricService; + + /** + * initializeNodeManagerService is responsible for initializing the NodeManagerService. + */ + public static void initializeNodeManagerService() { + if (healthMetricService == null) { + healthMetricService = new HealthMetricService(); + healthMetricService.createHealthMetricService(); + } + System.out.println("Initializing Node Manager Service"); + } + + /** + * registerNode is responsible for registering a node with the network. + * @param nodeRegistryRequest is the request that contains the node's certificate and port. + * @return the status of the node's registration. + */ + public static NodeStatus registerNode(NodeRegistryRequest nodeRegistryRequest) { + if (authenticateNodeRegistryCertificate(nodeRegistryRequest.getCertificate())) { + String nodeAddress = assembleNodeAddress(nodeRegistryRequest.getPort()); + Node node = new Node(nodeNetwork.size() + 1, nodeAddress, NodeStatus.ACTIVE, 0); + nodeNetwork.add(node); + return NodeStatus.ACTIVE; + } + + return NodeStatus.FAILED_REGISTRATION; + } + + /** + * authenticateNodeRegistryCertificate is responsible for authenticating a node's certificate. + * @param certificate is the certificate that is being authenticated. + * @return the status of the certificate's authentication. + */ + private static boolean authenticateNodeRegistryCertificate(String certificate) { + if (certificate.equals("secret-sauce")) { + return Boolean.TRUE; + } + return Boolean.FALSE; + } + + /** + * assembleNodeAddress is responsible for assembling a node's address. + * @param port is the port that the node is running on. + * @return the node's address. + */ + private static String assembleNodeAddress(int port) { + return "http://localhost:" + port + "/api/v1/node/getNodeStatus"; + } + + /** + * getRollCall is responsible for getting the roll call of the network. + * @return the status of the roll call. + */ + public static Boolean getRollCall() { + try { + System.out.println("getRollCall"); + Set nodeNetworkProxy = new HashSet<>(); + for (Node node : nodeNetwork) { + RestTemplate restTemplate = new RestTemplate(); + NodeStatus nodeStatus = restTemplate.getForEntity("http://localhost:8080/api/v1/node/getNodeStatus", NodeStatus.class).getBody(); + assert nodeStatus != null; + node.setNodeStatus(nodeStatus); + nodeNetworkProxy.add(node); + } + nodeNetwork = nodeNetworkProxy; + return Boolean.TRUE; + } catch (Exception exception) { + healthMetricService.updateHealth(ContaminationLevel.INFO, exception); + } + + return Boolean.FALSE; + } + + /** + * getNodeNetworkStatus is responsible for getting the status of the node network. + * @return the status of the node network. + */ + public static NodeStatusResponse[] getNodeNetworkStatus() { + NodeStatusResponse[] nodeStatusResponses = new NodeStatusResponse[nodeNetwork.size()]; + int i = 0; + for (Node node : nodeNetwork) { + NodeStatusResponse nodeStatusResponse = new NodeStatusResponse(); + nodeStatusResponse.setX(node.getId()); + nodeStatusResponse.setY(node.getTraffic()); + nodeStatusResponses[i] = nodeStatusResponse; + i++; + } + return nodeStatusResponses; + } +} diff --git a/src/main/java/com/hunteryavitz/blockchainapi/services/NodeService.java b/src/main/java/com/hunteryavitz/blockchainapi/services/NodeService.java new file mode 100644 index 0000000..d0f4d43 --- /dev/null +++ b/src/main/java/com/hunteryavitz/blockchainapi/services/NodeService.java @@ -0,0 +1,43 @@ +package com.hunteryavitz.blockchainapi.services; + +import com.hunteryavitz.blockchainapi.constants.AppConstants; +import com.hunteryavitz.blockchainapi.constants.NodeStatus; +import com.hunteryavitz.blockchainapi.entities.healthmetric.NodeRegistryRequest; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +/** + * Service class for node operations. + */ +@Service +public class NodeService { + + /** + * The status of the current node. + */ + public static NodeStatus self = NodeStatus.INACTIVE; + + /** + * Initializes the node service. + */ + public static void initializeNodeService() { + registerSelf(); + } + + /** + * Registers the current node with the registry. + */ + private static void registerSelf() { + NodeRegistryRequest nodeRegistryRequest = new NodeRegistryRequest(); + nodeRegistryRequest.setPort(AppConstants.getPort()); + nodeRegistryRequest.setCertificate(AppConstants.getCertificate()); + + RestTemplate restTemplate = new RestTemplate(); + + try { + self = restTemplate.postForObject(AppConstants.getRegistryAddress(), nodeRegistryRequest, NodeStatus.class); + } catch (Exception exception) { + self = NodeStatus.INACTIVE; + } + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b41d832..078a8ca 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,4 @@ -VERSION=0.0.15 \ No newline at end of file +REGISTRY_ADDRESS=http://localhost:8080/api/v1/node/registerNode +CERTIFICATE=secret-sauce +PORT=8080 +server.port=8080 diff --git a/src/test/java/com/hunteryavitz/blockchainapi/controllers/BlockControllerTests.java b/src/test/java/com/hunteryavitz/blockchainapi/controllers/BlockControllerTests.java index 47bf929..98cb5e2 100644 --- a/src/test/java/com/hunteryavitz/blockchainapi/controllers/BlockControllerTests.java +++ b/src/test/java/com/hunteryavitz/blockchainapi/controllers/BlockControllerTests.java @@ -21,24 +21,44 @@ public class BlockControllerTests { private TestRestTemplate restTemplate; /** - * The API version and endpoints. + * The API version and controller. */ - private static final String API_VERSION = "/api/v1"; + private static final String API_VERSION = "/api/v1/block"; /** * The readiness and readiness endpoints. */ - private static final String ADD_BLOCK_ENDPOINT = "/block/addBlockToBlockchain"; + private static final String ADD_BLOCK_ENDPOINT = "/addBlockToBlockchain"; /** - * Tests the addBlockToBlockchain method. + * The query parameter for testing. + */ + private static final String QUERY_PARAM_TEST = "?test=true"; + + /** + * Tests the addBlockToBlockchain method succeeds. */ @Test - void testAddBlockToBlockchain() { + void testAddBlockToBlockchain_onSuccess_returns200AndTrue() { ResponseEntity response = restTemplate.postForEntity( - API_VERSION + ADD_BLOCK_ENDPOINT, null, Boolean.class); + API_VERSION + + ADD_BLOCK_ENDPOINT, null, Boolean.class); assert response.getStatusCode().is2xxSuccessful(); assert (Boolean.TRUE.equals(response.getBody())); } + + /** + * Tests the addBlockToBlockchain method fails. + */ + @Test + void testAddBlockToBlockchain_onFail_returns200AndFalse() { + ResponseEntity response = restTemplate.postForEntity( + API_VERSION + + ADD_BLOCK_ENDPOINT + + QUERY_PARAM_TEST, null, Boolean.class); + + assert response.getStatusCode().is2xxSuccessful(); + assert (Boolean.FALSE.equals(response.getBody())); + } } diff --git a/src/test/java/com/hunteryavitz/blockchainapi/controllers/BlockchainControllerTests.java b/src/test/java/com/hunteryavitz/blockchainapi/controllers/BlockchainControllerTests.java index 1bf150a..7f37962 100644 --- a/src/test/java/com/hunteryavitz/blockchainapi/controllers/BlockchainControllerTests.java +++ b/src/test/java/com/hunteryavitz/blockchainapi/controllers/BlockchainControllerTests.java @@ -2,37 +2,31 @@ import com.hunteryavitz.blockchainapi.entities.Block; import com.hunteryavitz.blockchainapi.services.BlockchainService; - import org.junit.jupiter.api.Test; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.ResponseEntity; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.Arrays; +import java.util.Objects; + +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; /** - * Unit tests for the Main controller for the API. + * Unit tests for the Blockchain controller. */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class BlockchainControllerTests { /** - * The BlockchainService used to make requests to the API. + * The BlockchainService used to provide setup tasks. */ @Mock private BlockchainService blockchainService; - /** - * The BlockchainController used to make requests to the API. - */ - @InjectMocks - private BlockchainController blockchainController; - /** * The RestTemplate used to make requests to the API. */ @@ -40,61 +34,134 @@ public class BlockchainControllerTests { private TestRestTemplate restTemplate; /** - * The API version and endpoints. + * The API version and controller. */ - private static final String API_VERSION = "/api/v1"; + private static final String BLOCKCHAIN_PATH = "/api/v1/blockchain"; /** * The verify blockchain endpoint. */ - private static final String VERIFY_BLOCKCHAIN_ENDPOINT = "/blockchain/verifyBlockchain"; + private static final String VERIFY_BLOCKCHAIN_ENDPOINT = "/verifyBlockchain"; + + /** + * The get blockchain endpoint. + */ + private static final String GET_BLOCKCHAIN_ENDPOINT = "/getBlockchain"; + + /** + * The get block by id endpoint. + */ + private static final String GET_BLOCK_BY_ID_ENDPOINT = "/getBlockById"; + + /** + * The query string. + */ + private static final String QUERY = "?"; + + /** + * The query parameter id. + */ + private static final String QUERY_PARAM_ID = "id=0"; + + /** + * The ampersand. + */ + private static final String AND = "&"; + + /** + * The query parameter test. + */ + private static final String QUERY_PARAM_TEST = "test=true"; /** - * Tests the verifyBlockchain method. + * Tests the verifyBlockchain method returns true. */ @Test - void testVerifyBlockchain() { + void testVerifyBlockchain_whenBlockchainGood_returns200AndTrue() { blockchainService = new BlockchainService(); blockchainService.createInitialBlockchain(); ResponseEntity response = restTemplate.getForEntity( - API_VERSION + VERIFY_BLOCKCHAIN_ENDPOINT, Boolean.class); + BLOCKCHAIN_PATH + VERIFY_BLOCKCHAIN_ENDPOINT, Boolean.class); assert response.getStatusCode().is2xxSuccessful(); assert (Boolean.TRUE.equals(response.getBody())); } /** - * Tests the getBlockchain method. + * Tests the verifyBlockchain method returns false. */ @Test - void testGetBlockchain() { - // Arrange - Block[] mockBlockchain = {}; - when(blockchainService.getBlockchain()).thenReturn(mockBlockchain); + void testVerifyBlockchain_whenBlockchainBad_returns200AndFalse() { + blockchainService = new BlockchainService(); + blockchainService.createInitialBlockchain(); + blockchainService.addMungedBlockToBlockchain(); - // Act - ResponseEntity response = blockchainController.getBlockchain(); + ResponseEntity response = restTemplate.getForEntity( + BLOCKCHAIN_PATH + VERIFY_BLOCKCHAIN_ENDPOINT, Boolean.class); + + assert response.getStatusCode().is2xxSuccessful(); + assert (Boolean.FALSE.equals(response.getBody())); + } + + /** + * Tests the getBlockchain method returns blockchain. + */ + @Test + void testGetBlockchain_whenHasBlockchain_returns200AndBlockchain() { + ResponseEntity response = restTemplate.getForEntity( + BLOCKCHAIN_PATH + GET_BLOCKCHAIN_ENDPOINT, Block[].class); - // Assert - assertEquals(200, response.getStatusCode().value()); // checks if the status code is 200 OK - assertArrayEquals(mockBlockchain, response.getBody()); // checks if the returned blockchain matches the mock + assert response.getStatusCode().is2xxSuccessful(); + assertNotNull(response.getBody()); } /** - * Tests the getBlockById method. + * Tests the getBlockchain method returns empty. */ @Test - void testGetBlockById() { - // Arrange - Block mockBlock = blockchainService.getBlockById(0); - when(blockchainService.getBlockById(0)).thenReturn(mockBlock); + void testGetBlockchain_whenHasNoBlockchain_returns200AndEmptyArray() { + when(blockchainService.getBlockchain()).thenReturn(new Block[0]); + ResponseEntity response = restTemplate.getForEntity( + BLOCKCHAIN_PATH + + GET_BLOCKCHAIN_ENDPOINT + + QUERY + + QUERY_PARAM_TEST, Block[].class); - // Act - ResponseEntity response = blockchainController.getBlockById(0); + assert response.getStatusCode().is2xxSuccessful(); + assertEquals(0, + Arrays.stream(Objects.requireNonNull(response.getBody())).count()); + } - // Assert - assertEquals(200, response.getStatusCode().value()); // checks if the status code is 200 OK - assertEquals(mockBlock, response.getBody()); // checks if the returned block matches the mock + /** + * Tests the getBlockById returns block. + */ + @Test + void testGetBlockById_whenIsBlock_returns200AndBlock() { + ResponseEntity response = restTemplate.getForEntity( + BLOCKCHAIN_PATH + + GET_BLOCK_BY_ID_ENDPOINT + + QUERY + + QUERY_PARAM_ID, Block.class); + + assertEquals(200, response.getStatusCode().value()); + assertEquals(0, Objects.requireNonNull(response.getBody()).getIndex()); + } + + /** + * Tests the getBlockById returns null block. + */ + @Test + void testGetBlockById_whenNoBlock_returns200AndEmpty() { + ResponseEntity response = restTemplate.getForEntity( + BLOCKCHAIN_PATH + + GET_BLOCK_BY_ID_ENDPOINT + + QUERY + + QUERY_PARAM_ID + + AND + + QUERY_PARAM_TEST, Block.class); + + assertEquals(200, response.getStatusCode().value()); + assertNull(Objects.requireNonNull(response.getBody()).getHash()); } } diff --git a/src/test/java/com/hunteryavitz/blockchainapi/controllers/HealthMetricControllerTests.java b/src/test/java/com/hunteryavitz/blockchainapi/controllers/HealthMetricControllerTests.java index e7bdc2a..960aa61 100644 --- a/src/test/java/com/hunteryavitz/blockchainapi/controllers/HealthMetricControllerTests.java +++ b/src/test/java/com/hunteryavitz/blockchainapi/controllers/HealthMetricControllerTests.java @@ -7,8 +7,12 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.context.TestPropertySource; +import java.util.Objects; + +import static org.junit.jupiter.api.Assertions.assertNull; + /** - * Unit tests for the HealthMetric controller for the API. + * Unit tests for the HealthMetric controller. */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"spring.profiles.active=test"}) @@ -24,37 +28,106 @@ public class HealthMetricControllerTests { /** * The API version and endpoints. */ - private static final String API_VERSION = "/api/v1"; + private static final String API_VERSION = "/api/v1/healthMetric"; + + /** + * The health metric endpoint. + */ + private static final String UPDATE_PRODUCTION_ENDPOINT = "/updateProductionHealth"; /** * The health metric endpoint. */ - private static final String UPDATE_PRODUCTION_ENDPOINT = "/healthMetric/updateProduction"; + private static final String GET_PRODUCTION_HEALTH_ENDPOINT = "/getProductionHealth"; /** * The health metric endpoint. */ - private static final String GET_PRODUCTION_HEALTH_ENDPOINT = "/healthMetric/getProductionHealth"; + private static final String GET_EXCEPTION_HEALTH_ENDPOINT = "/getExceptionHealth"; /** - * Tests the updateProduction endpoint. + * The query parameter for testing. + */ + private static final String QUERY_PARAM_TEST = "?test=true"; + + /** + * Tests the updateProductionHealth endpoint succeeds. */ @Test - void testUpdateProduction() { + void testUpdateProductionHealth_onSuccess_returns200AndTrue() { ResponseEntity response = restTemplate.getForEntity( - API_VERSION + UPDATE_PRODUCTION_ENDPOINT, Boolean.class); + API_VERSION + + UPDATE_PRODUCTION_ENDPOINT, Boolean.class); + assert response.getStatusCode().is2xxSuccessful(); assert (Boolean.TRUE.equals(response.getBody())); } /** - * Tests the getProductionHealth endpoint. + * Tests the updateProductionHealth endpoint fails. + */ + @Test + void testUpdateProductionHealth_onFail_returns200AndFalse() { + ResponseEntity response = restTemplate.getForEntity( + API_VERSION + + UPDATE_PRODUCTION_ENDPOINT + + QUERY_PARAM_TEST, Boolean.class); + + assert response.getStatusCode().is2xxSuccessful(); + assert (Boolean.FALSE.equals(response.getBody())); + } + + /** + * Tests the getProductionHealth endpoint succeeds. + */ + @Test + void testGetProductionHealth_onSuccess_returns200AndProductionHealth() { + ResponseEntity response = restTemplate.getForEntity( + API_VERSION + + GET_PRODUCTION_HEALTH_ENDPOINT, String.class); + + assert response.getStatusCode().is2xxSuccessful(); + assert (response.getBody() != null); + } + + /** + * Tests the getProductionHealth endpoint fails. + */ + @Test + void testGetProductionHealth_onFail_returns200AndNull() { + ResponseEntity response = restTemplate.getForEntity( + API_VERSION + + GET_PRODUCTION_HEALTH_ENDPOINT + + QUERY_PARAM_TEST, String.class); + + assert response.getStatusCode().is2xxSuccessful(); + assertNull (response.getBody()); + } + + /** + * Tests the getExceptionHealth endpoint succeeds. */ @Test - void testGetProductionHealth() { + void testGetExceptionHealth_onSuccess_returns200AndExceptionHealth() { ResponseEntity response = restTemplate.getForEntity( - API_VERSION + GET_PRODUCTION_HEALTH_ENDPOINT, String.class); + API_VERSION + + GET_EXCEPTION_HEALTH_ENDPOINT, String.class); + assert response.getStatusCode().is2xxSuccessful(); assert (response.getBody() != null); } + + /** + * Tests the getExceptionHealth endpoint fails. + */ + @Test + void testGetExceptionHealth_onFail_returns200AndNull() { + ResponseEntity response = restTemplate.getForEntity( + API_VERSION + + GET_EXCEPTION_HEALTH_ENDPOINT + + QUERY_PARAM_TEST, String.class); + + assert response.getStatusCode().is2xxSuccessful(); + assert (Objects.requireNonNull(response.getBody()).equals("[]")); + } } diff --git a/src/test/java/com/hunteryavitz/blockchainapi/controllers/MainControllerTests.java b/src/test/java/com/hunteryavitz/blockchainapi/controllers/MainControllerTests.java index 88e8422..836d509 100644 --- a/src/test/java/com/hunteryavitz/blockchainapi/controllers/MainControllerTests.java +++ b/src/test/java/com/hunteryavitz/blockchainapi/controllers/MainControllerTests.java @@ -1,7 +1,5 @@ package com.hunteryavitz.blockchainapi.controllers; -import com.hunteryavitz.blockchainapi.services.BlockchainService; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -11,22 +9,19 @@ import org.springframework.test.context.TestPropertySource; import java.util.Arrays; +import java.util.Objects; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; /** - * Unit tests for the Main controller for the API. + * Unit tests for the Main controller. */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"spring.profiles.active=test"}) @TestPropertySource(locations = "classpath:application-test.properties") public class MainControllerTests { - /** - * The blockchain service. - */ - private static BlockchainService blockchainService; - /** * The RestTemplate used to make requests to the API. */ @@ -34,7 +29,7 @@ public class MainControllerTests { private TestRestTemplate restTemplate; /** - * The API version and endpoints. + * The API version and controller. */ private static final String API_VERSION = "/api/v1"; @@ -48,80 +43,120 @@ public class MainControllerTests { */ private static final String LIVENESS_ENDPOINT = "/liveness"; - /** - * The health endpoint. - */ - private static final String HEALTH_ENDPOINT = "/health"; - /** * The version endpoint. */ private static final String VERSION_ENDPOINT = "/version"; /** - * The addBlock endpoint. + * The test query parameter. */ - private static final String VERIFY_ENDPOINT = "/verifyBlockchain"; + private static final String QUERY_PARAM_TEST = "?test=true"; + /** + * The environment. + */ @Autowired private Environment environment; + /** + * Test the environment. + */ @Test - public void testActiveProfiles() { + public void testActiveProfiles_whenTest_showsTest() { assertTrue(Arrays.asList(environment.getActiveProfiles()).contains("test")); } + /** + * Tests the isReady method succeeds. + */ + @Test + void testIsReady_onSuccess_returns200AndTrue() { + ResponseEntity response = restTemplate.getForEntity( + API_VERSION + + READINESS_ENDPOINT, Boolean.class); + + assert response.getStatusCode().is2xxSuccessful(); + assert (Boolean.TRUE.equals(response.getBody())); + } /** - * Sets up the blockchain service. + * Tests the isReady method fails. */ - @BeforeAll - static void beforeAll() { - if (blockchainService == null) { - blockchainService = new BlockchainService(); - blockchainService.createInitialBlockchain(); - } + @Test + void testIsReady_onFail_returns200AndFalse() { + ResponseEntity response = restTemplate.getForEntity( + API_VERSION + + READINESS_ENDPOINT + + QUERY_PARAM_TEST, Boolean.class); + + assert response.getStatusCode().is2xxSuccessful(); + assert (Boolean.FALSE.equals(response.getBody())); } /** - * Tests the isReady method. + * Tests the isAlive method succeeds. */ @Test - void testIsReady() { - ResponseEntity response = restTemplate.getForEntity(API_VERSION + READINESS_ENDPOINT, Boolean.class); + void isAlive_onSuccess_returns200AndLiveness() { + ResponseEntity response = restTemplate.getForEntity( + API_VERSION + + LIVENESS_ENDPOINT, Integer.class); + assert response.getStatusCode().is2xxSuccessful(); - assert (Boolean.TRUE.equals(response.getBody())); + + try { + int liveness = Objects.requireNonNull(response.getBody()); + assert (liveness > -1); + } catch (NullPointerException nullPointerException) { + assert (true); + } } /** - * Tests the isAlive method. + * Tests the isAlive method fails. */ @Test - void isAlive() { - ResponseEntity response = restTemplate.getForEntity(API_VERSION + LIVENESS_ENDPOINT, Integer.class); + void isAlive_onFail_returns200AndNegativeOne() { + ResponseEntity response = restTemplate.getForEntity( + API_VERSION + + LIVENESS_ENDPOINT + + QUERY_PARAM_TEST, Integer.class); + assert response.getStatusCode().is2xxSuccessful(); - assert (response.getBody() != null); + + try { + int liveness = Objects.requireNonNull(response.getBody()); + assert (liveness == -1); + } catch (NullPointerException nullPointerException) { + assert (true); + } } /** - * Tests the getVersion method. + * Tests the getVersion method succeeds. */ @Test - void testGetVersion() { - ResponseEntity response = restTemplate.getForEntity(API_VERSION + VERSION_ENDPOINT, String.class); + void testGetVersion_onSuccess_returns200AndVersion() { + ResponseEntity response = restTemplate.getForEntity( + API_VERSION + + VERSION_ENDPOINT, String.class); + assert response.getStatusCode().is2xxSuccessful(); - assert ("0.0.16".equals(response.getBody())); + assert ("0.0.17".equals(response.getBody())); } /** - * Tests the verifyBlockchain method. + * Tests the getVersion method fails. */ @Test - void testVerifyBlockchain() { - blockchainService = new BlockchainService(); - blockchainService.createInitialBlockchain(); - ResponseEntity response = restTemplate.getForEntity(API_VERSION + VERIFY_ENDPOINT, Boolean.class); + void testGetVersion_onFail_returns200AndEmpty() { + ResponseEntity response = restTemplate.getForEntity( + API_VERSION + + VERSION_ENDPOINT + + QUERY_PARAM_TEST, String.class); + assert response.getStatusCode().is2xxSuccessful(); - assert (Boolean.TRUE.equals(response.getBody())); + assertNull (response.getBody()); } } diff --git a/src/test/java/com/hunteryavitz/blockchainapi/controllers/NodeControllerTests.java b/src/test/java/com/hunteryavitz/blockchainapi/controllers/NodeControllerTests.java new file mode 100644 index 0000000..3bdcf39 --- /dev/null +++ b/src/test/java/com/hunteryavitz/blockchainapi/controllers/NodeControllerTests.java @@ -0,0 +1,62 @@ +package com.hunteryavitz.blockchainapi.controllers; + +import com.hunteryavitz.blockchainapi.constants.NodeStatus; +import com.hunteryavitz.blockchainapi.services.NodeService; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.TestPropertySource; + +/** + * Unit tests for the Node controller. + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = {"spring.profiles.active=test"}) +@TestPropertySource(locations = "classpath:application-test.properties") +public class NodeControllerTests { + + /** + * The RestTemplate used to make requests to the API. + */ + @Autowired + private TestRestTemplate restTemplate; + + /** + * The API version and controller. + */ + private static final String API_VERSION = "/api/v1/node"; + + /** + * The getNodeStatus endpoint. + */ + private static final String GET_NODE_STATUS_ENDPOINT = "/getNodeStatus"; + + /** + * The test query parameter. + */ + private static final String QUERY_PARAM_TEST = "?test=true"; + + /** + * The test node status for success. + */ + @Test + public void testGetNodeStatus_onSuccess_returns200AndActive() { + NodeService.self = NodeStatus.ACTIVE; + ResponseEntity response = restTemplate.getForEntity(API_VERSION + + GET_NODE_STATUS_ENDPOINT, String.class); + assert NodeStatus.ACTIVE.toString().equals(response.getBody()); + } + + /** + * The test node status for failure. + */ + @Test + public void testGetNodeStatus_onFail_returns200AndUnresponsive() { + NodeService.self = NodeStatus.UNRESPONSIVE; + ResponseEntity response = restTemplate.getForEntity(API_VERSION + + GET_NODE_STATUS_ENDPOINT + QUERY_PARAM_TEST, String.class); + assert NodeStatus.UNRESPONSIVE.toString().equals(response.getBody()); + } +} diff --git a/src/test/java/com/hunteryavitz/blockchainapi/controllers/NodeManagerControllerTests.java b/src/test/java/com/hunteryavitz/blockchainapi/controllers/NodeManagerControllerTests.java new file mode 100644 index 0000000..a158287 --- /dev/null +++ b/src/test/java/com/hunteryavitz/blockchainapi/controllers/NodeManagerControllerTests.java @@ -0,0 +1,133 @@ +package com.hunteryavitz.blockchainapi.controllers; + +import com.hunteryavitz.blockchainapi.constants.NodeStatus; +import com.hunteryavitz.blockchainapi.entities.healthmetric.NodeRegistryRequest; +import com.hunteryavitz.blockchainapi.entities.healthmetric.NodeStatusResponse; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.TestPropertySource; + +/** + * Unit tests for the NodeManager controller for the API. + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = {"spring.profiles.active=test"}) +@TestPropertySource(locations = "classpath:application-test.properties") +public class NodeManagerControllerTests { + + /** + * The rest template. + */ + @Autowired + private TestRestTemplate restTemplate; + + /** + * The API version and controller. + */ + private static final String API_VERSION = "/api/v1/nodeManager"; + + /** + * The register node endpoint. + */ + private static final String REGISTER_NODE_ENDPOINT = "/registerNode"; + + /** + * The node network roll call endpoint. + */ + private static final String NODE_NETWORK_ROLL_CALL_ENDPOINT = "/nodeNetworkRollCall"; + + /** + * The get node network status endpoint. + */ + private static final String GET_NODE_NETWORK_STATUS_ENDPOINT = "/getNodeNetworkStatus"; + + /** + * The query param test. + */ + private static final String QUERY_PARAM_TEST = "?test=true"; + + /** + * Test register node succeeds. + */ + @Test + void testRegisterNode_onSuccess_returns200AndNodeStatusActive() { + NodeRegistryRequest nodeRegistryRequest = new NodeRegistryRequest(); + nodeRegistryRequest.setCertificate("secret-sauce"); + nodeRegistryRequest.setPort(9999); + ResponseEntity response = restTemplate.postForEntity(API_VERSION + + REGISTER_NODE_ENDPOINT, nodeRegistryRequest, NodeStatus.class); + + assert response.getStatusCode().is2xxSuccessful(); + assert NodeStatus.ACTIVE.equals(response.getBody()); + } + + /** + * Test register node fails. + */ + @Test + void testRegisterNode_onFail_returns200AndNodeStatusFailedRegistration() { + NodeRegistryRequest nodeRegistryRequest = new NodeRegistryRequest(); + nodeRegistryRequest.setCertificate("secret-sauce"); + nodeRegistryRequest.setPort(9999); + ResponseEntity response = restTemplate.postForEntity(API_VERSION + + REGISTER_NODE_ENDPOINT + + QUERY_PARAM_TEST, nodeRegistryRequest, NodeStatus.class); + + assert response.getStatusCode().is2xxSuccessful(); + assert NodeStatus.FAILED_REGISTRATION.equals(response.getBody()); + } + + /** + * Test get node network status succeeds. + */ + @Test + void testGetNodeNetworkStatus_onSuccess_returns200AndNodeNetworkStatus() { + + ResponseEntity response = restTemplate.getForEntity(API_VERSION + + GET_NODE_NETWORK_STATUS_ENDPOINT, NodeStatusResponse[].class); + + assert response.getStatusCode().is2xxSuccessful(); + assert response.getBody() != null; + } + + /** + * Test get node network status fails. + */ + @Test + void testGetNodeNetworkStatus_onFail_returns200AndEmptyArray() { + ResponseEntity response = restTemplate.getForEntity(API_VERSION + + GET_NODE_NETWORK_STATUS_ENDPOINT + + QUERY_PARAM_TEST, NodeStatusResponse[].class); + + assert response.getStatusCode().is2xxSuccessful(); + assert response.getBody() != null; + } + + /** + * Test node network roll call succeeds. + */ + @Test + void testNodeNetworkRollCall_onSuccess_returns200AndTrue() { + ResponseEntity response = restTemplate.getForEntity(API_VERSION + + NODE_NETWORK_ROLL_CALL_ENDPOINT, Boolean.class); + + assert response.getStatusCode().is2xxSuccessful(); + assert Boolean.TRUE.equals(response.getBody()); + } + + /** + * Test node network roll call fails. + */ + @Test + void testNodeNetworkRollCall_onFail_returns200AndFalse() { + ResponseEntity response = restTemplate.getForEntity(API_VERSION + + NODE_NETWORK_ROLL_CALL_ENDPOINT + + QUERY_PARAM_TEST, Boolean.class); + + assert response.getStatusCode().is2xxSuccessful(); + assert Boolean.FALSE.equals(response.getBody()); + } +} diff --git a/src/test/java/com/hunteryavitz/blockchainapi/controllers/TransactionControllerTests.java b/src/test/java/com/hunteryavitz/blockchainapi/controllers/TransactionControllerTests.java index ad07690..7a6eae2 100644 --- a/src/test/java/com/hunteryavitz/blockchainapi/controllers/TransactionControllerTests.java +++ b/src/test/java/com/hunteryavitz/blockchainapi/controllers/TransactionControllerTests.java @@ -1,10 +1,7 @@ package com.hunteryavitz.blockchainapi.controllers; -import com.hunteryavitz.blockchainapi.entities.Block; import com.hunteryavitz.blockchainapi.entities.Transaction; -import com.hunteryavitz.blockchainapi.services.TransactionService; import org.junit.jupiter.api.Test; -import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -18,12 +15,6 @@ @TestPropertySource(locations = "classpath:application-test.properties") public class TransactionControllerTests { - /** - * The TransactionService used to make requests to the API. - */ - @Mock - private TransactionService transactionService; - /** * The RestTemplate used to make requests to the API. */ @@ -31,57 +22,82 @@ public class TransactionControllerTests { private TestRestTemplate restTemplate; /** - * The API version and endpoints. + * The API version and controller. */ - private static final String API_VERSION = "/api/v1"; + private static final String API_VERSION = "/api/v1/transaction"; /** * The submit transaction endpoint. */ - private static final String SUBMIT_TRANSACTION_ENDPOINT = "/transaction/submitTransaction"; + private static final String SUBMIT_TRANSACTION_ENDPOINT = "/submitTransaction"; /** * The get transaction pool endpoint. */ - private static final String GET_BLOCK_BY_INDEX_ENDPOINT = "/blockchain/getBlockById?id=1"; + private static final String GET_TRANSACTION_POOL_ENDPOINT = "/getTransactionPool"; + + /** + * The query param for testing. + */ + private static final String QUERY_PARAM_TEST = "?test=true"; /** - * Tests the getBlockchain endpoint. + * Tests the getBlockchain endpoint succeeds. */ @Test - void testSubmitTransaction() { + void testSubmitTransaction_onSuccess_returns200AndTrue() { + Transaction transaction = new Transaction(999, "right_now", "your mom", "CREATED"); - ResponseEntity response = restTemplate.postForEntity( - API_VERSION + SUBMIT_TRANSACTION_ENDPOINT, transaction, Boolean.class); + ResponseEntity response = restTemplate.postForEntity(API_VERSION + + SUBMIT_TRANSACTION_ENDPOINT, transaction, Boolean.class); assert response.getStatusCode().is2xxSuccessful(); assert (Boolean.TRUE.equals(response.getBody())); } /** - * Tests the Transaction Service to add Block to Blockchain when full. + * Tests the getBlockchain endpoint fails. */ @Test - void testAddsBlockOnFullTransactionPool() { + void testSubmitTransaction_onFail_returns200AndFalse() { - transactionService = new TransactionService(); - transactionService.createInitialTransactionPool(); - Transaction transaction = new Transaction(999, "right_now", "your mom", "CREATED"); + Transaction transaction = new Transaction( + 999, "right_now", "your mom", "CREATED"); - int transactionPoolLength = transactionService.getTransactionPool().length; + ResponseEntity response = restTemplate.postForEntity(API_VERSION + + SUBMIT_TRANSACTION_ENDPOINT + + QUERY_PARAM_TEST, transaction, Boolean.class); - for (int i = 0; i < transactionPoolLength; i++) { - transactionService.submitTransaction(transaction); - } + System.out.println(response.getBody()); + assert response.getStatusCode().is2xxSuccessful(); + assert (Boolean.FALSE.equals(response.getBody())); + } - ResponseEntity response = restTemplate.getForEntity( - API_VERSION + GET_BLOCK_BY_INDEX_ENDPOINT, Block.class); + /** + * Tests the get transaction pool endpoint succeeds. + */ + @Test + void testGetTransactionPool_onSuccess_returns200AndTransactionPool() { + + ResponseEntity response = restTemplate.getForEntity(API_VERSION + + GET_TRANSACTION_POOL_ENDPOINT, Transaction[].class); assert response.getStatusCode().is2xxSuccessful(); + assert response.getBody() != null; + } + + /** + * Tests the get transaction pool endpoint fails. + */ + @Test + void testGetTransactionPool_onFail_returns200AndEmptyTransactionPool() { - Block block = response.getBody(); - System.out.println(block); - assert block != null; + ResponseEntity response = restTemplate.getForEntity(API_VERSION + + GET_TRANSACTION_POOL_ENDPOINT + + QUERY_PARAM_TEST, Transaction[].class); + + assert response.getStatusCode().is2xxSuccessful(); + assert response.getBody() != null; } } diff --git a/src/test/java/com/hunteryavitz/blockchainapi/services/BlockchainServiceTests.java b/src/test/java/com/hunteryavitz/blockchainapi/services/BlockchainServiceTests.java index 08c20d6..28ee74d 100644 --- a/src/test/java/com/hunteryavitz/blockchainapi/services/BlockchainServiceTests.java +++ b/src/test/java/com/hunteryavitz/blockchainapi/services/BlockchainServiceTests.java @@ -1,5 +1,6 @@ package com.hunteryavitz.blockchainapi.services; +import com.hunteryavitz.blockchainapi.entities.Block; import com.hunteryavitz.blockchainapi.entities.Transaction; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -69,3 +70,6 @@ public void testAddBlockToBlockchainFromTransaction() { assert transactionFromBlockchain.contains("your mom"); } } +// Block[] mockBlockchain = {}; +// when(blockchainService.getBlockchain()).thenReturn(mockBlockchain); +// ResponseEntity response = blockchainController.getBlockchain(); diff --git a/src/test/java/com/hunteryavitz/blockchainapi/services/TransactionServiceTests.java b/src/test/java/com/hunteryavitz/blockchainapi/services/TransactionServiceTests.java index 633d00c..7b054ea 100644 --- a/src/test/java/com/hunteryavitz/blockchainapi/services/TransactionServiceTests.java +++ b/src/test/java/com/hunteryavitz/blockchainapi/services/TransactionServiceTests.java @@ -1,9 +1,12 @@ package com.hunteryavitz.blockchainapi.services; +import com.hunteryavitz.blockchainapi.entities.Block; import com.hunteryavitz.blockchainapi.entities.Transaction; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.ResponseEntity; import org.springframework.test.context.TestPropertySource; /** @@ -19,6 +22,8 @@ public class TransactionServiceTests { @Mock private TransactionService transactionService; + TestRestTemplate restTemplate = new TestRestTemplate(); + /** * Tests the createInitialTransactionPool method. */ @@ -45,4 +50,30 @@ public void testSubmitTransaction() { assert transactionService.getTransactionPool()[0].getId() == 999; } + +// /** +// * Tests the Transaction Service to add Block to Blockchain when full. +// */ +// @Test +// void testAddsBlockOnFullTransactionPool() { +// +// transactionService = new TransactionService(); +// transactionService.createInitialTransactionPool(); +// Transaction transaction = new Transaction(999, "right_now", "your mom", "CREATED"); +// +// int transactionPoolLength = TransactionService.getTransactionPool().length; +// +// for (int i = 0; i < transactionPoolLength; i++) { +// transactionService.submitTransaction(transaction); +// } +// +// ResponseEntity response = restTemplate.getForEntity( +// API_VERSION + GET_BLOCK_BY_INDEX_ENDPOINT, Block.class); +// +// assert response.getStatusCode().is2xxSuccessful(); +// +// Block block = response.getBody(); +// System.out.println(block); +// assert block != null; +// } } diff --git a/src/test/java/com/hunteryavitz/blockchainapi/utils/UtilsTests.java b/src/test/java/com/hunteryavitz/blockchainapi/utils/UtilsTests.java index 88233ed..e7fadfa 100644 --- a/src/test/java/com/hunteryavitz/blockchainapi/utils/UtilsTests.java +++ b/src/test/java/com/hunteryavitz/blockchainapi/utils/UtilsTests.java @@ -43,12 +43,9 @@ public void testVerifyBlockchain() { BlockchainService blockchainService = new BlockchainService(); - assert blockchainService != null; - blockchainService.addBlockToBlockchain(); Block[] blockchain = blockchainService.getBlockchain(); - System.out.println(Arrays.toString(blockchain)); boolean isValid = Utils.verifyBlockchain(blockchain); assertTrue(isValid); diff --git a/target/classes/application.properties b/target/classes/application.properties deleted file mode 100644 index b41d832..0000000 --- a/target/classes/application.properties +++ /dev/null @@ -1 +0,0 @@ -VERSION=0.0.15 \ No newline at end of file diff --git a/target/classes/com/hunteryavitz/blockchainapi/BlockchainApiApplication.class b/target/classes/com/hunteryavitz/blockchainapi/BlockchainApiApplication.class deleted file mode 100644 index 1258bce..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/BlockchainApiApplication.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/constants/ContaminationLevel.class b/target/classes/com/hunteryavitz/blockchainapi/constants/ContaminationLevel.class deleted file mode 100644 index a6ae0e5..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/constants/ContaminationLevel.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/constants/Status.class b/target/classes/com/hunteryavitz/blockchainapi/constants/Status.class deleted file mode 100644 index 4c11941..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/constants/Status.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/controllers/BlockController.class b/target/classes/com/hunteryavitz/blockchainapi/controllers/BlockController.class deleted file mode 100644 index fed2706..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/controllers/BlockController.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/controllers/BlockchainController.class b/target/classes/com/hunteryavitz/blockchainapi/controllers/BlockchainController.class deleted file mode 100644 index c028de9..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/controllers/BlockchainController.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/controllers/HealthMetricController.class b/target/classes/com/hunteryavitz/blockchainapi/controllers/HealthMetricController.class deleted file mode 100644 index e072d6e..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/controllers/HealthMetricController.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/controllers/MainController.class b/target/classes/com/hunteryavitz/blockchainapi/controllers/MainController.class deleted file mode 100644 index 2d3ee5f..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/controllers/MainController.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/controllers/TransactionController.class b/target/classes/com/hunteryavitz/blockchainapi/controllers/TransactionController.class deleted file mode 100644 index bc2e287..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/controllers/TransactionController.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/entities/Block.class b/target/classes/com/hunteryavitz/blockchainapi/entities/Block.class deleted file mode 100644 index a377d56..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/entities/Block.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/entities/Transaction.class b/target/classes/com/hunteryavitz/blockchainapi/entities/Transaction.class deleted file mode 100644 index 7b0ab0c..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/entities/Transaction.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/entities/healthmetric/BlockchainProduction.class b/target/classes/com/hunteryavitz/blockchainapi/entities/healthmetric/BlockchainProduction.class deleted file mode 100644 index b37a616..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/entities/healthmetric/BlockchainProduction.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/entities/healthmetric/HealthMetricProductionModel$Data.class b/target/classes/com/hunteryavitz/blockchainapi/entities/healthmetric/HealthMetricProductionModel$Data.class deleted file mode 100644 index e2a107b..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/entities/healthmetric/HealthMetricProductionModel$Data.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/entities/healthmetric/HealthMetricProductionModel.class b/target/classes/com/hunteryavitz/blockchainapi/entities/healthmetric/HealthMetricProductionModel.class deleted file mode 100644 index 7b304ea..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/entities/healthmetric/HealthMetricProductionModel.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/services/BlockchainService.class b/target/classes/com/hunteryavitz/blockchainapi/services/BlockchainService.class deleted file mode 100644 index aa56639..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/services/BlockchainService.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/services/HealthMetricService.class b/target/classes/com/hunteryavitz/blockchainapi/services/HealthMetricService.class deleted file mode 100644 index 82fac56..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/services/HealthMetricService.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/services/TransactionService.class b/target/classes/com/hunteryavitz/blockchainapi/services/TransactionService.class deleted file mode 100644 index 1095c6f..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/services/TransactionService.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/utils/Utils.class b/target/classes/com/hunteryavitz/blockchainapi/utils/Utils.class deleted file mode 100644 index 99eb4d3..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/utils/Utils.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/utils/structures/SlidingWindow$IntPair.class b/target/classes/com/hunteryavitz/blockchainapi/utils/structures/SlidingWindow$IntPair.class deleted file mode 100644 index 6c1c93b..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/utils/structures/SlidingWindow$IntPair.class and /dev/null differ diff --git a/target/classes/com/hunteryavitz/blockchainapi/utils/structures/SlidingWindow.class b/target/classes/com/hunteryavitz/blockchainapi/utils/structures/SlidingWindow.class deleted file mode 100644 index a512dcb..0000000 Binary files a/target/classes/com/hunteryavitz/blockchainapi/utils/structures/SlidingWindow.class and /dev/null differ diff --git a/target/test-classes/application-test.properties b/target/test-classes/application-test.properties deleted file mode 100644 index b21d2ce..0000000 --- a/target/test-classes/application-test.properties +++ /dev/null @@ -1,12 +0,0 @@ -VERSION=0.0.15 - -BLOCKCHAIN_LENGTH=100 -TRANSACTION_POOL_SIZE=10 - -INITIAL_HASH_VALUE=0 -INITIAL_BLOCK_DATA=Genesis Block -INITIAL_BLOCK_INDEX=0 -SHA_ALGORITHM=SHA-256 -HASH_ADDRESS=0xff -HASH_LENGTH=1 -HASH_APPEND=0 diff --git a/target/test-classes/com/hunteryavitz/blockchainapi/BlockchainApiApplicationTests.class b/target/test-classes/com/hunteryavitz/blockchainapi/BlockchainApiApplicationTests.class deleted file mode 100644 index c539d74..0000000 Binary files a/target/test-classes/com/hunteryavitz/blockchainapi/BlockchainApiApplicationTests.class and /dev/null differ diff --git a/target/test-classes/com/hunteryavitz/blockchainapi/controllers/BlockControllerTests.class b/target/test-classes/com/hunteryavitz/blockchainapi/controllers/BlockControllerTests.class deleted file mode 100644 index 16c6646..0000000 Binary files a/target/test-classes/com/hunteryavitz/blockchainapi/controllers/BlockControllerTests.class and /dev/null differ diff --git a/target/test-classes/com/hunteryavitz/blockchainapi/controllers/BlockchainControllerTests.class b/target/test-classes/com/hunteryavitz/blockchainapi/controllers/BlockchainControllerTests.class deleted file mode 100644 index 0990706..0000000 Binary files a/target/test-classes/com/hunteryavitz/blockchainapi/controllers/BlockchainControllerTests.class and /dev/null differ diff --git a/target/test-classes/com/hunteryavitz/blockchainapi/controllers/HealthMetricControllerTests.class b/target/test-classes/com/hunteryavitz/blockchainapi/controllers/HealthMetricControllerTests.class deleted file mode 100644 index 2c8ee1e..0000000 Binary files a/target/test-classes/com/hunteryavitz/blockchainapi/controllers/HealthMetricControllerTests.class and /dev/null differ diff --git a/target/test-classes/com/hunteryavitz/blockchainapi/controllers/MainControllerTests.class b/target/test-classes/com/hunteryavitz/blockchainapi/controllers/MainControllerTests.class deleted file mode 100644 index b397734..0000000 Binary files a/target/test-classes/com/hunteryavitz/blockchainapi/controllers/MainControllerTests.class and /dev/null differ diff --git a/target/test-classes/com/hunteryavitz/blockchainapi/controllers/TransactionControllerTests.class b/target/test-classes/com/hunteryavitz/blockchainapi/controllers/TransactionControllerTests.class deleted file mode 100644 index 3d5df6d..0000000 Binary files a/target/test-classes/com/hunteryavitz/blockchainapi/controllers/TransactionControllerTests.class and /dev/null differ diff --git a/target/test-classes/com/hunteryavitz/blockchainapi/services/BlockchainServiceTests.class b/target/test-classes/com/hunteryavitz/blockchainapi/services/BlockchainServiceTests.class deleted file mode 100644 index ffe74c7..0000000 Binary files a/target/test-classes/com/hunteryavitz/blockchainapi/services/BlockchainServiceTests.class and /dev/null differ diff --git a/target/test-classes/com/hunteryavitz/blockchainapi/services/HealthMetricServiceTests.class b/target/test-classes/com/hunteryavitz/blockchainapi/services/HealthMetricServiceTests.class deleted file mode 100644 index 7ede3ad..0000000 Binary files a/target/test-classes/com/hunteryavitz/blockchainapi/services/HealthMetricServiceTests.class and /dev/null differ diff --git a/target/test-classes/com/hunteryavitz/blockchainapi/services/TransactionServiceTests.class b/target/test-classes/com/hunteryavitz/blockchainapi/services/TransactionServiceTests.class deleted file mode 100644 index 3810d22..0000000 Binary files a/target/test-classes/com/hunteryavitz/blockchainapi/services/TransactionServiceTests.class and /dev/null differ diff --git a/target/test-classes/com/hunteryavitz/blockchainapi/utils/UtilsTests.class b/target/test-classes/com/hunteryavitz/blockchainapi/utils/UtilsTests.class deleted file mode 100644 index 823037b..0000000 Binary files a/target/test-classes/com/hunteryavitz/blockchainapi/utils/UtilsTests.class and /dev/null differ diff --git a/target/test-classes/com/hunteryavitz/blockchainapi/utils/structures/SlidingWindowTests.class b/target/test-classes/com/hunteryavitz/blockchainapi/utils/structures/SlidingWindowTests.class deleted file mode 100644 index 0fef2bb..0000000 Binary files a/target/test-classes/com/hunteryavitz/blockchainapi/utils/structures/SlidingWindowTests.class and /dev/null differ