From 5bddcadec34857e8a93f0c748ddb9620cd733b5a Mon Sep 17 00:00:00 2001 From: Federico Mariani Date: Fri, 2 Jul 2021 16:24:42 +0200 Subject: [PATCH] Add support JDG8+ container --- Readme.md | 2 +- containers/jdg/Readme.md | 15 +++ containers/jdg/pom.xml | 54 +++++++++++ .../jboss/qa/jcontainer/jdg/JdgClient.java | 54 +++++++++++ .../qa/jcontainer/jdg/JdgConfiguration.java | 95 +++++++++++++++++++ .../jboss/qa/jcontainer/jdg/JdgContainer.java | 53 +++++++++++ .../org/jboss/qa/jcontainer/jdg/JdgUser.java | 21 ++++ .../jcontainer/jdg/test/JdgContainerTest.java | 79 +++++++++++++++ containers/pom.xml | 1 + pom.xml | 4 + 10 files changed, 377 insertions(+), 1 deletion(-) create mode 100644 containers/jdg/Readme.md create mode 100644 containers/jdg/pom.xml create mode 100644 containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgClient.java create mode 100644 containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgConfiguration.java create mode 100644 containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgContainer.java create mode 100644 containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgUser.java create mode 100644 containers/jdg/src/test/java/org/jboss/qa/jcontainer/jdg/test/JdgContainerTest.java diff --git a/Readme.md b/Readme.md index 2e0e268..ae5509c 100644 --- a/Readme.md +++ b/Readme.md @@ -5,7 +5,7 @@ - [Apache Karaf](containers/karaf/Readme.md) - [JBoss Fuse](containers/fuse/Readme.md) - [Apache Tomcat](containers/tomcat/Readme.md) - +- [Jboss Data Grid](containers/jdg/Readme.md) ## Tests diff --git a/containers/jdg/Readme.md b/containers/jdg/Readme.md new file mode 100644 index 0000000..2b1e1e4 --- /dev/null +++ b/containers/jdg/Readme.md @@ -0,0 +1,15 @@ +# Jboss Data Grid + +- homepage: https://www.redhat.com/it/technologies/jboss-middleware/data-grid + +## Usage +```java +final JdgConfiguration conf = JdgConfiguration.builder().httpPort(11222).build(); + +try (Container cont = new JdgContainer<>(conf)) { + cont.start() +} +``` + +## Compatibility +- Jdg 8+ diff --git a/containers/jdg/pom.xml b/containers/jdg/pom.xml new file mode 100644 index 0000000..f65f062 --- /dev/null +++ b/containers/jdg/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + containers-parent + org.jboss.qa.jcontainer.containers + 1.3.2-SNAPSHOT + + jdg + JContainer Manager :: Containers :: JDG + + 12.1.0.CR2 + 1.1.0 + + + + + org.infinispan + infinispan-bom + ${version.infinispan} + pom + import + + + + + + org.slf4j + slf4j-log4j12 + ${version.slf4j} + test + + + org.infinispan + infinispan-client-hotrod + + + + + + maven-jar-plugin + + + + test-jar + + + + + + + \ No newline at end of file diff --git a/containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgClient.java b/containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgClient.java new file mode 100644 index 0000000..fc0141c --- /dev/null +++ b/containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgClient.java @@ -0,0 +1,54 @@ +/* + * Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.qa.jcontainer.jdg; + +import org.jboss.qa.jcontainer.Client; + +import java.io.IOException; +import java.util.List; + +public class JdgClient extends Client { + private static final String ERROR_MSG = "JDG container does not support client"; + + public JdgClient(T configuration) { + super(configuration); + } + + @Override + public boolean isConnected() { + return false; + } + + @Override + protected void connectInternal() throws Exception { + throw new UnsupportedOperationException(ERROR_MSG); + } + + @Override + protected void executeInternal(String command) throws Exception { + throw new UnsupportedOperationException(ERROR_MSG); + } + + @Override + protected void executeInternal(List commands) throws Exception { + throw new UnsupportedOperationException(ERROR_MSG); + } + + @Override + protected void closeInternal() throws IOException { + throw new UnsupportedOperationException(ERROR_MSG); + } +} diff --git a/containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgConfiguration.java b/containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgConfiguration.java new file mode 100644 index 0000000..88bce85 --- /dev/null +++ b/containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgConfiguration.java @@ -0,0 +1,95 @@ +/* + * Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.qa.jcontainer.jdg; + +import org.apache.commons.lang3.SystemUtils; + +import org.jboss.qa.jcontainer.JavaConfiguration; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import lombok.Getter; + +public class JdgConfiguration extends JavaConfiguration { + + public static final int DEFAULT_HTTP_PORT = 11222; + private static final String START_COMMAND = "server"; + + @Getter + protected final int httpPort; + + public JdgConfiguration(Builder builder) { + super(builder); + httpPort = builder.httpPort; + } + + public static Builder builder() { + return new Builder2(); + } + + @Override + public int getBusyPort() { + return httpPort; + } + + @Override + public List generateCommand() { + final List cmd = new ArrayList<>(); + if (SystemUtils.IS_OS_WINDOWS) { + cmd.add("cmd"); + cmd.add("/c"); + cmd.add(new File(directory, "bin" + File.separator + START_COMMAND + ".bat").getAbsolutePath()); + } else { + cmd.add("bash"); + cmd.add(new File(directory, "bin" + File.separator + START_COMMAND + ".sh").getAbsolutePath()); + } + return cmd; + } + + public File getConfigurationFolder() { + return new File(directory, "server" + File.separator + "conf"); + } + + public abstract static class Builder> extends JavaConfiguration.Builder { + + protected int httpPort; + + public Builder() { + super(); + httpPort(DEFAULT_HTTP_PORT); + password(""); + logFileName("server.log"); + } + + public T httpPort(int httpPort) { + this.httpPort = httpPort; + return self(); + } + + public JdgConfiguration build() { + return new JdgConfiguration(this); + } + } + + private static class Builder2 extends Builder { + @Override + protected Builder2 self() { + return this; + } + } +} diff --git a/containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgContainer.java b/containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgContainer.java new file mode 100644 index 0000000..233d2cf --- /dev/null +++ b/containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgContainer.java @@ -0,0 +1,53 @@ +/* + * Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.qa.jcontainer.jdg; + +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.commons.lang3.StringUtils; + +import org.jboss.qa.jcontainer.AbstractContainer; + +import java.io.File; + +public class JdgContainer, V extends JdgUser> + extends AbstractContainer { + public JdgContainer(T configuration) { + super(configuration); + } + + @Override + protected String getBasicCommand() { + return null; + } + + @Override + protected File getLogDirInternal() { + return new File(configuration.getDirectory(), "server" + File.separator + "log"); + } + + @Override + public void addUser(V user) throws Exception { + final File usersFile = new File(configuration.getConfigurationFolder(), "users.properties"); + final File rolesFile = new File(configuration.getConfigurationFolder(), "groups.properties"); + final PropertiesConfiguration propConfUsers = new PropertiesConfiguration(usersFile); + propConfUsers.setProperty(user.getUsername(), user.getPassword()); + propConfUsers.save(); + + final PropertiesConfiguration propConfRoles = new PropertiesConfiguration(rolesFile); + propConfRoles.setProperty(user.getUsername(), StringUtils.join(user.getRoles(), ",")); + propConfRoles.save(); + } +} diff --git a/containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgUser.java b/containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgUser.java new file mode 100644 index 0000000..7e0ef4e --- /dev/null +++ b/containers/jdg/src/main/java/org/jboss/qa/jcontainer/jdg/JdgUser.java @@ -0,0 +1,21 @@ +/* + * Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.qa.jcontainer.jdg; + +import org.jboss.qa.jcontainer.User; + +public class JdgUser extends User { +} diff --git a/containers/jdg/src/test/java/org/jboss/qa/jcontainer/jdg/test/JdgContainerTest.java b/containers/jdg/src/test/java/org/jboss/qa/jcontainer/jdg/test/JdgContainerTest.java new file mode 100644 index 0000000..e84f775 --- /dev/null +++ b/containers/jdg/src/test/java/org/jboss/qa/jcontainer/jdg/test/JdgContainerTest.java @@ -0,0 +1,79 @@ +/* + * Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.qa.jcontainer.jdg.test; + +import org.jboss.qa.jcontainer.AbstractContainer; +import org.jboss.qa.jcontainer.jdg.JdgConfiguration; +import org.jboss.qa.jcontainer.jdg.JdgContainer; +import org.jboss.qa.jcontainer.jdg.JdgUser; +import org.jboss.qa.jcontainer.test.ContainerTest; +import org.jboss.qa.jcontainer.util.FileUtils; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RunWith(JUnit4.class) +public class JdgContainerTest extends ContainerTest { + public static final String JDG_HOME = "/home/federico/Downloads/redhat-datagrid-8.2.0-server"; //getProperty("jdg.home"); + protected static AbstractContainer container; + + @BeforeClass + public static void beforeClass() throws Exception { + final JdgConfiguration conf = JdgConfiguration.builder().directory(JDG_HOME).build(); + container = new JdgContainer(conf); + final JdgUser user = new JdgUser(); + user.setUsername("infinispanUsername"); + user.setPassword("infinispanPassword"); + user.addRoles("admin", "dev"); + container.addUser(user); + container.start(); + + System.out.println(container.isClientSupported()); + } + + @AfterClass + public static void afterClass() throws Exception { + if (container != null) { + container.stop(); + } + } + + @Test + public void baseTest() throws Exception { + Assert.assertTrue(container.isRunning()); + } + + @Test + public void defaultLogFileTest() throws Exception { + Assert.assertTrue(container.getDefaultLogFile().exists()); + log.debug("File '{}' - length = {}", container.getDefaultLogFile().getName(), container.getDefaultLogFile().length()); + Assert.assertFalse(FileUtils.isEmpty(container.getDefaultLogFile())); + } + + @Test + public void stdoutLogFileTest() throws Exception { + Assert.assertTrue(container.getStdoutLogFile().exists()); + log.debug("File '{}' - length = {}", container.getStdoutLogFile().getName(), container.getStdoutLogFile().length()); + Assert.assertFalse(FileUtils.isEmpty(container.getStdoutLogFile())); + } +} diff --git a/containers/pom.xml b/containers/pom.xml index c2915ed..e65809f 100644 --- a/containers/pom.xml +++ b/containers/pom.xml @@ -16,6 +16,7 @@ wildfly eap tomcat + jdg diff --git a/pom.xml b/pom.xml index d28bc78..eb99ec3 100644 --- a/pom.xml +++ b/pom.xml @@ -188,6 +188,10 @@ fuse.home ${fuse.home} + + jdg.home + ${jdg.home} +