-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH24992 Admin Logger: Test for logging write commands
- Loading branch information
Showing
3 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
66 changes: 66 additions & 0 deletions
66
...-logger/src/test/java/org/glassfish/main/test/extras/commandlogger/CommandLoggerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |