-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,556 additions
and
195 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
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
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
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
65 changes: 65 additions & 0 deletions
65
java/code/src/com/redhat/rhn/common/test/ErrorReportingStrategiesTest.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,65 @@ | ||
/* | ||
* Copyright (c) 2025 SUSE LLC | ||
* | ||
* This software is licensed to you under the GNU General Public License, | ||
* version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
* implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
* along with this software; if not, see | ||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
* | ||
* Red Hat trademarks are not licensed under GPLv2. No permission is | ||
* granted to use or replicate Red Hat trademarks that are incorporated | ||
* in this software or its documentation. | ||
*/ | ||
|
||
package com.redhat.rhn.common.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import com.redhat.rhn.common.ErrorReportingStrategies; | ||
import com.redhat.rhn.common.RhnError; | ||
import com.redhat.rhn.common.RhnGeneralException; | ||
import com.redhat.rhn.common.RhnReportStrategy; | ||
import com.redhat.rhn.common.RhnRuntimeException; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
public class ErrorReportingStrategiesTest { | ||
|
||
@Test | ||
public void testValidationReportingStrategyThrowsExceptionOnErrors() { | ||
RhnReportStrategy<RhnError> strategy = ErrorReportingStrategies.validationReportingStrategy(); | ||
List<RhnError> errors = List.of(new RhnError("Test error")); | ||
|
||
assertThrows(RhnGeneralException.class, () -> strategy.report(errors)); | ||
} | ||
|
||
@Test | ||
public void testRaiseAndLog() { | ||
String testMessage = "Test error message"; | ||
Supplier<RhnRuntimeException> exceptionSupplier = ErrorReportingStrategies.raiseAndLog(this, testMessage); | ||
|
||
RhnRuntimeException exception = exceptionSupplier.get(); | ||
assertTrue(exception.getMessage().contains(testMessage)); | ||
} | ||
|
||
@Test | ||
public void testRaiseAndLogLogsMessage() { | ||
String testMessage = "Test error message"; | ||
Supplier<RhnRuntimeException> exceptionSupplier = ErrorReportingStrategies.raiseAndLog(this, testMessage); | ||
|
||
// Capture the log output | ||
Logger logger = LogManager.getLogger(this.getClass().getName()); | ||
logger.error(testMessage); | ||
|
||
RhnRuntimeException exception = exceptionSupplier.get(); | ||
assertTrue(exception.getMessage().contains(testMessage)); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
java/code/src/com/redhat/rhn/common/test/RhnErrorReportTest.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,79 @@ | ||
/* | ||
* Copyright (c) 2025 SUSE LLC | ||
* | ||
* This software is licensed to you under the GNU General Public License, | ||
* version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
* implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
* along with this software; if not, see | ||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
* | ||
* Red Hat trademarks are not licensed under GPLv2. No permission is | ||
* granted to use or replicate Red Hat trademarks that are incorporated | ||
* in this software or its documentation. | ||
*/ | ||
|
||
package com.redhat.rhn.common.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import com.redhat.rhn.common.RhnError; | ||
import com.redhat.rhn.common.RhnErrorReport; | ||
import com.redhat.rhn.common.RhnGeneralException; | ||
import com.redhat.rhn.common.RhnReportStrategy; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
public class RhnErrorReportTest { | ||
|
||
public static final String DUMMY_ERROR_MESSAGE = "dummy error"; | ||
private RhnErrorReport errorReport; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
errorReport = new RhnErrorReport(); | ||
} | ||
|
||
|
||
@Test | ||
public void testHasErrors() { | ||
assertFalse(errorReport.hasErrors()); | ||
errorReport.register(DUMMY_ERROR_MESSAGE); | ||
assertTrue(errorReport.hasErrors()); | ||
} | ||
|
||
@Test | ||
public void testGetErrors() { | ||
errorReport.register("Test error 1"); | ||
errorReport.register("Test error 2"); | ||
List<RhnError> errors = errorReport.getErrors(); | ||
assertEquals(2, errors.size()); | ||
assertEquals("Test error 1", errors.get(0).getMessage()); | ||
assertEquals("Test error 2", errors.get(1).getMessage()); | ||
} | ||
|
||
@Test | ||
public void testReportWithStrategy() { | ||
RhnReportStrategy<RhnError> strategy = errors -> assertEquals(1, errors.size()); | ||
errorReport.register(DUMMY_ERROR_MESSAGE); | ||
errorReport.report(strategy); | ||
} | ||
|
||
@Test | ||
public void testReportWithDefaultStrategyThrowsException() { | ||
errorReport.register(DUMMY_ERROR_MESSAGE); | ||
assertThrows(RhnGeneralException.class, () -> errorReport.report()); | ||
} | ||
|
||
@Test | ||
public void testReportWithDefaultStrategyNoException() { | ||
assertDoesNotThrow(() -> errorReport.report()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
java/code/src/com/redhat/rhn/common/test/RhnErrorTest.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,32 @@ | ||
/* | ||
* Copyright (c) 2025 SUSE LLC | ||
* | ||
* This software is licensed to you under the GNU General Public License, | ||
* version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
* implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
* along with this software; if not, see | ||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
* | ||
* Red Hat trademarks are not licensed under GPLv2. No permission is | ||
* granted to use or replicate Red Hat trademarks that are incorporated | ||
* in this software or its documentation. | ||
*/ | ||
|
||
package com.redhat.rhn.common.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.redhat.rhn.common.RhnError; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class RhnErrorTest { | ||
|
||
@Test | ||
public void testGetMessage() { | ||
String testMessage = "Test error message"; | ||
RhnError error = new RhnError(testMessage); | ||
assertEquals(testMessage, error.getMessage()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
java/code/src/com/redhat/rhn/common/test/RhnGeneralExceptionTest.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,45 @@ | ||
/* | ||
* Copyright (c) 2025 SUSE LLC | ||
* | ||
* This software is licensed to you under the GNU General Public License, | ||
* version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
* implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
* along with this software; if not, see | ||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
* | ||
* Red Hat trademarks are not licensed under GPLv2. No permission is | ||
* granted to use or replicate Red Hat trademarks that are incorporated | ||
* in this software or its documentation. | ||
*/ | ||
|
||
package com.redhat.rhn.common.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.redhat.rhn.common.RhnError; | ||
import com.redhat.rhn.common.RhnGeneralException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
public class RhnGeneralExceptionTest { | ||
|
||
@Test | ||
public void testGetErrors() { | ||
final String dummyError1 = "Error 1"; | ||
final String dummyError2 = "Error 2"; | ||
String[] expectedMessages = {dummyError1, dummyError2}; | ||
|
||
RhnError error1 = new RhnError(dummyError1); | ||
RhnError error2 = new RhnError(dummyError2); | ||
|
||
List<RhnError> errors = List.of(error1, error2); | ||
RhnGeneralException exception = new RhnGeneralException(errors); | ||
|
||
assertEquals(errors, exception.getErrors()); | ||
assertArrayEquals(expectedMessages, exception.getErrorMessages()); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
java/code/src/com/redhat/rhn/common/test/RhnReportStrategyTest.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,57 @@ | ||
/* | ||
* Copyright (c) 2025 SUSE LLC | ||
* | ||
* This software is licensed to you under the GNU General Public License, | ||
* version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
* implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
* along with this software; if not, see | ||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
* | ||
* Red Hat trademarks are not licensed under GPLv2. No permission is | ||
* granted to use or replicate Red Hat trademarks that are incorporated | ||
* in this software or its documentation. | ||
*/ | ||
|
||
package com.redhat.rhn.common.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import com.redhat.rhn.common.RhnReportStrategy; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
public class RhnReportStrategyTest { | ||
|
||
private RhnReportStrategy<String> strategy; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
strategy = errors -> { | ||
if (errors == null || errors.isEmpty()) { | ||
throw new IllegalArgumentException("Errors list cannot be null or empty"); | ||
} | ||
}; | ||
} | ||
|
||
@Test | ||
public void testReportWithErrors() { | ||
List<String> errors = List.of("Error 1", "Error 2"); | ||
assertDoesNotThrow(() -> strategy.report(errors)); | ||
} | ||
|
||
@Test | ||
public void testReportWithEmptyErrors() { | ||
List<String> errors = List.of(); | ||
assertThrows(IllegalArgumentException.class, () -> strategy.report(errors)); | ||
} | ||
|
||
@Test | ||
public void testReportWithNullErrors() { | ||
assertThrows(IllegalArgumentException.class, () -> strategy.report(null)); | ||
} | ||
} |
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
Oops, something went wrong.