Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonar Fixes (4) #2210

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<ArtifactUrl> ddiUrls = urlHandlerUnderTest.getUrls(placeHolder, ApiType.DDI);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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}");

Expand All @@ -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}");
Expand All @@ -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}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -359,9 +359,9 @@ public DistributionSet createDistributionSet(final String prefix, final String v
final boolean isRequiredMigrationStep, final Collection<SoftwareModule> 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));
}

Expand Down Expand Up @@ -481,7 +481,7 @@ public List<Artifact> 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()));
}
Expand Down
Loading