Skip to content

Commit

Permalink
GH24992 Admin Logger: Test for logging write commands
Browse files Browse the repository at this point in the history
  • Loading branch information
OndroMih committed Jun 22, 2024
1 parent 0b3e32e commit 0c8a7bb
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 0 deletions.
83 changes: 83 additions & 0 deletions appserver/tests/extras/command-logger/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2024 Contributors to the Eclipse Foundation.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.glassfish.main.tests</groupId>
<artifactId>extras-tests-parent</artifactId>
<version>7.0.16-SNAPSHOT</version>
</parent>

<artifactId>command-logger-tests</artifactId>

<name>GlassFish Admin Command Logger Tests</name>

<dependencies>
<dependency>
<groupId>org.glassfish.main</groupId>
<artifactId>glassfish-itest-tools</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main</groupId>
<artifactId>test-utils</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main.distributions</groupId>
<artifactId>glassfish</artifactId>
<type>zip</type>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-glassfish</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>glassfish</includeArtifactIds>
<excludeTransitive>true</excludeTransitive>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */
package org.glassfish.main.test.extras.commandlogger;

import static org.glassfish.main.itest.tools.GlassFishTestEnvironment.getAsadmin;
import static org.glassfish.main.itest.tools.asadmin.AsadminResultMatcher.asadminOK;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.main.itest.tools.asadmin.Asadmin;
import org.glassfish.main.itest.tools.asadmin.AsadminResult;
import org.junit.jupiter.api.Test;

/**
*
* @author Ondro Mihalyi
*/
public class CommandLoggerTest {

private static final Asadmin ASADMIN = getAsadmin();

@Test
public void testLogWriteCommands() throws IOException {
assertThat(ASADMIN.exec("create-system-properties", "--target=server", "glassfish.commandlogger.logmode=WRITE_COMMANDS"), asadminOK());
ASADMIN.exec("delete-system-property", "X");
AsadminResult result = ASADMIN.exec("collect-log-files");
assertThat(result, asadminOK());
String path = StringUtils.substringBetween(result.getStdOut(), "Created Zip file under ", ".\n");
assertNotNull(path, () -> "zip file path parsed from " + result.getStdOut());
File file = new File(path);
assertThat(file.getName(), endsWith(".zip"));
final ZipFile zipFile = new ZipFile(file);
final ZipEntry entry = zipFile.getEntry("logs/server/server.log");
final BufferedReader reader = new BufferedReader(new InputStreamReader(zipFile.getInputStream(entry)));
List<String> lines = new ArrayList<>();
while (reader.ready()) {
lines.add(reader.readLine());
}
assertThat("log", lines, hasItem(containsString("delete-system-property X")));
}

}
37 changes: 37 additions & 0 deletions appserver/tests/extras/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2024 Contributors to the Eclipse Foundation.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.glassfish.main.tests</groupId>
<artifactId>tests</artifactId>
<version>7.0.16-SNAPSHOT</version>
</parent>

<artifactId>extras-tests-parent</artifactId>
<packaging>pom</packaging>

<name>GlassFish Extras Tests - Parent</name>

<modules>
<module>command-logger</module>
</modules>
</project>

0 comments on commit 0c8a7bb

Please sign in to comment.