Skip to content

Lab3#10

Closed
simonforsberg wants to merge 6 commits intomainfrom
lab3
Closed

Lab3#10
simonforsberg wants to merge 6 commits intomainfrom
lab3

Conversation

@simonforsberg
Copy link

@simonforsberg simonforsberg commented Nov 13, 2025

Summary by CodeRabbit

  • New Features

    • App transformed into a chat application with topic-based messaging: connect to a topic, send messages, and view a live message list; window title and size updated.
  • Tests

    • Added comprehensive unit and integration tests and test helpers covering sending, receiving, topic switching, and HTTP interaction.
  • Chores

    • Added environment config ignore and new runtime/test dependencies plus module requirements for networking and JSON handling.

@coderabbitai
Copy link

coderabbitai bot commented Nov 13, 2025

Walkthrough

Adds Ntfy-backed messaging: new NtfyConnection API and HttpClient implementation, model/controller bindings for send/receive, updated FXML chat UI, module and Maven dependency additions, .env added to .gitignore, and accompanying tests and test helpers.

Changes

Cohort / File(s) Summary
Build Configuration
\.gitignore`, `pom.xml`, `src/main/java/module-info.java``
Added .env to .gitignore. Added dependencies: io.github.cdimascio:dotenv-java:3.2.0, tools.jackson.core:jackson-databind:3.0.1, and org.wiremock:wiremock:4.0.0-beta.15 (test). Updated module-info.java to require dotenv, java.net.http, and Jackson databind.
Connection Layer
\src/main/java/com/example/NtfyConnection.java`, `src/main/java/com/example/NtfyConnectionImpl.java`, `src/main/java/com/example/NtfyMessageDto.java``
Added NtfyConnection interface (send/receive). Implemented NtfyConnectionImpl using HttpClient with Dotenv-based host config: POST for send, async GET streaming for receive, JSON parsing and handler dispatch. Added NtfyMessageDto record with @JsonIgnoreProperties and toString().
MVC Layer
\src/main/java/com/example/HelloModel.java`, `src/main/java/com/example/HelloController.java`, `src/main/java/com/example/HelloFX.java``
HelloModel now depends on NtfyConnection, exposes observable messages, messageToSend and topic properties, and methods sendMessage, connectToTopic, receiveMessage. HelloController binds UI fields and adds sendMessage(ActionEvent) and connectToTopic(ActionEvent). HelloFX title and window width updated.
UI Layer
\src/main/resources/com/example/hello-view.fxml``
Replaced previous layout with a VBox-based chat UI: topic input + Connect button, message input + Send button, and a ListView for messages; actions wired to controller methods.
Test Infrastructure
\src/test/java/com/example/HelloModelTest.java`, `src/test/java/com/example/NtfyConnectionSpy.java`, `src/test/java/com/example/NtfyConnectionStub.java``
Added HelloModelTest with unit and WireMock integration tests for send/receive/topic behavior. Added NtfyConnectionSpy to capture sends and NtfyConnectionStub to simulate incoming messages.

Sequence Diagram(s)

sequenceDiagram
    participant UI as UI (HelloFX)
    participant Ctrl as HelloController
    participant Model as HelloModel
    participant Conn as NtfyConnectionImpl
    participant Server as Ntfy Server
    participant View as ListView

    rect rgb(230, 245, 255)
    Note over UI,Model: Send message flow
    UI->>Ctrl: sendMessage(ActionEvent)
    Ctrl->>Model: sendMessage()
    Model->>Conn: send(topic, message)
    Conn->>Server: POST /{topic} (body)
    Server-->>Conn: 2xx/response
    Ctrl->>UI: clear inputField
    end

    rect rgb(245, 255, 230)
    Note over Model,Conn: Receive stream flow
    Model->>Conn: receive(topic, handler)
    Conn->>Server: GET /{topic}/json (stream)
    Server-->>Conn: NDJSON lines (events)
    Conn->>Model: handler(NtfyMessageDto) for "message" events
    Model->>Model: Platform.runLater(update observable list)
    Model->>View: messages observable changes
    View->>UI: render new message
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay attention to: NtfyConnectionImpl async stream parsing and error/interrupt handling.
  • Verify JavaFX threading (Platform.runLater) and FXML-controller field bindings.
  • Check module declarations and added dependencies for correctness and scope.
  • Review tests for reliable JavaFX and WireMock initialization/teardown.

Poem

🐰 I nibble code and hop with glee,
Topics set and messages roam free,
POSTs and streams make chat unfurl,
Tests that hum and UI pearls,
Hoppity hooray — a chatty bunny spree! 💬

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The pull request title 'Lab3' is vague and generic, providing no meaningful information about the actual changes made to the codebase. Replace the title with a specific description of the main changes, such as 'Add Ntfy chat messaging integration with JavaFX UI' or 'Implement real-time message sending and receiving functionality'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between efa87b1 and e245be3.

📒 Files selected for processing (1)
  • src/main/java/com/example/NtfyConnectionImpl.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/example/NtfyConnectionImpl.java

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
src/main/java/com/example/NtfyConnection.java (1)

5-10: Consider adding connection lifecycle and exception handling documentation.

The interface is clean but doesn't specify connection lifecycle (connect/disconnect) or document what exceptions might be thrown. Consider whether these should be part of the interface contract.

src/main/resources/com/example/hello-view.fxml (1)

23-24: Consider making the default topic configurable.

The topic field has a hardcoded default value of "mytopic". Consider whether this should be configurable via properties or environment variables, especially if different users/environments need different topics.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 21c51e8 and 81917ad.

📒 Files selected for processing (13)
  • .gitignore (1 hunks)
  • pom.xml (1 hunks)
  • src/main/java/com/example/HelloController.java (1 hunks)
  • src/main/java/com/example/HelloFX.java (1 hunks)
  • src/main/java/com/example/HelloModel.java (2 hunks)
  • src/main/java/com/example/NtfyConnection.java (1 hunks)
  • src/main/java/com/example/NtfyConnectionImpl.java (1 hunks)
  • src/main/java/com/example/NtfyMessageDto.java (1 hunks)
  • src/main/java/module-info.java (1 hunks)
  • src/main/resources/com/example/hello-view.fxml (1 hunks)
  • src/test/java/com/example/HelloModelTest.java (1 hunks)
  • src/test/java/com/example/NtfyConnectionSpy.java (1 hunks)
  • src/test/java/com/example/NtfyConnectionStub.java (1 hunks)
🔇 Additional comments (7)
.gitignore (1)

3-3: LGTM!

Adding .env to .gitignore is the correct practice to prevent environment configuration and secrets from being committed to version control.

src/main/java/com/example/HelloFX.java (1)

15-16: LGTM!

The window size increase and title update appropriately reflect the new chat functionality. The Unicode escape sequence correctly represents the chat emoji.

src/test/java/com/example/NtfyConnectionStub.java (1)

5-23: LGTM!

Clean test stub implementation with appropriate null checking. The stub correctly stores the message handler and provides a helper method to simulate incoming messages for testing purposes.

src/main/java/com/example/NtfyMessageDto.java (1)

5-11: LGTM!

Well-designed DTO using a record for immutability. The @JsonIgnoreProperties(ignoreUnknown = true) annotation provides forward compatibility, and the toString() override is appropriate for UI display in the ListView.

src/main/java/module-info.java (1)

4-6: The original review comment is incorrect—the Jackson coordinates are valid for version 3.0.1.

Jackson 3.0 migrated to the tools.jackson.core groupId. The correct coordinates for Jackson Databind 3.0.1 are groupId tools.jackson.core, artifactId jackson-databind, version 3.0.1. The module requirement and dependency declaration in your changes are correct.

Likely an incorrect or invalid review comment.

pom.xml (2)

53-57: Jackson dependency coordinates are correct.

The web search confirms that tools.jackson.core is the correct groupId for Jackson Databind 3.0.1. This represents a groupId change in Jackson 3.0+, moving from the earlier com.fasterxml.jackson.core used in version 2.x. The pom.xml configuration is accurate.


58-63: Upgrade to WireMock 3.13.1 or confirm beta is intentional.

WireMock 4.0.0-beta.15 is a pre-release version. The latest stable release is WireMock 3.13.1 (released June 11–12, 2025). Please either upgrade to the stable version or explicitly confirm that using the beta is intentional and necessary for your test requirements.

package com.example;

import io.github.cdimascio.dotenv.Dotenv;
import tools.jackson.databind.ObjectMapper;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix invalid Jackson import for ObjectMapper.

tools.jackson.databind.ObjectMapper does not exist, so this class will not compile. Switch to the correct Jackson package.

-import tools.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectMapper;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import tools.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
🤖 Prompt for AI Agents
In src/main/java/com/example/NtfyConnectionImpl.java around line 4, the import
uses the non-existent package tools.jackson.databind.ObjectMapper; replace it
with the correct Jackson import com.fasterxml.jackson.databind.ObjectMapper so
the class compiles and uses the proper ObjectMapper implementation from the
Jackson library.

@coderabbitai
Copy link

coderabbitai bot commented Nov 13, 2025

Warning

Docstrings generation - IN PROGRESS

Generating docstrings for this pull request

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
src/main/java/com/example/NtfyConnectionImpl.java (1)

4-4: Critical: Invalid Jackson import prevents compilation.

The import tools.jackson.databind.ObjectMapper is incorrect and will cause a compilation failure. This issue was flagged in a previous review but has not been fixed yet.

Apply this diff to fix the import:

-import tools.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectMapper;
🧹 Nitpick comments (1)
src/main/java/com/example/NtfyConnectionImpl.java (1)

62-68: Consider logging deserialization failures.

The generic Exception catch silently swallows all deserialization errors, making debugging difficult. Consider at least logging the exception for troubleshooting.

                         .map(s -> {
                             try {
                                 return mapper.readValue(s, NtfyMessageDto.class);
                             } catch (Exception e) {
+                                System.err.println("Failed to parse message: " + e.getMessage());
                                 return null;
                             }
                         })
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81917ad and efa87b1.

📒 Files selected for processing (1)
  • src/main/java/com/example/NtfyConnectionImpl.java (1 hunks)
🔇 Additional comments (7)
src/main/java/com/example/NtfyConnectionImpl.java (7)

17-20: LGTM! Good addition of receiveTask field.

The field declarations are well-structured, and the receiveTask field properly addresses the previous feedback about canceling subscriptions.


22-29: LGTM! Well-designed constructors.

The dual constructor approach supports both production (environment-based) and testing (explicit hostname) scenarios effectively. The fail-fast behavior with requireNonNull is appropriate.


43-46: Good fix: interrupt status is now restored.

The interrupt status is now properly restored, addressing the previous review feedback.


51-54: Excellent: subscription cancellation properly implemented.

The synchronized method with task cancellation correctly addresses the previous feedback about preventing multiple concurrent subscriptions.


60-60: Good: receive task is properly stored.

Storing the CompletableFuture enables proper cancellation on subsequent calls, completing the fix for the subscription management issue.


69-70: Excellent: null-safe filtering properly implemented.

The null check before dereferencing and the null-safe equality check correctly address the previous NPE concerns.


35-35: No issues found—code is already correct.

The Ntfy API supports the Cache header (alias for X-Cache), and setting it to "no" prevents server-side caching of published messages. The code at line 35 correctly uses .header("Cache", "no") per the Ntfy API specification. The review comment's suggested change to "Cache-Control", "no-cache" would be incorrect for this API.

Likely an incorrect or invalid review comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant