Skip to content
Snippets Groups Projects
Commit 00744f6e authored by Alexander Lovett's avatar Alexander Lovett
Browse files

Sonar fixes.

parent 7b9ca634
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@
<groupId>org.geant</groupId>
<artifactId>looking-glass-service</artifactId>
<version>2.0.13.RELEASE</version>
<version>2.0.13-SNAPSHOT</version>
<packaging>jar</packaging>
<name>looking-glass-service</name>
......
......@@ -6,7 +6,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.geant.lgservice.pojos.Command;
......@@ -108,8 +111,12 @@ public class CallableCommandExecutor implements Callable<CommandOutput> {
}
public String getCommandWithArguments() {
return ((this.arguments != null && this.arguments != "") ? this.command.getValue() + " " + this.arguments.trim()
: this.command.getValue()) + (this.displayAsXML ? " | display xml" : "");
return Stream.of(
this.command.getValue(),
this.arguments,
this.displayAsXML ? "| display xml" : "")
.filter(StringUtils::isNotBlank)
.collect(Collectors.joining(" "));
}
}
package org.geant.lgservice.security;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.velocity.app.VelocityEngine;
......@@ -80,6 +68,12 @@ import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuc
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.*;
import static org.springframework.web.util.UriComponentsBuilder.fromHttpUrl;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
......@@ -130,16 +124,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
// Bindings, encoders and decoders used for creating and parsing messages
@Bean
public HttpClient httpClient() {
URI metadataURI = null;
try {
metadataURI = new URI(metadataURL);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Protocol protocol = new Protocol(metadataURI.getScheme(), socketFactory(), metadataURI.getPort());
HttpClient httpClient = new HttpClient(this.multiThreadedHttpConnectionManager);
httpClient.getHostConfiguration().setHost(metadataURI.getHost());
httpClient.getHostConfiguration().setHost(
fromHttpUrl(metadataURL).build().toUri().getHost());
return httpClient;
}
......
......@@ -4,6 +4,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.geant.lgservice.ecmr.CommandExecutor;
import org.geant.lgservice.pojos.Command;
import org.geant.lgservice.pojos.CommandOutput;
......@@ -14,14 +15,15 @@ import org.geant.lgservice.utils.LookingGlassHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import static java.util.stream.Collectors.toMap;
@Service
@RequiredArgsConstructor
public class LookingGlassServiceImpl implements LookingGlassService {
@Autowired
LookingGlassHelper lookingGlassHelper;
private final LookingGlassHelper lookingGlassHelper;
@Autowired
CommandExecutor commandExecutor;
private final CommandExecutor commandExecutor;
@Override
public List<Group> getAllCommands(final LGUser user) {
......@@ -38,6 +40,6 @@ public class LookingGlassServiceImpl implements LookingGlassService {
final String arguments, final boolean displayAsXML) {
return selectedRouters.stream()
.map(router -> commandExecutor.execute(router, selectedCommand, arguments, displayAsXML))
.collect(Collectors.toMap(CommandOutput::getRouterName, output -> output));
.collect(toMap(CommandOutput::getRouterName, output -> output));
}
}
package org.geant.lgservice.services;
import org.assertj.core.api.Assertions;
import org.geant.lgservice.ecmr.CommandExecutor;
import org.geant.lgservice.pojos.Command;
import org.geant.lgservice.pojos.CommandOutput;
import org.geant.lgservice.pojos.Coordinates;
import org.geant.lgservice.pojos.Router;
import org.hibernate.result.Output;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import java.util.Collections;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.*;
public class LookingGlassServiceImplTest {
private CommandExecutor commandExecutor = mock(CommandExecutor.class);
private LookingGlassServiceImpl subject = new LookingGlassServiceImpl(null, commandExecutor);
@Before
public void setup() {
reset(commandExecutor);
}
@Test
public void testQuery() {
Router router = Router.builder()
.name("router.geant.org")
.build();
Command command = new Command();
String arguments = "some args";
CommandOutput output = new CommandOutput();
output.setRouterName(router.getName());
when(commandExecutor.execute(any(Router.class), any(Command.class), any(String.class), anyBoolean())).thenReturn(output);
Map<String, CommandOutput> result = subject.submitQuery(Collections.singletonList(router), command, arguments, false);
assertThat(result).hasSize(1);
assertThat(result).containsKey(router.getName());
assertThat(result.get(router.getName())).isEqualTo(output);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment