diff --git a/.gitignore b/.gitignore
index 5de38872..6ac465db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,2 @@
target/
/.idea/
-.env
-package-lock.json
diff --git a/pom.xml b/pom.xml
index 1d04e97f..c40f667e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,22 +45,6 @@
javafx-fxml
${javafx.version}
-
- tools.jackson.core
- jackson-databind
- 3.0.1
-
-
- io.github.cdimascio
- dotenv-java
- 3.2.0
-
-
- org.wiremock
- wiremock
- 4.0.0-beta.15
- test
-
diff --git a/src/main/java/com/example/HelloController.java b/src/main/java/com/example/HelloController.java
index 7d023ddd..fdd160a0 100644
--- a/src/main/java/com/example/HelloController.java
+++ b/src/main/java/com/example/HelloController.java
@@ -1,16 +1,14 @@
package com.example;
-import javafx.event.ActionEvent;
+
import javafx.fxml.FXML;
import javafx.scene.control.Label;
-import javafx.scene.control.ListView;
/**
* Controller layer: mediates between the view (FXML) and the model.
*/
public class HelloController {
- private final HelloModel model = new HelloModel(new NtfyConnectionImpl());
- public ListView messageView;
+ private final HelloModel model = new HelloModel();
@FXML
private Label messageLabel;
@@ -20,11 +18,5 @@ private void initialize() {
if (messageLabel != null) {
messageLabel.setText(model.getGreeting());
}
- messageView.setItems(model.getMessages());
-
- }
-
- public void sendMessage(ActionEvent actionEvent) {
- model.sendMessage();
}
}
diff --git a/src/main/java/com/example/HelloFX.java b/src/main/java/com/example/HelloFX.java
index b5001ada..96bdc5ca 100644
--- a/src/main/java/com/example/HelloFX.java
+++ b/src/main/java/com/example/HelloFX.java
@@ -1,4 +1,5 @@
package com.example;
+
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
@@ -12,7 +13,7 @@ public void start(Stage stage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader(HelloFX.class.getResource("hello-view.fxml"));
Parent root = fxmlLoader.load();
Scene scene = new Scene(root, 640, 480);
- stage.setTitle("Chatt Client");
+ stage.setTitle("Hello MVC");
stage.setScene(scene);
stage.show();
}
diff --git a/src/main/java/com/example/HelloModel.java b/src/main/java/com/example/HelloModel.java
index 2b8746fa..385cfd10 100644
--- a/src/main/java/com/example/HelloModel.java
+++ b/src/main/java/com/example/HelloModel.java
@@ -1,56 +1,15 @@
package com.example;
-import javafx.application.Platform;
-import javafx.beans.property.SimpleStringProperty;
-import javafx.beans.property.StringProperty;
-import javafx.collections.FXCollections;
-import javafx.collections.ObservableList;
-
/**
* Model layer: encapsulates application data and business logic.
*/
public class HelloModel {
-
- private final NtfyConnection connection;
-
- private final ObservableList messages = FXCollections.observableArrayList();
- private final StringProperty messageToSend = new SimpleStringProperty();
-
- public HelloModel(NtfyConnection connection) {
- this.connection = connection;
- receiveMessage();
- }
-
-
- public ObservableList getMessages() {
- return messages;
- }
-
- public String getMessageToSend() {
- return messageToSend.get();
- }
-
- public StringProperty messageToSendProperty() {
- return messageToSend;
- }
-
- public void setMessageToSend(String message) {
- messageToSend.set(message);
- }
-
/**
* Returns a greeting based on the current Java and JavaFX versions.
*/
public String getGreeting() {
- return "Chat Client by Adam";
- }
-
- public void sendMessage() {
- connection.send(messageToSend.get());
-
- }
-
- public void receiveMessage() {
- connection.receive(m->Platform.runLater(()->messages.add(m)));
+ String javaVersion = System.getProperty("java.version");
+ String javafxVersion = System.getProperty("javafx.version");
+ return "Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".";
}
}
diff --git a/src/main/java/com/example/ManyParameters.java b/src/main/java/com/example/ManyParameters.java
deleted file mode 100644
index 0610fba7..00000000
--- a/src/main/java/com/example/ManyParameters.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.example;
-
-public class ManyParameters {
-
- public ManyParameters(String computerName, int timeout, String method, int size, byte[] data){
-
- }
-
- static void main(){
- ManyParametersBuilder builder = new ManyParametersBuilder();
- builder
- .setComputerName("localhost") // Fluent API
- .setTimeout(10)
- .setSize(0)
- .createManyParameters();
- }
-}
diff --git a/src/main/java/com/example/ManyParametersBuilder.java b/src/main/java/com/example/ManyParametersBuilder.java
deleted file mode 100644
index fd49920d..00000000
--- a/src/main/java/com/example/ManyParametersBuilder.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.example;
-
-public class ManyParametersBuilder {
- private String computerName;
- private int timeout = 0;
- private String method;
- private int size = 0;
- private byte[] data = null;
-
- public ManyParametersBuilder setComputerName(String computerName) {
- this.computerName = computerName;
- return this;
- }
-
- public ManyParametersBuilder setTimeout(int timeout) {
- this.timeout = timeout;
- return this;
- }
-
- public ManyParametersBuilder setMethod(String method) {
- this.method = method;
- return this;
- }
-
- public ManyParametersBuilder setSize(int size) {
- this.size = size;
- return this;
- }
-
- public ManyParametersBuilder setData(byte[] data) {
- this.data = data;
- return this;
- }
-
- public ManyParameters createManyParameters() {
- return new ManyParameters(computerName, timeout, method, size, data);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/example/NtfyConnection.java b/src/main/java/com/example/NtfyConnection.java
deleted file mode 100644
index c239f3ab..00000000
--- a/src/main/java/com/example/NtfyConnection.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.example;
-
-import java.util.function.Consumer;
-
-public interface NtfyConnection {
- public boolean send(String message);
-
- public void receive(Consumer messageHandler);
-}
diff --git a/src/main/java/com/example/NtfyConnectionImpl.java b/src/main/java/com/example/NtfyConnectionImpl.java
deleted file mode 100644
index b89635d5..00000000
--- a/src/main/java/com/example/NtfyConnectionImpl.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.example;
-import io.github.cdimascio.dotenv.Dotenv;
-import tools.jackson.databind.ObjectMapper;
-import java.io.IOException;
-import java.net.URI;
-import java.net.http.HttpClient;
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
-import java.util.Objects;
-import java.util.function.Consumer;
-
-public class NtfyConnectionImpl implements NtfyConnection {
-
- private final HttpClient http = HttpClient.newHttpClient();
- private final String hostName;
- private final ObjectMapper mapper = new ObjectMapper();
-
- NtfyConnectionImpl(){
- Dotenv dotenv = Dotenv.load();
- hostName = Objects.requireNonNull(dotenv.get("HOST_NAME"));
- }
-
- public NtfyConnectionImpl(String hostName){
- this.hostName = hostName;
- }
-
- @Override
- public boolean send(String message) {
- HttpRequest httpRequest = HttpRequest.newBuilder()
- .POST(HttpRequest.BodyPublishers.ofString(message))
- .uri(URI.create(hostName + "/mytopic"))
- .build();
- try {
- // TODO: handle long blocking send requests to not freeze the JavaFX thread
- // 1. Use thread send message?
- // 2. Use async?
- var response = http.send(httpRequest, HttpResponse.BodyHandlers.ofString());
- return true;
- } catch (IOException e) {
- System.out.println("Error sending message");
- } catch (InterruptedException e) {
- System.out.println("Interrupted sending message");
- }
- return false;
- }
-
- @Override
- public void receive(Consumer messageHandler) {
- HttpRequest httpRequest = HttpRequest.newBuilder()
- .GET()
- .uri(URI.create(hostName + "/mytopic/json?since=wBuD2KGEaAe0"))
- .build();
-
- http.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofLines())
- .thenAccept(response -> response.body()
- .map(s->
- mapper.readValue(s, NtfyMessageDto.class))
- .filter(message -> message.event().equals("message"))
- .peek(System.out::println)
- .forEach(messageHandler));
- }
-}
diff --git a/src/main/java/com/example/NtfyMessageDto.java b/src/main/java/com/example/NtfyMessageDto.java
deleted file mode 100644
index ba65d213..00000000
--- a/src/main/java/com/example/NtfyMessageDto.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.example;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-@JsonIgnoreProperties(ignoreUnknown = true)
-public record NtfyMessageDto(String id, long time, String event, String topic, String message) {}
diff --git a/src/main/java/com/example/Singelton.java b/src/main/java/com/example/Singelton.java
deleted file mode 100644
index 3addf1e0..00000000
--- a/src/main/java/com/example/Singelton.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.example;
-
-public class Singelton {
- private final static Singelton instance = new Singelton();
-
- private Singelton() {
-
- }
-
- public static Singelton getInstance() {
- return instance;
- }
-}
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index 89e041cb..71574a27 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -1,10 +1,6 @@
module hellofx {
requires javafx.controls;
requires javafx.fxml;
- requires io.github.cdimascio.dotenv.java;
- requires java.net.http;
- requires tools.jackson.databind;
- requires javafx.graphics;
opens com.example to javafx.fxml;
exports com.example;
diff --git a/src/main/resources/com/example/hello-view.fxml b/src/main/resources/com/example/hello-view.fxml
index 025cc6a8..20a7dc82 100644
--- a/src/main/resources/com/example/hello-view.fxml
+++ b/src/main/resources/com/example/hello-view.fxml
@@ -1,12 +1,9 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/src/test/java/com/example/HelloModelTest.java b/src/test/java/com/example/HelloModelTest.java
deleted file mode 100644
index aaf7a8aa..00000000
--- a/src/test/java/com/example/HelloModelTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.example;
-
-import com.github.tomakehurst.wiremock.client.WireMock;
-import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
-import com.github.tomakehurst.wiremock.junit5.WireMockTest;
-import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.Test;
-
-import static com.github.tomakehurst.wiremock.client.WireMock.*;
-import static org.assertj.core.api.Assertions.assertThat;
-
-@WireMockTest
-class HelloModelTest {
-
- @Test
- @DisplayName("Given a model with messageToSend when calling sendMessage then send method on connection should be called ")
- void sendMessageCallsConnectionWithMessageToSend() {
-
- // Arrange Given
- var spy = new NtfyConnectionSpy();
- var model = new HelloModel(spy);
- model.setMessageToSend("Hello World");
-
- // Act When
- model.sendMessage();
-
- // Assert Then
- assertThat(spy.message).isEqualTo("Hello World");
- }
-
- @Test
- void sendMessageToFakeServer(WireMockRuntimeInfo wmRuntimeInfo) {
- var con = new NtfyConnectionImpl("http://localhost:" + wmRuntimeInfo.getHttpPort());
- var model = new HelloModel(con);
- model.setMessageToSend("Hello World");
- stubFor(post("/mytopic").willReturn(ok()));
-
- model.sendMessage();
-
- // Verify call made to server
- verify(postRequestedFor(urlEqualTo("/mytopic"))
- .withRequestBody(matching("Hello World")));
- }
-
-}
\ No newline at end of file
diff --git a/src/test/java/com/example/NtfyConnectionSpy.java b/src/test/java/com/example/NtfyConnectionSpy.java
deleted file mode 100644
index eac8d7f0..00000000
--- a/src/test/java/com/example/NtfyConnectionSpy.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.example;
-
-import java.util.function.Consumer;
-
-public class NtfyConnectionSpy implements NtfyConnection {
-
- String message;
- @Override
- public boolean send(String message) {
- this.message = message;
- return true;
- }
-
- @Override
- public void receive(Consumer messageHandler) {
-
- }
-}