diff --git a/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/artifact/repository/urlhandler/PropertyBasedArtifactUrlHandler.java b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/artifact/repository/urlhandler/PropertyBasedArtifactUrlHandler.java index 5dbe229c71..dfe3c77f9a 100644 --- a/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/artifact/repository/urlhandler/PropertyBasedArtifactUrlHandler.java +++ b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/artifact/repository/urlhandler/PropertyBasedArtifactUrlHandler.java @@ -62,8 +62,9 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler { private static final String TENANT_ID_BASE10_PLACEHOLDER = "tenantId"; private static final String TENANT_ID_BASE62_PLACEHOLDER = "tenantIdBase62"; private static final String SOFTWARE_MODULE_ID_BASE10_PLACEHOLDER = "softwareModuleId"; - final static String DEFAULT_URL_PROTOCOL_REF = "{" + PROTOCOL_PLACEHOLDER + "}://{" + HOSTNAME_PLACEHOLDER + "}:{" + PORT_PLACEHOLDER + "}{" + CONTEXT_PATH + "}/{" + TENANT_PLACEHOLDER + "}/controller/v1/{" + CONTROLLER_ID_PLACEHOLDER + "}/softwaremodules/{" + SOFTWARE_MODULE_ID_BASE10_PLACEHOLDER + "}/artifacts/{" + ARTIFACT_FILENAME_PLACEHOLDER + "}"; private static final String SOFTWARE_MODULE_ID_BASE62_PLACEHOLDER = "softwareModuleIdBase62"; + static final String DEFAULT_URL_PROTOCOL_REF = "{" + PROTOCOL_PLACEHOLDER + "}://{" + HOSTNAME_PLACEHOLDER + "}:{" + PORT_PLACEHOLDER + "}{" + CONTEXT_PATH + "}/{" + TENANT_PLACEHOLDER + "}/controller/v1/{" + CONTROLLER_ID_PLACEHOLDER + "}/softwaremodules/{" + SOFTWARE_MODULE_ID_BASE10_PLACEHOLDER + "}/artifacts/{" + ARTIFACT_FILENAME_PLACEHOLDER + "}"; + private final ArtifactUrlHandlerProperties urlHandlerProperties; private final String contextPath; diff --git a/hawkbit-artifact/hawkbit-artifact-api/src/test/java/org/eclipse/hawkbit/artifact/repository/urlhandler/PropertyBasedArtifactUrlHandlerTest.java b/hawkbit-artifact/hawkbit-artifact-api/src/test/java/org/eclipse/hawkbit/artifact/repository/urlhandler/PropertyBasedArtifactUrlHandlerTest.java index 504ea979f5..fbcb5bacd0 100644 --- a/hawkbit-artifact/hawkbit-artifact-api/src/test/java/org/eclipse/hawkbit/artifact/repository/urlhandler/PropertyBasedArtifactUrlHandlerTest.java +++ b/hawkbit-artifact/hawkbit-artifact-api/src/test/java/org/eclipse/hawkbit/artifact/repository/urlhandler/PropertyBasedArtifactUrlHandlerTest.java @@ -31,7 +31,7 @@ @Feature("Unit Tests - Artifact URL Handler") @Story("Test to generate the artifact download URL") @ExtendWith(MockitoExtension.class) -public class PropertyBasedArtifactUrlHandlerTest { +class PropertyBasedArtifactUrlHandlerTest { private static final String TEST_PROTO = "coap"; private static final String TEST_REL = "download-udp"; @@ -56,14 +56,14 @@ public class PropertyBasedArtifactUrlHandlerTest { private ArtifactUrlHandlerProperties properties; @BeforeEach - public void setup() { + void setup() { properties = new ArtifactUrlHandlerProperties(); urlHandlerUnderTest = new PropertyBasedArtifactUrlHandler(properties, ""); } @Test @Description("Tests the generation of http download url.") - public void urlGenerationWithDefaultConfiguration() { + void urlGenerationWithDefaultConfiguration() { properties.getProtocols().put("download-http", new UrlProtocol()); final List ddiUrls = urlHandlerUnderTest.getUrls(placeHolder, ApiType.DDI); @@ -78,7 +78,7 @@ public void urlGenerationWithDefaultConfiguration() { @Test @Description("Tests the generation of custom download url with a CoAP example that supports DMF only.") - public void urlGenerationWithCustomConfiguration() { + void urlGenerationWithCustomConfiguration() { final UrlProtocol proto = new UrlProtocol(); proto.setIp("127.0.0.1"); proto.setPort(5683); @@ -97,7 +97,7 @@ public void urlGenerationWithCustomConfiguration() { @Test @Description("Tests the generation of custom download url using Base62 references with a CoAP example that supports DMF only.") - public void urlGenerationWithCustomShortConfiguration() { + void urlGenerationWithCustomShortConfiguration() { final UrlProtocol proto = new UrlProtocol(); proto.setIp("127.0.0.1"); proto.setPort(5683); @@ -116,7 +116,7 @@ public void urlGenerationWithCustomShortConfiguration() { @Test @Description("Verifies that the full qualified host of the statically defined hostname is replaced with the host of the request.") - public void urlGenerationWithHostFromRequest() throws URISyntaxException { + void urlGenerationWithHostFromRequest() throws URISyntaxException { final String testHost = "ddi.host.com"; final UrlProtocol proto = new UrlProtocol(); @@ -136,7 +136,7 @@ public void urlGenerationWithHostFromRequest() throws URISyntaxException { @Test @Description("Verifies that the protocol of the statically defined hostname is replaced with the protocol of the request.") - public void urlGenerationWithProtocolFromRequest() throws URISyntaxException { + void urlGenerationWithProtocolFromRequest() throws URISyntaxException { final String testHost = "ddi.host.com"; final UrlProtocol proto = new UrlProtocol(); @@ -151,7 +151,7 @@ public void urlGenerationWithProtocolFromRequest() throws URISyntaxException { @Test @Description("Verifies that the port of the statically defined hostname is replaced with the port of the request.") - public void urlGenerationWithPortFromRequest() throws URISyntaxException { + void urlGenerationWithPortFromRequest() throws URISyntaxException { final UrlProtocol proto = new UrlProtocol(); proto.setRef("{protocol}://{hostname}:{portRequest}/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}"); @@ -172,7 +172,7 @@ public void urlGenerationWithPortFromRequest() throws URISyntaxException { @Test @Description("Verifies that if default protocol port in request is used then url is returned without port") - public void urlGenerationWithPortFromRequestForHttps() throws URISyntaxException { + void urlGenerationWithPortFromRequestForHttps() throws URISyntaxException { final String protocol = "https"; final UrlProtocol proto = new UrlProtocol(); proto.setRef("{protocolRequest}://{hostnameRequest}:{portRequest}/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}"); @@ -190,7 +190,7 @@ public void urlGenerationWithPortFromRequestForHttps() throws URISyntaxException @Test @Description("Verifies that the domain of the statically defined hostname is replaced with the domain of the request.") - public void urlGenerationWithDomainFromRequest() throws URISyntaxException { + void urlGenerationWithDomainFromRequest() throws URISyntaxException { final UrlProtocol proto = new UrlProtocol(); proto.setHostname("host.bumlux.net"); proto.setRef("{protocol}://{domainRequest}/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}"); diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/TestConfiguration.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/TestConfiguration.java index 3f826e5caf..24da7db829 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/TestConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/TestConfiguration.java @@ -55,7 +55,6 @@ import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.cloud.bus.ConditionalOnBusEnabled; import org.springframework.context.ApplicationEvent; -import org.springframework.context.annotation.AdviceMode; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @@ -98,7 +97,7 @@ public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { public ScheduledExecutorService scheduledExecutorService() { final AtomicLong count = new AtomicLong(0); return new DelegatingSecurityContextScheduledExecutorService( - Executors.newScheduledThreadPool(1, (runnable) -> { + Executors.newScheduledThreadPool(1, runnable -> { final Thread thread = Executors.defaultThreadFactory().newThread(runnable); thread.setName( String.format( diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/SecurityContextSwitch.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/SecurityContextSwitch.java index d5979e5548..906adf5d40 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/SecurityContextSwitch.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/SecurityContextSwitch.java @@ -17,6 +17,8 @@ import java.util.Objects; import java.util.concurrent.Callable; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.tenancy.TenantAwareAuthenticationDetails; import org.eclipse.hawkbit.tenancy.TenantAwareUser; @@ -25,6 +27,7 @@ import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class SecurityContextSwitch { public static final String DEFAULT_TENANT = "DEFAULT"; diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java index d5e1e23ba8..b2fd1998d5 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java @@ -13,7 +13,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.security.SecureRandom; import java.util.ArrayList; import java.util.Arrays; @@ -359,9 +359,9 @@ public DistributionSet createDistributionSet(final String prefix, final String v final boolean isRequiredMigrationStep, final Collection modules) { return distributionSetManagement.create( - entityFactory.distributionSet().create().name(prefix != null && prefix.length() > 0 ? prefix : "DS") + entityFactory.distributionSet().create().name(prefix != null && !prefix.isEmpty() ? prefix : "DS") .version(version).description(randomDescriptionShort()).type(findOrCreateDefaultTestDsType()) - .modules(modules.stream().map(SoftwareModule::getId).collect(Collectors.toList())) + .modules(modules.stream().map(SoftwareModule::getId).toList()) .requiredMigrationStep(isRequiredMigrationStep)); } @@ -481,7 +481,7 @@ public List createArtifacts(final Long moduleId) { * @return {@link Artifact} entity. */ public Artifact createArtifact(final String artifactData, final Long moduleId, final String filename) { - final InputStream stubInputStream = IOUtils.toInputStream(artifactData, Charset.forName("UTF-8")); + final InputStream stubInputStream = IOUtils.toInputStream(artifactData, StandardCharsets.UTF_8); return artifactManagement .create(new ArtifactUpload(stubInputStream, moduleId, filename, false, artifactData.length())); }