diff --git a/build.gradle b/build.gradle index 9716952..7b00e83 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ plugins { id 'java' id 'application' + id 'jacoco' id 'org.sonarqube' version '6.0.1.5171' } @@ -76,6 +77,17 @@ tasks.register('fatJar', Jar) { with jar } +tasks.test { + finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) // tests are required to run before generating the report + reports { + xml.required.set(true) + } +} + // SonarQube configuration sonar { properties { diff --git a/src/main/java/org/openmbee/flexo/cli/commands/InitCommand.java b/src/main/java/org/openmbee/flexo/cli/commands/InitCommand.java index c00cdbc..7e36953 100644 --- a/src/main/java/org/openmbee/flexo/cli/commands/InitCommand.java +++ b/src/main/java/org/openmbee/flexo/cli/commands/InitCommand.java @@ -213,18 +213,16 @@ private void waitForServices() throws Exception { // Wait for Fuseki (port 3030) and MMS (port 8080) to be available int maxAttempts = 30; int attempt = 0; - + while (attempt < maxAttempts) { try { - // Check Fuseki - java.net.Socket fusekiSocket = new java.net.Socket(); - fusekiSocket.connect(new java.net.InetSocketAddress("localhost", 3030), 1000); - fusekiSocket.close(); - - // Check MMS - java.net.Socket mmsSocket = new java.net.Socket(); - mmsSocket.connect(new java.net.InetSocketAddress("localhost", 8080), 1000); - mmsSocket.close(); + try (java.net.Socket fusekiSocket = new java.net.Socket()) { + fusekiSocket.connect(new java.net.InetSocketAddress("localhost", 3030), 1000); + } + + try (java.net.Socket mmsSocket = new java.net.Socket()) { + mmsSocket.connect(new java.net.InetSocketAddress("localhost", 8080), 1000); + } // Both services are up ConsoleUtil.success(" Services are ready"); diff --git a/src/test/java/org/openmbee/flexo/cli/client/FlexoMmsClientTest.java b/src/test/java/org/openmbee/flexo/cli/client/FlexoMmsClientTest.java index 6291e19..ed88f53 100644 --- a/src/test/java/org/openmbee/flexo/cli/client/FlexoMmsClientTest.java +++ b/src/test/java/org/openmbee/flexo/cli/client/FlexoMmsClientTest.java @@ -125,7 +125,7 @@ void testGetBranchSuccess() throws Exception { FlexoMmsClient client = createClientWithMockedHttp(); - Branch branch = client.getBranch("org1", "repo1", "develop"); + client.getBranch("org1", "repo1", "develop"); // Branch might be null if parsing returns empty list // The test verifies the method completes without exception @@ -155,7 +155,7 @@ void testCreateBranchSuccess() throws Exception { FlexoMmsClient client = createClientWithMockedHttp(); - Branch branch = client.createBranch("org1", "repo1", "feature", null); + client.createBranch("org1", "repo1", "feature", null); // Verify PUT was executed twice (create + get) verify(mockHttpClient, atLeastOnce()).execute(any(HttpUriRequestBase.class)); diff --git a/src/test/java/org/openmbee/flexo/cli/config/FlexoConfigTest.java b/src/test/java/org/openmbee/flexo/cli/config/FlexoConfigTest.java index 3a34f33..4cb35b7 100644 --- a/src/test/java/org/openmbee/flexo/cli/config/FlexoConfigTest.java +++ b/src/test/java/org/openmbee/flexo/cli/config/FlexoConfigTest.java @@ -15,17 +15,29 @@ class FlexoConfigTest { - private Map originalEnv; + /* + * These lifecycle methods are intentionally empty because: + * - System.getenv() cannot be modified or reset in Java, so storing the original + * environment doesn't help with isolation between tests + * - FlexoConfig instances are independent and don't share mutable state + * - Each test creates fresh FlexoConfig instances that load from defaults/files + * - Test isolation is achieved through fresh config objects per test, not through + * environment restoration which is not possible in Java + */ @BeforeEach void setUp() { - // Store original environment variables - originalEnv = new HashMap<>(System.getenv()); + // Lifecycle methods are intentionally empty. + // System.getenv() cannot be modified or reset in Java, so storing the original + // environment doesn't help with isolation between tests. Each test creates fresh + // FlexoConfig instances that load from defaults/files independently. } @AfterEach void tearDown() { - // Note: Cannot fully restore environment in Java, but tests are isolated + // Lifecycle methods are intentionally empty. + // Test isolation is achieved through fresh FlexoConfig objects per test, + // not through environment restoration which is not possible in Java. } @Test