Skip to content

Commit

Permalink
#27799 Fixing IT
Browse files Browse the repository at this point in the history
  • Loading branch information
jgambarios committed May 1, 2024
1 parent 64efe91 commit 36c0145
Showing 1 changed file with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package com.dotcms.cli.command;

import com.dotcms.DotCMSITProfile;
import com.dotcms.api.client.model.AuthenticationParam;
import com.dotcms.api.client.model.RemoteURLParam;
import com.dotcms.cli.command.language.LanguageCommand;
import com.dotcms.cli.command.language.LanguagePull;
import com.dotcms.common.WorkspaceManager;
import com.dotcms.model.config.Workspace;
import io.quarkus.arc.Arc;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.inject.Inject;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import picocli.CommandLine;
import picocli.CommandLine.ExitCode;
Expand All @@ -23,6 +26,21 @@ class RemoteURLTest extends CommandTest {
@Inject
WorkspaceManager workspaceManager;

@BeforeEach
void setUp() throws IOException {
serviceManager.removeAll();

final var remoteURLParam = Arc.container().instance(RemoteURLParam.class);
if (remoteURLParam.isAvailable() && remoteURLParam.get().getURL().isPresent()) {
remoteURLParam.get().setURL(null);
}

final var authenticationParam = Arc.container().instance(AuthenticationParam.class);
if (authenticationParam.isAvailable() && authenticationParam.get().getToken().isPresent()) {
authenticationParam.get().setToken(null);
}
}

/**
* Test case for the scenario where the dotcms-url is used but the token is missing.
*
Expand All @@ -33,7 +51,7 @@ void Test_Missing_Token() throws IOException {

// Create a temporal folder for the workspace
var tempFolder = createTempFolder();
final Workspace workspace = workspaceManager.getOrCreate(tempFolder);
workspaceManager.getOrCreate(tempFolder);

final CommandLine commandLine = createCommand();
final StringWriter writer = new StringWriter();
Expand All @@ -43,7 +61,7 @@ void Test_Missing_Token() throws IOException {

// Pulling all languages
var status = commandLine.execute(LanguageCommand.NAME, LanguagePull.NAME,
"--workspace", workspace.root().toString(),
"--workspace", tempFolder.toAbsolutePath().toString(),
"--dotcms-url", "http://localhost:8080");
Assertions.assertEquals(ExitCode.USAGE, status);

Expand All @@ -52,7 +70,7 @@ void Test_Missing_Token() throws IOException {
output.contains("The token is required when the dotCMS URL is set"));

} finally {
workspaceManager.destroy(workspace);
deleteTempDirectory(tempFolder);
}
}

Expand All @@ -66,7 +84,7 @@ void Test_Invalid_URL() throws IOException {

// Create a temporal folder for the workspace
var tempFolder = createTempFolder();
final Workspace workspace = workspaceManager.getOrCreate(tempFolder);
workspaceManager.getOrCreate(tempFolder);

final CommandLine commandLine = createCommand();
final StringWriter writer = new StringWriter();
Expand All @@ -76,15 +94,15 @@ void Test_Invalid_URL() throws IOException {

// Pulling all languages
var status = commandLine.execute(LanguageCommand.NAME, LanguagePull.NAME,
"--workspace", workspace.root().toString(),
"--workspace", tempFolder.toAbsolutePath().toString(),
"--dotcms-url", "not valid URL");
Assertions.assertEquals(ExitCode.USAGE, status);

final String output = writer.toString();
Assertions.assertTrue(output.contains("Invalid dotCMS URL"));

} finally {
workspaceManager.destroy(workspace);
deleteTempDirectory(tempFolder);
}
}

Expand All @@ -100,7 +118,7 @@ void Test_Invalid_Token() throws IOException {

// Create a temporal folder for the workspace
var tempFolder = createTempFolder();
final Workspace workspace = workspaceManager.getOrCreate(tempFolder);
workspaceManager.getOrCreate(tempFolder);

final CommandLine commandLine = createCommand();
final StringWriter writer = new StringWriter();
Expand All @@ -110,7 +128,7 @@ void Test_Invalid_Token() throws IOException {

// Pulling all languages
var status = commandLine.execute(LanguageCommand.NAME, LanguagePull.NAME,
"--workspace", workspace.root().toString(),
"--workspace", tempFolder.toAbsolutePath().toString(),
"--dotcms-url", "http://localhost:8080",
"--token", "invalid token");
Assertions.assertEquals(ExitCode.SOFTWARE, status);
Expand All @@ -119,7 +137,7 @@ void Test_Invalid_Token() throws IOException {
Assertions.assertTrue(output.contains("Invalid User"));

} finally {
workspaceManager.destroy(workspace);
deleteTempDirectory(tempFolder);
}
}

Expand All @@ -135,7 +153,7 @@ void Test_No_Configuration_Found() throws IOException {

// Create a temporal folder for the workspace
var tempFolder = createTempFolder();
final Workspace workspace = workspaceManager.getOrCreate(tempFolder);
workspaceManager.getOrCreate(tempFolder);

final CommandLine commandLine = createCommand();
final StringWriter writer = new StringWriter();
Expand All @@ -145,15 +163,15 @@ void Test_No_Configuration_Found() throws IOException {

// Pulling all languages
var status = commandLine.execute(LanguageCommand.NAME, LanguagePull.NAME,
"--workspace", workspace.root().toString());
"--workspace", tempFolder.toAbsolutePath().toString());
Assertions.assertEquals(ExitCode.SOFTWARE, status);

final String output = writer.toString();
Assertions.assertTrue(
output.contains("No dotCMS configured instances were found"));

} finally {
workspaceManager.destroy(workspace);
deleteTempDirectory(tempFolder);
}
}

Expand Down

0 comments on commit 36c0145

Please sign in to comment.