diff --git a/build-helper-mojo/src/test/java/com/oracle/wls/buildhelper/BuildHelperMojoTest.java b/build-helper-mojo/src/test/java/com/oracle/wls/buildhelper/BuildHelperMojoTest.java index 0112cfb8..29aef220 100644 --- a/build-helper-mojo/src/test/java/com/oracle/wls/buildhelper/BuildHelperMojoTest.java +++ b/build-helper-mojo/src/test/java/com/oracle/wls/buildhelper/BuildHelperMojoTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2020, 2021, Oracle and/or its affiliates. +// Copyright (c) 2020, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.buildhelper; @@ -26,7 +26,7 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -public class BuildHelperMojoTest { +class BuildHelperMojoTest { private final BuildHelperMojo mojo = new BuildHelperMojo(); private final List mementos = new ArrayList<>(); @@ -46,55 +46,55 @@ public void tearDown() { } @Test - public void helperImplementsMojo() { + void helperImplementsMojo() { assertThat(mojo, Matchers.instanceOf(AbstractMojo.class)); } @Test - public void mojoHasGoalAnnotation() { + void mojoHasGoalAnnotation() { assertThat(mojoTestSupport.getClassAnnotation(), notNullValue()); } @Test - public void mojoAnnotatedWithName() { + void mojoAnnotatedWithName() { assertThat(mojoTestSupport.getClassAnnotation().get("name"), equalTo("copy")); } @Test - public void mojoAnnotatedWithDefaultPhase() { + void mojoAnnotatedWithDefaultPhase() { assertThat(mojoTestSupport.getClassAnnotation().get("defaultPhase"), equalTo(PROCESS_RESOURCES)); } @Test - public void hasRequiredSourceFileParameter() throws NoSuchFieldException { + void hasRequiredSourceFileParameter() throws NoSuchFieldException { assertThat(mojoTestSupport.getParameterField("sourceFile").getType(), equalTo(String.class)); assertThat(mojoTestSupport.getParameterAnnotation("sourceFile").get("required"), is(true)); } @Test - public void hasAnnotatedTargetFileField_withNoDefault() throws NoSuchFieldException { + void hasAnnotatedTargetFileField_withNoDefault() throws NoSuchFieldException { assertThat(mojoTestSupport.getParameterField("targetFile").getType(), equalTo(File.class)); assertThat(mojoTestSupport.getParameterAnnotation("targetFile").get("defaultValue"), nullValue()); } @Test - public void targetFileField_isRequired() throws NoSuchFieldException { + void targetFileField_isRequired() throws NoSuchFieldException { assertThat(mojoTestSupport.getParameterAnnotation("targetFile").get("required"), is(true)); } @Test - public void hasAnnotatedUserDirFileField_withNullDefault() throws NoSuchFieldException { + void hasAnnotatedUserDirFileField_withNullDefault() throws NoSuchFieldException { assertThat(mojoTestSupport.getParameterField("userDir").getType(), equalTo(File.class)); assertThat(mojoTestSupport.getParameterAnnotation("userDir").get("defaultValue"), nullValue()); } @Test - public void userDirField_isNotRequired() throws NoSuchFieldException { + void userDirField_isNotRequired() throws NoSuchFieldException { assertThat(mojoTestSupport.getParameterAnnotation("userDir").get("required"), nullValue()); } @Test - public void whenSourceAndTargetAbsolute_useAbsolutePaths() throws Exception { + void whenSourceAndTargetAbsolute_useAbsolutePaths() throws Exception { setMojoParameter("sourceFile", "/root/source"); setMojoParameter("targetFile", new File("/root/target")); @@ -105,7 +105,7 @@ public void whenSourceAndTargetAbsolute_useAbsolutePaths() throws Exception { } @Test - public void whenSourcePathIsRelative_computeAbsoluteRelativeToUserDir() throws Exception { + void whenSourcePathIsRelative_computeAbsoluteRelativeToUserDir() throws Exception { setMojoParameter("sourceFile", "source"); setMojoParameter("targetFile", new File("/root/target")); setMojoParameter("userDir", new File("/root/nested")); @@ -117,7 +117,7 @@ public void whenSourcePathIsRelative_computeAbsoluteRelativeToUserDir() throws E } @Test - public void whenSourcePathIsRelativeAndNoUserDir_useSystemProperty() throws Exception { + void whenSourcePathIsRelativeAndNoUserDir_useSystemProperty() throws Exception { System.setProperty("user.dir", "/user"); setMojoParameter("sourceFile", "source"); setMojoParameter("targetFile", new File("/root/target")); diff --git a/wls-exporter-core/src/main/java/com/oracle/wls/exporter/ConfigurationDisplay.java b/wls-exporter-core/src/main/java/com/oracle/wls/exporter/ConfigurationDisplay.java index e465c970..218cc4ba 100644 --- a/wls-exporter-core/src/main/java/com/oracle/wls/exporter/ConfigurationDisplay.java +++ b/wls-exporter-core/src/main/java/com/oracle/wls/exporter/ConfigurationDisplay.java @@ -1,4 +1,4 @@ -// Copyright (c) 2021, Oracle and/or its affiliates. +// Copyright (c) 2021, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter; @@ -8,6 +8,10 @@ public class ConfigurationDisplay { + private ConfigurationDisplay() { + // no-op + } + public static void displayConfiguration(OutputStream outputStream) { try (PrintStream ps = new PrintStream(outputStream)) { ps.println("

Current Configuration

"); diff --git a/wls-exporter-core/src/main/java/com/oracle/wls/exporter/DemoInputs.java b/wls-exporter-core/src/main/java/com/oracle/wls/exporter/DemoInputs.java index f5b795ce..ecf87a2e 100644 --- a/wls-exporter-core/src/main/java/com/oracle/wls/exporter/DemoInputs.java +++ b/wls-exporter-core/src/main/java/com/oracle/wls/exporter/DemoInputs.java @@ -7,6 +7,11 @@ * @author Russell Gold */ class DemoInputs { + + private DemoInputs() { + // no-op + } + @SuppressWarnings("unused") static final String YAML_STRING = "---\n" + "startDelaySeconds: 5\n" + diff --git a/wls-exporter-core/src/main/java/com/oracle/wls/exporter/LiveConfiguration.java b/wls-exporter-core/src/main/java/com/oracle/wls/exporter/LiveConfiguration.java index b4a293fb..3439b0a4 100644 --- a/wls-exporter-core/src/main/java/com/oracle/wls/exporter/LiveConfiguration.java +++ b/wls-exporter-core/src/main/java/com/oracle/wls/exporter/LiveConfiguration.java @@ -24,6 +24,10 @@ */ public class LiveConfiguration { + private LiveConfiguration() { + // no-op + } + /** The address used to access WLS (cannot use the address found in the request due to potential server-side request forgery. */ static final String WLS_HOST; @@ -190,7 +194,7 @@ public static void updateConfiguration() { installNewConfiguration(updater.getUpdate()); } - private synchronized static void installNewConfiguration(ConfigurationUpdate update) { + private static synchronized void installNewConfiguration(ConfigurationUpdate update) { if (update.getTimestamp() > timestamp) { getConfig().replace(toConfiguration(update.getConfiguration())); timestamp = update.getTimestamp(); diff --git a/wls-exporter-core/src/main/java/com/oracle/wls/exporter/domain/MapUtils.java b/wls-exporter-core/src/main/java/com/oracle/wls/exporter/domain/MapUtils.java index 1fc403a3..950c10e0 100644 --- a/wls-exporter-core/src/main/java/com/oracle/wls/exporter/domain/MapUtils.java +++ b/wls-exporter-core/src/main/java/com/oracle/wls/exporter/domain/MapUtils.java @@ -1,4 +1,4 @@ -// Copyright (c) 2017, 2020, Oracle and/or its affiliates. +// Copyright (c) 2017, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter.domain; @@ -13,6 +13,9 @@ */ public class MapUtils { + private MapUtils() { + // no-op + } private static final String ILLEGAL_VALUE_FORMAT = "Illegal value for %s: %s. Value must be %s"; /** @@ -51,8 +54,8 @@ static Boolean getBooleanValue(Map map, String key) { throw createBadTypeException(key, value, "a boolean"); } - private final static String[] TRUE_VALUES = {"true", "t", "yes", "on", "y"}; - private final static String[] FALSE_VALUES = {"false", "f", "no", "off", "n"}; + private static final String[] TRUE_VALUES = {"true", "t", "yes", "on", "y"}; + private static final String[] FALSE_VALUES = {"false", "f", "no", "off", "n"}; private static boolean inValues(Object candidate, String... matches) { for (String match : matches) diff --git a/wls-exporter-core/src/main/java/com/oracle/wls/exporter/domain/SnakeCaseUtil.java b/wls-exporter-core/src/main/java/com/oracle/wls/exporter/domain/SnakeCaseUtil.java index 12025a42..e858c1cd 100644 --- a/wls-exporter-core/src/main/java/com/oracle/wls/exporter/domain/SnakeCaseUtil.java +++ b/wls-exporter-core/src/main/java/com/oracle/wls/exporter/domain/SnakeCaseUtil.java @@ -1,4 +1,4 @@ -// Copyright (c) 2017, 2020, Oracle and/or its affiliates. +// Copyright (c) 2017, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter.domain; @@ -11,6 +11,11 @@ * @author Russell Gold */ public class SnakeCaseUtil { + + private SnakeCaseUtil() { + // no-op + } + private static final Pattern SNAKE_CASE_PATTERN = Pattern.compile("([a-z0-9])([A-Z])"); static String convert(String s) { diff --git a/wls-exporter-core/src/main/java/com/oracle/wls/exporter/webapp/ServletUtils.java b/wls-exporter-core/src/main/java/com/oracle/wls/exporter/webapp/ServletUtils.java index 91c1e1f0..60110fb5 100644 --- a/wls-exporter-core/src/main/java/com/oracle/wls/exporter/webapp/ServletUtils.java +++ b/wls-exporter-core/src/main/java/com/oracle/wls/exporter/webapp/ServletUtils.java @@ -1,4 +1,4 @@ -// Copyright (c) 2021, Oracle and/or its affiliates. +// Copyright (c) 2021, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter.webapp; @@ -12,6 +12,10 @@ public class ServletUtils { + private ServletUtils() { + // no-op + } + /** The path to the configuration file within the web application. */ public static final String CONFIG_YML = "/config.yml"; diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationFormCallTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationFormCallTest.java index a1978c45..37e2482c 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationFormCallTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationFormCallTest.java @@ -20,7 +20,7 @@ import static org.hamcrest.Matchers.startsWith; import static org.junit.jupiter.api.Assertions.assertThrows; -public class ConfigurationFormCallTest { +class ConfigurationFormCallTest { private static final String CONFIGURATION = "hostName: " + HOST_NAME + "\n" + @@ -72,7 +72,7 @@ public void setUp() { } @Test - public void whenNoConfigurationSpecified_reportFailure() { + void whenNoConfigurationSpecified_reportFailure() { assertThrows(RuntimeException.class, () -> handleConfigurationFormCall(context)); } @@ -83,35 +83,35 @@ private void handleConfigurationFormCall(InvocationContextStub context) throws I } @Test - public void whenRequestUsesHttp_authenticateWithHttp() throws Exception { + void whenRequestUsesHttp_authenticateWithHttp() throws Exception { handleConfigurationFormCall(context.withConfigurationForm("replace", CONFIGURATION)); assertThat(factory.getClientUrl(), startsWith("http:")); } @Test - public void whenRequestUsesHttps_authenticateWithHttps() throws Exception { + void whenRequestUsesHttps_authenticateWithHttps() throws Exception { handleConfigurationFormCall(context.withHttps().withConfigurationForm("replace", CONFIGURATION)); assertThat(factory.getClientUrl(), startsWith("https:")); } @Test - public void afterUploadWithReplace_useNewConfiguration() throws Exception { + void afterUploadWithReplace_useNewConfiguration() throws Exception { handleConfigurationFormCall(context.withConfigurationForm("replace", CONFIGURATION)); assertThat(LiveConfiguration.asString(), equalTo(CONFIGURATION)); } @Test - public void afterUpload_redirectToMainPage() throws Exception { + void afterUpload_redirectToMainPage() throws Exception { handleConfigurationFormCall(context.withConfigurationForm("replace", CONFIGURATION)); assertThat(context.getRedirectLocation(), equalTo(WebAppConstants.MAIN_PAGE)); } @Test - public void whenRestPortInaccessible_switchToSpecifiedPort() throws Exception { + void whenRestPortInaccessible_switchToSpecifiedPort() throws Exception { LiveConfiguration.loadFromString(CONFIGURATION_WITH_REST_PORT); factory.throwConnectionFailure("localhost", REST_PORT); @@ -121,14 +121,14 @@ public void whenRestPortInaccessible_switchToSpecifiedPort() throws Exception { } @Test - public void afterUploadWithAppend_useCombinedConfiguration() throws Exception { + void afterUploadWithAppend_useCombinedConfiguration() throws Exception { handleConfigurationFormCall(context.withConfigurationForm("append", ADDED_CONFIGURATION)); assertThat(LiveConfiguration.asString(), equalTo(COMBINED_CONFIGURATION)); } @Test - public void whenSelectedFileIsNotYaml_reportError() throws Exception { + void whenSelectedFileIsNotYaml_reportError() throws Exception { handleConfigurationFormCall(context.withConfigurationForm("replace", NON_YAML)); assertThat(context.getResponse(), containsString(ConfigurationException.NOT_YAML_FORMAT)); @@ -138,7 +138,7 @@ public void whenSelectedFileIsNotYaml_reportError() throws Exception { "this is not yaml\n"; @Test - public void whenSelectedFileHasPartialYaml_reportError() throws Exception { + void whenSelectedFileHasPartialYaml_reportError() throws Exception { handleConfigurationFormCall(context.withConfigurationForm("replace", PARTIAL_YAML)); assertThat(context.getResponse(), containsString(ConfigurationException.BAD_YAML_FORMAT)); @@ -148,7 +148,7 @@ public void whenSelectedFileHasPartialYaml_reportError() throws Exception { "queries:\nkey name\n"; @Test - public void whenSelectedFileHasBadBooleanValue_reportError() throws Exception { + void whenSelectedFileHasBadBooleanValue_reportError() throws Exception { handleConfigurationFormCall(context.withConfigurationForm("append", ADDED_CONFIGURATION_WITH_BAD_BOOLEAN)); assertThat(context.getResponse(), containsString(BAD_BOOLEAN_STRING)); @@ -162,14 +162,14 @@ public void whenSelectedFileHasBadBooleanValue_reportError() throws Exception { " values: [age, sex]\n"; @Test - public void afterSelectedFileHasBadBooleanValue_configurationIsUnchanged() throws Exception { + void afterSelectedFileHasBadBooleanValue_configurationIsUnchanged() throws Exception { handleConfigurationFormCall(context.withConfigurationForm("append", ADDED_CONFIGURATION_WITH_BAD_BOOLEAN)); assertThat(LiveConfiguration.asString(), equalTo(CONFIGURATION)); } @Test - public void whenServerSends403StatusOnGet_returnToClient() throws Exception { + void whenServerSends403StatusOnGet_returnToClient() throws Exception { factory.reportNotAuthorized(); handleConfigurationFormCall(context.withConfigurationForm("replace", CONFIGURATION)); @@ -178,7 +178,7 @@ public void whenServerSends403StatusOnGet_returnToClient() throws Exception { } @Test - public void whenServerSends401StatusOnGet_returnToClient() throws Exception { + void whenServerSends401StatusOnGet_returnToClient() throws Exception { factory.reportAuthenticationRequired("Test-Realm"); handleConfigurationFormCall(context.withConfigurationForm("replace", CONFIGURATION)); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationPutCallTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationPutCallTest.java index 949dbee6..c895d3d5 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationPutCallTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationPutCallTest.java @@ -59,21 +59,21 @@ private void handleConfigurationPutCall(InvocationContextStub context) throws IO } @Test - public void whenSpecifiedConfigurationHasBadBooleanValue_reportError() throws Exception { + void whenSpecifiedConfigurationHasBadBooleanValue_reportError() throws Exception { handleConfigurationPutCall(context.withConfiguration("application/yaml", CONFIGURATION_WITH_BAD_BOOLEAN)); assertThat(context.getResponseStatus(), equalTo(HttpURLConnection.HTTP_BAD_REQUEST)); } @Test - public void updateSpecifiedConfiguration() throws Exception { + void updateSpecifiedConfiguration() throws Exception { handleConfigurationPutCall(context.withConfiguration("application/yaml", YAML_CONFIGURATION)); assertThat(LiveConfiguration.asString(), equalTo(YAML_CONFIGURATION)); } @Test - public void updateConfigurationWithJson() throws Exception { + void updateConfigurationWithJson() throws Exception { handleConfigurationPutCall(context.withConfiguration("application/json", JSON_CONFIGURATION)); assertThat(LiveConfiguration.asString(), equalTo(YAML_CONFIGURATION)); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationUpdaterImplTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationUpdaterImplTest.java index 91d8558a..b57be9de 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationUpdaterImplTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationUpdaterImplTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2017, 2021, Oracle and/or its affiliates. +// Copyright (c) 2017, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter; @@ -15,7 +15,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; -public class ConfigurationUpdaterImplTest { +class ConfigurationUpdaterImplTest { private static final long TIMESTAMP_1 = 17; private static final String CONFIGURATION_1 = "first yaml config"; @@ -49,14 +49,14 @@ public void setUp() { } @Test - public void whenUnableToReachServer_returnedTimestampIsZero() { + void whenUnableToReachServer_returnedTimestampIsZero() { factory.throwWebClientException(new WebClientException()); assertThat(impl.getLatestConfigurationTimestamp(), equalTo(0L)); } @Test - public void whenUnableToReachServer_addReasonToLog() { + void whenUnableToReachServer_addReasonToLog() { factory.throwWebClientException(new WebClientException("Unable to reach server")); impl.setErrorLog(errorLog); @@ -66,14 +66,14 @@ public void whenUnableToReachServer_addReasonToLog() { } @Test - public void extractTimestampFromReply() { + void extractTimestampFromReply() { factory.addJsonResponse(RESPONSE_1); assertThat(impl.getLatestConfigurationTimestamp(), equalTo(TIMESTAMP_1)); } @Test - public void whenUpdateFetched_specifyConfiguredUrl() { + void whenUpdateFetched_specifyConfiguredUrl() { impl.configure("http://repeater/", 0); impl.getLatestConfigurationTimestamp(); @@ -82,7 +82,7 @@ public void whenUpdateFetched_specifyConfiguredUrl() { } @Test - public void whenAskedForConfigurationWithinUpdateInterval_returnCachedValue() { + void whenAskedForConfigurationWithinUpdateInterval_returnCachedValue() { clock.setCurrentMsec(0); factory.addJsonResponse(RESPONSE_1); impl.getLatestConfigurationTimestamp(); @@ -94,7 +94,7 @@ public void whenAskedForConfigurationWithinUpdateInterval_returnCachedValue() { } @Test - public void whenAskedForConfigurationAfterUpdateInterval_returnNewValue() { + void whenAskedForConfigurationAfterUpdateInterval_returnNewValue() { clock.setCurrentMsec(0); factory.addJsonResponse(RESPONSE_1); impl.getLatestConfigurationTimestamp(); @@ -106,14 +106,14 @@ public void whenAskedForConfigurationAfterUpdateInterval_returnNewValue() { } @Test - public void afterRetrieveUpdate_returnIt() { + void afterRetrieveUpdate_returnIt() { factory.addJsonResponse(RESPONSE_1); assertThat(impl.getUpdate().getConfiguration(), equalTo(CONFIGURATION_1)); } @Test - public void onShareConfiguration_connectToConfiguredUrl() { + void onShareConfiguration_connectToConfiguredUrl() { impl.configure("http://posttarget", 0); impl.shareConfiguration(CONFIGURATION_1); @@ -122,14 +122,14 @@ public void onShareConfiguration_connectToConfiguredUrl() { } @Test - public void onShareConfiguration_sendsConfigurationInJsonObject() { + void onShareConfiguration_sendsConfigurationInJsonObject() { impl.shareConfiguration(CONFIGURATION_1); assertThat(factory.getPostedString(), hasJsonPath("$.configuration").withValue(CONFIGURATION_1)); } @Test - public void onShareConfiguration_sendsTimestampInJsonObject() { + void onShareConfiguration_sendsTimestampInJsonObject() { clock.setCurrentMsec(23); impl.shareConfiguration(CONFIGURATION_1); @@ -138,7 +138,7 @@ public void onShareConfiguration_sendsTimestampInJsonObject() { } @Test - public void whenUnableToShareConfiguration_logProblem() { + void whenUnableToShareConfiguration_logProblem() { factory.throwWebClientException(new WebClientException("Unable to reach server")); impl.setErrorLog(errorLog); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ErrorLogTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ErrorLogTest.java index ac996ead..890146e6 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ErrorLogTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ErrorLogTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2019, 2021, Oracle and/or its affiliates. +// Copyright (c) 2019, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter; @@ -17,25 +17,25 @@ import static com.oracle.wls.exporter.ErrorLogTest.LogMatcher.containsErrors; import static org.hamcrest.MatcherAssert.assertThat; -public class ErrorLogTest { +class ErrorLogTest { private final ErrorLog errorLog = new ErrorLog(); @Test - public void afterExceptionReported_isAddedToLog() { + void afterExceptionReported_isAddedToLog() { errorLog.log(new IOException("Unable to read value")); assertThat(errorLog, containsErrors("IOException: Unable to read value")); } @Test - public void afterExceptionWithNoMessageReported_logSimpleNameOnly() { + void afterExceptionWithNoMessageReported_logSimpleNameOnly() { errorLog.log(new IOException()); assertThat(errorLog, containsErrors("IOException")); } @Test - public void afterExceptionWithNestedThrowableReported_addToLog() { + void afterExceptionWithNestedThrowableReported_addToLog() { errorLog.log(new IOException("Unable to read value", new RuntimeException("has impossible format"))); assertThat(errorLog, containsErrors("IOException: Unable to read value", " RuntimeException: has impossible format")); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ExporterCallTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ExporterCallTest.java index 98e36f0a..01be53bf 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ExporterCallTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ExporterCallTest.java @@ -1,5 +1,6 @@ // Copyright (c) 2021, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + package com.oracle.wls.exporter; import java.io.IOException; @@ -13,7 +14,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; -public class ExporterCallTest { +class ExporterCallTest { private static final String URL_PATTERN = "http://%s:%d/management/weblogic/latest/serverRuntime/search"; private static final String SECURE_URL_PATTERN = "https://%s:%d/management/weblogic/latest/serverRuntime/search"; private static final String ONE_VALUE_CONFIG = "queries:\n- groups:\n key: name\n values: testSample1"; @@ -28,7 +29,7 @@ public void setUp() { } @Test - public void whenConfigFileNameNotFound_getReportsTheIssue() throws Exception { + void whenConfigFileNameNotFound_getReportsTheIssue() throws Exception { LiveConfiguration.loadFromString(""); handleMetricsCall(context); @@ -43,7 +44,7 @@ private void handleMetricsCall(InvocationContextStub context) throws IOException } @Test - public void onPlaintextGet_defineConnectionUrlFromContext() throws Exception { + void onPlaintextGet_defineConnectionUrlFromContext() throws Exception { LiveConfiguration.loadFromString(ONE_VALUE_CONFIG); handleMetricsCall(context); @@ -52,7 +53,7 @@ public void onPlaintextGet_defineConnectionUrlFromContext() throws Exception { } @Test - public void onSecurePlaintextGet_defineConnectionUrlFromContext() throws Exception { + void onSecurePlaintextGet_defineConnectionUrlFromContext() throws Exception { LiveConfiguration.loadFromString(ONE_VALUE_CONFIG); handleMetricsCall(context.withHttps()); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ExporterServletTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ExporterServletTest.java index bba43906..ec3e7f3a 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ExporterServletTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/ExporterServletTest.java @@ -47,7 +47,7 @@ /** * @author Russell Gold */ -public class ExporterServletTest { +class ExporterServletTest { private static final String localHostName = ServletInvocationContext.getLocalHostName(); private static final int REST_PORT = 7654; private static final int LOCAL_PORT = 7001; @@ -88,24 +88,24 @@ public void tearDown() { } @Test - public void exporter_isHttpServlet() { + void exporter_isHttpServlet() { assertThat(servlet, instanceOf(HttpServlet.class)); } @Test - public void servlet_hasWebServletAnnotation() { + void servlet_hasWebServletAnnotation() { assertThat(ExporterServlet.class.getAnnotation(WebServlet.class), notNullValue()); } @Test - public void servletAnnotationIndicatesMetricsPage() { + void servletAnnotationIndicatesMetricsPage() { WebServlet annotation = ExporterServlet.class.getAnnotation(WebServlet.class); assertThat(annotation.value(), arrayContaining("/metrics")); } @Test - public void whenConfigParamNotFound_configurationHasNoQueries() throws Exception { + void whenConfigParamNotFound_configurationHasNoQueries() throws Exception { servlet.init(withNoParams()); servlet.doGet(request, response); @@ -114,7 +114,7 @@ public void whenConfigParamNotFound_configurationHasNoQueries() throws Exception } @Test - public void whenConfigFileNameNotAbsolute_getReportsTheIssue() throws Exception { + void whenConfigFileNameNotAbsolute_getReportsTheIssue() throws Exception { servlet.init(withNoParams()); servlet.doGet(request, response); @@ -123,7 +123,7 @@ public void whenConfigFileNameNotAbsolute_getReportsTheIssue() throws Exception } @Test - public void whenConfigFileNotFound_getReportsTheIssue() throws Exception { + void whenConfigFileNotFound_getReportsTheIssue() throws Exception { servlet.init(withNoParams()); servlet.doGet(request, response); @@ -132,7 +132,7 @@ public void whenConfigFileNotFound_getReportsTheIssue() throws Exception { } @Test - public void onPlaintextGet_defineConnectionUrlFromContext() throws Exception { + void onPlaintextGet_defineConnectionUrlFromContext() throws Exception { initServlet(ONE_VALUE_CONFIG); servlet.doGet(request, response); @@ -142,7 +142,7 @@ public void onPlaintextGet_defineConnectionUrlFromContext() throws Exception { } @Test - public void onSecurePlaintextGet_defineConnectionUrlFromContext() throws Exception { + void onSecurePlaintextGet_defineConnectionUrlFromContext() throws Exception { initServlet(ONE_VALUE_CONFIG); request.setSecure(true); @@ -153,7 +153,7 @@ public void onSecurePlaintextGet_defineConnectionUrlFromContext() throws Excepti } @Test - public void whenRestPortDefined_connectionUrlUsesRestPort() throws IOException { + void whenRestPortDefined_connectionUrlUsesRestPort() throws IOException { initServlet(REST_PORT_CONFIG); servlet.doGet(request, response); @@ -162,7 +162,7 @@ public void whenRestPortDefined_connectionUrlUsesRestPort() throws IOException { } @Test - public void whenRestPortAccessFails_switchToLocalPort() throws IOException { + void whenRestPortAccessFails_switchToLocalPort() throws IOException { initServlet(REST_PORT_CONFIG); factory.throwConnectionFailure(request.getLocalName(), REST_PORT); factory.addJsonResponse(new HashMap<>()); @@ -173,7 +173,7 @@ public void whenRestPortAccessFails_switchToLocalPort() throws IOException { } @Test - public void whenRequestHostNameAccessFails_switchToLocalhost() throws IOException { + void whenRequestHostNameAccessFails_switchToLocalhost() throws IOException { request.withLocalHostName("inaccessibleServer"); initServlet(ONE_VALUE_CONFIG); factory.throwConnectionFailure("inaccessibleServer", LOCAL_PORT); @@ -185,7 +185,7 @@ public void whenRequestHostNameAccessFails_switchToLocalhost() throws IOExceptio } @Test - public void whenServerSends403StatusOnGet_returnToClient() throws Exception { + void whenServerSends403StatusOnGet_returnToClient() throws Exception { initServlet(ONE_VALUE_CONFIG); factory.reportNotAuthorized(); @@ -195,7 +195,7 @@ public void whenServerSends403StatusOnGet_returnToClient() throws Exception { } @Test - public void whenServerSends400StatusOnGet_reportErrorInComments() throws Exception { + void whenServerSends400StatusOnGet_reportErrorInComments() throws Exception { initServlet(ONE_VALUE_CONFIG); factory.reportBadQuery(); @@ -205,7 +205,7 @@ public void whenServerSends400StatusOnGet_reportErrorInComments() throws Excepti } @Test - public void whenServerSends401StatusOnGet_returnToClient() throws Exception { + void whenServerSends401StatusOnGet_returnToClient() throws Exception { initServlet(ONE_VALUE_CONFIG); factory.reportAuthenticationRequired("Test-Realm"); @@ -216,7 +216,7 @@ public void whenServerSends401StatusOnGet_returnToClient() throws Exception { } @Test - public void whenClientSendsAuthenticationHeader_passToServer() throws Exception { + void whenClientSendsAuthenticationHeader_passToServer() throws Exception { initServlet(ONE_VALUE_CONFIG); request.setHeader(AUTHENTICATION_HEADER, "auth-credentials"); @@ -226,7 +226,7 @@ public void whenClientSendsAuthenticationHeader_passToServer() throws Exception } @Test - public void onGet_sendJsonQuery() throws Exception { + void onGet_sendJsonQuery() throws Exception { initServlet(ONE_VALUE_CONFIG); servlet.doGet(request, response); @@ -241,7 +241,7 @@ private void initServlet(String configuration) { } @Test - public void onGet_recordJsonQuery() throws Exception { + void onGet_recordJsonQuery() throws Exception { initServlet(ONE_VALUE_CONFIG); servlet.doGet(request, response); @@ -250,7 +250,7 @@ public void onGet_recordJsonQuery() throws Exception { } @Test - public void onGet_sendXRequestedHeader() throws Exception { + void onGet_sendXRequestedHeader() throws Exception { initServlet(ONE_VALUE_CONFIG); servlet.doGet(request, response); @@ -259,7 +259,7 @@ public void onGet_sendXRequestedHeader() throws Exception { } @Test - public void onGet_displayMetrics() throws Exception { + void onGet_displayMetrics() throws Exception { factory.addJsonResponse(getGroupResponseMap()); initServlet(TWO_VALUE_CONFIG); @@ -283,7 +283,7 @@ private Map getGroupResponseMap() { } @Test - public void whenNewConfigAvailable_loadBeforeGeneratingMetrics() throws Exception { + void whenNewConfigAvailable_loadBeforeGeneratingMetrics() throws Exception { factory.addJsonResponse(getGroupResponseMap()); initServlet(ONE_VALUE_CONFIG); ConfigurationUpdaterStub.newConfiguration(1, TWO_VALUE_CONFIG); @@ -294,7 +294,7 @@ public void whenNewConfigAvailable_loadBeforeGeneratingMetrics() throws Exceptio } @Test - public void onGet_displayMetricsInSnakeCase() throws Exception { + void onGet_displayMetricsInSnakeCase() throws Exception { factory.addJsonResponse(getGroupResponseMap()); initServlet("metricsNameSnakeCase: true\nqueries:\n- groups:\n" + " prefix: groupValue_\n key: name\n values: [testSample1,testSample2]"); @@ -305,7 +305,7 @@ public void onGet_displayMetricsInSnakeCase() throws Exception { } @Test - public void onGet_metricsArePrometheusCompliant() throws Exception { + void onGet_metricsArePrometheusCompliant() throws Exception { factory.addJsonResponse(getGroupResponseMap()); initServlet(CONFIG_WITH_CATEGORY_VALUE); @@ -315,7 +315,7 @@ public void onGet_metricsArePrometheusCompliant() throws Exception { } @Test - public void onGet_producePerformanceMetrics() throws Exception { + void onGet_producePerformanceMetrics() throws Exception { factory.addJsonResponse(getGroupResponseMap()); initServlet(CONFIG_WITH_CATEGORY_VALUE); @@ -325,7 +325,7 @@ public void onGet_producePerformanceMetrics() throws Exception { } @Test - public void onGetInForeignLocale_performanceMetricsUsePeriodForFloatingPoint() throws Exception { + void onGetInForeignLocale_performanceMetricsUsePeriodForFloatingPoint() throws Exception { factory.addJsonResponse(getGroupResponseMap()); initServlet(CONFIG_WITH_CATEGORY_VALUE); @@ -347,7 +347,7 @@ private String getMetricValue(String metricsName) throws IOException { } @Test - public void onGetWithMultipleQueries_displayMetrics() throws Exception { + void onGetWithMultipleQueries_displayMetrics() throws Exception { factory.addJsonResponse(getGroupResponseMap()); factory.addJsonResponse(getColorResponseMap()); initServlet(MULTI_QUERY_CONFIG); @@ -368,7 +368,7 @@ private Map getColorResponseMap() { } @Test - public void whenNoQueries_produceNoOutput() throws Exception { + void whenNoQueries_produceNoOutput() throws Exception { initServlet(""); servlet.doGet(request, response); @@ -377,14 +377,14 @@ public void whenNoQueries_produceNoOutput() throws Exception { } @Test - public void whenNoConfiguration_produceNoOutput() throws Exception { + void whenNoConfiguration_produceNoOutput() throws Exception { servlet.doGet(request, response); assertThat(toHtml(response), containsOnlyComments()); } @Test - public void whenHttpConnectionFails_produceConnectionWarning() throws Exception { + void whenHttpConnectionFails_produceConnectionWarning() throws Exception { initServlet(CONFIG_WITH_CATEGORY_VALUE); factory.throwConnectionFailure(WLS_HOST, LOCAL_PORT); factory.throwConnectionFailure("localhost", LOCAL_PORT); @@ -399,7 +399,7 @@ public void whenHttpConnectionFails_produceConnectionWarning() throws Exception } @Test - public void whenKeyAlsoListedAsValue_dontDisplayIt() throws Exception { + void whenKeyAlsoListedAsValue_dontDisplayIt() throws Exception { factory.addJsonResponse(getGroupResponseMap()); initServlet("queries:" + "\n- groups:\n prefix: groupValue_\n key: testSample1\n values: [testSample1]"); @@ -410,14 +410,11 @@ public void whenKeyAlsoListedAsValue_dontDisplayIt() throws Exception { } @Test - public void whenSessionActiveDuringGet_invalidateOnExit() throws Exception { + void whenSessionActiveDuringGet_invalidateOnExit() throws Exception { request.getSession(true); servlet.doGet(request, response); assertThat(request.hasInvalidatedSession(), is(true)); } - - - } diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/HeaderTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/HeaderTest.java index 556c631c..b8f0bdf1 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/HeaderTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/HeaderTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2020, 2021, Oracle and/or its affiliates. +// Copyright (c) 2020, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter; @@ -8,31 +8,31 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -public class HeaderTest { +class HeaderTest { @Test - public void fetchHeaderName() { + void fetchHeaderName() { Header header = new Header("Content-type: text/plain"); assertThat(header.getName(), equalTo("Content-type")); } @Test - public void fetchMainValue() { + void fetchMainValue() { Header header = new Header("Content-type: text/plain"); assertThat(header.getValue(), equalTo("text/plain")); } @Test - public void whenSeparatorPresent_truncateValue() { + void whenSeparatorPresent_truncateValue() { Header header = new Header("Content-type: text/plain; more stuff"); assertThat(header.getValue(), equalTo("text/plain")); } @Test - public void whenParametersPresent_fetchValues() { + void whenParametersPresent_fetchValues() { Header header = new Header("Content-disposition: form-data; name=\"file1\"; filename=\"a.txt\""); assertThat(header.getValue(), equalTo("form-data")); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/LiveConfigurationTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/LiveConfigurationTest.java index df8a9f3a..c5f113ec 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/LiveConfigurationTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/LiveConfigurationTest.java @@ -26,7 +26,7 @@ /** * @author Russell Gold */ -public class LiveConfigurationTest { +class LiveConfigurationTest { private static final String CONFIGURATION = "hostName: " + HOST_NAME + "\n" + "port: " + PORT + "\n" + @@ -82,7 +82,7 @@ public void tearDown() { } @Test - public void afterInitCalled_haveQueries() { + void afterInitCalled_haveQueries() { init(CONFIGURATION); assertThat(LiveConfiguration.hasQueries(), is(true)); @@ -94,26 +94,26 @@ private void init(String configuration) { } @Test - public void whenInitNotCalled_haveNoQueries() { + void whenInitNotCalled_haveNoQueries() { assertThat(LiveConfiguration.hasQueries(), is(false)); } @Test - public void whenInitCalledWithNoConfig_haveNoQueries() { + void whenInitCalledWithNoConfig_haveNoQueries() { ServletUtils.initializeConfiguration(withNoParams()); assertThat(LiveConfiguration.hasQueries(), is(false)); } @Test - public void afterInitCalled_haveExpectedConfiguration() { + void afterInitCalled_haveExpectedConfiguration() { init(CONFIGURATION); assertThat(LiveConfiguration.asString(), equalTo(CONFIGURATION)); } @Test - public void afterInitCalledTwice_haveFirstConfiguration() { + void afterInitCalledTwice_haveFirstConfiguration() { init(CONFIGURATION); init(ADDED_CONFIGURATION); @@ -121,14 +121,14 @@ public void afterInitCalledTwice_haveFirstConfiguration() { } @Test - public void afterInitTimestampIsZero() { + void afterInitTimestampIsZero() { init(CONFIGURATION); assertThat(LiveConfiguration.getTimestamp(), equalTo(0L)); } @Test - public void afterReplaceQueryCalled_configurationIsUpdated() { + void afterReplaceQueryCalled_configurationIsUpdated() { init(CONFIGURATION); LiveConfiguration.replaceConfiguration(toConfiguration(ADDED_CONFIGURATION)); @@ -142,7 +142,7 @@ private ExporterConfig toConfiguration(String configuration) { } @Test - public void afterReplaceQueryCalled_shareUpdatedConfiguration() { + void afterReplaceQueryCalled_shareUpdatedConfiguration() { init(CONFIGURATION); LiveConfiguration.replaceConfiguration(toConfiguration(ADDED_CONFIGURATION)); @@ -151,7 +151,7 @@ public void afterReplaceQueryCalled_shareUpdatedConfiguration() { } @Test - public void afterReplaceQueryCalled_timestampIsUpdated() { + void afterReplaceQueryCalled_timestampIsUpdated() { init(CONFIGURATION); long originalTimestamp = LiveConfiguration.getTimestamp(); @@ -161,7 +161,7 @@ public void afterReplaceQueryCalled_timestampIsUpdated() { } @Test - public void afterAppendQueryCalled_configurationIsUpdated() { + void afterAppendQueryCalled_configurationIsUpdated() { init(CONFIGURATION); LiveConfiguration.appendConfiguration(toConfiguration(ADDED_CONFIGURATION)); @@ -170,7 +170,7 @@ public void afterAppendQueryCalled_configurationIsUpdated() { } @Test - public void afterAppendQueryCalled_shareUpdatedConfiguration() { + void afterAppendQueryCalled_shareUpdatedConfiguration() { init(CONFIGURATION); LiveConfiguration.appendConfiguration(toConfiguration(ADDED_CONFIGURATION)); @@ -179,7 +179,7 @@ public void afterAppendQueryCalled_shareUpdatedConfiguration() { } @Test - public void afterAppendQueryCalled_timestampIsUpdated() { + void afterAppendQueryCalled_timestampIsUpdated() { init(CONFIGURATION); long originalTimestamp = LiveConfiguration.getTimestamp(); @@ -189,7 +189,7 @@ public void afterAppendQueryCalled_timestampIsUpdated() { } @Test - public void whenSharedTimestampIndicatesNewConfiguration_updateLiveConfiguration() { + void whenSharedTimestampIndicatesNewConfiguration_updateLiveConfiguration() { init(CONFIGURATION); long newTimestamp = LiveConfiguration.getTimestamp() + 1; @@ -202,7 +202,7 @@ public void whenSharedTimestampIndicatesNewConfiguration_updateLiveConfiguration } @Test - public void whenSharedTimestampIndicatesHaveLatestConfiguration_dontUpdateLiveConfiguration() { + void whenSharedTimestampIndicatesHaveLatestConfiguration_dontUpdateLiveConfiguration() { init(CONFIGURATION); long newTimestamp = LiveConfiguration.getTimestamp(); @@ -214,7 +214,7 @@ public void whenSharedTimestampIndicatesHaveLatestConfiguration_dontUpdateLiveCo } @Test - public void whenConfigurationSpecifiesSynchronization_installHttpBasedUpdater() throws Exception { + void whenConfigurationSpecifiesSynchronization_installHttpBasedUpdater() throws Exception { init(CONFIGURATION_WITH_SYNC); assertThat(getConfigurationUpdater(), instanceOf(ConfigurationUpdaterImpl.class)); @@ -226,7 +226,7 @@ private ConfigurationUpdater getConfigurationUpdater() throws NoSuchFieldExcepti } @Test - public void whenConfigurationSpecifiesSynchronization_configureUpdater() throws Exception { + void whenConfigurationSpecifiesSynchronization_configureUpdater() throws Exception { init(CONFIGURATION_WITH_SYNC); ConfigurationUpdaterImpl configurationUpdater = (ConfigurationUpdaterImpl) getConfigurationUpdater(); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/MetricsStreamTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/MetricsStreamTest.java index cb599f66..359098ed 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/MetricsStreamTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/MetricsStreamTest.java @@ -27,7 +27,7 @@ /** * @author Russell Gold */ -public class MetricsStreamTest { +class MetricsStreamTest { private static final long NANOSEC_PER_SECONDS = 1000000000; private static final String LINE_SEPARATOR = "line.separator"; private static final String WINDOWS_LINE_SEPARATOR = "\r\n"; @@ -56,7 +56,7 @@ public void tearDown() { } @Test - public void whenNoMetricsScraped_reportNoneScraped() { + void whenNoMetricsScraped_reportNoneScraped() { assertThat(getPrintedMetrics(), containsString("wls_scrape_mbeans_count_total{instance=\"wlshost:7201\"} 0")); } @@ -67,7 +67,7 @@ private String getPrintedMetrics() { } @Test - public void whenMetricsPrinted_eachHasItsOwnLineSeparatedByCarriageReturns() { + void whenMetricsPrinted_eachHasItsOwnLineSeparatedByCarriageReturns() { metrics.printMetric("a", 12); metrics.printMetric("b", 120); metrics.printMetric("c", 0); @@ -76,7 +76,7 @@ public void whenMetricsPrinted_eachHasItsOwnLineSeparatedByCarriageReturns() { } @Test - public void whenMetricsPrintedOnWindows_eachHasItsOwnLineSeparatedByCarriageReturns() throws NoSuchFieldException { + void whenMetricsPrintedOnWindows_eachHasItsOwnLineSeparatedByCarriageReturns() throws NoSuchFieldException { simulateWindows(); metrics.printMetric("a", 12); @@ -97,7 +97,7 @@ private List getPrintedMetricValues() { } @Test - public void afterMetricsScraped_reportScrapedCount() { + void afterMetricsScraped_reportScrapedCount() { metrics.printMetric("a", 12); metrics.printMetric("b", 120); metrics.printMetric("c", 0); @@ -107,7 +107,7 @@ public void afterMetricsScraped_reportScrapedCount() { } @Test - public void afterTimePasses_reportScrapeDuration() { + void afterTimePasses_reportScrapeDuration() { performanceProbe.incrementElapsedTime(12.4); assertThat(getPrintedMetrics(), @@ -115,7 +115,7 @@ public void afterTimePasses_reportScrapeDuration() { } @Test - public void afterProcessing_reportCpuPercent() { + void afterProcessing_reportCpuPercent() { performanceProbe.incrementCpuTime(3.2); assertThat(getPrintedMetrics(), @@ -123,7 +123,7 @@ public void afterProcessing_reportCpuPercent() { } @Test - public void producedMetricsAreCompliant() { + void producedMetricsAreCompliant() { performanceProbe.incrementElapsedTime(20); performanceProbe.incrementCpuTime(3); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/MultipartContentParserTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/MultipartContentParserTest.java index 4ecda723..1a0c0a73 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/MultipartContentParserTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/MultipartContentParserTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2020, 2021, Oracle and/or its affiliates. +// Copyright (c) 2020, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter; @@ -32,7 +32,7 @@ import static org.hamcrest.Matchers.sameInstance; import static org.junit.jupiter.api.Assertions.assertThrows; -public class MultipartContentParserTest { +class MultipartContentParserTest { private static final String BOUNDARY = "---------------------------9051914041544843365972754266"; private MultipartContentParser parser; @@ -43,29 +43,29 @@ public void setUp() { } @Test - public void whenContentTypeIsNotMultiForm_throwException() { + void whenContentTypeIsNotMultiForm_throwException() { assertThrows(RuntimeException.class, () -> new MultipartContentParser("text/plain")); } @Test - public void whenCreated_boundaryIsDefined() { + void whenCreated_boundaryIsDefined() { assertThat(parser.getBoundary(), equalTo(BOUNDARY)); } @Test - public void parseInitialState() { + void parseInitialState() { assertThat(parser.getState(), sameInstance(ParserState.INITIAL)); } @Test - public void whenInitialStateAndReceivedBoundary_watchForHeaders() { + void whenInitialStateAndReceivedBoundary_watchForHeaders() { parser.process("--" + BOUNDARY); assertThat(parser.getState(), sameInstance(ParserState.HEADERS)); } @Test - public void WhenReceiveFieldContentDispositionHeaderInHeaderState_defineField() { + void WhenReceiveFieldContentDispositionHeaderInHeaderState_defineField() { parser.process("--" + BOUNDARY); parser.process("Content-Disposition: form-data; name=\"text\""); @@ -75,7 +75,7 @@ public void WhenReceiveFieldContentDispositionHeaderInHeaderState_defineField() } @Test - public void WhenReceiveBlankLineInHeaderState_watchForContent() { + void WhenReceiveBlankLineInHeaderState_watchForContent() { parser.process("--" + BOUNDARY); parser.process("Content-Disposition: form-data; name=\"text\""); @@ -85,12 +85,12 @@ public void WhenReceiveBlankLineInHeaderState_watchForContent() { } @Test - public void WhenNoContentReceived_itemHasEmptyData() { + void WhenNoContentReceived_itemHasEmptyData() { assertThat(parser.getCurrentItem().getString(), equalTo("")); } @Test - public void WhenReceiveDataInContentState_addToDefinition() { + void WhenReceiveDataInContentState_addToDefinition() { parser.process("--" + BOUNDARY); parser.process("Content-Disposition: form-data; name=\"text\""); parser.process(""); @@ -100,7 +100,7 @@ public void WhenReceiveDataInContentState_addToDefinition() { } @Test - public void WhenReceiveNewBoundaryInContentState_defineItem() { + void WhenReceiveNewBoundaryInContentState_defineItem() { parser.process("--" + BOUNDARY); parser.process("Content-Disposition: form-data; name=\"text\""); parser.process(""); @@ -111,7 +111,7 @@ public void WhenReceiveNewBoundaryInContentState_defineItem() { } @Test - public void parseFormFields() throws IOException { + void parseFormFields() throws IOException { BufferedReader sample = new BufferedReader(new StringReader(SAMPLE)); sample.lines().forEach(parser::process); @@ -157,7 +157,7 @@ private String readInputStream(InputStream is) { @Test - public void whenMultipartRequestNotParseable_throwException() { + void whenMultipartRequestNotParseable_throwException() { HttpServletRequest request = HttpServletRequestStub.createPostRequest(); assertThrows(RuntimeException.class, @@ -165,7 +165,7 @@ public void whenMultipartRequestNotParseable_throwException() { } @Test - public void whenMultipartRequestContainsFormFields_allAreMarkedAsFormFields() throws IOException { + void whenMultipartRequestContainsFormFields_allAreMarkedAsFormFields() throws IOException { HttpEntity httpEntity = MultipartEntityBuilder.create() .setBoundary(BOUNDARY) .addTextBody("field1", "value1") @@ -186,7 +186,7 @@ protected static HttpServletRequest toPostRequest(HttpEntity httpEntity) throws } @Test - public void whenMultipartRequestContainsFormFields_retrieveThem() throws IOException { + void whenMultipartRequestContainsFormFields_retrieveThem() throws IOException { HttpEntity httpEntity = MultipartEntityBuilder.create() .setBoundary(BOUNDARY) .addTextBody("field1", "value1") @@ -200,7 +200,7 @@ public void whenMultipartRequestContainsFormFields_retrieveThem() throws IOExcep } @Test - public void whenMultipartRequestContainsBinaryEntries_nonAreMarkedAsFormFields() throws IOException { + void whenMultipartRequestContainsBinaryEntries_nonAreMarkedAsFormFields() throws IOException { HttpEntity httpEntity = MultipartEntityBuilder.create() .setBoundary(BOUNDARY) .addBinaryBody("file1", "value1".getBytes(), ContentType.DEFAULT_BINARY, "/path/to/file1.txt") @@ -211,7 +211,7 @@ public void whenMultipartRequestContainsBinaryEntries_nonAreMarkedAsFormFields() } @Test - public void whenMultipartRequestContainsBinaryEntries_retrieveThem() throws IOException { + void whenMultipartRequestContainsBinaryEntries_retrieveThem() throws IOException { HttpEntity httpEntity = MultipartEntityBuilder.create() .setBoundary(BOUNDARY) .addBinaryBody("file1", "value1".getBytes(UTF_8), ContentType.DEFAULT_BINARY, "/path/to/file1.txt") diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/UrlBuilderTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/UrlBuilderTest.java index fd6b0582..993b425b 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/UrlBuilderTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/UrlBuilderTest.java @@ -16,7 +16,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertThrows; -public class UrlBuilderTest { +class UrlBuilderTest { private static final String URL_PATTERN = "%s://%s:%d/path"; private static final String REST_HOSTNAME = "restHost"; @@ -38,7 +38,7 @@ void tearDown() { } @Test - public void whenNoRestPortOrHostNameDefined_generateUrl() { + void whenNoRestPortOrHostNameDefined_generateUrl() { UrlBuilder builder = createUrlBuilder().withHostName(HOSTNAME).withPort(LOCAL_PORT); assertThat(builder.createUrl(URL_PATTERN), equalTo(String.format(URL_PATTERN, "http", HOSTNAME, LOCAL_PORT))); @@ -49,14 +49,14 @@ private UrlBuilder createUrlBuilder() { } @Test - public void whenRestPortDefined_generateUrlWithRestPort() { + void whenRestPortDefined_generateUrlWithRestPort() { UrlBuilder builder = createUrlBuilder().withHostName(HOSTNAME).withPort(REST_PORT).withPort(LOCAL_PORT); assertThat(builder.createUrl(URL_PATTERN), equalTo(String.format(URL_PATTERN, "http", HOSTNAME, REST_PORT))); } @Test - public void whenNoRestPortAndConnectionFails_reportFailure() { + void whenNoRestPortAndConnectionFails_reportFailure() { UrlBuilder builder = createUrlBuilder().withHostName(HOSTNAME).withPort(LOCAL_PORT); builder.createUrl(URL_PATTERN); @@ -64,7 +64,7 @@ public void whenNoRestPortAndConnectionFails_reportFailure() { } @Test - public void afterRestPortFails_retryWithLocalPort() { + void afterRestPortFails_retryWithLocalPort() { UrlBuilder builder = createUrlBuilder().withHostName(HOSTNAME).withPort(REST_PORT).withPort(LOCAL_PORT); builder.createUrl(URL_PATTERN); builder.reportFailure(connectionException); @@ -73,7 +73,7 @@ public void afterRestPortFails_retryWithLocalPort() { } @Test - public void afterRestPortFailsAndSecondRetryFails_reportFailure() { + void afterRestPortFailsAndSecondRetryFails_reportFailure() { UrlBuilder builder = createUrlBuilder().withHostName(HOSTNAME).withPort(REST_PORT).withPort(LOCAL_PORT); builder.createUrl(URL_PATTERN); builder.reportFailure(connectionException); @@ -82,7 +82,7 @@ public void afterRestPortFailsAndSecondRetryFails_reportFailure() { } @Test - public void afterLocalPortSucceeds_newBuilderPrefersLocalPort() { + void afterLocalPortSucceeds_newBuilderPrefersLocalPort() { UrlBuilder builder = createUrlBuilder().withHostName(HOSTNAME).withPort(REST_PORT).withPort(LOCAL_PORT); builder.createUrl(URL_PATTERN); builder.reportFailure(connectionException); @@ -94,7 +94,7 @@ public void afterLocalPortSucceeds_newBuilderPrefersLocalPort() { } @Test - public void afterRestHostNameFails_retryWithBackupHost() { + void afterRestHostNameFails_retryWithBackupHost() { UrlBuilder builder = createUrlBuilder().withHostName(REST_HOSTNAME).withHostName(HOSTNAME).withPort(LOCAL_PORT); builder.createUrl(URL_PATTERN); builder.reportFailure(connectionException); @@ -103,7 +103,7 @@ public void afterRestHostNameFails_retryWithBackupHost() { } @Test - public void afterRestHostNameFailsAndSecondRetryFails_reportFailure() { + void afterRestHostNameFailsAndSecondRetryFails_reportFailure() { UrlBuilder builder = createUrlBuilder().withHostName(REST_HOSTNAME).withHostName(HOSTNAME).withPort(LOCAL_PORT); builder.createUrl(URL_PATTERN); builder.reportFailure(connectionException); @@ -112,7 +112,7 @@ public void afterRestHostNameFailsAndSecondRetryFails_reportFailure() { } @Test - public void afterLocalHostSucceeds_newBuilderPrefersLocalHost() { + void afterLocalHostSucceeds_newBuilderPrefersLocalHost() { UrlBuilder builder = createUrlBuilder().withHostName(REST_HOSTNAME).withHostName(HOSTNAME).withPort(LOCAL_PORT); builder.createUrl(URL_PATTERN); builder.reportFailure(connectionException); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/WebClientFactoryImplTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/WebClientFactoryImplTest.java index 09f51332..86770f03 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/WebClientFactoryImplTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/WebClientFactoryImplTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2017, 2021, Oracle and/or its affiliates. +// Copyright (c) 2017, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter; @@ -15,7 +15,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.sameInstance; -public class WebClientFactoryImplTest { +class WebClientFactoryImplTest { private final List mementos = new ArrayList<>(); private final Function> apacheClassesMissing = WebClientFactoryImplTest::reportApacheClassesMissing; @@ -35,12 +35,12 @@ public void tearDown() { } @Test - public void whenApacheClientDependentClassesFound_selectApacheClient() { + void whenApacheClientDependentClassesFound_selectApacheClient() { assertThat(WebClientFactoryImpl.getClientConstructor().getDeclaringClass(), sameInstance(WebClientImpl.class)); } @Test - public void whenApacheClientDependentClassesMissing_selectJKD8Client() throws NoSuchFieldException { + void whenApacheClientDependentClassesMissing_selectJKD8Client() throws NoSuchFieldException { mementos.add(StaticStubSupport.install(WebClientFactoryImpl.class, "loadClientClass", apacheClassesMissing)); assertThat(WebClientFactoryImpl.getClientConstructor().getDeclaringClass(), sameInstance(WebClient8Impl.class)); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/ConfigurationExceptionTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/ConfigurationExceptionTest.java index 58bf4cfb..4856a328 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/ConfigurationExceptionTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/ConfigurationExceptionTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2017, 2021, Oracle and/or its affiliates. +// Copyright (c) 2017, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter.domain; @@ -11,9 +11,9 @@ /** * @author Russell Gold */ -public class ConfigurationExceptionTest { +class ConfigurationExceptionTest { @Test - public void afterAddMultipleContexts_messageContainsFullContext() { + void afterAddMultipleContexts_messageContainsFullContext() { ConfigurationException exception = new ConfigurationException("Something went wrong"); exception.addContext("second"); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/ExporterConfigTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/ExporterConfigTest.java index 39056796..28abfe75 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/ExporterConfigTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/ExporterConfigTest.java @@ -40,8 +40,7 @@ /** * @author Russell Gold */ -public class ExporterConfigTest { - private static final String EXPECTED_HOST = "somehost"; +class ExporterConfigTest { private static final int EXPECTED_PORT = 3456; private static final String SERVLET_CONFIG = "---\n" + "queries:\n" + @@ -74,19 +73,19 @@ void tearDown() { } @Test - public void whenYamlConfigEmpty_returnNonNullConfiguration() { + void whenYamlConfigEmpty_returnNonNullConfiguration() { assertThat(ExporterConfig.loadConfig(NULL_MAP), notNullValue()); } @Test - public void byDefaultSnakeCase_isDisabled() { + void byDefaultSnakeCase_isDisabled() { ExporterConfig config = ExporterConfig.loadConfig(NULL_MAP); assertThat(config.getMetricsNameSnakeCase(), equalTo(false)); } @Test - public void whenSnakeNameEnabledByDefault_isSetInEmptyConfiguration() { + void whenSnakeNameEnabledByDefault_isSetInEmptyConfiguration() { ExporterConfig.setDefaultMetricsNameSnakeCase(true); ExporterConfig config = ExporterConfig.loadConfig(NULL_MAP); @@ -94,14 +93,14 @@ public void whenSnakeNameEnabledByDefault_isSetInEmptyConfiguration() { } @Test - public void whenYamlConfigEmpty_queryReturnsEmptyArray() { + void whenYamlConfigEmpty_queryReturnsEmptyArray() { ExporterConfig config = ExporterConfig.loadConfig(NULL_MAP); assertThat(config.getQueries(), emptyArray()); } @Test - public void whenSpecified_readSnakeCaseSettingFromYaml() { + void whenSpecified_readSnakeCaseSettingFromYaml() { yamlConfig.put(ExporterConfig.SNAKE_CASE, true); ExporterConfig config = ExporterConfig.loadConfig(yamlConfig); @@ -110,7 +109,7 @@ public void whenSpecified_readSnakeCaseSettingFromYaml() { } @Test - public void whenDomainQualifierNotSpecified_dontModifyQueries() { + void whenDomainQualifierNotSpecified_dontModifyQueries() { ExporterConfig config = loadFromString(SERVLET_CONFIG); MBeanSelector[] queries = config.getEffectiveQueries(); @@ -120,7 +119,7 @@ public void whenDomainQualifierNotSpecified_dontModifyQueries() { } @Test - public void whenSpecified_prependConfigurationQuery() { + void whenSpecified_prependConfigurationQuery() { ExporterConfig config = loadFromString(DOMAIN_QUALIFIER_CONFIG); MBeanSelector[] queries = config.getEffectiveQueries(); @@ -131,21 +130,21 @@ public void whenSpecified_prependConfigurationQuery() { } @Test - public void whenNotSpecified_wlsPortIsNull() { + void whenNotSpecified_wlsPortIsNull() { ExporterConfig config = ExporterConfig.loadConfig(yamlConfig); assertThat(config.getRestPort(), nullValue()); } @Test - public void whenNotSpecified_wlsPortIsNotIncludedInToString() { + void whenNotSpecified_wlsPortIsNotIncludedInToString() { ExporterConfig config = ExporterConfig.loadConfig(yamlConfig); assertThat(config.toString(), not(containsString(ExporterConfig.REST_PORT))); } @Test - public void whenSpecified_readWlsPortFromYaml() { + void whenSpecified_readWlsPortFromYaml() { yamlConfig.put(ExporterConfig.REST_PORT, EXPECTED_PORT); ExporterConfig config = ExporterConfig.loadConfig(yamlConfig); @@ -154,7 +153,7 @@ public void whenSpecified_readWlsPortFromYaml() { } @Test - public void whenSpecified_wlsPortIsIncludedInToString() { + void whenSpecified_wlsPortIsIncludedInToString() { yamlConfig.put(ExporterConfig.REST_PORT, EXPECTED_PORT); ExporterConfig config = ExporterConfig.loadConfig(yamlConfig); @@ -163,14 +162,14 @@ public void whenSpecified_wlsPortIsIncludedInToString() { } @Test - public void whenNotSpecified_querySyncConfigurationIsNull() { + void whenNotSpecified_querySyncConfigurationIsNull() { ExporterConfig config = ExporterConfig.loadConfig(yamlConfig); assertThat(config.getQuerySyncConfiguration(), nullValue()); } @Test - public void whenQuerySyncDefinedWithoutProperties_throwException() { + void whenQuerySyncDefinedWithoutProperties_throwException() { assertThrows(ConfigurationException.class, () -> loadFromString(CONFIG_WITH_MISSING_SYNC_PROPERTIES)); } @@ -179,7 +178,7 @@ public void whenQuerySyncDefinedWithoutProperties_throwException() { @Test - public void whenQuerySyncDefinedWithoutUrl_throwException() { + void whenQuerySyncDefinedWithoutUrl_throwException() { assertThrows(ConfigurationException.class, () -> loadFromString(CONFIG_WITH_MISSING_SYNC_URL)); } @@ -188,7 +187,7 @@ public void whenQuerySyncDefinedWithoutUrl_throwException() { @Test - public void whenQuerySyncDefined_returnIt() { + void whenQuerySyncDefined_returnIt() { ExporterConfig config = loadFromString(CONFIG_WITH_SYNC_SPEC); final QuerySyncConfiguration syncConfiguration = config.getQuerySyncConfiguration(); @@ -201,7 +200,7 @@ public void whenQuerySyncDefined_returnIt() { @Test - public void whenQuerySyncDefinedWithoutInterval_useDefault() { + void whenQuerySyncDefinedWithoutInterval_useDefault() { ExporterConfig config = loadFromString(CONFIG_WITH_SYNC_URL); final QuerySyncConfiguration syncConfiguration = config.getQuerySyncConfiguration(); @@ -213,7 +212,7 @@ public void whenQuerySyncDefinedWithoutInterval_useDefault() { "query_sync:\n url: http://sync:8999/\n"; @Test - public void whenSpecified_readQueriesFromYaml() { + void whenSpecified_readQueriesFromYaml() { ExporterConfig config = loadFromString(SERVLET_CONFIG); assertThat(config.getQueries(), arrayWithSize(1)); @@ -226,21 +225,21 @@ private ExporterConfig loadFromString(String yamlString) { } @Test - public void afterLoad_hasExpectedQuery() { + void afterLoad_hasExpectedQuery() { ExporterConfig config = loadFromString(SERVLET_CONFIG); assertThat(config, hasQueryFor("applicationRuntimes", "componentRuntimes")); } @Test - public void afterLoad_convertToString() { + void afterLoad_convertToString() { ExporterConfig config = loadFromString(SNAKE_CASE_CONFIG); assertThat(config.toString(), equalToIgnoringWhiteSpace(SNAKE_CASE_CONFIG)); } @Test - public void includeTopLevelFieldsInString() { + void includeTopLevelFieldsInString() { ExporterConfig config = loadFromString(CONFIG_WITH_TOP_LEVEL_FIELDS); assertThat(config.toString(), equalToIgnoringWhiteSpace(CONFIG_WITH_TOP_LEVEL_FIELDS)); @@ -256,7 +255,7 @@ public void includeTopLevelFieldsInString() { " values: [heapFreeCurrent, heapFreePercent, heapSizeCurrent]\n"; @Test - public void includeSnakeCaseTrueSettingInToString() { + void includeSnakeCaseTrueSettingInToString() { ExporterConfig config = loadFromString(SNAKE_CASE_CONFIG); assertThat(config.toString(), equalToIgnoringWhiteSpace(SNAKE_CASE_CONFIG)); @@ -273,7 +272,7 @@ public void includeSnakeCaseTrueSettingInToString() { " values: [pendingRequests, completedRequests, stuckThreadCount]\n"; @Test - public void includeRestPortSettingInToString() { + void includeRestPortSettingInToString() { ExporterConfig config = loadFromString(REST_PORT_CONFIG); assertThat(config.toString(), equalToIgnoringWhiteSpace(REST_PORT_CONFIG)); @@ -326,40 +325,40 @@ private ExporterConfig getAppendedConfiguration(String firstConfiguration, Strin " values: [pendingRequests, completedRequests, stuckThreadCount]\n"; @Test - public void afterAppend_configHasOriginalSnakeCase() { + void afterAppend_configHasOriginalSnakeCase() { assertThat(getAppendedConfiguration(SERVLET_CONFIG, WORK_MANAGER_CONFIG).getMetricsNameSnakeCase(), is(false)); assertThat(getAppendedConfiguration(WORK_MANAGER_CONFIG, SERVLET_CONFIG).getMetricsNameSnakeCase(), is(true)); } @Test - public void afterAppend_configHasOriginalRestPort() { + void afterAppend_configHasOriginalRestPort() { assertThat(getAppendedConfiguration(SERVLET_CONFIG, REST_PORT_CONFIG).getRestPort(), nullValue()); assertThat(getAppendedConfiguration(REST_PORT_CONFIG, SERVLET_CONFIG).getRestPort(), equalTo(1234)); } @Test - public void afterAppend_configHasOriginalQuery() { + void afterAppend_configHasOriginalQuery() { ExporterConfig config = getAppendedConfiguration(SERVLET_CONFIG, WORK_MANAGER_CONFIG); assertThat(config, hasQueryFor("applicationRuntimes", "componentRuntimes", "servlets")); } @Test - public void afterAppend_configContainsNewQuery() { + void afterAppend_configContainsNewQuery() { ExporterConfig config = getAppendedConfiguration(SERVLET_CONFIG, WORK_MANAGER_CONFIG); assertThat(config, hasQueryFor("applicationRuntimes", "workManagerRuntimes")); } @Test - public void whenAppendToNoQueries_configHasNewQuery() { + void whenAppendToNoQueries_configHasNewQuery() { ExporterConfig config = getAppendedConfiguration("", WORK_MANAGER_CONFIG); assertThat(config, hasQueryFor("applicationRuntimes", "workManagerRuntimes")); } @Test - public void whenAppendedConfigurationHasNoQueries_configHasOriginalQuery() { + void whenAppendedConfigurationHasNoQueries_configHasOriginalQuery() { ExporterConfig config = getAppendedConfiguration(SERVLET_CONFIG, ""); assertThat(config, hasQueryFor("applicationRuntimes", "componentRuntimes", "servlets")); @@ -373,39 +372,39 @@ private ExporterConfig getReplacedConfiguration(String firstConfiguration, Strin } @Test - public void afterReplace_configHasChangedSnakeCase() { + void afterReplace_configHasChangedSnakeCase() { assertThat(getReplacedConfiguration(SERVLET_CONFIG, WORK_MANAGER_CONFIG).getMetricsNameSnakeCase(), is(true)); assertThat(getReplacedConfiguration(WORK_MANAGER_CONFIG, SERVLET_CONFIG).getMetricsNameSnakeCase(), is(false)); } @Test - public void afterReplace_configHasChangedRestPort() { + void afterReplace_configHasChangedRestPort() { assertThat(getReplacedConfiguration(SERVLET_CONFIG, REST_PORT_CONFIG).getRestPort(), equalTo(1234)); assertThat(getReplacedConfiguration(REST_PORT_CONFIG, SERVLET_CONFIG).getRestPort(), nullValue()); } @Test - public void afterReplace_configHasChangedDomainQualifier() { + void afterReplace_configHasChangedDomainQualifier() { assertThat(getReplacedConfiguration(SERVLET_CONFIG, DOMAIN_QUALIFIER_CONFIG).useDomainQualifier(), is(true)); assertThat(getReplacedConfiguration(DOMAIN_QUALIFIER_CONFIG, SERVLET_CONFIG).useDomainQualifier(), is(false)); } @Test - public void afterReplace_configHasNewQuery() { + void afterReplace_configHasNewQuery() { ExporterConfig config = getReplacedConfiguration(SERVLET_CONFIG, WORK_MANAGER_CONFIG); assertThat(config, hasQueryFor("applicationRuntimes", "workManagerRuntimes")); } @Test - public void afterReplace_configDoesNotHaveOriginalQuery() { + void afterReplace_configDoesNotHaveOriginalQuery() { ExporterConfig config = getReplacedConfiguration(SERVLET_CONFIG, WORK_MANAGER_CONFIG); assertThat(config, not(hasQueryFor("applicationRuntimes", "componentRuntimes", "servlets"))); } @Test - public void afterReplaceWithEmptyConfig_configHasNoQueries() { + void afterReplaceWithEmptyConfig_configHasNoQueries() { ExporterConfig config = getReplacedConfiguration(SERVLET_CONFIG, ""); assertThat(config.getQueries(), arrayWithSize(0)); @@ -413,7 +412,7 @@ public void afterReplaceWithEmptyConfig_configHasNoQueries() { @Test - public void whenYamlContainsMergeableQueries_MergeThem() { + void whenYamlContainsMergeableQueries_MergeThem() { ExporterConfig config = loadFromString(MERGEABLE_CONFIG); assertThat(config.toString(), equalTo(MERGED_CONFIG)); @@ -460,7 +459,7 @@ public void whenYamlContainsMergeableQueries_MergeThem() { " values: [invocationTotalCount, executionTimeTotal]\n"; @Test - public void afterAppendWithNewTopLevelQuery_configHasMultipleTopLevelQueries() { + void afterAppendWithNewTopLevelQuery_configHasMultipleTopLevelQueries() { ExporterConfig config = getAppendedConfiguration(SERVLET_CONFIG, PARTITION_CONFIG); assertThat(config.getQueries(), arrayWithSize(2)); @@ -480,14 +479,14 @@ public void afterAppendWithNewTopLevelQuery_configHasMultipleTopLevelQueries() { @Test - public void afterAppendWithMatchingTopLevelQuery_configHasMergedQueries() { + void afterAppendWithMatchingTopLevelQuery_configHasMergedQueries() { ExporterConfig config = getAppendedConfiguration(SERVLET_CONFIG, WORK_MANAGER_CONFIG); assertThat(config.getQueries(), arrayWithSize(1)); } @Test - public void whenConfigHasSingleValue_displayAsScalar() { + void whenConfigHasSingleValue_displayAsScalar() { ExporterConfig exporterConfig = loadFromString(CONFIG_WITH_SINGLE_VALUE); assertThat(exporterConfig.toString(), equalTo(CONFIG_WITH_SINGLE_VALUE)); @@ -501,7 +500,7 @@ public void whenConfigHasSingleValue_displayAsScalar() { " values: heapFreeCurrent\n"; @Test - public void whenConfigHasDuplicateValues_reportFailure() { + void whenConfigHasDuplicateValues_reportFailure() { assertThrows(ConfigurationException.class, () -> loadFromString(CONFIG_WITH_DUPLICATE_VALUE)); } @@ -515,7 +514,7 @@ public void whenConfigHasDuplicateValues_reportFailure() { " values: [heapFreeCurrent,heapFreeCurrent]\n"; @Test - public void whenConfigHasNoValues_reportFailure() { + void whenConfigHasNoValues_reportFailure() { assertThrows(ConfigurationException.class, () -> loadFromString(CONFIG_WITH_NO_VALUES)); } @@ -526,7 +525,7 @@ public void whenConfigHasNoValues_reportFailure() { " values: []\n"; @Test - public void defineEmptyConfiguration() { + void defineEmptyConfiguration() { assertThat(ExporterConfig.createEmptyConfig().toString(), equalTo(EMPTY_CONFIG)); } @@ -534,7 +533,7 @@ public void defineEmptyConfiguration() { "queries:\n"; @Test - public void afterReplaceEmptyConfig_haveReplacementConfig() { + void afterReplaceEmptyConfig_haveReplacementConfig() { ExporterConfig config = ExporterConfig.createEmptyConfig(); config.replace(loadFromString(PARTITION_CONFIG)); @@ -543,7 +542,7 @@ public void afterReplaceEmptyConfig_haveReplacementConfig() { } @Test - public void afterAppendEmptyConfig_haveAppendedConfig() { + void afterAppendEmptyConfig_haveAppendedConfig() { ExporterConfig config = ExporterConfig.createEmptyConfig(); config.append(loadFromString(PARTITION_CONFIG)); @@ -560,7 +559,7 @@ void whenEnvironmentVariableDefined_configHasDomainName() { } @Test - public void afterScrapingServerConfig_hasDomainName() { + void afterScrapingServerConfig_hasDomainName() { ExporterConfig exporterConfig = loadFromString(DOMAIN_QUALIFIER_CONFIG); exporterConfig.scrapeMetrics(MBeanSelector.DOMAIN_NAME_SELECTOR, getJsonResponse(CONFIG_RESPONSE)); @@ -569,7 +568,7 @@ public void afterScrapingServerConfig_hasDomainName() { } @Test - public void afterScrapingMetricsIncludeDomainNameQualifier() { + void afterScrapingMetricsIncludeDomainNameQualifier() { ExporterConfig exporterConfig = loadFromString(DOMAIN_QUALIFIER_CONFIG); Map metrics = getMetrics(exporterConfig); @@ -591,7 +590,7 @@ private String getResponse(MBeanSelector selector) { } @Test - public void secondScrapeWithDomainQualifierDoesNotAddStringMetric() { + void secondScrapeWithDomainQualifierDoesNotAddStringMetric() { ExporterConfig exporterConfig = loadFromString(DOMAIN_QUALIFIER_CONFIG); getMetrics(exporterConfig); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/MBeanSelectorTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/MBeanSelectorTest.java index c33f8cc5..fb41d05c 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/MBeanSelectorTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/MBeanSelectorTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2017, 2021, Oracle and/or its affiliates. +// Copyright (c) 2017, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter.domain; @@ -28,7 +28,7 @@ /** * @author Russell Gold */ -public class MBeanSelectorTest { +class MBeanSelectorTest { private static final String EXPECTED_TYPE = "WebAppComponentRuntime"; private static final String EXPECTED_PREFIX = "webapp_"; @@ -38,7 +38,7 @@ public class MBeanSelectorTest { private static final String[] EXPECTED_COMPONENT_VALUES = {"age", "beauty"}; @Test - public void byDefault_useRuntimeRestUrl() { + void byDefault_useRuntimeRestUrl() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of()); assertThat(selector.getUrl(Protocol.HTTP, "myhost", 1234), @@ -46,7 +46,7 @@ public void byDefault_useRuntimeRestUrl() { } @Test - public void whenConfigurationQuerySpecified_useConfigurationRestUrl() { + void whenConfigurationQuerySpecified_useConfigurationRestUrl() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of()); selector.setQueryType(QueryType.CONFIGURATION); @@ -55,70 +55,70 @@ public void whenConfigurationQuerySpecified_useConfigurationRestUrl() { } @Test - public void whenNoTypeInMap_selectorHasNoType() { + void whenNoTypeInMap_selectorHasNoType() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of()); assertThat(selector.getType(), emptyOrNullString()); } @Test - public void whenMapHasType_selectorHasType() { + void whenMapHasType_selectorHasType() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of(MBeanSelector.TYPE, EXPECTED_TYPE)); assertThat(selector.getType(), equalTo(EXPECTED_TYPE)); } @Test - public void whenNoPrefixInMap_selectorHasNoPrefix() { + void whenNoPrefixInMap_selectorHasNoPrefix() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of()); assertThat(selector.getPrefix(), emptyOrNullString()); } @Test - public void whenMapHasPrefix_selectorHasPrefix() { + void whenMapHasPrefix_selectorHasPrefix() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of(MBeanSelector.PREFIX, EXPECTED_PREFIX)); assertThat(selector.getPrefix(), equalTo(EXPECTED_PREFIX)); } @Test - public void whenNoKeyInMap_selectorHasNoKey() { + void whenNoKeyInMap_selectorHasNoKey() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of()); assertThat(selector.getKey(), emptyOrNullString()); } @Test - public void whenMapHasKey_selectorHasKey() { + void whenMapHasKey_selectorHasKey() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of(MBeanSelector.QUERY_KEY, EXPECTED_KEY)); assertThat(selector.getKey(), equalTo(EXPECTED_KEY)); } @Test - public void whenNoKeyNameInMap_selectorHasNoKeyName() { + void whenNoKeyNameInMap_selectorHasNoKeyName() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of()); assertThat(selector.getKeyName(), emptyOrNullString()); } @Test - public void whenMapHasKeyName_selectorHasKeyName() { + void whenMapHasKeyName_selectorHasKeyName() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of(MBeanSelector.KEY_NAME, EXPECTED_KEY_NAME)); assertThat(selector.getKeyName(), equalTo(EXPECTED_KEY_NAME)); } @Test - public void whenMapHasKeyNameButNoKeyName_selectorUsesKeyAsName() { + void whenMapHasKeyNameButNoKeyName_selectorUsesKeyAsName() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of(MBeanSelector.QUERY_KEY, EXPECTED_KEY)); assertThat(selector.getKeyName(), equalTo(EXPECTED_KEY)); } @Test - public void whenMapHasBothKeyAndKeyName_selectorUsesKeyName() { + void whenMapHasBothKeyAndKeyName_selectorUsesKeyName() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of(MBeanSelector.QUERY_KEY, EXPECTED_KEY, MBeanSelector.KEY_NAME, EXPECTED_KEY_NAME)); @@ -126,14 +126,14 @@ public void whenMapHasBothKeyAndKeyName_selectorUsesKeyName() { } @Test - public void whenNoValuesInMap_selectorHasNoValues() { + void whenNoValuesInMap_selectorHasNoValues() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of()); assertThat(selector.getValues(), emptyArray()); } @Test - public void whenMapHasValues_selectorHasValues() { + void whenMapHasValues_selectorHasValues() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of(MBeanSelector.VALUES, EXPECTED_VALUES)); assertThat(selector.getValues(), equalTo(EXPECTED_VALUES)); @@ -141,15 +141,14 @@ public void whenMapHasValues_selectorHasValues() { @Test - public void whenNoNestedSelectorsInMap_selectorHasNoNestedSelectors() { + void whenNoNestedSelectorsInMap_selectorHasNoNestedSelectors() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of()); assertThat(selector.getNestedSelectors(), anEmptyMap()); } - @Test - public void whenMapHasNestedSelector_createInParent() { + void whenMapHasNestedSelector_createInParent() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of("servlets", getServletMap())); @@ -164,7 +163,7 @@ private Map getServletMap() { } @Test - public void queryFieldsMatchValues() { + void queryFieldsMatchValues() { MBeanSelector selector = MBeanSelector.create( ImmutableMap.of(MBeanSelector.VALUES, EXPECTED_COMPONENT_VALUES)); @@ -176,7 +175,7 @@ private static String querySpec(MBeanSelector selector) { } @Test - public void whenKeySpecified_isIncludedInQueryFields() { + void whenKeySpecified_isIncludedInQueryFields() { MBeanSelector selector = MBeanSelector.create( ImmutableMap.of(MBeanSelector.VALUES, EXPECTED_COMPONENT_VALUES, MBeanSelector.QUERY_KEY, "name")); @@ -184,7 +183,7 @@ public void whenKeySpecified_isIncludedInQueryFields() { } @Test - public void whenTypeSpecified_standardFieldTypeIsIncludedInQueryFields() { + void whenTypeSpecified_standardFieldTypeIsIncludedInQueryFields() { MBeanSelector selector = MBeanSelector.create( ImmutableMap.of(MBeanSelector.VALUES, EXPECTED_COMPONENT_VALUES, MBeanSelector.TYPE, "OneTypeOnly")); @@ -192,7 +191,7 @@ public void whenTypeSpecified_standardFieldTypeIsIncludedInQueryFields() { } @Test - public void whenMapHasNestedElements_pathIncludesChildren() { + void whenMapHasNestedElements_pathIncludesChildren() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of("servlets", ImmutableMap.of(MBeanSelector.VALUES, new String[] {"first", "second"}))); @@ -200,7 +199,7 @@ public void whenMapHasNestedElements_pathIncludesChildren() { } @Test - public void whenMergingLeafElements_combineValues() { + void whenMergingLeafElements_combineValues() { MBeanSelector selector1 = createLeaf("first", "second"); MBeanSelector selector2 = createLeaf("second", "third"); @@ -208,7 +207,7 @@ public void whenMergingLeafElements_combineValues() { } @Test - public void whenLeafElementsHaveMatchingAttributes_mayCombine() { + void whenLeafElementsHaveMatchingAttributes_mayCombine() { MBeanSelector selector1 = createLeaf("type:Type1", "prefix:#_", "key:name", "keyName:numbers", "first", "second"); MBeanSelector selector2 = createLeaf("type:Type1", "prefix:#_", "key:name", "keyName:numbers", "second", "third"); @@ -216,7 +215,7 @@ public void whenLeafElementsHaveMatchingAttributes_mayCombine() { } @Test - public void whenLeafElementsHaveMatchingAttributes_mergedResultHasOriginalAttributes() { + void whenLeafElementsHaveMatchingAttributes_mergedResultHasOriginalAttributes() { MBeanSelector selector1 = createLeaf("type:Type1", "prefix:#_", "key:name", "keyName:numbers", "first", "second"); MBeanSelector selector2 = createLeaf("type:Type1", "prefix:#_", "key:name", "keyName:numbers", "second", "third"); @@ -228,7 +227,7 @@ public void whenLeafElementsHaveMatchingAttributes_mergedResultHasOriginalAttrib } @Test - public void whenLeafElementsHaveMisMatchedAttributes_mayNotCombine() { + void whenLeafElementsHaveMisMatchedAttributes_mayNotCombine() { assertThat(createLeaf("keyName:numbers", "first", "second").mayMergeWith(createLeaf("second", "third")), is(false)); assertThat(createLeaf("prefix:_", "key:Name").mayMergeWith(createLeaf("prefix:_", "aValue")), is(false)); assertThat(createLeaf("key:_", "type:Name").mayMergeWith(createLeaf("key:_", "type:color")), is(false)); @@ -249,7 +248,7 @@ private MBeanSelector createLeaf(String... params) { } @Test - public void whenSelectorsNoCommonNestedElementsWithSameName_mayMerge() { + void whenSelectorsNoCommonNestedElementsWithSameName_mayMerge() { MBeanSelector selector1 = MBeanSelector.create(ImmutableMap.of("servlets", ImmutableMap.of(MBeanSelector.QUERY_KEY, "oneKey", MBeanSelector.VALUES, new String[] {"first", "second"}))); MBeanSelector selector2 = MBeanSelector.create(ImmutableMap.of("kidlets", @@ -259,7 +258,7 @@ public void whenSelectorsNoCommonNestedElementsWithSameName_mayMerge() { } @Test - public void whenSelectorsHaveMismatchedNestedElementsWithSameName_mayNotMerge() { + void whenSelectorsHaveMismatchedNestedElementsWithSameName_mayNotMerge() { MBeanSelector selector1 = MBeanSelector.create(ImmutableMap.of("servlets", ImmutableMap.of(MBeanSelector.QUERY_KEY, "oneKey", MBeanSelector.VALUES, new String[] {"first", "second"}))); MBeanSelector selector2 = MBeanSelector.create(ImmutableMap.of("servlets", @@ -269,7 +268,7 @@ public void whenSelectorsHaveMismatchedNestedElementsWithSameName_mayNotMerge() } @Test - public void whenSelectorsHaveMismatchedNestedElementsWithDifferentName_merge() { + void whenSelectorsHaveMismatchedNestedElementsWithDifferentName_merge() { MBeanSelector selector1 = MBeanSelector.create(ImmutableMap.of("servlets", ImmutableMap.of(MBeanSelector.QUERY_KEY, "oneKey", MBeanSelector.VALUES, new String[] {"first", "second"}))); MBeanSelector selector2 = MBeanSelector.create(ImmutableMap.of("ejbs", @@ -280,7 +279,7 @@ public void whenSelectorsHaveMismatchedNestedElementsWithDifferentName_merge() { } @Test - public void whenSelectorsHaveDeeplyNestedElementsWithDifferentName_mayMerge() { + void whenSelectorsHaveDeeplyNestedElementsWithDifferentName_mayMerge() { MBeanSelector selector1 = MBeanSelector.create( ImmutableMap.of("components", ImmutableMap.of("servlets", @@ -294,7 +293,7 @@ public void whenSelectorsHaveDeeplyNestedElementsWithDifferentName_mayMerge() { } @Test - public void whenSelectorsHaveDeeplyNestedElementsWithDifferentName_merge() { + void whenSelectorsHaveDeeplyNestedElementsWithDifferentName_merge() { MBeanSelector selector1 = MBeanSelector.create( ImmutableMap.of("components", ImmutableMap.of("servlets", @@ -310,7 +309,7 @@ public void whenSelectorsHaveDeeplyNestedElementsWithDifferentName_merge() { } @Test - public void generateJsonRequest() { + void generateJsonRequest() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of("applicationRuntimes", getApplicationMap())); JsonParser parser = new JsonParser(); @@ -328,13 +327,13 @@ private Map getComponentMap() { } @Test - public void domainNameSelector_selectsConfigurationUrl() { + void domainNameSelector_selectsConfigurationUrl() { assertThat(MBeanSelector.DOMAIN_NAME_SELECTOR.getUrl(Protocol.HTTP, "myhost", 1234), equalTo(String.format(QueryType.CONFIGURATION_URL_PATTERN, "http", "myhost", 1234))); } @Test - public void domainNameSelector_requestsName() { + void domainNameSelector_requestsName() { assertThat(MBeanSelector.DOMAIN_NAME_SELECTOR.getValues(), arrayContaining("name")); } @@ -374,7 +373,7 @@ else if (!Character.isWhitespace(c)) "}"; @Test - public void whenNoValuesListedForSerlvets_generateJsonRequest() { + void whenNoValuesListedForSerlvets_generateJsonRequest() { MBeanSelector selector = MBeanSelector.create(ImmutableMap.of("applicationRuntimes", getNoServletValuesApplicationMap())); JsonParser parser = new JsonParser(); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/MapUtilsTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/MapUtilsTest.java index e42bac32..5a5ef553 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/MapUtilsTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/MapUtilsTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2017, 2021, Oracle and/or its affiliates. +// Copyright (c) 2017, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter.domain; @@ -15,26 +15,26 @@ /** * @author Russell Gold */ -public class MapUtilsTest { +class MapUtilsTest { private static final String[] STRING_ARRAY = {"1", "2", "3"}; @Test - public void whenStringArrayValueIsStringArray_returnAsIs() { + void whenStringArrayValueIsStringArray_returnAsIs() { Map map = ImmutableMap.of("values", STRING_ARRAY); assertThat(MapUtils.getStringArray(map, "values"), arrayContaining(STRING_ARRAY)); } @Test - public void whenStringArrayValueIsSingleObject_returnAsLengthOneArray() { + void whenStringArrayValueIsSingleObject_returnAsLengthOneArray() { Map map = ImmutableMap.of("values", 33); assertThat(MapUtils.getStringArray(map, "values"), arrayContaining("33")); } @Test - public void whenStringArrayValueIsList_returnAsArray() { + void whenStringArrayValueIsList_returnAsArray() { Map map = ImmutableMap.of("values", Arrays.asList(7, 8, true)); assertThat(MapUtils.getStringArray(map, "values"), arrayContaining("7", "8", "true")); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/MetricsScraperTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/MetricsScraperTest.java index 6f47480d..4e473d7d 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/MetricsScraperTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/MetricsScraperTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2017, 2021, Oracle and/or its affiliates. +// Copyright (c) 2017, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter.domain; @@ -313,7 +313,6 @@ private Map getFullMap() { "componentRuntimes", componentMap)); } - @Test void generateFromFullResponseUsingSnakeCase() { scraper.setMetricNameSnakeCase(true); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/QueryTypeTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/QueryTypeTest.java index 00254265..b6b61863 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/QueryTypeTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/QueryTypeTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2019, 2021, Oracle and/or its affiliates. +// Copyright (c) 2019, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter.domain; @@ -18,33 +18,33 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; -public class QueryTypeTest { +class QueryTypeTest { private final Map metrics = new HashMap<>(); private Map selectedMetrics; @Test - public void runtimeQueryType_usesRuntimeMbeanUrl() { + void runtimeQueryType_usesRuntimeMbeanUrl() { assertThat(RUNTIME.getUrlPattern(), equalTo(QueryType.RUNTIME_URL_PATTERN)); } @Test - public void configurationQueryType_usesConfigMbeanUrl() { + void configurationQueryType_usesConfigMbeanUrl() { assertThat(CONFIGURATION.getUrlPattern(), equalTo(QueryType.CONFIGURATION_URL_PATTERN)); } @Test - public void runtimeQueryType_ignoresStrings() { + void runtimeQueryType_ignoresStrings() { assertThat(RUNTIME.acceptsStrings(), is(false)); } @Test - public void configurationQueryType_acceptsStrings() { + void configurationQueryType_acceptsStrings() { assertThat(CONFIGURATION.acceptsStrings(), is(true)); } @Test - public void runtimeQueryType_doesNotProcessMetrics() { + void runtimeQueryType_doesNotProcessMetrics() { metrics.put("name", "domain1"); RUNTIME.processMetrics(metrics, this::invokeProcessing); @@ -52,7 +52,7 @@ public void runtimeQueryType_doesNotProcessMetrics() { } @Test - public void configurationQueryType_processesNameAsDomainName() { + void configurationQueryType_processesNameAsDomainName() { metrics.put("name", "domain1"); CONFIGURATION.processMetrics(metrics, this::invokeProcessing); @@ -60,7 +60,7 @@ public void configurationQueryType_processesNameAsDomainName() { } @Test - public void configurationQueryType_removesNameFromMetrics() { + void configurationQueryType_removesNameFromMetrics() { metrics.put("name", "domain1"); CONFIGURATION.processMetrics(metrics, this::invokeProcessing); @@ -68,7 +68,7 @@ public void configurationQueryType_removesNameFromMetrics() { } @Test - public void whenNameNotPresent_configurationQueryTypeDoesNotInvokeProcessing() { + void whenNameNotPresent_configurationQueryTypeDoesNotInvokeProcessing() { CONFIGURATION.processMetrics(metrics, this::invokeProcessing); assertThat(selectedMetrics, nullValue()); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/SnakeCaseUtilTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/SnakeCaseUtilTest.java index bc3fb0fd..41425733 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/SnakeCaseUtilTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/domain/SnakeCaseUtilTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2017, 2021, Oracle and/or its affiliates. +// Copyright (c) 2017, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter.domain; @@ -12,10 +12,10 @@ /** * @author Russell Gold */ -public class SnakeCaseUtilTest { +class SnakeCaseUtilTest { @Test - public void convertToSnakeCase() { + void convertToSnakeCase() { assertThat(SnakeCaseUtil.convert("simple"), equalTo("simple")); assertThat(SnakeCaseUtil.convert("already_snake_case"), equalTo("already_snake_case")); assertThat(SnakeCaseUtil.convert("isCamelCase"), equalTo("is_camel_case")); @@ -23,7 +23,7 @@ public void convertToSnakeCase() { } @Test - public void verifiesSnakeCase() { + void verifiesSnakeCase() { assertThat(SnakeCaseUtil.isCompliant("simple"), is(true)); assertThat(SnakeCaseUtil.isCompliant("an_example_with_multiple_words"), is(true)); assertThat(SnakeCaseUtil.isCompliant("camelCaseWithMultipleWords"), is(false)); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/matchers/PrometheusMetricsMatcherTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/matchers/PrometheusMetricsMatcherTest.java index fd34ccfe..b1b6d1d5 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/matchers/PrometheusMetricsMatcherTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/matchers/PrometheusMetricsMatcherTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2017, 2021, Oracle and/or its affiliates. +// Copyright (c) 2017, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter.matchers; @@ -15,12 +15,12 @@ /** * @author Russell Gold */ -public class PrometheusMetricsMatcherTest { +class PrometheusMetricsMatcherTest { private final PrometheusMetricsMatcher matcher = followsPrometheusRules(); @Test - public void whenMetricsAreGrouped_matcherPasses() { + void whenMetricsAreGrouped_matcherPasses() { assertTrue(matcher.matches(toHtml(ORDERED_LIST))); } @@ -32,7 +32,7 @@ private String toHtml(String... metrics) { } @Test - public void whenMetricsAreInterspersed_matcherFails() { + void whenMetricsAreInterspersed_matcherFails() { assertFalse(matcher.matches(toHtml(MISORDERED_LIST))); } @@ -40,7 +40,7 @@ public void whenMetricsAreInterspersed_matcherFails() { {"metric2{name='red'} 23", "metric1 1", "metric2{name='blue'} 34"}; @Test - public void whenMetricsHaveNonNumericValues_matcherFails() { + void whenMetricsHaveNonNumericValues_matcherFails() { assertFalse(matcher.matches(toHtml(TEXT_LIST))); } diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/ConfigurationServletTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/ConfigurationServletTest.java index 86b3840e..0936c68f 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/ConfigurationServletTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/ConfigurationServletTest.java @@ -40,7 +40,7 @@ /** * @author Russell Gold */ -public class ConfigurationServletTest { +class ConfigurationServletTest { private final static int REST_PORT = 7651; @@ -57,17 +57,17 @@ public void setUp() throws Exception { } @Test - public void configuration_isHttpServlet() { + void configuration_isHttpServlet() { assertThat(servlet, instanceOf(HttpServlet.class)); } @Test - public void servlet_hasWebServletAnnotation() { + void servlet_hasWebServletAnnotation() { assertThat(ConfigurationServlet.class.getAnnotation(WebServlet.class), notNullValue()); } @Test - public void servletAnnotationIndicatesConfigurationPage() { + void servletAnnotationIndicatesConfigurationPage() { WebServlet annotation = ConfigurationServlet.class.getAnnotation(WebServlet.class); assertThat(annotation.value(), arrayContaining("/" + CONFIGURATION_PAGE)); @@ -114,19 +114,19 @@ public void servletAnnotationIndicatesConfigurationPage() { " values: [age, sex]\n"; @Test - public void whenPostWithoutFile_reportFailure() { + void whenPostWithoutFile_reportFailure() { assertThrows(ServletException.class, () -> servlet.doPost(createPostRequest(), response)); } @Test - public void whenRequestUsesHttp_authenticateWithHttp() throws Exception { + void whenRequestUsesHttp_authenticateWithHttp() throws Exception { servlet.doPost(createUploadRequest(createEncodedForm("replace", CONFIGURATION)), response); assertThat(factory.getClientUrl(), Matchers.startsWith("http:")); } @Test - public void whenRequestUsesHttps_authenticateWithHttps() throws Exception { + void whenRequestUsesHttps_authenticateWithHttps() throws Exception { HttpServletRequestStub request = createUploadRequest(createEncodedForm("replace", CONFIGURATION)); request.setSecure(true); servlet.doPost(request, response); @@ -135,21 +135,21 @@ public void whenRequestUsesHttps_authenticateWithHttps() throws Exception { } @Test - public void afterUploadWithReplace_useNewConfiguration() throws Exception { + void afterUploadWithReplace_useNewConfiguration() throws Exception { servlet.doPost(createUploadRequest(createEncodedForm("replace", CONFIGURATION)), response); assertThat(LiveConfiguration.asString(), equalTo(CONFIGURATION)); } @Test - public void afterUpload_redirectToMainPage() throws Exception { + void afterUpload_redirectToMainPage() throws Exception { servlet.doPost(createUploadRequest(createEncodedForm("replace", CONFIGURATION)), response); assertThat(response.getRedirectLocation(), equalTo("")); } @Test - public void whenRestPortInaccessible_switchToLocalPort() throws Exception { + void whenRestPortInaccessible_switchToLocalPort() throws Exception { LiveConfiguration.loadFromString(CONFIGURATION_WITH_REST_PORT); factory.throwConnectionFailure("localhost", REST_PORT); @@ -178,7 +178,7 @@ protected void invoke(WebClient webClient, InvocationContext context) { } @Test - public void afterUploadWithAppend_useBothConfiguration() throws Exception { + void afterUploadWithAppend_useBothConfiguration() throws Exception { LiveConfiguration.loadFromString(CONFIGURATION); servlet.doPost(createUploadRequest(createEncodedForm("append", ADDED_CONFIGURATION)), createServletResponse()); @@ -186,7 +186,7 @@ public void afterUploadWithAppend_useBothConfiguration() throws Exception { } @Test - public void whenSelectedFileIsNotYaml_reportError() throws Exception { + void whenSelectedFileIsNotYaml_reportError() throws Exception { LiveConfiguration.loadFromString(CONFIGURATION); servlet.doPost(createUploadRequest(createEncodedForm("append", NON_YAML)), response); @@ -197,7 +197,7 @@ public void whenSelectedFileIsNotYaml_reportError() throws Exception { "this is not yaml\n"; @Test - public void whenSelectedFileHasPartialYaml_reportError() throws Exception { + void whenSelectedFileHasPartialYaml_reportError() throws Exception { LiveConfiguration.loadFromString(CONFIGURATION); servlet.doPost(createUploadRequest(createEncodedForm("append", PARTIAL_YAML)), response); @@ -208,7 +208,7 @@ public void whenSelectedFileHasPartialYaml_reportError() throws Exception { "queries:\nkey name\n"; @Test - public void whenSelectedFileHasBadBooleanValue_reportError() throws Exception { + void whenSelectedFileHasBadBooleanValue_reportError() throws Exception { LiveConfiguration.loadFromString(CONFIGURATION); servlet.doPost(createUploadRequest(createEncodedForm("append", ADDED_CONFIGURATION_WITH_BAD_BOOLEAN)), response); @@ -216,7 +216,7 @@ public void whenSelectedFileHasBadBooleanValue_reportError() throws Exception { } @Test - public void afterSelectedFileHasBadBooleanValue_configurationIsUnchanged() throws Exception { + void afterSelectedFileHasBadBooleanValue_configurationIsUnchanged() throws Exception { LiveConfiguration.loadFromString(CONFIGURATION); servlet.doPost(createUploadRequest(createEncodedForm("append", ADDED_CONFIGURATION_WITH_BAD_BOOLEAN)), response); @@ -231,7 +231,7 @@ public void afterSelectedFileHasBadBooleanValue_configurationIsUnchanged() throw " values: [age, sex]\n"; @Test - public void whenServerSends403StatusOnGet_returnToClient() throws Exception { + void whenServerSends403StatusOnGet_returnToClient() throws Exception { factory.reportNotAuthorized(); servlet.doPost(request, response); @@ -239,7 +239,7 @@ public void whenServerSends403StatusOnGet_returnToClient() throws Exception { } @Test - public void whenServerSends401StatusOnGet_returnToClient() throws Exception { + void whenServerSends401StatusOnGet_returnToClient() throws Exception { factory.reportAuthenticationRequired("Test-Realm"); servlet.doPost(request, response); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/LogServletTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/LogServletTest.java index 7cb419d8..610cf1dd 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/LogServletTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/LogServletTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2019, 2021, Oracle and/or its affiliates. +// Copyright (c) 2019, 2022, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.wls.exporter.webapp; @@ -25,7 +25,7 @@ import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.notNullValue; -public class LogServletTest { +class LogServletTest { private final LogServlet servlet = new LogServlet(); private final HttpServletRequestStub request = HttpServletRequestStub.createGetRequest(); @@ -45,31 +45,31 @@ public void tearDown() { } @Test - public void landingPage_isHttpServlet() { + void landingPage_isHttpServlet() { assertThat(servlet, instanceOf(HttpServlet.class)); } @Test - public void servlet_hasWebServletAnnotation() { + void servlet_hasWebServletAnnotation() { assertThat(LogServlet.class.getAnnotation(WebServlet.class), notNullValue()); } @Test - public void servletAnnotationIndicatesMainPage() { + void servletAnnotationIndicatesMainPage() { WebServlet annotation = LogServlet.class.getAnnotation(WebServlet.class); assertThat(annotation.value(), arrayContaining("/log")); } @Test - public void whenNoErrorsReported_saySo() throws IOException { + void whenNoErrorsReported_saySo() throws IOException { servlet.doGet(request, response); assertThat(response.getHtml(), containsString("No errors reported.")); } @Test - public void whenErrorsReported_listThem() throws NoSuchFieldException, IOException { + void whenErrorsReported_listThem() throws NoSuchFieldException, IOException { ErrorLog errorLog = new ErrorLog(); mementos.add(StaticStubSupport.install(LiveConfiguration.class, "errorLog", errorLog)); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/MainServletTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/MainServletTest.java index f29f5bd4..dea30f9e 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/MainServletTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/MainServletTest.java @@ -24,7 +24,7 @@ /** * @author Russell Gold */ -public class MainServletTest { +class MainServletTest { private final MainServlet servlet = new MainServlet(); private final HttpServletRequestStub request = HttpServletRequestStub.createGetRequest(); @@ -45,24 +45,24 @@ public void tearDown() { } @Test - public void landingPage_isHttpServlet() { + void landingPage_isHttpServlet() { assertThat(servlet, instanceOf(HttpServlet.class)); } @Test - public void servlet_hasWebServletAnnotation() { + void servlet_hasWebServletAnnotation() { assertThat(MainServlet.class.getAnnotation(WebServlet.class), notNullValue()); } @Test - public void servletAnnotationIndicatesMainPage() { + void servletAnnotationIndicatesMainPage() { WebServlet annotation = MainServlet.class.getAnnotation(WebServlet.class); assertThat(annotation.value(), arrayContaining("/")); } @Test - public void whenServletPathIsSlash_showSimpleLinkToMetrics() throws Exception { + void whenServletPathIsSlash_showSimpleLinkToMetrics() throws Exception { request.setServletPath("/"); servlet.doGet(request, response); @@ -70,7 +70,7 @@ public void whenServletPathIsSlash_showSimpleLinkToMetrics() throws Exception { } @Test - public void whenServletPathIsEmpty_showFullLinkToMetrics() throws Exception { + void whenServletPathIsEmpty_showFullLinkToMetrics() throws Exception { request.setServletPath(""); servlet.doGet(request, response); @@ -78,7 +78,7 @@ public void whenServletPathIsEmpty_showFullLinkToMetrics() throws Exception { } @Test - public void getRequest_containsConfigurationForm() throws Exception { + void getRequest_containsConfigurationForm() throws Exception { request.setServletPath("/"); servlet.doGet(request, response); @@ -87,7 +87,7 @@ public void getRequest_containsConfigurationForm() throws Exception { } @Test - public void whenServletPathIsEmpty_showFullPathToConfigurationServlet() throws Exception { + void whenServletPathIsEmpty_showFullPathToConfigurationServlet() throws Exception { request.setServletPath(""); servlet.doGet(request, response); @@ -95,7 +95,7 @@ public void whenServletPathIsEmpty_showFullPathToConfigurationServlet() throws E } @Test - public void getRequestShowsCurrentConfiguration() throws Exception { + void getRequestShowsCurrentConfiguration() throws Exception { InMemoryFileSystem.defineResource(ServletUtils.CONFIG_YML, PARSED_CONFIGURATION); servlet.init(withNoParams()); @@ -105,7 +105,7 @@ public void getRequestShowsCurrentConfiguration() throws Exception { } @Test - public void whenNewConfigAvailable_getRequestShowsNewConfiguration() throws Exception { + void whenNewConfigAvailable_getRequestShowsNewConfiguration() throws Exception { InMemoryFileSystem.defineResource(ServletUtils.CONFIG_YML, EMPTY_CONFIGURATION); servlet.init(withNoParams()); @@ -116,7 +116,7 @@ public void whenNewConfigAvailable_getRequestShowsNewConfiguration() throws Exce } @Test - public void whenNewConfigHasNoQueries_displayEmptyConfiguration() throws Exception { + void whenNewConfigHasNoQueries_displayEmptyConfiguration() throws Exception { InMemoryFileSystem.defineResource(ServletUtils.CONFIG_YML, PARSED_CONFIGURATION); servlet.init(withNoParams()); diff --git a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/ServletInvocationContextTest.java b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/ServletInvocationContextTest.java index f8444414..eb5ec04f 100644 --- a/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/ServletInvocationContextTest.java +++ b/wls-exporter-core/src/test/java/com/oracle/wls/exporter/webapp/ServletInvocationContextTest.java @@ -20,14 +20,14 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -public class ServletInvocationContextTest { +class ServletInvocationContextTest { private final HttpServletRequestStub request = HttpServletRequestStub.createPostRequest(); private final HttpServletResponseStub response = HttpServletResponseStub.createServletResponse(); private final ServletInvocationContext context = new ServletInvocationContext(request, response); @Test - public void afterClose_requestSessionIsInvalidated() { + void afterClose_requestSessionIsInvalidated() { request.getSession(true); context.close(); @@ -36,33 +36,33 @@ public void afterClose_requestSessionIsInvalidated() { } @Test - public void obtainAuthenticationHeader() { + void obtainAuthenticationHeader() { request.setHeader(AUTHENTICATION_HEADER, "A value"); assertThat(context.getAuthenticationHeader(), equalTo("A value")); } @Test - public void obtainContentType() { + void obtainContentType() { request.setContent("text/plain", "Abcedef"); assertThat(context.getContentType(), equalTo("text/plain")); } @Test - public void obtainInstanceName() { + void obtainInstanceName() { assertThat(context.getInstanceName(), equalTo(HOST_NAME + ":" + PORT)); } @Test - public void dataFromClient_isReadableFromRequestStream() throws IOException { + void dataFromClient_isReadableFromRequestStream() throws IOException { request.setContent("text/plain", "Abcedef"); assertThat(new BufferedReader(new InputStreamReader(context.getRequestStream())).readLine(), equalTo("Abcedef")); } @Test - public void dataWrittenToResponseStream_isSentToClient() throws IOException { + void dataWrittenToResponseStream_isSentToClient() throws IOException { try (PrintStream ps = context.getResponseStream()) { ps.println("This is a line"); } @@ -71,7 +71,7 @@ public void dataWrittenToResponseStream_isSentToClient() throws IOException { } @Test - public void whenErrorCodeSent_statusAndContentAreSet() throws IOException { + void whenErrorCodeSent_statusAndContentAreSet() throws IOException { context.sendError(413, "That's OK"); assertThat(response.getStatus(), equalTo(413)); @@ -79,7 +79,7 @@ public void whenErrorCodeSent_statusAndContentAreSet() throws IOException { } @Test - public void whenNullMessageSent_useSingleArgVersionOfServletResponse() throws IOException { + void whenNullMessageSent_useSingleArgVersionOfServletResponse() throws IOException { context.sendError(413, null); assertThat(response.getStatus(), equalTo(413)); @@ -87,7 +87,7 @@ public void whenNullMessageSent_useSingleArgVersionOfServletResponse() throws IO } @Test - public void whenRedirectSent_statusAndHeaderAreSet() throws IOException { + void whenRedirectSent_statusAndHeaderAreSet() throws IOException { context.sendRedirect("new/location"); assertThat(response.getStatus(), equalTo(HTTP_MOVED_TEMP)); @@ -95,14 +95,14 @@ public void whenRedirectSent_statusAndHeaderAreSet() throws IOException { } @Test - public void whenResponseHeaderSet_isSetOnResponse() { + void whenResponseHeaderSet_isSetOnResponse() { context.setResponseHeader("Header", "value"); assertThat(response.getHeaders("Header").stream().findFirst().orElse(null), equalTo("value")); } @Test - public void whenStatusSet_responseIsUpdated() { + void whenStatusSet_responseIsUpdated() { context.setStatus(371); assertThat(response.getStatus(), equalTo(371)); diff --git a/wls-exporter-sidecar/src/test/java/com/oracle/wls/exporter/sidecar/SidecarConfigurationTest.java b/wls-exporter-sidecar/src/test/java/com/oracle/wls/exporter/sidecar/SidecarConfigurationTest.java index a0fdc651..7cea2a9f 100644 --- a/wls-exporter-sidecar/src/test/java/com/oracle/wls/exporter/sidecar/SidecarConfigurationTest.java +++ b/wls-exporter-sidecar/src/test/java/com/oracle/wls/exporter/sidecar/SidecarConfigurationTest.java @@ -23,7 +23,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -public class SidecarConfigurationTest { +class SidecarConfigurationTest { private final List mementos = new ArrayList<>();