diff --git a/pom.xml b/pom.xml index 994c12d6..546ae152 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ api jar ${project.groupId}:${project.artifactId} - 3.4.1-SNAPSHOT + 4.0.0-SNAPSHOT Hygieia Rest API Layer https://github.com/Hygieia/api @@ -44,6 +44,16 @@ CapitalOne http://www.capitalone.com + + erictice + Eric Tice + eric.tice@wipro.com + https://github.com/erictice + + maintainer + + America/Chicago + @@ -54,26 +64,27 @@ org.springframework.boot spring-boot-starter-parent - 1.5.22.RELEASE + 2.5.3 - 3.14.0 - 4.2.18.RELEASE - 8.5.57 + 4.0.0 + 5.5.1 + 10.1.0-M2 1.9.4 - 1.14 + 1.15 4.1 2.4 3.10 2.2.0-RC2 - 29.0-jre - 5.4.2.Final - 2.10.3 + 30.1.1-jre + 6.1.5.Final + 2.11.4 1.18 1.2.3 - 3.6.4 + 2.14.1 + 4.0.6 0.6.0 2.4.0 3.9.0 @@ -84,8 +95,8 @@ 0.8.3 0.200 300 - 1.8 - 1.8 + 14 + 14 3.1 2.12.1 3.0.0 @@ -136,7 +147,39 @@ org.springframework.boot spring-boot-starter-web + 2.5.3 + + + org.apache.tomcat.embed + tomcat-embed-websocket + + + + + javax.servlet + javax.servlet-api + 4.0.1 + provided + + + + + org.apache.logging.log4j + log4j-api + ${log4j2.version} + + + org.apache.logging.log4j + log4j-core + ${log4j2.version} + + + + org.apache.commons + commons-compress + 1.21 + org.springframework.boot @@ -153,9 +196,16 @@ spring-boot-starter-aop + + org.springframework.boot + spring-boot-configuration-processor + true + + org.springframework.boot spring-boot-starter-test + 2.5.3 test @@ -232,8 +282,10 @@ ${java.compilation.source} ${java.compilation.target} + + org.apache.maven.plugins maven-checkstyle-plugin @@ -668,8 +720,8 @@ maven-compiler-plugin 3.5.1 - 1.8 - 1.8 + ${java.compilation.source} + ${java.compilation.target} @@ -732,4 +784,4 @@ - + \ No newline at end of file diff --git a/src/main/java/com/capitalone/dashboard/Application.java b/src/main/java/com/capitalone/dashboard/Application.java index 2aad11ba..c72577c7 100644 --- a/src/main/java/com/capitalone/dashboard/Application.java +++ b/src/main/java/com/capitalone/dashboard/Application.java @@ -4,7 +4,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.Bean; import com.capitalone.dashboard.config.MongoConfig; diff --git a/src/main/java/com/capitalone/dashboard/auth/access/MethodLevelSecurityHandler.java b/src/main/java/com/capitalone/dashboard/auth/access/MethodLevelSecurityHandler.java index 0f22b385..dc86c1c9 100644 --- a/src/main/java/com/capitalone/dashboard/auth/access/MethodLevelSecurityHandler.java +++ b/src/main/java/com/capitalone/dashboard/auth/access/MethodLevelSecurityHandler.java @@ -1,5 +1,7 @@ package com.capitalone.dashboard.auth.access; +import java.util.Optional; + import org.bson.types.ObjectId; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -21,10 +23,11 @@ public MethodLevelSecurityHandler(DashboardRepository dashboardRepository) { } public boolean isOwnerOfDashboard(ObjectId dashboardId) { - Dashboard dashboard = dashboardRepository.findOne(dashboardId); - if (dashboard == null) { + Optional optDash = dashboardRepository.findById(dashboardId); + if (optDash == null) { return false; } + Dashboard dashboard = optDash.get(); String username = AuthenticationUtil.getUsernameFromContext(); AuthType authType = AuthenticationUtil.getAuthTypeFromContext(); diff --git a/src/main/java/com/capitalone/dashboard/auth/ldap/CustomUserDetailsContextMapper.java b/src/main/java/com/capitalone/dashboard/auth/ldap/CustomUserDetailsContextMapper.java index 6f022cdb..c0aff8c8 100644 --- a/src/main/java/com/capitalone/dashboard/auth/ldap/CustomUserDetailsContextMapper.java +++ b/src/main/java/com/capitalone/dashboard/auth/ldap/CustomUserDetailsContextMapper.java @@ -1,6 +1,7 @@ package com.capitalone.dashboard.auth.ldap; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.context.annotation.Configuration; import org.springframework.ldap.core.DirContextAdapter; import org.springframework.ldap.core.DirContextOperations; @@ -14,7 +15,7 @@ @Configuration public class CustomUserDetailsContextMapper extends LdapUserDetailsMapper { - private static final Logger LOGGER = Logger.getLogger(CustomUserDetailsContextMapper.class); + private static final Logger LOGGER = LogManager.getLogger(CustomUserDetailsContextMapper.class); @Override public CustomUserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection authorities) { diff --git a/src/main/java/com/capitalone/dashboard/auth/sso/SsoAuthenticationFilter.java b/src/main/java/com/capitalone/dashboard/auth/sso/SsoAuthenticationFilter.java index 7c703ecc..c2d1bdbd 100644 --- a/src/main/java/com/capitalone/dashboard/auth/sso/SsoAuthenticationFilter.java +++ b/src/main/java/com/capitalone/dashboard/auth/sso/SsoAuthenticationFilter.java @@ -7,7 +7,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.core.Authentication; @@ -19,7 +20,7 @@ @Component public class SsoAuthenticationFilter extends UsernamePasswordAuthenticationFilter { - private static final Logger LOGGER = Logger.getLogger(SsoAuthenticationFilter.class); + private static final Logger LOGGER = LogManager.getLogger(SsoAuthenticationFilter.class); @Autowired private SsoAuthenticationService ssoAuthenticationService; diff --git a/src/main/java/com/capitalone/dashboard/auth/sso/SsoAuthenticationServiceImpl.java b/src/main/java/com/capitalone/dashboard/auth/sso/SsoAuthenticationServiceImpl.java index 640bf780..334a2ccf 100644 --- a/src/main/java/com/capitalone/dashboard/auth/sso/SsoAuthenticationServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/auth/sso/SsoAuthenticationServiceImpl.java @@ -5,7 +5,8 @@ import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; @@ -17,7 +18,7 @@ @Component public class SsoAuthenticationServiceImpl implements SsoAuthenticationService { - private static final Logger LOGGER = Logger.getLogger(SsoAuthenticationServiceImpl.class); + private static final Logger LOGGER = LogManager.getLogger(SsoAuthenticationServiceImpl.class); @Autowired private SsoAuthenticationUtil ssoAuthenticationUtil; diff --git a/src/main/java/com/capitalone/dashboard/auth/sso/SsoAuthenticationUtil.java b/src/main/java/com/capitalone/dashboard/auth/sso/SsoAuthenticationUtil.java index 8803e071..1ef873fc 100644 --- a/src/main/java/com/capitalone/dashboard/auth/sso/SsoAuthenticationUtil.java +++ b/src/main/java/com/capitalone/dashboard/auth/sso/SsoAuthenticationUtil.java @@ -3,7 +3,8 @@ import java.util.ArrayList; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; @@ -16,7 +17,7 @@ @Component public class SsoAuthenticationUtil { - private static final Logger LOGGER = Logger.getLogger(SsoAuthenticationUtil.class); + private static final Logger LOGGER = LogManager.getLogger(SsoAuthenticationUtil.class); @Autowired private AuthProperties authProperties; diff --git a/src/main/java/com/capitalone/dashboard/auth/token/JwtAuthenticationFilter.java b/src/main/java/com/capitalone/dashboard/auth/token/JwtAuthenticationFilter.java index b1297440..f2310814 100644 --- a/src/main/java/com/capitalone/dashboard/auth/token/JwtAuthenticationFilter.java +++ b/src/main/java/com/capitalone/dashboard/auth/token/JwtAuthenticationFilter.java @@ -11,7 +11,8 @@ import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.Order; import org.springframework.security.core.Authentication; @@ -24,7 +25,7 @@ @Order(2) public class JwtAuthenticationFilter extends OncePerRequestFilter { - private static final Logger LOGGER = Logger.getLogger(JwtAuthenticationFilter.class); + private static final Logger LOGGER = LogManager.getLogger(JwtAuthenticationFilter.class); private TokenAuthenticationService tokenAuthenticationService; @Autowired diff --git a/src/main/java/com/capitalone/dashboard/config/WebSecurityConfig.java b/src/main/java/com/capitalone/dashboard/config/WebSecurityConfig.java index afdc9c08..03fdf550 100644 --- a/src/main/java/com/capitalone/dashboard/config/WebSecurityConfig.java +++ b/src/main/java/com/capitalone/dashboard/config/WebSecurityConfig.java @@ -15,12 +15,13 @@ import com.capitalone.dashboard.settings.ApiSettings; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.security.Http401AuthenticationEntryPoint; +import org.springframework.security.web.authentication.HttpStatusEntryPoint; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer; @@ -100,7 +101,7 @@ protected void configure(HttpSecurity http) throws Exception { .addFilterBefore(apiTokenRequestFilter(), UsernamePasswordAuthenticationFilter.class) .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) .addFilterBefore(githubWebhookRequestFilter(), UsernamePasswordAuthenticationFilter.class) - .exceptionHandling().authenticationEntryPoint(new Http401AuthenticationEntryPoint("Authorization")); + .exceptionHandling().authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.ACCEPTED)); } @Override diff --git a/src/main/java/com/capitalone/dashboard/logging/LoggingFilter.java b/src/main/java/com/capitalone/dashboard/logging/LoggingFilter.java index 358e1a37..7071f1eb 100644 --- a/src/main/java/com/capitalone/dashboard/logging/LoggingFilter.java +++ b/src/main/java/com/capitalone/dashboard/logging/LoggingFilter.java @@ -1,37 +1,8 @@ package com.capitalone.dashboard.logging; -import com.capitalone.dashboard.misc.HygieiaException; -import com.capitalone.dashboard.model.RequestLog; -import com.capitalone.dashboard.repository.RequestLogRepository; -import com.capitalone.dashboard.settings.ApiSettings; -import com.mongodb.util.JSON; -import org.apache.commons.io.output.TeeOutputStream; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.apache.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.annotation.Order; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Component; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import javax.activation.MimeType; -import javax.activation.MimeTypeParseException; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ReadListener; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletOutputStream; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.WriteListener; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; -import javax.servlet.http.HttpServletResponse; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -49,13 +20,45 @@ import java.util.Locale; import java.util.Map; -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; +import javax.activation.MimeType; +import javax.activation.MimeTypeParseException; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ReadListener; +import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletOutputStream; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.WriteListener; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.output.TeeOutputStream; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.annotation.Order; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Component; + +import com.capitalone.dashboard.misc.HygieiaException; +import com.capitalone.dashboard.model.RequestLog; +import com.capitalone.dashboard.repository.RequestLogRepository; +import com.capitalone.dashboard.settings.ApiSettings; +import com.mongodb.BasicDBObject; @Component @Order(1) public class LoggingFilter implements Filter { - private static final Logger LOGGER = Logger.getLogger("LoggingFilter"); + private static final Logger LOGGER = LogManager.getLogger("LoggingFilter"); private static final String API_USER_KEY = "apiUser"; @@ -107,10 +110,10 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha boolean skipBody = settings.checkIgnoreBodyEndPoint(endPointURI); if ((httpServletRequest.getContentType() != null) && (new MimeType(httpServletRequest.getContentType()).match(new MimeType(APPLICATION_JSON_VALUE)))) { - requestLog.setRequestBody(JSON.parse(bufferedRequest.getRequestBody())); + requestLog.setRequestBody(BasicDBObject.parse(bufferedRequest.getRequestBody())); } if ((bufferedResponse.getContentType() != null) && (new MimeType(bufferedResponse.getContentType()).match(new MimeType(APPLICATION_JSON_VALUE)))) { - requestLog.setResponseBody( skipBody ? StringUtils.EMPTY : JSON.parse(bufferedResponse.getContent())); + requestLog.setResponseBody( skipBody ? StringUtils.EMPTY : BasicDBObject.parse(bufferedResponse.getContent())); } } catch (MimeTypeParseException e) { diff --git a/src/main/java/com/capitalone/dashboard/request/DashboardRemoteRequest.java b/src/main/java/com/capitalone/dashboard/request/DashboardRemoteRequest.java index e1e98469..6e908df9 100644 --- a/src/main/java/com/capitalone/dashboard/request/DashboardRemoteRequest.java +++ b/src/main/java/com/capitalone/dashboard/request/DashboardRemoteRequest.java @@ -7,7 +7,7 @@ import com.capitalone.dashboard.model.CollectorType; import com.capitalone.dashboard.model.Owner; import com.capitalone.dashboard.util.GitHubParsedUrl; -import org.hibernate.validator.constraints.NotEmpty; +import javax.validation.constraints.NotEmpty; import javax.validation.Valid; import javax.validation.constraints.NotNull; diff --git a/src/main/java/com/capitalone/dashboard/request/PipelineSearchRequest.java b/src/main/java/com/capitalone/dashboard/request/PipelineSearchRequest.java index d06a0c98..c560d214 100644 --- a/src/main/java/com/capitalone/dashboard/request/PipelineSearchRequest.java +++ b/src/main/java/com/capitalone/dashboard/request/PipelineSearchRequest.java @@ -2,7 +2,7 @@ import com.capitalone.dashboard.model.CollectorItem; import org.bson.types.ObjectId; -import org.hibernate.validator.constraints.NotEmpty; +import javax.validation.constraints.NotEmpty; import java.util.List; diff --git a/src/main/java/com/capitalone/dashboard/request/TestResultRequest.java b/src/main/java/com/capitalone/dashboard/request/TestResultRequest.java index ad71aa75..97f1717f 100644 --- a/src/main/java/com/capitalone/dashboard/request/TestResultRequest.java +++ b/src/main/java/com/capitalone/dashboard/request/TestResultRequest.java @@ -1,12 +1,14 @@ package com.capitalone.dashboard.request; -import com.capitalone.dashboard.model.TestSuiteType; +import java.util.ArrayList; +import java.util.List; + +import javax.validation.constraints.NotNull; + import org.bson.types.ObjectId; import org.hibernate.validator.constraints.Range; -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.List; +import com.capitalone.dashboard.model.TestSuiteType; public class TestResultRequest { @NotNull diff --git a/src/main/java/com/capitalone/dashboard/rest/PingController.java b/src/main/java/com/capitalone/dashboard/rest/PingController.java index 1e256fa2..be4ea66d 100644 --- a/src/main/java/com/capitalone/dashboard/rest/PingController.java +++ b/src/main/java/com/capitalone/dashboard/rest/PingController.java @@ -1,6 +1,7 @@ package com.capitalone.dashboard.rest; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; import org.springframework.http.HttpStatus; @@ -15,7 +16,7 @@ @RestController public class PingController { - private static final Logger LOGGER = Logger.getLogger(PingController.class); + private static final Logger LOGGER = LogManager.getLogger(PingController.class); @Value("${version.number}") private String versionNumber; diff --git a/src/main/java/com/capitalone/dashboard/rest/ScoreController.java b/src/main/java/com/capitalone/dashboard/rest/ScoreController.java index 477207f9..2cbc2a17 100644 --- a/src/main/java/com/capitalone/dashboard/rest/ScoreController.java +++ b/src/main/java/com/capitalone/dashboard/rest/ScoreController.java @@ -1,6 +1,7 @@ package com.capitalone.dashboard.rest; import com.capitalone.dashboard.model.DataResponse; +import com.capitalone.dashboard.model.score.QScoreMetric; import com.capitalone.dashboard.model.score.ScoreMetric; import com.capitalone.dashboard.service.ScoreService; import org.bson.types.ObjectId; diff --git a/src/main/java/com/capitalone/dashboard/service/ApiTokenServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/ApiTokenServiceImpl.java index f3ee5394..a164c3b2 100644 --- a/src/main/java/com/capitalone/dashboard/service/ApiTokenServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/ApiTokenServiceImpl.java @@ -1,9 +1,27 @@ package com.capitalone.dashboard.service; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.bson.types.ObjectId; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.stereotype.Component; + import com.capitalone.dashboard.misc.HygieiaException; import com.capitalone.dashboard.model.ApiToken; -import com.capitalone.dashboard.model.AuthType; -import com.capitalone.dashboard.model.Authentication; import com.capitalone.dashboard.model.UserInfo; import com.capitalone.dashboard.model.UserRole; import com.capitalone.dashboard.repository.ApiTokenRepository; @@ -12,30 +30,11 @@ import com.capitalone.dashboard.util.EncryptionException; import com.capitalone.dashboard.util.UnsafeDeleteException; import com.google.common.collect.Sets; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.log4j.Logger; -import org.bson.types.ObjectId; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.authentication.BadCredentialsException; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.stereotype.Component; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashSet; -import java.util.List; @Component public class ApiTokenServiceImpl implements ApiTokenService { - private static final Logger LOGGER = Logger.getLogger(ApiTokenServiceImpl.class); + private static final Logger LOGGER = LogManager.getLogger(ApiTokenServiceImpl.class); private ApiTokenRepository apiTokenRepository; @@ -101,26 +100,28 @@ private boolean isUserAdmin(UserInfo user) { @Override public void deleteToken(ObjectId id) { - ApiToken apiToken = apiTokenRepository.findOne(id); + Optional apiToken = apiTokenRepository.findById(id); if(apiToken == null) { throw new UnsafeDeleteException("Cannot delete token "); }else{ - apiTokenRepository .delete(apiToken); + ApiToken token = apiToken.get(); + apiTokenRepository.delete(token); } } @Override public String updateToken(Long expirationDt, ObjectId id) throws HygieiaException{ - ApiToken apiToken = apiTokenRepository.findOne(id); + Optional apiToken = apiTokenRepository.findById(id); + ApiToken token = null; if(apiToken == null) { throw new HygieiaException("Cannot find token ", HygieiaException.BAD_DATA); }else{ - - apiToken.setExpirationDt(expirationDt); - apiTokenRepository.save(apiToken); + token = apiToken.get(); + token.setExpirationDt(expirationDt); + apiTokenRepository.save(token); } - return apiToken.getId().toString(); + return token.getId().toString(); } private Collection createAuthorities(Collection authorities) { Collection grantedAuthorities = new HashSet<>(); diff --git a/src/main/java/com/capitalone/dashboard/service/AutoDiscoveryServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/AutoDiscoveryServiceImpl.java index 7f89a3c5..7147f770 100644 --- a/src/main/java/com/capitalone/dashboard/service/AutoDiscoveryServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/AutoDiscoveryServiceImpl.java @@ -1,5 +1,21 @@ package com.capitalone.dashboard.service; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +import javax.validation.constraints.NotNull; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.bson.types.ObjectId; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + import com.capitalone.dashboard.misc.HygieiaException; import com.capitalone.dashboard.model.AutoDiscoveredEntry; import com.capitalone.dashboard.model.AutoDiscovery; @@ -13,19 +29,6 @@ import com.capitalone.dashboard.util.FeatureFlagsEnum; import com.capitalone.dashboard.util.HygieiaUtils; import com.google.common.collect.Iterables; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.bson.types.ObjectId; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; @Service public class AutoDiscoveryServiceImpl implements AutoDiscoveryService { @@ -41,7 +44,7 @@ public AutoDiscoveryServiceImpl(AutoDiscoveryRepository autoDiscoveryRepository, this.featureFlagRepository = featureFlagRepository; } - @Override + public AutoDiscovery save(AutoDiscoveryRemoteRequest request) throws HygieiaException { String autoDiscoveryId = request.getAutoDiscoveryId(); if (autoDiscoveryId==null || !ObjectId.isValid(autoDiscoveryId)) { @@ -49,24 +52,28 @@ public AutoDiscovery save(AutoDiscoveryRemoteRequest request) throws HygieiaExce } ObjectId id = new ObjectId(autoDiscoveryId); - AutoDiscovery autoDiscovery; + Optional autoDiscovery; FeatureFlag featureFlag = featureFlagRepository.findByName(FeatureFlagsEnum.auto_discover.toString()); - - if (autoDiscoveryRepository.exists(id)) { + AutoDiscovery ad = null; + if (autoDiscoveryRepository.existsById(id)) { // update existing AutoDiscovery record with the status from request - autoDiscovery = autoDiscoveryRepository.findOne(id); - updateAutoDiscovery(autoDiscovery, request, featureFlag); - autoDiscovery.setModifiedTimestamp(System.currentTimeMillis()); + autoDiscovery = autoDiscoveryRepository.findById(id); + if(autoDiscovery != null) { + throw new HygieiaException("Cannot find autoDiscovery ", HygieiaException.BAD_DATA); + } + ad = autoDiscovery.get(); + updateAutoDiscovery(ad, request, featureFlag); + ad.setModifiedTimestamp(System.currentTimeMillis()); } else { // create new AutoDiscovery record - autoDiscovery = requestToAutoiscovery(request, featureFlag); + ad = requestToAutoiscovery(request, featureFlag); long currTime = System.currentTimeMillis(); - autoDiscovery.setCreatedTimestamp(currTime); - autoDiscovery.setModifiedTimestamp(currTime); + ad.setCreatedTimestamp(currTime); + ad.setModifiedTimestamp(currTime); } - autoDiscoveryRepository.save(autoDiscovery); - return autoDiscovery; + autoDiscoveryRepository.save(ad); + return ad; } /** diff --git a/src/main/java/com/capitalone/dashboard/service/BinaryArtifactServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/BinaryArtifactServiceImpl.java index 7f907185..dd3991fd 100644 --- a/src/main/java/com/capitalone/dashboard/service/BinaryArtifactServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/BinaryArtifactServiceImpl.java @@ -1,5 +1,15 @@ package com.capitalone.dashboard.service; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.ObjectUtils; +import org.bson.types.ObjectId; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + import com.capitalone.dashboard.model.BinaryArtifact; import com.capitalone.dashboard.model.Build; import com.capitalone.dashboard.model.DataResponse; @@ -10,15 +20,6 @@ import com.capitalone.dashboard.request.BinaryArtifactCreateRequest; import com.capitalone.dashboard.request.BinaryArtifactSearchRequest; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.lang3.ObjectUtils; -import org.bson.types.ObjectId; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - @Service public class BinaryArtifactServiceImpl implements BinaryArtifactService { @@ -73,10 +74,9 @@ public DataResponse> search(BinaryArtifactSearchRequest } private Build getBuildById(ObjectId buildId){ - return buildRepository.findOne(buildId); + return buildRepository.findById(buildId).get(); } - @Override public String create(BinaryArtifactCreateRequest request) { BinaryArtifact ba = new BinaryArtifact(); ba.setArtifactName(request.getArtifactName()); @@ -126,7 +126,7 @@ private void setBuildInformation(BinaryArtifact ba, ObjectId buildId) { ba.setBuildNumber(build.getNumber()); } - JobCollectorItem ci = jobRepository.findOne(build.getCollectorItemId()); + JobCollectorItem ci = jobRepository.findById(build.getCollectorItemId()).get(); if (ci != null) { if (ba.getInstanceUrl() == null) { ba.setInstanceUrl(ci.getInstanceUrl()); diff --git a/src/main/java/com/capitalone/dashboard/service/BuildServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/BuildServiceImpl.java index 27a364a5..a5e53f6a 100644 --- a/src/main/java/com/capitalone/dashboard/service/BuildServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/BuildServiceImpl.java @@ -27,7 +27,8 @@ import com.querydsl.core.BooleanBuilder; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.bson.types.ObjectId; import org.joda.time.LocalDate; import org.springframework.beans.factory.annotation.Autowired; @@ -60,7 +61,7 @@ public class BuildServiceImpl implements BuildService { @Autowired private ApiSettings settings; - private static final Logger LOGGER = Logger.getLogger(BuildService.class); + private static final Logger LOGGER = LogManager.getLogger(BuildService.class); @Autowired public BuildServiceImpl(BuildRepository buildRepository, @@ -84,7 +85,7 @@ public BuildServiceImpl(BuildRepository buildRepository, @Override public DataResponse> search(BuildSearchRequest request) { CollectorItem item = null; - Component component = componentRepository.findOne(request.getComponentId()); + Component component = componentRepository.findById(request.getComponentId()).get(); if ( (component == null) || ((item = component.getLastUpdatedCollectorItemForType(CollectorType.Build)) == null) ) { Iterable results = new ArrayList<>(); @@ -115,13 +116,13 @@ public DataResponse> search(BuildSearchRequest request) { builder.and(build.buildStatus.in(request.getBuildStatuses())); } - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); Iterable result; if (request.getMax() == null) { result = buildRepository.findAll(builder.getValue()); } else { - PageRequest pageRequest = new PageRequest(0, request.getMax(), Sort.Direction.DESC, "timestamp"); + PageRequest pageRequest = PageRequest.of(0, request.getMax(), Sort.Direction.DESC, "timestamp"); result = buildRepository.findAll(builder.getValue(), pageRequest).getContent(); } @@ -184,7 +185,7 @@ public BuildDataCreateResponse createV3(BuildDataCreateRequest request) throws H } } // Will be refactored soon - CollectorItem buildCollectorItem = collectorItemRepository.findOne(build.getCollectorItemId()); + CollectorItem buildCollectorItem = collectorItemRepository.findById(build.getCollectorItemId()).get(); if(buildCollectorItem != null) { LOGGER.info("buildUrl=" + build.getBuildUrl() + ", buildDuration=" + build.getDuration() @@ -202,7 +203,7 @@ public BuildDataCreateResponse createV3(BuildDataCreateRequest request) throws H private void populateDashboardId(BuildDataCreateResponse response) { if (response == null) return; - CollectorItem collectorItem = collectorItemRepository.findOne(response.getCollectorItemId()); + CollectorItem collectorItem = collectorItemRepository.findById(response.getCollectorItemId()).get(); if (collectorItem == null) return; List dashboards = dashboardService.getDashboardsByCollectorItems diff --git a/src/main/java/com/capitalone/dashboard/service/CloudInstanceServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/CloudInstanceServiceImpl.java index 3fdb0edb..9ea7e6c1 100644 --- a/src/main/java/com/capitalone/dashboard/service/CloudInstanceServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/CloudInstanceServiceImpl.java @@ -51,7 +51,7 @@ public Collection getInstanceDetails(CollectorItem item) { } private CollectorItem getCollectorItem(ObjectId componentId) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); if (CollectionUtils.isEmpty(component.getCollectorItems())) return null; return component.getCollectorItems().get(CollectorType.Cloud).get(0); } @@ -106,7 +106,7 @@ public Collection refreshInstances(CloudInstanceListRefreshRequest reque } } if (CollectionUtils.isEmpty(toDelete)) { - cloudInstanceRepository.delete(toDelete); + cloudInstanceRepository.deleteAll(toDelete); } return deletedIds; } diff --git a/src/main/java/com/capitalone/dashboard/service/CloudSubnetServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/CloudSubnetServiceImpl.java index 1f6c8a85..b7f1b5cc 100644 --- a/src/main/java/com/capitalone/dashboard/service/CloudSubnetServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/CloudSubnetServiceImpl.java @@ -37,7 +37,7 @@ public CloudSubnetServiceImpl(CloudSubNetworkRepository cloudSubNetworkRepositor private CollectorItem getCollectorItem(ObjectId componentId) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); if (CollectionUtils.isEmpty(component.getCollectorItems())) return null; return component.getCollectorItems().get(CollectorType.Cloud).get(0); } @@ -67,7 +67,7 @@ public Collection refreshSubnets(CloudInstanceListRefreshRequest request } } if (CollectionUtils.isEmpty(toDelete)) { - cloudSubNetworkRepository.delete(toDelete); + cloudSubNetworkRepository.deleteAll(toDelete); } return deletedIds; } diff --git a/src/main/java/com/capitalone/dashboard/service/CloudVirtualNetworkServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/CloudVirtualNetworkServiceImpl.java index bc325a85..872a82ef 100644 --- a/src/main/java/com/capitalone/dashboard/service/CloudVirtualNetworkServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/CloudVirtualNetworkServiceImpl.java @@ -39,7 +39,7 @@ public CloudVirtualNetworkServiceImpl(CloudVirtualNetworkRepository cloudVirtual } private CollectorItem getCollectorItem(ObjectId componentId) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); if (CollectionUtils.isEmpty(component.getCollectorItems())) return null; return component.getCollectorItems().get(CollectorType.Cloud).get(0); } diff --git a/src/main/java/com/capitalone/dashboard/service/CloudVolumeServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/CloudVolumeServiceImpl.java index 5f99eaa1..43ca509c 100644 --- a/src/main/java/com/capitalone/dashboard/service/CloudVolumeServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/CloudVolumeServiceImpl.java @@ -51,7 +51,7 @@ public Collection getVolumeDetails(CollectorItem item) { } private CollectorItem getCollectorItem(ObjectId componentId) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); if (CollectionUtils.isEmpty(component.getCollectorItems())) return null; return component.getCollectorItems().get(CollectorType.Cloud).get(0); } @@ -112,7 +112,7 @@ public Collection refreshVolumes(CloudVolumeListRefreshRequest request) } } if (CollectionUtils.isEmpty(toDelete)) { - cloudVolumeRepository.delete(toDelete); + cloudVolumeRepository.deleteAll(toDelete); } return deletedIds; } diff --git a/src/main/java/com/capitalone/dashboard/service/CmdbServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/CmdbServiceImpl.java index 6eabbe23..768c59ef 100644 --- a/src/main/java/com/capitalone/dashboard/service/CmdbServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/CmdbServiceImpl.java @@ -52,7 +52,7 @@ public String configurationItemNameByObjectId(ObjectId objectId){ } @Override public Cmdb configurationItemsByObjectId(ObjectId objectId){ - Cmdb cmdb = cmdbRepository.findOne(objectId); + Cmdb cmdb = cmdbRepository.findById(objectId).get(); return cmdb; } @Override diff --git a/src/main/java/com/capitalone/dashboard/service/CodeQualityServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/CodeQualityServiceImpl.java index 1e6e91c5..b71fc46e 100644 --- a/src/main/java/com/capitalone/dashboard/service/CodeQualityServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/CodeQualityServiceImpl.java @@ -95,20 +95,20 @@ private DataResponse> searchType(CodeQualityRequest reques result = codeQualityRepository.findAll(builder.getValue(), quality.timestamp.desc()); } else { PageRequest pageRequest = - new PageRequest(0, request.getMax(), Sort.Direction.DESC, "timestamp"); + PageRequest.of(0, request.getMax(), Sort.Direction.DESC, "timestamp"); result = codeQualityRepository.findAll(builder.getValue(), pageRequest).getContent(); } String instanceUrl = (String)item.getOptions().get("instanceUrl"); String projectId = (String) item.getOptions().get("projectId"); String reportUrl = getReportURL(instanceUrl,"dashboard/index/",projectId); - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); long lastExecuted = (collector == null) ? 0 : collector.getLastExecuted(); return new DataResponse<>(result, lastExecuted,reportUrl); } protected CollectorItem getCollectorItem(CodeQualityRequest request) { - Component component = componentRepository.findOne(request.getComponentId()); + Component component = componentRepository.findById(request.getComponentId()).get(); if (component == null) { return null; } diff --git a/src/main/java/com/capitalone/dashboard/service/CollectorServiceAspect.java b/src/main/java/com/capitalone/dashboard/service/CollectorServiceAspect.java index 4282238e..4ec0191f 100644 --- a/src/main/java/com/capitalone/dashboard/service/CollectorServiceAspect.java +++ b/src/main/java/com/capitalone/dashboard/service/CollectorServiceAspect.java @@ -45,7 +45,7 @@ private boolean isGit(Collector collector) { } private void normalizeOptions(CollectorItem item, Map uniqueOptions) { - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); if (collector.getCollectorType() == CollectorType.SCM && isGit(collector)) { String repoUrl = (String)uniqueOptions.get("url"); GitHubParsedUrl gitHubParsed = new GitHubParsedUrl(repoUrl); diff --git a/src/main/java/com/capitalone/dashboard/service/CollectorServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/CollectorServiceImpl.java index bd59f0ce..65d3b99c 100644 --- a/src/main/java/com/capitalone/dashboard/service/CollectorServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/CollectorServiceImpl.java @@ -71,7 +71,9 @@ public List collectorsByType(CollectorType collectorType) { @Override public List collectorsById(ObjectId id) { - return collectorRepository.findById(id); + List ids = new ArrayList(); + ids.add(collectorRepository.findById(id).get()); + return ids; } @Override @@ -151,11 +153,11 @@ public void initProductCollectorOnStartup() { @Override public CollectorItem getCollectorItem(ObjectId id) throws HygieiaException { - CollectorItem item = collectorItemRepository.findOne(id); + CollectorItem item = collectorItemRepository.findById(id).get(); if(item == null){ throw new HygieiaException("Failed to find collectorItem by Id.", HygieiaException.BAD_DATA); } - item.setCollector(collectorRepository.findOne(item.getCollectorId())); + item.setCollector(collectorRepository.findById(item.getCollectorId()).get()); return item; } @@ -179,7 +181,7 @@ private List lookUpCollectorItem(CollectorItem collectorItem){ if (collectorItem==null){ return Collections.emptyList(); } - Collector collector = collectorRepository.findOne(collectorItem.getCollectorId()); + Collector collector = collectorRepository.findById(collectorItem.getCollectorId()).get(); if (collector == null){ return Collections.emptyList(); } @@ -199,7 +201,7 @@ private List lookUpCollectorItem(CollectorItem collectorItem){ // just update the new credentials. @Override public CollectorItem createCollectorItemSelectOptions(CollectorItem item, Map allOptions, Map uniqueOptions) { - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); Map uniqueFieldsFromCollector = collector.getUniqueFields(); List existing = customRepositoryQuery.findCollectorItemsBySubsetOptions( item.getCollectorId(), allOptions, uniqueOptions,uniqueFieldsFromCollector); @@ -282,7 +284,7 @@ public Collector createCollector(Collector collector) { public List getCollectorItemForComponent(String id, String type) { ObjectId oid = new ObjectId(id); CollectorType ctype = CollectorType.fromString(type); - Component component = componentRepository.findOne(oid); + Component component = componentRepository.findById(oid).get(); List items = component.getCollectorItems(ctype); @@ -292,13 +294,13 @@ public List getCollectorItemForComponent(String id, String type) for (CollectorItem item : items) { ids.add(item.getId()); } - return (List) collectorItemRepository.findAll(ids); + return (List) collectorItemRepository.findAllById(ids); } @Override public void deletePropertiesInCollectorById(String id) { ObjectId objectId = new ObjectId(id); - Collector collectorById = collectorRepository.findOne(objectId); + Collector collectorById = collectorRepository.findById(objectId).get(); Map blankMap = new HashMap<>(); if(collectorById.getProperties().size() > 0) { @@ -335,7 +337,7 @@ public void deleteCollectorItem(String id, boolean deleteFromComponent) throws H } //delete the collector item. - collectorItemRepository.delete(objectId); + collectorItemRepository.deleteById(objectId); } private Collector collectorById(ObjectId collectorId, List collectors) { diff --git a/src/main/java/com/capitalone/dashboard/service/CommitServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/CommitServiceImpl.java index a41b2925..324aed5c 100644 --- a/src/main/java/com/capitalone/dashboard/service/CommitServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/CommitServiceImpl.java @@ -55,7 +55,7 @@ public DataResponse> search(CommitRequest request) { BooleanBuilder builder = new BooleanBuilder(); CollectorItem item = null; - Component component = componentRepository.findOne(request.getComponentId()); + Component component = componentRepository.findById(request.getComponentId()).get(); if ( (component == null) || ((item = component.getLastUpdatedCollectorItemForType(CollectorType.SCM)) == null) ) { @@ -88,7 +88,7 @@ public DataResponse> search(CommitRequest request) { builder.and(commit.scmCommitLog.contains(request.getMessageContains())); } - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); return new DataResponse<>(commitRepository.findAll(builder.getValue()), collector.getLastExecuted()); } diff --git a/src/main/java/com/capitalone/dashboard/service/ConfigurationServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/ConfigurationServiceImpl.java index d506d2cf..831ceebf 100644 --- a/src/main/java/com/capitalone/dashboard/service/ConfigurationServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/ConfigurationServiceImpl.java @@ -32,7 +32,7 @@ public List insertConfigurationData(List configLis for (Configuration config : configList) { config.decryptOrEncrptInfo(); } - return (List) configurationRepository.save(configList); + return (List) configurationRepository.saveAll(configList); } @Override diff --git a/src/main/java/com/capitalone/dashboard/service/DashboardRemoteServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/DashboardRemoteServiceImpl.java index 5b8dcd22..6ce54eb7 100644 --- a/src/main/java/com/capitalone/dashboard/service/DashboardRemoteServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/DashboardRemoteServiceImpl.java @@ -145,7 +145,7 @@ public Dashboard remoteCreate(DashboardRemoteRequest request, boolean isUpdate) Set incomingTypes = new HashSet<>(); List entries = request.getAllEntries(); Map allWidgetRequests = generateRequestWidgetList( entries, dashboard, incomingTypes); - Component component = componentRepository.findOne(dashboard.getApplication().getComponents().get(0).getId()); + Component component = componentRepository.findById(dashboard.getApplication().getComponents().get(0).getId()).get(); Set existingTypes = new HashSet<>(component.getCollectorItems().keySet()); //adds widgets diff --git a/src/main/java/com/capitalone/dashboard/service/DashboardServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/DashboardServiceImpl.java index 25c973c6..3e9539a3 100644 --- a/src/main/java/com/capitalone/dashboard/service/DashboardServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/DashboardServiceImpl.java @@ -111,7 +111,7 @@ public DashboardServiceImpl(DashboardRepository dashboardRepository, @Override public Iterable all() { - Iterable dashboards = dashboardRepository.findAll(new Sort(Sort.Direction.ASC, "title")); + Iterable dashboards = dashboardRepository.findAll(Sort.by(Sort.Direction.ASC, "title")); for(Dashboard dashboard: dashboards){ String appName = dashboard.getConfigurationItemBusServName(); String compName = dashboard.getConfigurationItemBusAppName(); @@ -136,7 +136,7 @@ public Iterable allTemplate(String template){ @Override public Dashboard get(ObjectId id) { - Dashboard dashboard = dashboardRepository.findOne(id); + Dashboard dashboard = dashboardRepository.findById(id).get(); String appName = dashboard.getConfigurationItemBusServName(); String compName = dashboard.getConfigurationItemBusAppName(); @@ -182,7 +182,7 @@ private Dashboard create(Dashboard dashboard, boolean isUpdate) throws HygieiaEx if(!isUpdate) { dashboard.setCreatedAt(System.currentTimeMillis()); - components = componentRepository.save(dashboard.getApplication().getComponents()); + components = componentRepository.saveAll(dashboard.getApplication().getComponents()); } dashboard.setUpdatedAt(System.currentTimeMillis()); @@ -199,7 +199,7 @@ private Dashboard create(Dashboard dashboard, boolean isUpdate) throws HygieiaEx } catch (Exception e) { //Exclude deleting of components if this is an update request if(!isUpdate) { - componentRepository.delete(components); + componentRepository.deleteAll(components); } if(e instanceof HygieiaException){ @@ -221,7 +221,7 @@ public Dashboard update(Dashboard dashboard) throws HygieiaException { @Override public void delete(ObjectId id) { - Dashboard dashboard = dashboardRepository.findOne(id); + Dashboard dashboard = dashboardRepository.findById(id).get(); if (!isSafeDelete(dashboard)) { throw new UnsafeDeleteException("Cannot delete team dashboard " + dashboard.getTitle() + " as it is referenced by program dashboards."); @@ -229,7 +229,7 @@ public void delete(ObjectId id) { // Remove this Dashboard's services and service dependencies - serviceRepository.delete(serviceRepository.findByDashboardId(id)); + serviceRepository.deleteAll(serviceRepository.findByDashboardId(id)); for (com.capitalone.dashboard.model.Service service : serviceRepository.findByDependedBy(id)) { //NOPMD - using fully qualified or we pickup an incorrect spring class service.getDependedBy().remove(id); serviceRepository.save(service); @@ -239,7 +239,7 @@ public void delete(ObjectId id) { * Delete Dashboard. Then delete component. Then disable collector items if needed */ dashboardRepository.delete(dashboard); - componentRepository.delete(dashboard.getApplication().getComponents()); + componentRepository.deleteAll(dashboard.getApplication().getComponents()); handleCollectorItems(dashboard.getApplication().getComponents()); if (dashboard.isScoreEnabled()) { this.scoreDashboardService.disableScoreForDashboard(dashboard); @@ -300,7 +300,7 @@ public Component associateCollectorToComponent(ObjectId componentId, List collectorItemIds, ObjectId currentCollectorId = null; Collector collector = null; for (ObjectId collectorItemId : collectorItemIds) { - CollectorItem collectorItem = collectorItemRepository.findOne(collectorItemId); + CollectorItem collectorItem = collectorItemRepository.findById(collectorItemId).get(); incomingCollectorItems.put(collectorItemId, collectorItem); if(collectorItem == null) { LOG.warn(METHOD_NAME + " Bad CollectorItemId passed in the request : " + collectorItemId); continue; } if(collector == null || currentCollectorId != collectorItem.getCollectorId()) { - collector = collectorRepository.findOne(collectorItem.getCollectorId()); + collector = collectorRepository.findById(collectorItem.getCollectorId()).get(); currentCollectorId = collector.getId(); } if (!incomingTypes.contains(collector.getCollectorType())) { @@ -387,7 +387,7 @@ private void associateCollectorItemsToComponent(List collectorItemIds, collectorItem.setLastUpdated(System.currentTimeMillis()); } if(collector == null || currentCollectorId != collectorItem.getCollectorId()) { - collector = collectorRepository.findOne(collectorItem.getCollectorId()); + collector = collectorRepository.findById(collectorItem.getCollectorId()).get(); currentCollectorId = collector.getId(); } component.addCollectorItem(collector.getCollectorType(), collectorItem); @@ -396,7 +396,7 @@ private void associateCollectorItemsToComponent(List collectorItemIds, collectorItem.setCollector(collector); } - collectorItemRepository.save(new HashSet<>(toSaveCollectorItems.values())); + collectorItemRepository.saveAll(new HashSet<>(toSaveCollectorItems.values())); if(save){ componentRepository.save(component); } @@ -470,7 +470,7 @@ private Iterable collectorsFromItems(Map collectors) { @@ -517,7 +517,7 @@ public Iterable updateOwners(ObjectId dashboardId, Iterable owners } } - Dashboard dashboard = dashboardRepository.findOne(dashboardId); + Dashboard dashboard = dashboardRepository.findById(dashboardId).get(); dashboard.setOwners(Lists.newArrayList(owners)); Dashboard result = dashboardRepository.save(dashboard); @@ -542,7 +542,7 @@ private DashboardType getDashboardType(Dashboard dashboard) { @Override public Component getComponent(ObjectId componentId){ - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); return component; } @Override @@ -651,7 +651,7 @@ public Dashboard updateDashboardWidgets(ObjectId dashboardId, Dashboard request) dashboard.setActiveWidgets(request.getActiveWidgets()); dashboard = update(dashboard); if(componentId!=null){ - com.capitalone.dashboard.model.Component component = componentRepository.findOne(componentId); + com.capitalone.dashboard.model.Component component = componentRepository.findById(componentId).get(); for (CollectorType cType :collectorTypesToDelete) { component.getCollectorItems().remove(cType); } diff --git a/src/main/java/com/capitalone/dashboard/service/DefaultAuthenticationServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/DefaultAuthenticationServiceImpl.java index ef543a73..53e61a5c 100644 --- a/src/main/java/com/capitalone/dashboard/service/DefaultAuthenticationServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/DefaultAuthenticationServiceImpl.java @@ -33,7 +33,7 @@ public Iterable all() { @Override public Authentication get(ObjectId id) { - Authentication authentication = authenticationRepository.findOne(id); + Authentication authentication = authenticationRepository.findById(id).get(); return authentication; } @@ -60,7 +60,7 @@ public String update(String username, String password) { @Override public void delete(ObjectId id) { - Authentication authentication = authenticationRepository.findOne(id); + Authentication authentication = authenticationRepository.findById(id).get(); if (authentication != null) { authenticationRepository.delete(authentication); } diff --git a/src/main/java/com/capitalone/dashboard/service/DeployServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/DeployServiceImpl.java index 9b09b2f2..9ee5cf34 100644 --- a/src/main/java/com/capitalone/dashboard/service/DeployServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/DeployServiceImpl.java @@ -91,7 +91,7 @@ public DeployServiceImpl(ComponentRepository componentRepository, @Override public DataResponse> getDeployStatus(ObjectId componentId) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); Collection cis = component.getCollectorItems() .get(CollectorType.Deployment); @@ -126,7 +126,7 @@ private DataResponse> getDeployStatus(Collection lastExecuted) { lastExecuted = collector.getLastExecuted(); @@ -255,7 +255,7 @@ public String createV3(DeployDataCreateRequest request) throws HygieiaException BuildDataCreateRequest buildRequest = buildRequestFromDeployRequest(request); BuildDataCreateResponse buildResponse = buildService.createV3(buildRequest); ObjectId buildId = buildResponse.getId(); - Build build = buildRepository.findOne(buildId); + Build build = buildRepository.findById(buildId).get(); HashMap metadata = new HashMap<>(); metadata.put("appName", request.getAppName()); metadata.put("appServiceName",request.getAppServiceName()); diff --git a/src/main/java/com/capitalone/dashboard/service/DynamicPipelineServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/DynamicPipelineServiceImpl.java index 0043ce84..bbdf224c 100644 --- a/src/main/java/com/capitalone/dashboard/service/DynamicPipelineServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/DynamicPipelineServiceImpl.java @@ -16,7 +16,8 @@ import com.capitalone.dashboard.misc.HygieiaException; import org.apache.commons.lang3.ObjectUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.bson.types.ObjectId; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -65,7 +66,7 @@ */ @Service("dynamic-pipeline") public class DynamicPipelineServiceImpl implements PipelineService { - private static final Logger logger = Logger.getLogger(DynamicPipelineServiceImpl.class); + private static final Logger logger = LogManager.getLogger(DynamicPipelineServiceImpl.class); private static final int PROD_COMMIT_DATE_RANGE_DEFAULT = -90; @@ -145,8 +146,8 @@ private PipelineResponse buildPipelineResponse(Pipeline pipeline, Long lowerBoun /** * get the collector item and dashboard */ - CollectorItem dashboardCollectorItem = collectorItemRepository.findOne(pipeline.getCollectorItemId()); - Dashboard dashboard = dashboardRepository.findOne(new ObjectId((String)dashboardCollectorItem.getOptions().get("dashboardId"))); + CollectorItem dashboardCollectorItem = collectorItemRepository.findById(pipeline.getCollectorItemId()).get(); + Dashboard dashboard = dashboardRepository.findById(new ObjectId((String)dashboardCollectorItem.getOptions().get("dashboardId"))).get(); PipelineResponse pipelineResponse = new PipelineResponse(); pipelineResponse.setCollectorItemId(dashboardCollectorItem.getId()); @@ -202,8 +203,8 @@ private PipelineResponse buildPipelineResponse(Pipeline pipeline, Long lowerBoun * @return the pipeline passed in */ protected Pipeline buildPipeline(Pipeline pipeline, Long lowerBound, Long upperBound) { - CollectorItem dashboardCollectorItem = collectorItemRepository.findOne(pipeline.getCollectorItemId()); - Dashboard dashboard = dashboardRepository.findOne(new ObjectId((String)dashboardCollectorItem.getOptions().get("dashboardId"))); + CollectorItem dashboardCollectorItem = collectorItemRepository.findById(pipeline.getCollectorItemId()).get(); + Dashboard dashboard = dashboardRepository.findById(new ObjectId((String)dashboardCollectorItem.getOptions().get("dashboardId"))).get(); // First gather information about our dashboard diff --git a/src/main/java/com/capitalone/dashboard/service/FeatureFlagServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/FeatureFlagServiceImpl.java index 60c226dc..f068f995 100644 --- a/src/main/java/com/capitalone/dashboard/service/FeatureFlagServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/FeatureFlagServiceImpl.java @@ -6,7 +6,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import org.apache.commons.collections4.IterableUtils; -import org.apache.log4j.Logger; import org.bson.types.ObjectId; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -46,7 +45,7 @@ public List getFeatureFlags(){ @Override public void deleteFlags(ObjectId id){ - featureFlagRepository.delete(id); + featureFlagRepository.deleteById(id); } } diff --git a/src/main/java/com/capitalone/dashboard/service/FeatureServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/FeatureServiceImpl.java index 9b34e432..9e4afe10 100644 --- a/src/main/java/com/capitalone/dashboard/service/FeatureServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/FeatureServiceImpl.java @@ -90,7 +90,7 @@ public FeatureServiceImpl(ComponentRepository componentRepository, */ @Override public DataResponse> getStory(ObjectId componentId, String storyNumber) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); if ((component == null) || CollectionUtils.isEmpty(component.getCollectorItems()) || CollectionUtils .isEmpty(component.getCollectorItems().get(CollectorType.AgileTool)) @@ -106,7 +106,7 @@ public DataResponse> getStory(ObjectId componentId, String storyNu // Get one story based on story number, based on component List story = featureRepository.getStoryByNumber(storyNumber); - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); return new DataResponse<>(story, collector.getLastExecuted()); } @@ -124,7 +124,7 @@ public DataResponse> getStory(ObjectId componentId, String storyNu @Override public DataResponse> getRelevantStories(ObjectId componentId, String teamId, String projectId, Optional agileType) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); if ((component == null) || CollectionUtils.isEmpty(component.getCollectorItems()) || CollectionUtils .isEmpty(component.getCollectorItems().get(CollectorType.AgileTool)) @@ -141,7 +141,7 @@ public DataResponse> getRelevantStories(ObjectId componentId, Stri // Get teamId first from available collector item, based on component List relevantStories = getFeaturesForCurrentSprints(teamId, projectId, item.getCollectorId(), agileType.isPresent()? agileType.get() : null, false); - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); return new DataResponse<>(relevantStories, collector.getLastExecuted()); } @@ -162,7 +162,7 @@ public DataResponse> getRelevantStories(ObjectId componentId, Stri @Override public DataResponse> getFeatureEpicEstimates(ObjectId componentId, String teamId, String projectId, Optional agileType, Optional estimateMetricType) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); if ((component == null) || CollectionUtils.isEmpty(component.getCollectorItems()) || CollectionUtils @@ -210,14 +210,14 @@ public DataResponse> getFeatureEpicEstimates(ObjectId componentId, } } - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); return new DataResponse<>(new ArrayList<>(epicIDToEpicFeatureMap.values()), collector.getLastExecuted()); } @Override public DataResponse getAggregatedSprintEstimates(ObjectId componentId, String teamId, String projectId, Optional agileType, Optional estimateMetricType) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); if ((component == null) || CollectionUtils.isEmpty(component.getCollectorItems()) || CollectionUtils .isEmpty(component.getCollectorItems().get(CollectorType.AgileTool)) @@ -226,7 +226,7 @@ public DataResponse getAggregatedSprintEstimates(ObjectId compon } CollectorItem item = component.getCollectorItems().get(CollectorType.AgileTool).get(0); - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); SprintEstimate estimate = getSprintEstimates(teamId, projectId, item.getCollectorId(), agileType, estimateMetricType); return new DataResponse<>(estimate, collector.getLastExecuted()); @@ -248,7 +248,7 @@ public DataResponse getAggregatedSprintEstimates(ObjectId compon @Deprecated public DataResponse> getTotalEstimate(ObjectId componentId, String teamId, Optional agileType, Optional estimateMetricType) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); if ((component == null) || CollectionUtils.isEmpty(component.getCollectorItems()) || CollectionUtils @@ -264,7 +264,7 @@ public DataResponse> getTotalEstimate(ObjectId componentId, String List list = Collections.singletonList(new Feature()); list.get(0).setsEstimate(Integer.toString(estimate.getTotalEstimate())); - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); return new DataResponse<>(list, collector.getLastExecuted()); } @@ -284,7 +284,7 @@ public DataResponse> getTotalEstimate(ObjectId componentId, String @Deprecated public DataResponse> getInProgressEstimate(ObjectId componentId, String teamId, Optional agileType, Optional estimateMetricType) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); if ((component == null) || CollectionUtils.isEmpty(component.getCollectorItems()) || CollectionUtils @@ -300,7 +300,7 @@ public DataResponse> getInProgressEstimate(ObjectId componentId, S List list = Collections.singletonList(new Feature()); list.get(0).setsEstimate(Integer.toString(estimate.getInProgressEstimate())); - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); return new DataResponse<>(list, collector.getLastExecuted()); } @@ -320,7 +320,7 @@ public DataResponse> getInProgressEstimate(ObjectId componentId, S @Deprecated public DataResponse> getDoneEstimate(ObjectId componentId, String teamId, Optional agileType, Optional estimateMetricType) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); if ((component == null) || CollectionUtils.isEmpty(component.getCollectorItems()) || CollectionUtils @@ -336,7 +336,7 @@ public DataResponse> getDoneEstimate(ObjectId componentId, String List list = Collections.singletonList(new Feature()); list.get(0).setsEstimate(Integer.toString(estimate.getCompleteEstimate())); - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); return new DataResponse<>(list, collector.getLastExecuted()); } @@ -354,7 +354,7 @@ public DataResponse> getDoneEstimate(ObjectId componentId, String @Override public DataResponse> getCurrentSprintDetail(ObjectId componentId, String teamId, String projectId, Optional agileType) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); if ((component == null) || CollectionUtils.isEmpty(component.getCollectorItems()) || CollectionUtils .isEmpty(component.getCollectorItems().get(CollectorType.AgileTool)) @@ -367,7 +367,7 @@ public DataResponse> getCurrentSprintDetail(ObjectId componentId, // Get teamId first from available collector item, based on component List sprintResponse = getFeaturesForCurrentSprints(teamId, projectId, item.getCollectorId(), agileType.isPresent()? agileType.get() : null, true); - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); return new DataResponse<>(sprintResponse, collector.getLastExecuted()); } diff --git a/src/main/java/com/capitalone/dashboard/service/GenericCollectorItemServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/GenericCollectorItemServiceImpl.java index 424fa01c..7a927f70 100644 --- a/src/main/java/com/capitalone/dashboard/service/GenericCollectorItemServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/GenericCollectorItemServiceImpl.java @@ -88,7 +88,7 @@ public String create(GenericCollectorItemCreateRequest request) throws HygieiaEx @Override public String createGenericBinaryArtifactData(GenericCollectorItemCreateRequest request){ ObjectId id = new ObjectId(request.getBuildId()); - Build currentBuild = buildRepository.findOne(id); + Build currentBuild = buildRepository.findById(id).get(); String artifactName = captureArtifactAttributes(apiSettings.getCapturePattern(),request.getRawData(),ARTIFACT_NAME); String artifactVersion = captureArtifactAttributes(apiSettings.getCapturePattern(),request.getRawData(),ARTIFACT_VERSION); String artifactGroupId = captureArtifactAttributes(apiSettings.getCapturePattern(),request.getRawData(),ARTIFACT_GROUP); diff --git a/src/main/java/com/capitalone/dashboard/service/GitRequestServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/GitRequestServiceImpl.java index 43ab2756..3f6ceefc 100644 --- a/src/main/java/com/capitalone/dashboard/service/GitRequestServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/GitRequestServiceImpl.java @@ -53,7 +53,7 @@ public DataResponse> search(GitRequestRequest request, BooleanBuilder builder = new BooleanBuilder(); CollectorItem item = null; - Component component = componentRepository.findOne(request.getComponentId()); + Component component = componentRepository.findById(request.getComponentId()).get(); if ( (component == null) || ((item = component.getLastUpdatedCollectorItemForType(CollectorType.SCM)) == null) ) { Iterable results = new ArrayList<>(); @@ -75,7 +75,7 @@ public DataResponse> search(GitRequestRequest request, (state.toLowerCase().equals("closed")) || (state.toLowerCase().equals("merged")))) { builder.and(gitRequest.state.eq(state)); } - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); if ((collector == null) || (collector.getId() == null)) { Iterable results = new ArrayList<>(); return new DataResponse<>(results, new Date().getTime()); diff --git a/src/main/java/com/capitalone/dashboard/service/LibraryPolicyServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/LibraryPolicyServiceImpl.java index 1ac9cf17..748cd059 100644 --- a/src/main/java/com/capitalone/dashboard/service/LibraryPolicyServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/LibraryPolicyServiceImpl.java @@ -73,7 +73,7 @@ public DataResponse> search(LibraryPolicyRequest reque itemResult = libraryPolicyResultsRepository.findAll(builder.getValue(), policyResult.timestamp.desc()); } else { PageRequest pageRequest = - new PageRequest(0, request.getMax(), Sort.Direction.DESC, "timestamp"); + PageRequest.of(0, request.getMax(), Sort.Direction.DESC, "timestamp"); itemResult = libraryPolicyResultsRepository.findAll(builder.getValue(), pageRequest).getContent(); } if (itemResult != null) { @@ -82,7 +82,7 @@ public DataResponse> search(LibraryPolicyRequest reque results.add(lpr); } } - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); long runTime = (collector == null) ? 0 : collector.getLastExecuted(); lastExecuted = (runTime < lastExecuted) ? runTime : lastExecuted; } @@ -91,7 +91,7 @@ public DataResponse> search(LibraryPolicyRequest reque protected List getCollectorItems(LibraryPolicyRequest request) { - Component component = componentRepository.findOne(request.getComponentId()); + Component component = componentRepository.findById(request.getComponentId()).get(); return (component != null) ? component.getCollectorItems(CollectorType.LibraryPolicy) : null; } } diff --git a/src/main/java/com/capitalone/dashboard/service/LogAnalysisServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/LogAnalysisServiceImpl.java index 22b7afc8..c3854fa1 100644 --- a/src/main/java/com/capitalone/dashboard/service/LogAnalysisServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/LogAnalysisServiceImpl.java @@ -38,7 +38,7 @@ public DataResponse> search(LogAnalysisSearchRequest reque if (null == request) { return emptyResponse(); } - Component component = componentRepository.findOne(request.getComponentId()); + Component component = componentRepository.findById(request.getComponentId()).get(); if (null == component) { return emptyResponse(); } @@ -54,11 +54,11 @@ public DataResponse> search(LogAnalysisSearchRequest reque if (null == request.getMax()) { result = this.repository.findAll(builder.getValue(), log.timestamp.desc()); } else { - PageRequest pageRequest = new PageRequest(0, request.getMax(), Sort.Direction.DESC, "timestamp"); + PageRequest pageRequest = PageRequest.of(0, request.getMax(), Sort.Direction.DESC, "timestamp"); result = this.repository.findAll(builder.getValue(), pageRequest); } - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); return new DataResponse<>(result,collector.getLastExecuted()); } diff --git a/src/main/java/com/capitalone/dashboard/service/Monitor2ServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/Monitor2ServiceImpl.java index 2afae5e2..3249d915 100644 --- a/src/main/java/com/capitalone/dashboard/service/Monitor2ServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/Monitor2ServiceImpl.java @@ -36,7 +36,7 @@ public List dashboardMonitor2es(ObjectId dashboardId) { @Override public Monitor2 get(ObjectId monitor2Id) { - return monitor2Repository.findOne(monitor2Id); + return monitor2Repository.findById(monitor2Id).get(); } @Override @@ -48,7 +48,7 @@ public Monitor2 create(ObjectId dashboardId, Monitor2DataCreateRequest monitor2D monitor2.setDashboardId(dashboardId); monitor2.setLastUpdated(System.currentTimeMillis()); - Dashboard dashboard = dashboardRepository.findOne(dashboardId); + Dashboard dashboard = dashboardRepository.findById(dashboardId).get(); monitor2.setApplicationName(dashboard.getApplication().getName()); return monitor2Repository.save(monitor2); diff --git a/src/main/java/com/capitalone/dashboard/service/PerformanceServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/PerformanceServiceImpl.java index bf2275dc..5bed4512 100644 --- a/src/main/java/com/capitalone/dashboard/service/PerformanceServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/PerformanceServiceImpl.java @@ -90,16 +90,16 @@ private DataResponse> searchType(PerformanceSearchRequest result = performanceRepository.findAll(builder.getValue(), performance.timestamp.desc()); } else { PageRequest pageRequest = - new PageRequest(0, request.getMax(), Sort.Direction.DESC, "timestamp"); + PageRequest.of(0, request.getMax(), Sort.Direction.DESC, "timestamp"); result = performanceRepository.findAll(builder.getValue(), pageRequest).getContent(); } - Collector collector = collectorRepository.findOne(item.getCollectorId()); + Collector collector = collectorRepository.findById(item.getCollectorId()).get(); long lastExecuted = (collector == null) ? 0 : collector.getLastExecuted(); return new DataResponse<>(result, lastExecuted); } protected CollectorItem getCollectorItem(PerformanceSearchRequest request) { - Component component = componentRepository.findOne(request.getComponentId()); + Component component = componentRepository.findById(request.getComponentId()).get(); if (component == null) { return null; } diff --git a/src/main/java/com/capitalone/dashboard/service/PipelineServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/PipelineServiceImpl.java index a9b6ec42..35856187 100644 --- a/src/main/java/com/capitalone/dashboard/service/PipelineServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/PipelineServiceImpl.java @@ -80,12 +80,12 @@ private PipelineResponse buildPipelineResponse(Pipeline pipeline, Long beginDate /** * get the collector item and dashboard */ - CollectorItem dashboardCollectorItem = collectorItemRepository.findOne(pipeline.getCollectorItemId()); + CollectorItem dashboardCollectorItem = collectorItemRepository.findById(pipeline.getCollectorItemId()).get(); if(dashboardCollectorItem.getOptions().get("dashboardId") == null) { throw new HygieiaException(" Collector Item: " + dashboardCollectorItem.getId() + " is not associated to a dashboard. ", HygieiaException.BAD_DATA); } String dashboardId = (String) dashboardCollectorItem.getOptions().get("dashboardId"); - Dashboard dashboard = dashboardRepository.findOne(new ObjectId(dashboardId)); + Dashboard dashboard = dashboardRepository.findById(new ObjectId(dashboardId)).get(); if(dashboard == null) { throw new HygieiaException(" Dashboard " + dashboardId + " is not found for collectorItem: " + dashboardCollectorItem.getId() + " ", HygieiaException.BAD_DATA); } diff --git a/src/main/java/com/capitalone/dashboard/service/RallyFeatureServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/RallyFeatureServiceImpl.java index 6ce65846..d4740b2b 100644 --- a/src/main/java/com/capitalone/dashboard/service/RallyFeatureServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/RallyFeatureServiceImpl.java @@ -65,7 +65,7 @@ public List rallyWidgetDataDetails(CollectorItem collectorItem) { public CollectorItem getCollectorItem(RallyFeatureRequest request) { - Component component = componentRepository.findOne(request.getComponentId()); + Component component = componentRepository.findById(request.getComponentId()).get(); if (component == null) { return null; } diff --git a/src/main/java/com/capitalone/dashboard/service/ScopeServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/ScopeServiceImpl.java index 26ea63ef..ff559db9 100644 --- a/src/main/java/com/capitalone/dashboard/service/ScopeServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/ScopeServiceImpl.java @@ -53,7 +53,7 @@ public List getAllScopes() { for (Scope scope : scopes) { Collector collector = collectorRepository - .findOne(scope.getCollectorId()); + .findById(scope.getCollectorId()).get(); scope.setCollector(collector); } @@ -75,7 +75,7 @@ public List getAllScopes() { @Override public DataResponse> getScope(ObjectId componentId, String scopeId) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); CollectorItem item = component.getCollectorItems() .get(CollectorType.AgileTool).get(0); QScopeOwner team = new QScopeOwner("team"); @@ -87,7 +87,7 @@ public DataResponse> getScope(ObjectId componentId, List scope = scopeRepository.getScopeById(scopeId); Collector collector = collectorRepository - .findOne(item.getCollectorId()); + .findById(item.getCollectorId()).get(); return new DataResponse<>(scope, collector.getLastExecuted()); } diff --git a/src/main/java/com/capitalone/dashboard/service/ScoreDashboardServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/ScoreDashboardServiceImpl.java index ab76278a..1abccf70 100644 --- a/src/main/java/com/capitalone/dashboard/service/ScoreDashboardServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/ScoreDashboardServiceImpl.java @@ -8,7 +8,8 @@ import com.capitalone.dashboard.repository.CollectorItemRepository; import com.capitalone.dashboard.repository.ScoreCollectorItemRepository; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.bson.types.ObjectId; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -18,7 +19,7 @@ @Service public class ScoreDashboardServiceImpl implements ScoreDashboardService { - private static final Logger LOGGER = Logger.getLogger(ScoreDashboardServiceImpl.class); + private static final Logger LOGGER = LogManager.getLogger(ScoreDashboardServiceImpl.class); private final CollectorService collectorService; private final ScoreCollectorItemRepository scoreCollectorItemRepository; diff --git a/src/main/java/com/capitalone/dashboard/service/ServiceAccountServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/ServiceAccountServiceImpl.java index f1cbbc4a..56cc864c 100644 --- a/src/main/java/com/capitalone/dashboard/service/ServiceAccountServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/ServiceAccountServiceImpl.java @@ -3,7 +3,8 @@ import com.capitalone.dashboard.model.ServiceAccount; import com.capitalone.dashboard.repository.ServiceAccountRepository; import com.google.common.collect.Sets; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.bson.types.ObjectId; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -13,7 +14,7 @@ @Component public class ServiceAccountServiceImpl implements ServiceAccountService { - private static final Logger LOGGER = Logger.getLogger(ServiceAccountServiceImpl.class); + private static final Logger LOGGER = LogManager.getLogger(ServiceAccountServiceImpl.class); private ServiceAccountRepository serviceAccountRepository; @@ -40,7 +41,7 @@ public Collection getAllServiceAccounts() { @Override public String updateAccount(String serviceAccount, String fileNames, ObjectId id){ - ServiceAccount sa = serviceAccountRepository.findOne(id); + ServiceAccount sa = serviceAccountRepository.findById(id).get(); sa.setServiceAccountName(serviceAccount); sa.setFileNames(fileNames); serviceAccountRepository.save(sa); @@ -49,7 +50,7 @@ public String updateAccount(String serviceAccount, String fileNames, ObjectId id @Override public void deleteAccount(ObjectId id ){ - serviceAccountRepository.delete(id); + serviceAccountRepository.deleteById(id); } diff --git a/src/main/java/com/capitalone/dashboard/service/ServiceServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/ServiceServiceImpl.java index a53fe526..a9cbae2b 100644 --- a/src/main/java/com/capitalone/dashboard/service/ServiceServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/ServiceServiceImpl.java @@ -52,7 +52,7 @@ public List dashboardDependentServices(ObjectId dashboardId) { @Override public Service get(ObjectId id) { - return serviceRepository.findOne(id); + return serviceRepository.findById(id).get(); } @Override @@ -63,7 +63,7 @@ public Service create(ObjectId dashboardId, String name, String url) { service.setDashboardId(dashboardId); service.setStatus(ServiceStatus.Warning); service.setLastUpdated(System.currentTimeMillis()); - Dashboard dashboard = dashboardRepository.findOne(dashboardId); + Dashboard dashboard = dashboardRepository.findById(dashboardId).get(); service.setApplicationName(dashboard.getApplication().getName()); return serviceRepository.save(service); } @@ -112,7 +112,7 @@ public void refreshService(ObjectId dashboardId, ObjectId serviceId) { service.setDashboardId(dashboardId); service.setStatus(getServiceStatus(service.getUrl(), dashboardId)); service.setLastUpdated(System.currentTimeMillis()); - Dashboard dashboard = dashboardRepository.findOne(dashboardId); + Dashboard dashboard = dashboardRepository.findById(dashboardId).get(); service.setApplicationName(dashboard.getApplication().getName()); serviceRepository.save(service); } diff --git a/src/main/java/com/capitalone/dashboard/service/TeamInventoryServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/TeamInventoryServiceImpl.java index 21769319..42ab68a1 100644 --- a/src/main/java/com/capitalone/dashboard/service/TeamInventoryServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/TeamInventoryServiceImpl.java @@ -25,7 +25,7 @@ public TeamInventoryServiceImpl(TeamInventoryRepository teamInventoryRepository, @Override public DataResponse getTeamData(String teamName, String teamId) { TeamInventory teamInventory = teamInventoryRepository.findByNameAndTeamId(teamName,teamId); - Collector collector = collectorRepository.findOne(teamInventory.getCollectorId()); + Collector collector = collectorRepository.findById(teamInventory.getCollectorId()).get(); return new DataResponse<>(teamInventory, collector.getLastExecuted()); } } diff --git a/src/main/java/com/capitalone/dashboard/service/TeamServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/TeamServiceImpl.java index 2c401e8d..e145911b 100644 --- a/src/main/java/com/capitalone/dashboard/service/TeamServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/TeamServiceImpl.java @@ -56,7 +56,7 @@ public Iterable getAllTeams() { for (Team team : teams) { Collector collector = collectorRepository - .findOne(team.getCollectorId()); + .findById(team.getCollectorId()).get(); team.setCollector(collector); } @@ -78,7 +78,7 @@ public Iterable getAllTeams() { @Override public DataResponse getTeam(ObjectId componentId, String teamId) { - Component component = componentRepository.findOne(componentId); + Component component = componentRepository.findById(componentId).get(); CollectorItem item = component.getCollectorItems() .get(CollectorType.AgileTool).get(0); @@ -86,7 +86,7 @@ public DataResponse getTeam(ObjectId componentId, Team team = teamRepository.findByTeamId(teamId); Collector collector = collectorRepository - .findOne(item.getCollectorId()); + .findById(item.getCollectorId()).get(); return new DataResponse<>(team, collector.getLastExecuted()); } diff --git a/src/main/java/com/capitalone/dashboard/service/TemplateServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/TemplateServiceImpl.java index 90dd898a..4ff1780a 100644 --- a/src/main/java/com/capitalone/dashboard/service/TemplateServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/TemplateServiceImpl.java @@ -40,13 +40,13 @@ public Template update(Template template) throws HygieiaException { @Override public void delete(ObjectId id) { - templateRepository.delete(id); + templateRepository.deleteById(id); } @Override public Template get(ObjectId id) { - Template template = templateRepository.findOne(id); + Template template = templateRepository.findById(id).get(); return template; } diff --git a/src/main/java/com/capitalone/dashboard/service/TestResultServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/TestResultServiceImpl.java index 9249b61a..0f52b6d7 100644 --- a/src/main/java/com/capitalone/dashboard/service/TestResultServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/TestResultServiceImpl.java @@ -20,7 +20,8 @@ import hygieia.transformer.JunitXmlToTestCapabilityTransformer; import hygieia.transformer.JunitXmlToTestCapabilityTransformerV2; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.bson.types.ObjectId; import org.joda.time.format.DateTimeFormat; import org.springframework.beans.factory.annotation.Autowired; @@ -52,7 +53,7 @@ public class TestResultServiceImpl implements TestResultService { private final CmdbService cmdbService; private final ApiSettings apiSettings; - private static final Logger LOGGER = Logger.getLogger(ApiTokenServiceImpl.class); + private static final Logger LOGGER = LogManager.getLogger(ApiTokenServiceImpl.class); @Autowired public TestResultServiceImpl(TestResultRepository testResultRepository, @@ -71,7 +72,7 @@ public TestResultServiceImpl(TestResultRepository testResultRepository, @Override public DataResponse> search(com.capitalone.dashboard.request.TestResultRequest request) { - Component component = componentRepository.findOne(request.getComponentId()); + Component component = componentRepository.findById(request.getComponentId()).get(); if ((component == null) || !component.getCollectorItems().containsKey(CollectorType.Test)) { return new DataResponse<>(null, 0L); @@ -80,7 +81,7 @@ public DataResponse> search(com.capitalone.dashboard.reques validateAllCollectorItems(request, component, result); //One collector per Type. get(0) is hardcoded. if (!CollectionUtils.isEmpty(component.getCollectorItems().get(CollectorType.Test)) && (component.getCollectorItems().get(CollectorType.Test).get(0) != null)) { - Collector collector = collectorRepository.findOne(component.getCollectorItems().get(CollectorType.Test).get(0).getCollectorId()); + Collector collector = collectorRepository.findById(component.getCollectorItems().get(CollectorType.Test).get(0).getCollectorId()).get(); if (collector != null) { return new DataResponse<>(pruneToDepth(result, request.getDepth()), collector.getLastExecuted()); } @@ -109,7 +110,7 @@ private void addAllTestResultRepositories(com.capitalone.dashboard.request.TestR if (request.getMax() == null) { result.addAll(Lists.newArrayList(testResultRepository.findAll(builder.getValue(), testResult.timestamp.desc()))); } else { - PageRequest pageRequest = new PageRequest(0, request.getMax(), Sort.Direction.DESC, "timestamp"); + PageRequest pageRequest = PageRequest.of(0, request.getMax(), Sort.Direction.DESC, "timestamp"); result.addAll(Lists.newArrayList(testResultRepository.findAll(builder.getValue(), pageRequest).getContent())); } } @@ -669,8 +670,9 @@ private String getConfigurationItem(String configurationItem, String targetAppNa return configurationItem; } else if (StringUtils.isNotBlank(targetAppName) ){ + List cmdb = cmdbService.configurationItemsByTypeWithFilter("", targetAppName, - new PageRequest(0, 1)).getContent(); + PageRequest.of(0, 1)).getContent(); if(cmdb.size() > 0){ return cmdb.get(0).getConfigurationItem(); } diff --git a/src/main/java/com/capitalone/dashboard/service/UserInfoServiceImpl.java b/src/main/java/com/capitalone/dashboard/service/UserInfoServiceImpl.java index b897da3b..b4357a13 100644 --- a/src/main/java/com/capitalone/dashboard/service/UserInfoServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/service/UserInfoServiceImpl.java @@ -6,7 +6,8 @@ import com.capitalone.dashboard.auth.AuthProperties; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -32,7 +33,7 @@ @Component public class UserInfoServiceImpl implements UserInfoService { - private static final Logger LOGGER = Logger.getLogger(UserInfoServiceImpl.class); + private static final Logger LOGGER = LogManager.getLogger(UserInfoServiceImpl.class); private UserInfoRepository userInfoRepository; @Autowired diff --git a/src/main/java/com/capitalone/dashboard/webhook/datasync/ArtifactDataSyncDelegate.java b/src/main/java/com/capitalone/dashboard/webhook/datasync/ArtifactDataSyncDelegate.java index 6186bd3e..647fc220 100644 --- a/src/main/java/com/capitalone/dashboard/webhook/datasync/ArtifactDataSyncDelegate.java +++ b/src/main/java/com/capitalone/dashboard/webhook/datasync/ArtifactDataSyncDelegate.java @@ -53,7 +53,7 @@ public DataSyncResponse clean(Collector collector) { bs.sort(Comparator.comparing(BinaryArtifact::getTimestamp).reversed()); BinaryArtifact binaryArtifact = bs.stream().filter(Objects::nonNull).findFirst().orElse(null); if (Objects.nonNull(binaryArtifact)) { - CollectorItem collectorItem = dataSyncServiceImpl.getCollectorItemRepository().findOne(binaryArtifact.getCollectorItemId()); + CollectorItem collectorItem = dataSyncServiceImpl.getCollectorItemRepository().findById(binaryArtifact.getCollectorItemId()).get(); List suspectCollectorItems = dataSyncUtils.deleteCollectorItems(collectorItems, collectorItem, suspects); collectorItemsCount += suspectCollectorItems.size(); if (CollectionUtils.isEmpty(components)) continue; diff --git a/src/main/java/com/capitalone/dashboard/webhook/datasync/DataSyncUtils.java b/src/main/java/com/capitalone/dashboard/webhook/datasync/DataSyncUtils.java index 2f95614e..ee5a49cd 100644 --- a/src/main/java/com/capitalone/dashboard/webhook/datasync/DataSyncUtils.java +++ b/src/main/java/com/capitalone/dashboard/webhook/datasync/DataSyncUtils.java @@ -38,7 +38,7 @@ public DataSyncUtils(DataSyncServiceImpl dataSyncServiceImpl) { } public int pages(Collector collector) { - Page collectorItemsPage = dataSyncServiceImpl.getCollectorItemRepository().findByCollectorIdIn(Collections.singleton(collector.getId()), new PageRequest(MAX_PAGE_SIZE, MAX_PAGE_SIZE)); + Page collectorItemsPage = dataSyncServiceImpl.getCollectorItemRepository().findByCollectorIdIn(Collections.singleton(collector.getId()), PageRequest.of(MAX_PAGE_SIZE, MAX_PAGE_SIZE)); if (Objects.isNull(collectorItemsPage)) return ZERO; return collectorItemsPage.getTotalPages(); } @@ -47,7 +47,7 @@ public List getAllCollectorItems(Collector collector, int total) LOG.info("starting - collecting collector items"); List collectorItems = new ArrayList<>(); IntStream.range(ZERO, total).forEach(idx -> { - Page collectorItemsPage = dataSyncServiceImpl.getCollectorItemRepository().findByCollectorIdIn(Collections.singleton(collector.getId()), new PageRequest(idx, MAX_PAGE_SIZE)); + Page collectorItemsPage = dataSyncServiceImpl.getCollectorItemRepository().findByCollectorIdIn(Collections.singleton(collector.getId()), PageRequest.of(idx, MAX_PAGE_SIZE)); collectorItems.addAll(collectorItemsPage.getContent()); LOG.info("completed " + idx + " run"); }); @@ -89,7 +89,7 @@ public int clearDuplicateCollectorItemsAndUpdateComponents(List c suspectsList.removeIf(sci -> sci.getId().equals(first.getId())); suspectsList.forEach(sci -> { collectorItems.removeIf(cItem -> cItem.getId().equals(sci.getId())); - dataSyncServiceImpl.getCollectorItemRepository().delete(sci.getId()); + dataSyncServiceImpl.getCollectorItemRepository().deleteById(sci.getId()); }); if (CollectionUtils.isEmpty(components)) return componentCount; int componentsUpdated = updateComponents(collector, components, first, collectorType); @@ -118,7 +118,7 @@ public List deleteCollectorItems(List collectorIte suspectCollectorItems.removeIf(cItem -> cItem.getId().equals(collectorItem.getId())); suspectCollectorItems.forEach(colItem -> { collectorItems.removeIf(cItem -> cItem.getId().equals(colItem.getId())); - dataSyncServiceImpl.getCollectorItemRepository().delete(colItem.getId()); + dataSyncServiceImpl.getCollectorItemRepository().deleteById(colItem.getId()); }); return suspectCollectorItems; } diff --git a/src/main/java/com/capitalone/dashboard/webhook/datasync/GithubDataSyncDelegate.java b/src/main/java/com/capitalone/dashboard/webhook/datasync/GithubDataSyncDelegate.java index 8171967a..45b538be 100644 --- a/src/main/java/com/capitalone/dashboard/webhook/datasync/GithubDataSyncDelegate.java +++ b/src/main/java/com/capitalone/dashboard/webhook/datasync/GithubDataSyncDelegate.java @@ -55,7 +55,7 @@ public DataSyncResponse clean(Collector collector) { gs.sort(Comparator.comparing(GitRequest::getTimestamp).reversed()); GitRequest pullRequest = gs.stream().filter(Objects::nonNull).findFirst().orElse(null); if (Objects.nonNull(pullRequest)) { - CollectorItem collectorItem = dataSyncServiceImpl.getCollectorItemRepository().findOne(pullRequest.getCollectorItemId()); + CollectorItem collectorItem = dataSyncServiceImpl.getCollectorItemRepository().findById(pullRequest.getCollectorItemId()).get(); List suspectCollectorItems = dataSyncUtils.deleteCollectorItems(collectorItems, collectorItem, suspects); collectorItemsCount += suspectCollectorItems.size(); if (CollectionUtils.isEmpty(components)) continue; diff --git a/src/main/java/com/capitalone/dashboard/webhook/datasync/LibraryPolicyDataSyncDelegate.java b/src/main/java/com/capitalone/dashboard/webhook/datasync/LibraryPolicyDataSyncDelegate.java index f7f85b4d..42dfd4e3 100644 --- a/src/main/java/com/capitalone/dashboard/webhook/datasync/LibraryPolicyDataSyncDelegate.java +++ b/src/main/java/com/capitalone/dashboard/webhook/datasync/LibraryPolicyDataSyncDelegate.java @@ -56,7 +56,7 @@ public DataSyncResponse clean(Collector collector) { lp.sort(Comparator.comparing(LibraryPolicyResult::getTimestamp).reversed()); LibraryPolicyResult libraryPolicyResult = lp.stream().filter(Objects::nonNull).findFirst().orElse(null); if (Objects.nonNull(libraryPolicyResult)) { - CollectorItem collectorItem = dataSyncServiceImpl.getCollectorItemRepository().findOne(libraryPolicyResult.getCollectorItemId()); + CollectorItem collectorItem = dataSyncServiceImpl.getCollectorItemRepository().findById(libraryPolicyResult.getCollectorItemId()).get(); List suspectCollectorItems = dataSyncUtils.deleteCollectorItems(collectorItems,collectorItem,suspects); collectorItemsCount += suspectCollectorItems.size(); if (CollectionUtils.isEmpty(components)) continue; diff --git a/src/main/java/com/capitalone/dashboard/webhook/datasync/SonarDataSyncDelegate.java b/src/main/java/com/capitalone/dashboard/webhook/datasync/SonarDataSyncDelegate.java index 09c0c01b..a60f6f6e 100644 --- a/src/main/java/com/capitalone/dashboard/webhook/datasync/SonarDataSyncDelegate.java +++ b/src/main/java/com/capitalone/dashboard/webhook/datasync/SonarDataSyncDelegate.java @@ -53,7 +53,7 @@ public DataSyncResponse clean(Collector collector) { cq.sort(Comparator.comparing(CodeQuality::getTimestamp).reversed()); CodeQuality codeQuality = cq.stream().filter(Objects::nonNull).findFirst().orElse(null); if (Objects.nonNull(codeQuality)) { - CollectorItem collectorItem = dataSyncServiceImpl.getCollectorItemRepository().findOne(codeQuality.getCollectorItemId()); + CollectorItem collectorItem = dataSyncServiceImpl.getCollectorItemRepository().findById(codeQuality.getCollectorItemId()).get(); List suspectCollectorItems = dataSyncUtils.deleteCollectorItems(collectorItems, collectorItem, suspects); collectorItemsCount += suspectCollectorItems.size(); if (CollectionUtils.isEmpty(components)) continue; diff --git a/src/main/java/com/capitalone/dashboard/webhook/datasync/StaticSecurityDataSyncDelegate.java b/src/main/java/com/capitalone/dashboard/webhook/datasync/StaticSecurityDataSyncDelegate.java index 1120f889..8780d4b3 100644 --- a/src/main/java/com/capitalone/dashboard/webhook/datasync/StaticSecurityDataSyncDelegate.java +++ b/src/main/java/com/capitalone/dashboard/webhook/datasync/StaticSecurityDataSyncDelegate.java @@ -53,7 +53,7 @@ public DataSyncResponse clean(Collector collector) { cq.sort(Comparator.comparing(CodeQuality::getTimestamp).reversed()); CodeQuality staticSecurity = cq.stream().filter(Objects::nonNull).findFirst().orElse(null); if (Objects.nonNull(staticSecurity)) { - CollectorItem collectorItem = dataSyncServiceImpl.getCollectorItemRepository().findOne(staticSecurity.getCollectorItemId()); + CollectorItem collectorItem = dataSyncServiceImpl.getCollectorItemRepository().findById(staticSecurity.getCollectorItemId()).get(); List suspectCollectorItems = dataSyncUtils.deleteCollectorItems(collectorItems, collectorItem, suspects); collectorItemsCount += suspectCollectorItems.size(); if (CollectionUtils.isEmpty(components)) continue; diff --git a/src/main/java/com/capitalone/dashboard/webhook/datasync/TestDataSyncDelegate.java b/src/main/java/com/capitalone/dashboard/webhook/datasync/TestDataSyncDelegate.java index f47b89e0..3878b970 100644 --- a/src/main/java/com/capitalone/dashboard/webhook/datasync/TestDataSyncDelegate.java +++ b/src/main/java/com/capitalone/dashboard/webhook/datasync/TestDataSyncDelegate.java @@ -39,7 +39,7 @@ public DataSyncResponse clean(Collector collector) { TestResult testResult = dataSyncServiceImpl.getTestResultRepository().findTop1ByCollectorItemIdOrderByTimestampDesc(c.getId()); LOG.info("collectorItem run +++" + count + " of " + collectorItems.size()); if (Objects.nonNull(testResult)) { - CollectorItem collectorItem = dataSyncServiceImpl.getCollectorItemRepository().findOne(testResult.getCollectorItemId()); + CollectorItem collectorItem = dataSyncServiceImpl.getCollectorItemRepository().findById(testResult.getCollectorItemId()).get(); collectorItem.getOptions().put(TEST_TYPE, testResult.getType()); dataSyncServiceImpl.getCollectorItemRepository().save(collectorItem); collectorItemsCount++; diff --git a/src/main/java/com/capitalone/dashboard/webhook/github/GitHubCommitV3.java b/src/main/java/com/capitalone/dashboard/webhook/github/GitHubCommitV3.java index bb32e667..07a18c67 100644 --- a/src/main/java/com/capitalone/dashboard/webhook/github/GitHubCommitV3.java +++ b/src/main/java/com/capitalone/dashboard/webhook/github/GitHubCommitV3.java @@ -111,7 +111,7 @@ public String process(JSONObject jsonObject) throws MalformedURLException, Hygie List commitList = getCommits(commitsObjectList, repoUrl, branch, gitHubWebHookToken, senderObj); updateCollectorItemLastUpdated(repoUrl, branch); - commitRepository.save(commitList); + commitRepository.saveAll(commitList); return result; } diff --git a/src/main/java/com/capitalone/dashboard/webhook/github/GitHubSyncServiceImpl.java b/src/main/java/com/capitalone/dashboard/webhook/github/GitHubSyncServiceImpl.java index 13dc03f7..16115a8b 100644 --- a/src/main/java/com/capitalone/dashboard/webhook/github/GitHubSyncServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/webhook/github/GitHubSyncServiceImpl.java @@ -593,7 +593,7 @@ private int processCommits(GitHubRepo repo) { if (existingCount == 0) { List newCommits = getCommits(); newCommits.forEach(c -> c.setCollectorItemId(repo.getId())); - Iterable saved = commitRepository.save(newCommits); + Iterable saved = commitRepository.saveAll(newCommits); count = saved != null ? Lists.newArrayList(saved).size() : 0; } else { Collection nonDupCommits = getCommits().stream() @@ -666,7 +666,7 @@ private void processOrphanCommits(GitHubRepo repo) { List orphanSaveList = orphanCommits.stream().filter(c -> !StringUtils.isEmpty(c.getPullNumber())).collect(Collectors.toList()); orphanSaveList.forEach(c -> LOG.info("Updating orphan " + c.getScmRevisionNumber() + " " + new DateTime(c.getScmCommitTimestamp()).toString("yyyy-MM-dd hh:mm:ss.SSa") + " with pull " + c.getPullNumber())); - commitRepository.save(orphanSaveList); + commitRepository.saveAll(orphanSaveList); } diff --git a/src/main/java/com/capitalone/dashboard/webhook/sonarqube/SonarQubeHookServiceImpl.java b/src/main/java/com/capitalone/dashboard/webhook/sonarqube/SonarQubeHookServiceImpl.java index 9c9a6b5c..d7899ad9 100644 --- a/src/main/java/com/capitalone/dashboard/webhook/sonarqube/SonarQubeHookServiceImpl.java +++ b/src/main/java/com/capitalone/dashboard/webhook/sonarqube/SonarQubeHookServiceImpl.java @@ -1,5 +1,29 @@ package com.capitalone.dashboard.webhook.sonarqube; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.annotation.Nullable; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestClientException; + import com.capitalone.dashboard.client.RestClient; import com.capitalone.dashboard.client.RestUserInfo; import com.capitalone.dashboard.misc.HygieiaException; @@ -20,28 +44,6 @@ import com.google.common.base.Strings; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; -import org.springframework.web.client.RestClientException; - -import javax.annotation.Nullable; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicInteger; @Service public class SonarQubeHookServiceImpl implements SonarQubeHookService { @@ -343,7 +345,7 @@ public ResponseEntity syncData(SonarDataSyncRequest request) throws Hygi String math = updatedProjects.size() + "/" + projects.size(); String message = math + " sonar collector items and " + compIndex + " dashboard components can be updated"; if (isSync) { - sonarProjectRepository.save(updatedProjects); + sonarProjectRepository.saveAll(updatedProjects); message = math + " sonar collector items and " + compIndex + " dashboard components updated"; } LOG.info(message); diff --git a/src/test/java/com/capitalone/dashboard/auth/DefaultSecurityTest.java b/src/test/java/com/capitalone/dashboard/auth/DefaultSecurityTest.java index 682bf206..40058ac5 100644 --- a/src/test/java/com/capitalone/dashboard/auth/DefaultSecurityTest.java +++ b/src/test/java/com/capitalone/dashboard/auth/DefaultSecurityTest.java @@ -1,6 +1,6 @@ package com.capitalone.dashboard.auth; import static com.capitalone.dashboard.fixture.DashboardFixture.makeDashboard; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; @@ -9,14 +9,13 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - import com.capitalone.dashboard.model.*; - import org.bson.types.ObjectId; +import org.bson.types.ObjectId; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; - import org.springframework.boot.test.context.SpringBootTest; - import org.springframework.http.MediaType; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; import org.springframework.test.annotation.Rollback; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -31,7 +30,13 @@ import com.capitalone.dashboard.config.TestDefaultAuthConfig; import com.capitalone.dashboard.config.WebMVCConfig; import com.capitalone.dashboard.config.WebSecurityConfig; - import com.capitalone.dashboard.repository.AuthenticationRepository; +import com.capitalone.dashboard.model.AuthType; +import com.capitalone.dashboard.model.Authentication; +import com.capitalone.dashboard.model.Dashboard; +import com.capitalone.dashboard.model.DashboardType; +import com.capitalone.dashboard.model.UserInfo; +import com.capitalone.dashboard.model.UserRole; +import com.capitalone.dashboard.repository.AuthenticationRepository; import com.capitalone.dashboard.repository.DashboardRepository; import com.capitalone.dashboard.repository.UserInfoRepository; import com.capitalone.dashboard.service.DashboardService; @@ -100,7 +105,7 @@ public void owner_deleteDashboard() throws Exception{ Dashboard dashboard = makeDashboard("t1", "title", "app", "comp","someUser", DashboardType.Team, "ASVTEST", "BAPTEST"); String stringObjectId = "54b982620364c80a6136c9f2"; ObjectId objectId = new ObjectId(stringObjectId); - when(dashboardTestRepository.findOne(objectId)).thenReturn(dashboard); + when(dashboardTestRepository.findById(objectId).get()).thenReturn(dashboard); doNothing().when(dashboardTestService).delete(isA(ObjectId.class)); mockMvc.perform(delete("/dashboard/"+ stringObjectId) diff --git a/src/test/java/com/capitalone/dashboard/auth/access/MethodLevelSecurityHandlerTest.java b/src/test/java/com/capitalone/dashboard/auth/access/MethodLevelSecurityHandlerTest.java index 65208691..c34f2dc4 100644 --- a/src/test/java/com/capitalone/dashboard/auth/access/MethodLevelSecurityHandlerTest.java +++ b/src/test/java/com/capitalone/dashboard/auth/access/MethodLevelSecurityHandlerTest.java @@ -43,7 +43,7 @@ public void setup() { @Test public void testIsOwnerOfDashboard_noDashFound() { - when(dashboardRepository.findOne(any(ObjectId.class))).thenReturn(null); + when(dashboardRepository.findById(any(ObjectId.class).get())).thenReturn(null); assertFalse(handler.isOwnerOfDashboard(new ObjectId())); } @@ -54,7 +54,7 @@ public void testIsOwnerOfDashboard_legacyDashFound() { List activeWidgets = new ArrayList<>(); Dashboard dashboard = new Dashboard("team", "title", null, null, DashboardType.Team, configItemAppName,configItemComponentName,activeWidgets, false, ScoreDisplayType.HEADER); dashboard.setOwner(USERNAME); - when(dashboardRepository.findOne(any(ObjectId.class))).thenReturn(dashboard); + when(dashboardRepository.findById(any(ObjectId.class)).get()).thenReturn(dashboard); assertTrue(handler.isOwnerOfDashboard(new ObjectId())); } @@ -66,7 +66,7 @@ public void testIsOwnerOfDashboard_newDashFound() { List owners = new ArrayList<>(); owners.add(new Owner(USERNAME, AuthType.STANDARD)); Dashboard dashboard = new Dashboard("team", "title", null, owners, DashboardType.Team, configItemAppName,configItemComponentName,activeWidgets, false, ScoreDisplayType.HEADER); - when(dashboardRepository.findOne(any(ObjectId.class))).thenReturn(dashboard); + when(dashboardRepository.findById(any(ObjectId.class)).get()).thenReturn(dashboard); assertTrue(handler.isOwnerOfDashboard(new ObjectId())); } @@ -77,7 +77,7 @@ public void testIsNotOwnerOfDashboard() { List activeWidgets = new ArrayList<>(); Dashboard dashboard = new Dashboard("team", "title", null, null, DashboardType.Team,configItemAppName,configItemComponentName,activeWidgets, false, ScoreDisplayType.HEADER); dashboard.setOwner(SOME_OTHER_USER); - when(dashboardRepository.findOne(any(ObjectId.class))).thenReturn(dashboard); + when(dashboardRepository.findById(any(ObjectId.class)).get()).thenReturn(dashboard); assertFalse(handler.isOwnerOfDashboard(new ObjectId())); } diff --git a/src/test/java/com/capitalone/dashboard/config/FongoConfig.java b/src/test/java/com/capitalone/dashboard/config/FongoConfig.java index 2a9a526f..76e21a62 100644 --- a/src/test/java/com/capitalone/dashboard/config/FongoConfig.java +++ b/src/test/java/com/capitalone/dashboard/config/FongoConfig.java @@ -1,19 +1,22 @@ package com.capitalone.dashboard.config; -import com.github.fakemongo.Fongo; -import com.mongodb.MongoClient; import org.springframework.context.annotation.Bean; +import com.capitalone.dashboard.config.MongoConfig; +//import com.github.fakemongo.Fongo; +import com.mongodb.client.MongoClient; + public class FongoConfig extends MongoConfig { @Override @Bean - public MongoClient mongo() { - return new Fongo(getDatabaseName()).getMongo(); + public MongoClient mongoClient() { + return super.mongoClient(); + // return new Fongo(getDatabaseName()).getMongo(); } @Override protected String getDatabaseName() { return "test-db"; } -} +} \ No newline at end of file diff --git a/src/test/java/com/capitalone/dashboard/logging/LoggingFilterTest.java b/src/test/java/com/capitalone/dashboard/logging/LoggingFilterTest.java index 7b631f4f..bd87d067 100644 --- a/src/test/java/com/capitalone/dashboard/logging/LoggingFilterTest.java +++ b/src/test/java/com/capitalone/dashboard/logging/LoggingFilterTest.java @@ -11,7 +11,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; diff --git a/src/test/java/com/capitalone/dashboard/service/AutoDiscoveryRemoteServiceTest.java b/src/test/java/com/capitalone/dashboard/service/AutoDiscoveryRemoteServiceTest.java index 50ea5bb5..0969918d 100644 --- a/src/test/java/com/capitalone/dashboard/service/AutoDiscoveryRemoteServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/AutoDiscoveryRemoteServiceTest.java @@ -183,7 +183,7 @@ public static void loadCollector (CollectorRepository collectorRepository) throw Gson gson = GsonUtil.getGson(); String json = IOUtils.toString(Resources.getResource("./collectors/coll.json")); List collector = gson.fromJson(json, new TypeToken>(){}.getType()); - collectorRepository.save(collector); + collectorRepository.saveAll(collector); } } diff --git a/src/test/java/com/capitalone/dashboard/service/BuildServiceTest.java b/src/test/java/com/capitalone/dashboard/service/BuildServiceTest.java index dcce522f..12d239fc 100644 --- a/src/test/java/com/capitalone/dashboard/service/BuildServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/BuildServiceTest.java @@ -1,5 +1,32 @@ package com.capitalone.dashboard.service; +import static org.junit.Assert.assertEquals; +import org.mockito.ArgumentMatcher; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import org.bson.types.ObjectId; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; +import org.joda.time.LocalDate; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + import com.capitalone.dashboard.misc.HygieiaException; import com.capitalone.dashboard.model.Build; import com.capitalone.dashboard.model.BuildStatus; @@ -26,31 +53,6 @@ import com.capitalone.dashboard.webhook.settings.JenkinsBuildWebHookSettings; import com.capitalone.dashboard.webhook.settings.WebHookSettings; import com.querydsl.core.types.Predicate; -import org.bson.types.ObjectId; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; -import org.joda.time.LocalDate; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.argThat; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class BuildServiceTest { @@ -79,12 +81,12 @@ public void search() { BuildSearchRequest request = new BuildSearchRequest(); request.setComponentId(componentId); - when(componentRepository.findOne(request.getComponentId())).thenReturn(makeComponent(collectorItemId, collectorId, true)); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(componentRepository.findById(request.getComponentId()).get()).thenReturn(makeComponent(collectorItemId, collectorId, true)); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); buildService.search(request); - verify(buildRepository, times(1)).findAll(argThat(hasPredicate("build.collectorItemId = " + collectorItemId.toString()))); + verify(buildRepository, times(1)).findAll((Predicate) argThat((ArgumentMatcher)hasPredicate("build.collectorItemId = " + collectorItemId.toString()))); } @Test @@ -96,8 +98,8 @@ public void search_Empty_Response_No_CollectorItems() { BuildSearchRequest request = new BuildSearchRequest(); request.setComponentId(componentId); - when(componentRepository.findOne(request.getComponentId())).thenReturn(makeComponent(collectorItemId, collectorId, false)); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(componentRepository.findById(request.getComponentId()).get()).thenReturn(makeComponent(collectorItemId, collectorId, false)); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); DataResponse> response = buildService.search(request); @@ -110,8 +112,8 @@ public void search_Empty_Response_No_Component() { ObjectId collectorId = ObjectId.get(); BuildSearchRequest request = new BuildSearchRequest(); - when(componentRepository.findOne(request.getComponentId())).thenReturn(null); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(componentRepository.findById(request.getComponentId())).thenReturn(null); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); DataResponse> response = buildService.search(request); @@ -129,14 +131,14 @@ public void search_14days() { request.setComponentId(componentId); request.setNumberOfDays(14); - when(componentRepository.findOne(request.getComponentId())).thenReturn(makeComponent(collectorItemId, collectorId, true)); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(componentRepository.findById(request.getComponentId()).get()).thenReturn(makeComponent(collectorItemId, collectorId, true)); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); buildService.search(request); long endTimeTarget = new LocalDate().minusDays(request.getNumberOfDays()).toDate().getTime(); String expectedPredicate = "build.collectorItemId = " + collectorItemId.toString() + " && build.endTime >= " + endTimeTarget; - verify(buildRepository, times(1)).findAll(argThat(hasPredicate(expectedPredicate))); + verify(buildRepository, times(1)).findAll((Predicate) argThat((ArgumentMatcher)hasPredicate(expectedPredicate))); } @Test @@ -145,7 +147,7 @@ public void createWithGoodRequest() throws HygieiaException { BuildDataCreateRequest request = makeBuildRequest(); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); @@ -165,7 +167,7 @@ public void createV2WithGoodRequest() throws HygieiaException { BuildDataCreateRequest request = makeBuildRequest(); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); @@ -184,10 +186,10 @@ public void createV3WithGoodRequest() throws HygieiaException { ObjectId collectorId = ObjectId.get(); BuildDataCreateRequest request = makeBuildRequest(); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); - when(collectorItemRepository.findOne(any(ObjectId.class))).thenReturn(new CollectorItem()); + when(collectorItemRepository.findById(any(ObjectId.class)).get()).thenReturn(new CollectorItem()); Build build = makeBuild(); List dashboards = new ArrayList<>(); when(buildRepository.save(any(Build.class))).thenReturn(build); @@ -207,10 +209,10 @@ public void createV3WithGoodRequestEnableDashboardLookup() throws HygieiaExcepti Build build = makeBuild(); build.getCodeRepos().add(new RepoBranch("https://github.com/someorg/somerepo","master", RepoBranch.RepoType.GIT)); List dashboards = Collections.singletonList(new Dashboard("team", "title", null, null, DashboardType.Team, "configItemAppName", "configItemComponentName", null, false, ScoreDisplayType.HEADER)); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); - when(collectorItemRepository.findOne(any(ObjectId.class))).thenReturn(new CollectorItem()); + when(collectorItemRepository.findById(any(ObjectId.class)).get()).thenReturn(new CollectorItem()); when(buildRepository.save(any(Build.class))).thenReturn(build); when(apiSettings.isLookupDashboardForBuildDataCreate()).thenReturn(Boolean.TRUE); when(dashboardService.getDashboardsByCollectorItems(any(Set.class), any(CollectorType.class))).thenReturn(dashboards); @@ -231,10 +233,10 @@ public void createV3WithGoodRequestLibraryThresholdExceed() throws HygieiaExcept Build build = makeBuild(); build.getCodeRepos().add(new RepoBranch("https://github.com/someorg/somerepo","master", RepoBranch.RepoType.GIT)); List dashboards = Collections.singletonList(new Dashboard("team", "title", null, null, DashboardType.Team, "configItemAppName", "configItemComponentName", null, false, ScoreDisplayType.HEADER)); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); - when(collectorItemRepository.findOne(any(ObjectId.class))).thenReturn(new CollectorItem()); + when(collectorItemRepository.findById(any(ObjectId.class)).get()).thenReturn(new CollectorItem()); when(buildRepository.save(any(Build.class))).thenReturn(build); when(apiSettings.isLookupDashboardForBuildDataCreate()).thenReturn(Boolean.FALSE); when(dashboardService.getDashboardsByCollectorItems(any(Set.class), any(CollectorType.class))).thenReturn(dashboards); @@ -253,11 +255,11 @@ public void createV3WithGoodRequestExistingSCMCollectorItem() throws HygieiaExce BuildDataCreateRequest request = makeBuildRequest(); request.setCodeRepos(makeRepoBranches()); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); when(collectorRepository.findByName(anyString())).thenReturn(new Collector()); - when(collectorItemRepository.findOne(any(ObjectId.class))).thenReturn(new CollectorItem()); + when(collectorItemRepository.findById(any(ObjectId.class)).get()).thenReturn(new CollectorItem()); when(collectorItemRepository.findRepoByUrlAndBranch(any(ObjectId.class), anyString(), anyString())).thenReturn(new CollectorItem()); Build build = makeBuild(); build.setCodeRepos(makeRepoBranches()); @@ -277,11 +279,11 @@ public void createV3WithGoodRequestNewSCMCollectorItem() throws HygieiaException BuildDataCreateRequest request = makeBuildRequest(); request.setCodeRepos(makeRepoBranches()); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); when(collectorRepository.findByName(anyString())).thenReturn(new Collector()); - when(collectorItemRepository.findOne(any(ObjectId.class))).thenReturn(new CollectorItem()); + when(collectorItemRepository.findById(any(ObjectId.class)).get()).thenReturn(new CollectorItem()); when(collectorItemRepository.findRepoByUrlAndBranch(any(ObjectId.class), anyString(), anyString())).thenReturn(null); Build build = makeBuild(); build.setCodeRepos(makeRepoBranches()); diff --git a/src/test/java/com/capitalone/dashboard/service/CodeQualityServiceTest.java b/src/test/java/com/capitalone/dashboard/service/CodeQualityServiceTest.java index b2daf41e..67d10f9e 100644 --- a/src/test/java/com/capitalone/dashboard/service/CodeQualityServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/CodeQualityServiceTest.java @@ -39,7 +39,7 @@ public void createWithGoodRequest() throws HygieiaException { CodeQualityCreateRequest request = makeCodeQualityRequest(); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); @@ -57,7 +57,7 @@ public void createV2WithGoodRequest() throws HygieiaException { CodeQualityCreateRequest request = makeCodeQualityRequest(); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); @@ -72,7 +72,7 @@ public void createV2WithGoodRequest() throws HygieiaException { @Test public void getCollectorItemTest() { CodeQualityRequest request = new CodeQualityRequest(); - when(componentRepository.findOne(request.getComponentId())).thenReturn(null); + when(componentRepository.findById(request.getComponentId()).get()).thenReturn(null); CollectorItem item = codeQualityService.getCollectorItem(request); diff --git a/src/test/java/com/capitalone/dashboard/service/CollectorServiceTest.java b/src/test/java/com/capitalone/dashboard/service/CollectorServiceTest.java index 94c6d11c..973bc9e0 100644 --- a/src/test/java/com/capitalone/dashboard/service/CollectorServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/CollectorServiceTest.java @@ -118,12 +118,12 @@ public void testCreateCollectorItem(){ CollectorItem c1 = makeCollectorItemWithOptions(true,uniqueOptions,ObjectId.get(),1557332269095L); CollectorItem c2 = makeCollectorItemWithOptions(true,uniqueOptions2,ObjectId.get(),1557947220000L); - when(collectorRepository.findOne(any(ObjectId.class))).thenReturn(c); + when(collectorRepository.findById(any(ObjectId.class)).get()).thenReturn(c); when(collectorItemRepository.findAllByOptionMapAndCollectorIdsIn(anyMap(),anyList())).thenReturn(Arrays.asList(c2)); when(collectorItemRepository.save(any(CollectorItem.class))).thenReturn(c1); CollectorItem actual = collectorService.createCollectorItem(c1); assertTrue(actual.getId().equals(c2.getId())); - verify(collectorRepository,times(1)).findOne(any(ObjectId.class)); + verify(collectorRepository,times(1)).findById(any(ObjectId.class)).get(); verify(collectorItemRepository,times(1)).findAllByOptionMapAndCollectorIdsIn(anyMap(),anyList()); verify(collectorItemRepository,times(1)).save(any(CollectorItem.class)); } @@ -143,12 +143,12 @@ public void testCreateCollectorItemWithMoreOptions(){ CollectorItem c1 = makeCollectorItemWithOptions(true,uniqueOptions,ObjectId.get(),1557947220000L); CollectorItem c2 = makeCollectorItemWithOptions(true,uniqueOptions2,ObjectId.get(),1557332269095L); - when(collectorRepository.findOne(any(ObjectId.class))).thenReturn(c); + when(collectorRepository.findById(any(ObjectId.class)).get()).thenReturn(c); when(collectorItemRepository.findAllByOptionMapAndCollectorIdsIn(anyMap(),anyList())).thenReturn(Arrays.asList(c1)); when(collectorItemRepository.save(any(CollectorItem.class))).thenReturn(c2); CollectorItem actual = collectorService.createCollectorItem(c2); assertTrue(actual.getId().equals(c1.getId())); - verify(collectorRepository,times(1)).findOne(any(ObjectId.class)); + verify(collectorRepository,times(1)).findById(any(ObjectId.class)).get(); verify(collectorItemRepository,times(1)).findAllByOptionMapAndCollectorIdsIn(anyMap(),anyList()); verify(collectorItemRepository,times(1)).save(any(CollectorItem.class)); } @@ -168,12 +168,12 @@ public void testCreateCollectorItemWithMoreOptionsWithDisabled(){ CollectorItem c1 = makeCollectorItemWithOptions(false,uniqueOptions,ObjectId.get(),1557332269095L); CollectorItem c2 = makeCollectorItemWithOptions(true,uniqueOptions2,ObjectId.get(),1557332269095L); - when(collectorRepository.findOne(any(ObjectId.class))).thenReturn(c); + when(collectorRepository.findById(any(ObjectId.class)).get()).thenReturn(c); when(collectorItemRepository.findAllByOptionMapAndCollectorIdsIn(anyMap(),anyList())).thenReturn(Arrays.asList(c1)); when(collectorItemRepository.save(any(CollectorItem.class))).thenReturn(c2); CollectorItem actual = collectorService.createCollectorItem(c2); assertTrue(actual.getId().equals(c1.getId())); - verify(collectorRepository,times(1)).findOne(any(ObjectId.class)); + verify(collectorRepository,times(1)).findById(any(ObjectId.class)); verify(collectorItemRepository,times(1)).findAllByOptionMapAndCollectorIdsIn(anyMap(),anyList()); verify(collectorItemRepository,times(1)).save(any(CollectorItem.class)); } @@ -187,12 +187,12 @@ public void testCreateCollectorItemWithNonExisting(){ uniqueOptions.put("instanceUrl","https://a.com"); CollectorItem c1 = makeCollectorItemWithOptions(false,uniqueOptions,ObjectId.get(),1557332269095L); - when(collectorRepository.findOne(any(ObjectId.class))).thenReturn(c); + when(collectorRepository.findById(any(ObjectId.class)).get()).thenReturn(c); when(collectorItemRepository.findAllByOptionMapAndCollectorIdsIn(anyMap(),anyList())).thenReturn(null); when(collectorItemRepository.save(any(CollectorItem.class))).thenReturn(c1); CollectorItem actual = collectorService.createCollectorItem(c1); assertNotNull(actual); - verify(collectorRepository,times(1)).findOne(any(ObjectId.class)); + verify(collectorRepository,times(1)).findById(any(ObjectId.class)); verify(collectorItemRepository,times(1)).findAllByOptionMapAndCollectorIdsIn(anyMap(),anyList()); verify(collectorItemRepository,times(1)).save(any(CollectorItem.class)); } @@ -221,12 +221,12 @@ public void testCreateCollectorItemWithMoreOptionsWithEnabledAndDisabled(){ CollectorItem c1 = makeCollectorItemWithOptions(false,uniqueOptions,ObjectId.get(),1557947220000L); CollectorItem c2 = makeCollectorItemWithOptions(true,uniqueOptions2,ObjectId.get(),1557947220000L); CollectorItem c3 = makeCollectorItemWithOptions(true,uniqueOptions3,ObjectId.get(),1557332269095L); - when(collectorRepository.findOne(any(ObjectId.class))).thenReturn(c); + when(collectorRepository.findById(any(ObjectId.class)).get()).thenReturn(c); when(collectorItemRepository.findAllByOptionMapAndCollectorIdsIn(anyMap(),anyList())).thenReturn(Arrays.asList(c1,c3)); when(collectorItemRepository.save(any(CollectorItem.class))).thenReturn(c2); CollectorItem actual = collectorService.createCollectorItem(c2); assertTrue(actual.getId().equals(c3.getId())); - verify(collectorRepository,times(1)).findOne(any(ObjectId.class)); + verify(collectorRepository,times(1)).findById(any(ObjectId.class)); verify(collectorItemRepository,times(1)).findAllByOptionMapAndCollectorIdsIn(anyMap(),anyList()); verify(collectorItemRepository,times(1)).save(any(CollectorItem.class)); } @@ -255,13 +255,13 @@ public void testCreateCollectorItemWithLastUpdatedAndEnabled(){ CollectorItem c2 = makeCollectorItemWithOptions(true,uniqueOptions2,ObjectId.get(),1557947220000L); CollectorItem c3 = makeCollectorItemWithOptions(true,uniqueOptions3,ObjectId.get(),1557860820000L); CollectorItem c4 = makeCollectorItemWithOptions(true,uniqueOptions3,ObjectId.get(),1557949459000L); - when(collectorRepository.findOne(any(ObjectId.class))).thenReturn(c); + when(collectorRepository.findById(any(ObjectId.class)).get()).thenReturn(c); when(collectorItemRepository.findAllByOptionMapAndCollectorIdsIn(anyMap(),anyList())).thenReturn(Arrays.asList(c1,c3,c4)); when(collectorItemRepository.save(any(CollectorItem.class))).thenReturn(c2); CollectorItem actual = collectorService.createCollectorItem(c2); assertTrue(actual.getId().equals(c4.getId())); - verify(collectorRepository,times(1)).findOne(any(ObjectId.class)); + verify(collectorRepository,times(1)).findById(any(ObjectId.class)); verify(collectorItemRepository,times(1)).findAllByOptionMapAndCollectorIdsIn(anyMap(),anyList()); verify(collectorItemRepository,times(1)).save(any(CollectorItem.class)); } diff --git a/src/test/java/com/capitalone/dashboard/service/CommitServiceTest.java b/src/test/java/com/capitalone/dashboard/service/CommitServiceTest.java index 505ddc2b..65380542 100644 --- a/src/test/java/com/capitalone/dashboard/service/CommitServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/CommitServiceTest.java @@ -50,8 +50,8 @@ public void searchTest() { CommitRequest request = new CommitRequest(); request.setComponentId(componentId); - when(componentRepository.findOne(request.getComponentId())).thenReturn(makeComponent(collectorItemId, collectorId, true)); - when(collectorRepository.findOne(collectorId)).thenReturn(collector); + when(componentRepository.findById(request.getComponentId()).get()).thenReturn(makeComponent(collectorItemId, collectorId, true)); + when(collectorRepository.findById(collectorId).get()).thenReturn(collector); commitService.search(request); @@ -62,7 +62,7 @@ public void searchTest() { public void search_Empty_Response_No_Component() { CommitRequest request = new CommitRequest(); - when(componentRepository.findOne(request.getComponentId())).thenReturn(null); + when(componentRepository.findById(request.getComponentId()).get()).thenReturn(null); DataResponse> response = commitService.search(request); @@ -79,7 +79,7 @@ public void search_Empty_Response_No_CollectorItems() { CommitRequest request = new CommitRequest(); request.setComponentId(componentId); - when(componentRepository.findOne(request.getComponentId())).thenReturn(makeComponent(collectorItemId, collectorId, false)); + when(componentRepository.findById(request.getComponentId()).get()).thenReturn(makeComponent(collectorItemId, collectorId, false)); DataResponse> response = commitService.search(request); diff --git a/src/test/java/com/capitalone/dashboard/service/ConfigurationServiceTest.java b/src/test/java/com/capitalone/dashboard/service/ConfigurationServiceTest.java index d0dfa3d2..8f63050d 100644 --- a/src/test/java/com/capitalone/dashboard/service/ConfigurationServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/ConfigurationServiceTest.java @@ -42,9 +42,9 @@ public void testCreate() throws Exception { for(Configuration create : createRequest) { create.setId(new ObjectId()); } - Mockito.doReturn(createRequest).when(configurationRepository).save(Matchers.anyListOf(Configuration.class)); + Mockito.doReturn(createRequest).when(configurationRepository).saveAll(Matchers.anyListOf(Configuration.class)); service.insertConfigurationData(createRequest); - Mockito.verify(configurationRepository, times(1)).save(createRequest); + Mockito.verify(configurationRepository, times(1)).saveAll(createRequest); } diff --git a/src/test/java/com/capitalone/dashboard/service/DashboardRemoteServiceTest.java b/src/test/java/com/capitalone/dashboard/service/DashboardRemoteServiceTest.java index d1e99593..5be81da7 100644 --- a/src/test/java/com/capitalone/dashboard/service/DashboardRemoteServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/DashboardRemoteServiceTest.java @@ -84,7 +84,7 @@ public void remoteUpdateCodeRepo() throws IOException, HygieiaException { dashboardRemoteService.remoteCreate(request, true); List dashboard = dashboardService.getByTitle("TestSSA"); - Component component = componentRepository.findOne(dashboard.get(0).getApplication().getComponents().get(0).getId()); + Component component = componentRepository.findById(dashboard.get(0).getApplication().getComponents().get(0).getId()).get(); assertEquals(2, component.getCollectorItems().get(CollectorType.SCM).size()); } @@ -93,7 +93,7 @@ public void remoteUpdateAllEntries() throws IOException, HygieiaException { DashboardRemoteRequest request = getRemoteRequest("./dashboardRemoteRequests/0-Remote-Update-All.json"); dashboardRemoteService.remoteCreate(request, true); List dashboard = dashboardService.getByTitle("TestSSA"); - Component component = componentRepository.findOne(dashboard.get(0).getApplication().getComponents().get(0).getId()); + Component component = componentRepository.findById(dashboard.get(0).getApplication().getComponents().get(0).getId()).get(); assertEquals(3, component.getCollectorItems().get(CollectorType.SCM).size()); assertEquals(2, component.getCollectorItems().get(CollectorType.Build).size()); assertEquals(2, component.getCollectorItems().get(CollectorType.LibraryPolicy).size()); @@ -105,7 +105,7 @@ public void remoteUpdateAllEmptyEntries() throws IOException, HygieiaException { DashboardRemoteRequest request = getRemoteRequest("./dashboardRemoteRequests/0-Remote-Update-All-Empty.json"); dashboardRemoteService.remoteCreate(request, true); List dashboard = dashboardService.getByTitle("TestSSA"); - Component component = componentRepository.findOne(dashboard.get(0).getApplication().getComponents().get(0).getId()); + Component component = componentRepository.findById(dashboard.get(0).getApplication().getComponents().get(0).getId()).get(); assertNull( component.getCollectorItems().get(CollectorType.SCM)); assertNull(component.getCollectorItems().get(CollectorType.Build)); assertNull( component.getCollectorItems().get(CollectorType.LibraryPolicy)); @@ -275,7 +275,7 @@ public void remoteCreateSCM() throws HygieiaException, IOException { dashboardRemoteService.remoteCreate(request, false); List dashboard = dashboardService.getByTitle("newDashboard3"); - Component component = componentRepository.findOne(dashboard.get(0).getApplication().getComponents().get(0).getId()); + Component component = componentRepository.findById(dashboard.get(0).getApplication().getComponents().get(0).getId()).get(); assertEquals(1, component.getCollectorItems().get(CollectorType.SCM).size()); } @@ -297,7 +297,7 @@ public void remoteCreateBuild() throws HygieiaException, IOException { dashboardRemoteService.remoteCreate(request, false); List dashboard = dashboardService.getByTitle("newDashboard4"); - Component component = componentRepository.findOne(dashboard.get(0).getApplication().getComponents().get(0).getId()); + Component component = componentRepository.findById(dashboard.get(0).getApplication().getComponents().get(0).getId()).get(); assertEquals(1, component.getCollectorItems().get(CollectorType.Build).size()); assertEquals(2, dashboard.get(0).getOwners().size()); } @@ -343,7 +343,7 @@ public void remoteUpdateLibraryScan() throws HygieiaException, IOException { dashboardRemoteService.remoteCreate(request, true); List dashboard = dashboardService.getByTitle("TestSSA"); - Component component = componentRepository.findOne(dashboard.get(0).getApplication().getComponents().get(0).getId()); + Component component = componentRepository.findById(dashboard.get(0).getApplication().getComponents().get(0).getId()).get(); assertEquals(2, component.getCollectorItems().get(CollectorType.LibraryPolicy).size()); assertNull(component.getCollectorItems().get(CollectorType.CodeQuality)); assertNull(component.getCollectorItems().get(CollectorType.Test)); diff --git a/src/test/java/com/capitalone/dashboard/service/DashboardServiceTest.java b/src/test/java/com/capitalone/dashboard/service/DashboardServiceTest.java index 47a04919..7ee585ac 100644 --- a/src/test/java/com/capitalone/dashboard/service/DashboardServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/DashboardServiceTest.java @@ -111,7 +111,7 @@ public void get() { Dashboard expected = makeTeamDashboard("template", "title", "AppName", "",configItemBusServName,configItemBusAppName,"comp1"); when(cmdbService.configurationItemByConfigurationItem(configItemBusServName)).thenReturn(getConfigItem(configItemBusServName)); when(cmdbService.configurationItemByConfigurationItem(configItemBusAppName)).thenReturn(getConfigItem(configItemBusAppName)); - when(dashboardRepository.findOne(id)).thenReturn(expected); + when(dashboardRepository.findById(id).get()).thenReturn(expected); assertThat(dashboardService.get(id), is(expected)); } @@ -123,7 +123,7 @@ public void create() throws HygieiaException { when(dashboardRepository.save(expected)).thenReturn(expected); when(scoreDashboardService.addScoreForDashboard(any())).thenReturn(null); assertThat(dashboardService.create(expected), is(expected)); - verify(componentRepository, times(1)).save(expected.getApplication().getComponents()); + verify(componentRepository, times(1)).saveAll(expected.getApplication().getComponents()); } @Test @@ -133,7 +133,7 @@ public void createWithScoreEnabled() throws HygieiaException { when(dashboardRepository.save(expected)).thenReturn(expected); when(scoreDashboardService.addScoreForDashboard(expected)).thenReturn(new CollectorItem()); assertThat(dashboardService.create(expected), is(expected)); - verify(componentRepository, times(1)).save(expected.getApplication().getComponents()); + verify(componentRepository, times(1)).saveAll(expected.getApplication().getComponents()); } @Test @@ -142,7 +142,7 @@ public void create_dup_name_dash() throws HygieiaException { Dashboard firstDash = makeTeamDashboard("template", "title", "appName", "johns",configItemBusServName,configItemBusAppName, "comp1", "comp2"); when(dashboardRepository.save(firstDash)).thenReturn(firstDash); assertThat(dashboardService.create(firstDash), is(firstDash)); - verify(componentRepository, times(1)).save(firstDash.getApplication().getComponents()); + verify(componentRepository, times(1)).saveAll(firstDash.getApplication().getComponents()); Dashboard secondDash = makeTeamDashboard("template", "title", "appName", "johns",configItemBusServName,configItemBusAppName, "comp1", "comp2"); @@ -151,7 +151,7 @@ public void create_dup_name_dash() throws HygieiaException { when(dashboardRepository.save(secondDash)).thenThrow(excep); Iterable components = secondDash.getApplication().getComponents(); - when(componentRepository.save(secondDash.getApplication().getComponents())).thenReturn(components); + when(componentRepository.saveAll(secondDash.getApplication().getComponents())).thenReturn(components); try { dashboardService.create(secondDash); @@ -160,7 +160,7 @@ public void create_dup_name_dash() throws HygieiaException { assertEquals(excep.getMessage(), e.getMessage()); } - verify(componentRepository).delete(components); + verify(componentRepository).deleteAll(components); } @Test @@ -204,9 +204,9 @@ public void associateCollectorToComponent() { collector.setCollectorType(CollectorType.Build); Component component = new Component(); - when(collectorItemRepository.findOne(collItemId)).thenReturn(item); - when(collectorRepository.findOne(collId)).thenReturn(collector); - when(componentRepository.findOne(compId)).thenReturn(component); + when(collectorItemRepository.findById(collItemId).get()).thenReturn(item); + when(collectorRepository.findById(collId).get()).thenReturn(collector); + when(componentRepository.findById(compId).get()).thenReturn(component); dashboardService.associateCollectorToComponent(compId, collItemIds, true); @@ -238,11 +238,11 @@ public void associateCollectorToComponentWithoutCleanUpQuality() { collector2.setCollectorType(CollectorType.LibraryPolicy); Component component = new Component(); - when(collectorItemRepository.findOne(collItemId1)).thenReturn(item1); - when(collectorItemRepository.findOne(collItemId2)).thenReturn(item2); - when(collectorRepository.findOne(collId1)).thenReturn(collector1); - when(collectorRepository.findOne(collId2)).thenReturn(collector2); - when(componentRepository.findOne(compId)).thenReturn(component); + when(collectorItemRepository.findById(collItemId1).get()).thenReturn(item1); + when(collectorItemRepository.findById(collItemId2).get()).thenReturn(item2); + when(collectorRepository.findById(collId1).get()).thenReturn(collector1); + when(collectorRepository.findById(collId2).get()).thenReturn(collector2); + when(componentRepository.findById(compId).get()).thenReturn(component); dashboardService.associateCollectorToComponent(compId, collItemIds, false); @@ -270,16 +270,16 @@ public void associateCollectorToComponentWithDisabledCollectorItem() { HashSet set = new HashSet<>(); set.add(item); - when(collectorItemRepository.findOne(collItemId)).thenReturn(item); - when(collectorRepository.findOne(collId)).thenReturn(collector); - when(componentRepository.findOne(compId)).thenReturn(component); + when(collectorItemRepository.findById(collItemId).get()).thenReturn(item); + when(collectorRepository.findById(collId).get()).thenReturn(collector); + when(componentRepository.findById(compId).get()).thenReturn(component); dashboardService.associateCollectorToComponent(compId, collItemIds, true); assertThat(component.getCollectorItems().get(CollectorType.Build), contains(item)); verify(componentRepository).save(component); - verify(collectorItemRepository).save(set); + verify(collectorItemRepository).saveAll(set); } @Test @@ -301,9 +301,9 @@ public void associateCollectorToComponent_Item_with_two_components() { Component component2 = new Component(); - when(collectorItemRepository.findOne(collItemId)).thenReturn(item); - when(collectorRepository.findOne(collId)).thenReturn(collector); - when(componentRepository.findOne(compId)).thenReturn(component1); + when(collectorItemRepository.findById(collItemId).get()).thenReturn(item); + when(collectorRepository.findById(collId).get()).thenReturn(collector); + when(componentRepository.findById(compId).get()).thenReturn(component1); when(customRepositoryQuery.findComponents(collector, item)).thenReturn(Arrays.asList(component1, component2)); dashboardService.associateCollectorToComponent(compId, collItemIds, true); @@ -311,7 +311,7 @@ public void associateCollectorToComponent_Item_with_two_components() { assertThat(component1.getCollectorItems().get(CollectorType.Build), contains(item)); assertThat(item.isEnabled(), is(true)); verify(componentRepository).save(component1); - verify(collectorItemRepository).save(set); + verify(collectorItemRepository).saveAll(set); } @Test @@ -330,9 +330,9 @@ public void associateCollectorToComponent_collectorItemDisabled_willBecomeEnable HashSet set = new HashSet<>(); set.add(item); - when(collectorItemRepository.findOne(collItemId)).thenReturn(item); - when(collectorRepository.findOne(collId)).thenReturn(collector); - when(componentRepository.findOne(compId)).thenReturn(component); + when(collectorItemRepository.findById(collItemId).get()).thenReturn(item); + when(collectorRepository.findById(collId).get()).thenReturn(collector); + when(componentRepository.findById(compId).get()).thenReturn(component); dashboardService.associateCollectorToComponent(compId, collItemIds, true); @@ -340,7 +340,7 @@ public void associateCollectorToComponent_collectorItemDisabled_willBecomeEnable assertThat(item.isEnabled(), is(true)); verify(componentRepository).save(component); - verify(collectorItemRepository).save((set)); + verify(collectorItemRepository).saveAll((set)); } @@ -373,10 +373,10 @@ public void associateCollectorToComponent_switch_Item1_with_Item2() { set.add(item2); - when(collectorItemRepository.findOne(collItemId1)).thenReturn(item1); - when(collectorItemRepository.findOne(collItemId2)).thenReturn(item2); - when(collectorRepository.findOne(collId)).thenReturn(collector); - when(componentRepository.findOne(compId)).thenReturn(component); + when(collectorItemRepository.findById(collItemId1).get()).thenReturn(item1); + when(collectorItemRepository.findById(collItemId2).get()).thenReturn(item2); + when(collectorRepository.findById(collId).get()).thenReturn(collector); + when(componentRepository.findById(compId).get()).thenReturn(component); dashboardService.associateCollectorToComponent(compId, collItemIds, true); @@ -385,7 +385,7 @@ public void associateCollectorToComponent_switch_Item1_with_Item2() { assertThat(item2.isEnabled(), is(true)); verify(componentRepository).save(component); - verify(collectorItemRepository).save((set)); + verify(collectorItemRepository).saveAll((set)); } @Test @@ -420,10 +420,10 @@ public void associateCollectorToComponent_switch_Item1_with_Item2_Multiple_Compo set.add(item2); - when(collectorItemRepository.findOne(collItemId1)).thenReturn(item1); - when(collectorItemRepository.findOne(collItemId2)).thenReturn(item2); - when(collectorRepository.findOne(collId)).thenReturn(collector); - when(componentRepository.findOne(compId)).thenReturn(component1); + when(collectorItemRepository.findById(collItemId1).get()).thenReturn(item1); + when(collectorItemRepository.findById(collItemId2).get()).thenReturn(item2); + when(collectorRepository.findById(collId).get()).thenReturn(collector); + when(componentRepository.findById(compId).get()).thenReturn(component1); when(customRepositoryQuery.findComponents(collector, item1)).thenReturn(Arrays.asList(component1, component2)); dashboardService.associateCollectorToComponent(compId, collItemIds, true); @@ -433,7 +433,7 @@ public void associateCollectorToComponent_switch_Item1_with_Item2_Multiple_Compo assertThat(item2.isEnabled(), is(true)); verify(componentRepository).save(component1); - verify(collectorItemRepository).save((set)); + verify(collectorItemRepository).saveAll((set)); } @Test @@ -470,11 +470,11 @@ public void associateCollectorToComponent_replace_Item1_with_Item2_and_3() { item3.setId(collItemId3); set.add(item3); - when(collectorItemRepository.findOne(collItemId1)).thenReturn(item1); - when(collectorItemRepository.findOne(collItemId2)).thenReturn(item2); - when(collectorItemRepository.findOne(collItemId3)).thenReturn(item3); - when(collectorRepository.findOne(collId)).thenReturn(collector); - when(componentRepository.findOne(compId)).thenReturn(component); + when(collectorItemRepository.findById(collItemId1).get()).thenReturn(item1); + when(collectorItemRepository.findById(collItemId2).get()).thenReturn(item2); + when(collectorItemRepository.findById(collItemId3).get()).thenReturn(item3); + when(collectorRepository.findById(collId).get()).thenReturn(collector); + when(componentRepository.findById(compId).get()).thenReturn(component); dashboardService.associateCollectorToComponent(compId, collItemIds, true); @@ -484,7 +484,7 @@ public void associateCollectorToComponent_replace_Item1_with_Item2_and_3() { assertThat(item3.isEnabled(), is(true)); verify(componentRepository).save(component); - verify(collectorItemRepository).save((set)); + verify(collectorItemRepository).saveAll((set)); } @Test @@ -524,11 +524,11 @@ public void associateCollectorToComponent_replace_Item1_and_2_with_Item3() { item3.setId(collItemId3); set.add(item3); - when(collectorItemRepository.findOne(collItemId1)).thenReturn(item1); - when(collectorItemRepository.findOne(collItemId2)).thenReturn(item2); - when(collectorItemRepository.findOne(collItemId3)).thenReturn(item3); - when(collectorRepository.findOne(collId)).thenReturn(collector); - when(componentRepository.findOne(compId)).thenReturn(component); + when(collectorItemRepository.findById(collItemId1).get()).thenReturn(item1); + when(collectorItemRepository.findById(collItemId2).get()).thenReturn(item2); + when(collectorItemRepository.findById(collItemId3).get()).thenReturn(item3); + when(collectorRepository.findById(collId).get()).thenReturn(collector); + when(componentRepository.findById(compId).get()).thenReturn(component); dashboardService.associateCollectorToComponent(compId, collItemIds, true); @@ -538,14 +538,14 @@ public void associateCollectorToComponent_replace_Item1_and_2_with_Item3() { assertThat(item3.isEnabled(), is(true)); verify(componentRepository).save(component); - verify(collectorItemRepository).save((set)); + verify(collectorItemRepository).saveAll((set)); } @Test public void delete() { ObjectId id = ObjectId.get(); Dashboard expected = makeTeamDashboard("template", "title", "appName", "",configItemBusServName, configItemBusAppName,"comp1", "comp2"); - when(dashboardRepository.findOne(id)).thenReturn(expected); + when(dashboardRepository.findById(id).get()).thenReturn(expected); List services = Arrays.asList(new Service()); Service depService = new Service(); @@ -556,8 +556,8 @@ public void delete() { when(scoreDashboardService.disableScoreForDashboard(any())).thenReturn(null); dashboardService.delete(id); - verify(componentRepository).delete(expected.getApplication().getComponents()); - verify(serviceRepository).delete(services); + verify(componentRepository).deleteAll(expected.getApplication().getComponents()); + verify(serviceRepository).deleteAll(services); verify(serviceRepository).save(depService); verify(dashboardRepository).delete(expected); @@ -591,13 +591,13 @@ public void deleteTestCollectorItemDisable() { Dashboard expected = makeTeamDashboard("template", "title", "appName", "",configItemBusServName, configItemBusAppName,"comp1"); expected.getApplication().getComponents().get(0).addCollectorItem(CollectorType.Build, item1); expected.getApplication().getComponents().get(0).addCollectorItem(CollectorType.Build, item2); - when(dashboardRepository.findOne(id)).thenReturn(expected); + when(dashboardRepository.findById(id).get()).thenReturn(expected); when(customRepositoryQuery.findComponents(collId, CollectorType.Build, item1)).thenReturn(Arrays.asList()); when(customRepositoryQuery.findComponents(collId, CollectorType.Build, item2)).thenReturn(Arrays.asList()); when(scoreDashboardService.disableScoreForDashboard(any())).thenReturn(null); dashboardService.delete(id); - verify(componentRepository).delete(expected.getApplication().getComponents()); + verify(componentRepository).deleteAll(expected.getApplication().getComponents()); verify(dashboardRepository).delete(expected); assertThat(item1.isEnabled(), is(false)); assertThat(item2.isEnabled(),is(false)); @@ -631,14 +631,14 @@ public void deleteTestCollectorOneItemDisable() { Dashboard expected = makeTeamDashboard("template", "title", "appName", "",configItemBusServName, configItemBusAppName,"comp1"); expected.getApplication().getComponents().get(0).addCollectorItem(CollectorType.Build, item1); expected.getApplication().getComponents().get(0).addCollectorItem(CollectorType.Build, item2); - when(dashboardRepository.findOne(id)).thenReturn(expected); + when(dashboardRepository.findById(id).get()).thenReturn(expected); when(customRepositoryQuery.findComponents(collId, CollectorType.Build, item1)).thenReturn(Arrays.asList(component)); when(customRepositoryQuery.findComponents(collId, CollectorType.Build, item2)).thenReturn(Arrays.asList()); when(scoreDashboardService.disableScoreForDashboard(any())).thenReturn(null); dashboardService.delete(id); - verify(componentRepository).delete(expected.getApplication().getComponents()); + verify(componentRepository).deleteAll(expected.getApplication().getComponents()); verify(dashboardRepository).delete(expected); assertThat(item1.isEnabled(), is(true)); assertThat(item2.isEnabled(),is(false)); @@ -671,14 +671,14 @@ public void deleteTestCollectorNothingDisabled() { Dashboard expected = makeTeamDashboard("template", "title", "appName", "",configItemBusServName, configItemBusAppName,"comp1"); expected.getApplication().getComponents().get(0).addCollectorItem(CollectorType.Build, item1); expected.getApplication().getComponents().get(0).addCollectorItem(CollectorType.Build, item2); - when(dashboardRepository.findOne(id)).thenReturn(expected); + when(dashboardRepository.findById(id).get()).thenReturn(expected); when(customRepositoryQuery.findComponents(collId, CollectorType.Build, item1)).thenReturn(Arrays.asList(component)); when(customRepositoryQuery.findComponents(collId, CollectorType.Build, item2)).thenReturn(Arrays.asList(component)); when(scoreDashboardService.disableScoreForDashboard(any())).thenReturn(null); dashboardService.delete(id); - verify(componentRepository).delete(expected.getApplication().getComponents()); + verify(componentRepository).deleteAll(expected.getApplication().getComponents()); verify(dashboardRepository).delete(expected); assertThat(item1.isEnabled(), is(true)); assertThat(item2.isEnabled(),is(true)); @@ -738,7 +738,7 @@ public void deleteWidget() { Component c = new Component(); c.setId(compId); - when(componentRepository.findOne(compId)).thenReturn(c); + when(componentRepository.findById(compId).get()).thenReturn(c); dashboardService.deleteWidget(d, expected, compId, collIds, true); verify(componentRepository, times(1)).save(any(Component.class)); } @@ -761,7 +761,7 @@ public void deleteWidgetQuality() { c.setId(compId); c.setCollectorItems(componentCIs); - when(componentRepository.findOne(compId)).thenReturn(c); + when(componentRepository.findById(compId).get()).thenReturn(c); dashboardService.deleteWidget(d, quality, compId, collIds, false); assertTrue(d.getWidgets().get(0).equals(quality)); } @@ -773,13 +773,13 @@ public void updateOwners_empty_owner_set() { List activeWidgets = new ArrayList<>(); Dashboard dashboard = new Dashboard("template", "title", new Application("Application"), null, DashboardType.Team, configItemBusServName, configItemBusAppName, activeWidgets, false, ScoreDisplayType.HEADER); - when(dashboardRepository.findOne(dashboard.getId())).thenReturn(dashboard); + when(dashboardRepository.findById(dashboard.getId()).get()).thenReturn(dashboard); when(dashboardRepository.save(dashboard)).thenReturn(dashboard); Iterable result = dashboardService.updateOwners(dashboard.getId(), owners); assertTrue(Iterables.size(result) == 0); - when(dashboardRepository.findOne(dashboard.getId())).thenReturn(dashboard); + when(dashboardRepository.findById(dashboard.getId()).get()).thenReturn(dashboard); when(dashboardRepository.save(dashboard)).thenReturn(dashboard); } @@ -809,7 +809,7 @@ public void updateOwners() { Dashboard dashboard = new Dashboard("template", "title", new Application("Application"), existingOwners, DashboardType.Team,configItemBusServName,configItemBusAppName, activeWidgets, false, ScoreDisplayType.HEADER); when(userInfoServiceImpl.isUserValid("existing", AuthType.LDAP)).thenReturn(true); - when(dashboardRepository.findOne(dashboard.getId())).thenReturn(dashboard); + when(dashboardRepository.findById(dashboard.getId()).get()).thenReturn(dashboard); when(dashboardRepository.save(dashboard)).thenReturn(dashboard); Iterable owners = Lists.newArrayList(existingOwner); @@ -819,7 +819,7 @@ public void updateOwners() { assertEquals(1, result.size()); assertEquals(existingOwner, result.get(0)); - verify(dashboardRepository).findOne(eq(dashboard.getId())); + verify(dashboardRepository).findById(eq(dashboard.getId())); verify(dashboardRepository).save(eq(dashboard)); } @Test @@ -842,7 +842,7 @@ public void updateDashboardBusinessItems() throws HygieiaException{ when(cmdbService.configurationItemByConfigurationItem(configItemBusServName)).thenReturn(getConfigItem(configItemBusServName)); when(cmdbService.configurationItemByConfigurationItem(configItemBusAppName)).thenReturn(getConfigItem(configItemBusAppName)); - when(dashboardRepository.findOne(id)).thenReturn(myDashboard); + when(dashboardRepository.findById(id).get()).thenReturn(myDashboard); when(cmdbService.configurationItemByConfigurationItem(newServiceName)).thenReturn(serviceUpdated); when(cmdbService.configurationItemByConfigurationItem(newAppName)).thenReturn(appUpdated); @@ -856,7 +856,7 @@ public void updateDashboardWidgets() throws HygieiaException{ ObjectId id = ObjectId.get(); Dashboard myDashboard = makeTeamDashboard("template", "title", "appName", "amit",null, null, "comp1", "comp2"); Dashboard dashboardRequest = makeTeamDashboard("template", "title", "appName", "amit",null, null, "comp1", "comp2"); - when(dashboardRepository.findOne(id)).thenReturn(myDashboard); + when(dashboardRepository.findById(id).get()).thenReturn(myDashboard); when(scoreDashboardService.addScoreForDashboard(any())).thenReturn(null); when(dashboardRepository.save(myDashboard)).thenReturn(myDashboard); assertNotNull(dashboardService.updateDashboardWidgets(id,dashboardRequest)); @@ -884,7 +884,7 @@ public void updateScoreSettings() { Dashboard myDashboard = makeTeamDashboard("template", "title", "appName", "amit",null, null, "comp1", "comp2"); myDashboard.setScoreEnabled(false); myDashboard.setId(ObjectId.get()); - when(dashboardRepository.findOne(myDashboard.getId())).thenReturn(myDashboard); + when(dashboardRepository.findById(myDashboard.getId()).get()).thenReturn(myDashboard); Dashboard myDashboardResponse = makeTeamDashboard("template", "title", "appName", "amit",null, null, "comp1", "comp2"); myDashboardResponse.setScoreEnabled(true); diff --git a/src/test/java/com/capitalone/dashboard/service/DataSyncServiceTest.java b/src/test/java/com/capitalone/dashboard/service/DataSyncServiceTest.java index d873467b..636b36a8 100644 --- a/src/test/java/com/capitalone/dashboard/service/DataSyncServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/DataSyncServiceTest.java @@ -103,7 +103,7 @@ public void dataCleanGIT() { when(dataSyncService.getGitRequestRepository().findTopByCollectorItemIdOrderByTimestampDesc(any())).thenReturn(getGitRequest(collectorItemId, 1584127005000L)); when(dataSyncService.getGitRequestRepository().findTopByCollectorItemIdOrderByTimestampDesc(any())).thenReturn(getGitRequest(collectorItemId2, 1581621405000L)); when(dataSyncService.getComponentRepository().findBySCMCollectorItemId(any())).thenReturn(Arrays.asList(getComponent(collectorItemId))); - when(dataSyncService.getCollectorItemRepository().findOne(any(ObjectId.class))).thenReturn(getGitRepo(collectorItemId, "http://github.com/repo1", "master")); + when(dataSyncService.getCollectorItemRepository().findById(any(ObjectId.class)).get()).thenReturn(getGitRepo(collectorItemId, "http://github.com/repo1", "master")); DataSyncResponse response = dataSyncService.refresh(getDataSyncRequest(GITHUB)); assertEquals(response.getCollectorItemCount(), 1); assertEquals(response.getComponentCount(), 2); @@ -122,7 +122,7 @@ public void dataCleanSonar() { when(dataSyncService.getCodeQualityRepository().findTop1ByCollectorItemIdOrderByTimestampDesc(any())).thenReturn(getCodeQuality(collectorItemId, 1584127005000L)); when(dataSyncService.getCodeQualityRepository().findTop1ByCollectorItemIdOrderByTimestampDesc(any())).thenReturn(getCodeQuality(collectorItemId2, 1581621405000L)); when(dataSyncService.getComponentRepository().findByCodeQualityCollectorItems(any())).thenReturn(Arrays.asList(getComponent(collectorItemId))); - when(dataSyncService.getCollectorItemRepository().findOne(any(ObjectId.class))).thenReturn(getSonarProject(collectorItemId, "sonarProjectName1", "http://sonarqube.com")); + when(dataSyncService.getCollectorItemRepository().findById(any(ObjectId.class)).get()).thenReturn(getSonarProject(collectorItemId, "sonarProjectName1", "http://sonarqube.com")); DataSyncResponse response = dataSyncService.refresh(getDataSyncRequest(SONAR)); assertEquals(response.getCollectorItemCount(), 1); assertEquals(response.getComponentCount(), 2); @@ -142,7 +142,7 @@ public void dataCleanArtifact() { when(dataSyncService.getBinaryArtifactRepository().findTopByCollectorItemIdOrderByTimestampDesc(any())).thenReturn(getBinaryArtifact(collectorItemId, 1584127005000L)); when(dataSyncService.getBinaryArtifactRepository().findTopByCollectorItemIdOrderByTimestampDesc(any())).thenReturn(getBinaryArtifact(collectorItemId2, 1581621405000L)); when(dataSyncService.getComponentRepository().findByArtifactCollectorItems(any())).thenReturn(Arrays.asList(getComponent(collectorItemId))); - when(dataSyncService.getCollectorItemRepository().findOne(any(ObjectId.class))).thenReturn(getArtifactItem(collectorItemId, "artifactName1", "repoName", "path", "http://artifactory.com")); + when(dataSyncService.getCollectorItemRepository().findById(any(ObjectId.class)).get()).thenReturn(getArtifactItem(collectorItemId, "artifactName1", "repoName", "path", "http://artifactory.com")); DataSyncResponse response = dataSyncService.refresh(getDataSyncRequest(ARTIFACTORY)); assertEquals(response.getCollectorItemCount(), 1); assertEquals(response.getComponentCount(), 2); @@ -161,7 +161,7 @@ public void dataCleanStaticSecurity() { when(dataSyncService.getCodeQualityRepository().findTop1ByCollectorItemIdOrderByTimestampDesc(any())).thenReturn(getCodeQuality(collectorItemId, 1584127005000L)); when(dataSyncService.getCodeQualityRepository().findTop1ByCollectorItemIdOrderByTimestampDesc(any())).thenReturn(getCodeQuality(collectorItemId2, 1581621405000L)); when(dataSyncService.getComponentRepository().findByStaticSecurityScanCollectorItems(any())).thenReturn(Arrays.asList(getComponent(collectorItemId))); - when(dataSyncService.getCollectorItemRepository().findOne(any(ObjectId.class))).thenReturn(getStaticSecurityCollectorItem(collectorItemId, "staticSecurityProjectName1", "http://nexusiq.com")); + when(dataSyncService.getCollectorItemRepository().findById(any(ObjectId.class)).get()).thenReturn(getStaticSecurityCollectorItem(collectorItemId, "staticSecurityProjectName1", "http://nexusiq.com")); DataSyncResponse response = dataSyncService.refresh(getDataSyncRequest(STATIC_SECURITY)); assertEquals(response.getCollectorItemCount(), 1); assertEquals(response.getComponentCount(), 2); @@ -180,7 +180,7 @@ public void dataCleanLibraryPolicy() { when(dataSyncService.getLibraryPolicyResultsRepository().findTopByCollectorItemIdOrderByTimestampDesc(any())).thenReturn(getLibraryPolicy(collectorItemId, 1584127005000L)); when(dataSyncService.getLibraryPolicyResultsRepository().findTopByCollectorItemIdOrderByTimestampDesc(any())).thenReturn(getLibraryPolicy(collectorItemId2, 1581621405000L)); when(dataSyncService.getComponentRepository().findByLibraryPolicyCollectorItems(any())).thenReturn(Arrays.asList(getComponent(collectorItemId))); - when(dataSyncService.getCollectorItemRepository().findOne(any(ObjectId.class))).thenReturn(getLibraryPolicyCollectorItem(collectorItemId, "libraryPolicyProjectName1", "http://whitesource.com")); + when(dataSyncService.getCollectorItemRepository().findById(any(ObjectId.class)).get()).thenReturn(getLibraryPolicyCollectorItem(collectorItemId, "libraryPolicyProjectName1", "http://whitesource.com")); DataSyncResponse response = dataSyncService.refresh(getDataSyncRequest(LIBRARY_POLICY)); assertEquals(response.getCollectorItemCount(), 1); assertEquals(response.getComponentCount(), 2); diff --git a/src/test/java/com/capitalone/dashboard/service/DeployServiceTest.java b/src/test/java/com/capitalone/dashboard/service/DeployServiceTest.java index 8e8bc615..807d0bb4 100644 --- a/src/test/java/com/capitalone/dashboard/service/DeployServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/DeployServiceTest.java @@ -68,8 +68,8 @@ public void getDeployStatus() { item.setId(ObjectId.get()); item.setCollectorId(ObjectId.get()); component.getCollectorItems().put(CollectorType.Deployment, Collections.singletonList(item)); - when(componentRepository.findOne(compId)).thenReturn(component); - when(collectorRepository.findOne(item.getCollectorId())).thenReturn(new Collector()); + when(componentRepository.findById(compId).get()).thenReturn(component); + when(collectorRepository.findById(item.getCollectorId()).get()).thenReturn(new Collector()); EnvironmentComponent c_qa_api = makeEnvComponent("QA", "API", "1.1", true); EnvironmentComponent c_qa_ui = makeEnvComponent("QA", "UI", "1.1", true); @@ -175,9 +175,9 @@ public void testGetDeployStatus_MultipleServers() { item2.setId(ObjectId.get()); item2.setCollectorId(ObjectId.get()); component.getCollectorItems().put(CollectorType.Deployment, Arrays.asList(item, item2)); - when(componentRepository.findOne(compId)).thenReturn(component); - when(collectorRepository.findOne(item.getCollectorId())).thenReturn(new Collector()); - when(collectorRepository.findOne(item2.getCollectorId())).thenReturn(new Collector()); + when(componentRepository.findById(compId).get()).thenReturn(component); + when(collectorRepository.findById(item.getCollectorId()).get()).thenReturn(new Collector()); + when(collectorRepository.findById(item2.getCollectorId()).get()).thenReturn(new Collector()); EnvironmentComponent c_qa_api = makeEnvComponent("QA", "API", "1.1", true); EnvironmentComponent c_qa_ui = makeEnvComponent("QA", "UI", "1.1", true); @@ -341,7 +341,7 @@ public void getDeployStatusSearchesAllPossibleCollectorNamesForMatches() { .thenReturn(Collections.emptyList()); Collector collector = makeCollector(); collector.setLastExecuted(234234L); - when(collectorRepository.findOne(any())) + when(collectorRepository.findById(any()).get()) .thenReturn(collector); DataResponse> envs = deployService.getDeployStatus("appName"); assertEquals(234234L,envs.getLastUpdated()); @@ -397,7 +397,7 @@ public void createDeployRequest_v2() throws Exception { DeployDataCreateRequest request = makeDataCreateRequest(); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); @@ -417,7 +417,7 @@ public void createDeployRequest() throws Exception { DeployDataCreateRequest request = makeDataCreateRequest(); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); diff --git a/src/test/java/com/capitalone/dashboard/service/DynamicPipelineServiceImplTest.java b/src/test/java/com/capitalone/dashboard/service/DynamicPipelineServiceImplTest.java index a0be0ffb..c814252d 100644 --- a/src/test/java/com/capitalone/dashboard/service/DynamicPipelineServiceImplTest.java +++ b/src/test/java/com/capitalone/dashboard/service/DynamicPipelineServiceImplTest.java @@ -149,8 +149,8 @@ public void testSearch() throws HygieiaException { List environments = setupEnvironments(); List binaryArtifacts = setupBinaryArtifacts(); - Mockito.when(collectorItemRepository.findOne(Mockito.eq(COLLECTOR_ITEM_PIPELINE_ID))).thenReturn(pipelineCI); - Mockito.when(dashboardRepository.findOne(Mockito.eq(DASHBOARD_ID))).thenReturn(dashboard); + Mockito.when(collectorItemRepository.findById(Mockito.eq(COLLECTOR_ITEM_PIPELINE_ID)).get()).thenReturn(pipelineCI); + Mockito.when(dashboardRepository.findById(Mockito.eq(DASHBOARD_ID)).get()).thenReturn(dashboard); Mockito.when(commitService.search(Mockito.any(CommitRequest.class))).thenReturn(new DataResponse<>(commits, 0)); Mockito.when(buildService.search(Mockito.any(BuildSearchRequest.class))).thenReturn(new DataResponse<>(builds, 0)); Mockito.when(deployService.getDeployStatus(Mockito.eq(COMPONENT_ID))).thenReturn(new DataResponse<>(environments, 0)); @@ -223,8 +223,8 @@ public void testPipeline() { List environments = setupEnvironments(); List binaryArtifacts = setupBinaryArtifacts(); - Mockito.when(collectorItemRepository.findOne(Mockito.eq(COLLECTOR_ITEM_PIPELINE_ID))).thenReturn(pipelineCI); - Mockito.when(dashboardRepository.findOne(Mockito.eq(DASHBOARD_ID))).thenReturn(dashboard); + Mockito.when(collectorItemRepository.findById(Mockito.eq(COLLECTOR_ITEM_PIPELINE_ID)).get()).thenReturn(pipelineCI); + Mockito.when(dashboardRepository.findById(Mockito.eq(DASHBOARD_ID)).get()).thenReturn(dashboard); Mockito.when(commitService.search(Mockito.any(CommitRequest.class))).thenReturn(new DataResponse<>(commits, 0)); Mockito.when(buildService.search(Mockito.any(BuildSearchRequest.class))).thenReturn(new DataResponse<>(builds, 0)); Mockito.when(deployService.getDeployStatus(Mockito.eq(COMPONENT_ID))).thenReturn(new DataResponse<>(environments, 0)); diff --git a/src/test/java/com/capitalone/dashboard/service/FeatureServiceImplTest.java b/src/test/java/com/capitalone/dashboard/service/FeatureServiceImplTest.java index d1e321cb..a4668812 100644 --- a/src/test/java/com/capitalone/dashboard/service/FeatureServiceImplTest.java +++ b/src/test/java/com/capitalone/dashboard/service/FeatureServiceImplTest.java @@ -217,8 +217,8 @@ public void cleanup() { @Test public void testGetFeatureEstimates_ManySameSuperFeatures_OneSuperFeatureRs() { - when(componentRepository.findOne(mockComponentId)).thenReturn(mockComponent); - when(collectorRepository.findOne(mockItem2.getCollectorId())).thenReturn(mockJiraCollector); + when(componentRepository.findById(mockComponentId).get()).thenReturn(mockComponent); + when(collectorRepository.findById(mockItem2.getCollectorId()).get()).thenReturn(mockJiraCollector); when(featureRepository.findByActiveEndingSprints(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Arrays.asList(mockJiraFeature, mockJiraFeature2)); @@ -234,8 +234,8 @@ public void testGetFeatureEstimates_ManySameSuperFeatures_OneSuperFeatureRs() { @Test public void testGetFeatureEstimates_ManySameSuperFeatures_OneSuperFeatureRs_Hours() { - when(componentRepository.findOne(mockComponentId)).thenReturn(mockComponent); - when(collectorRepository.findOne(mockItem2.getCollectorId())).thenReturn(mockJiraCollector); + when(componentRepository.findById(mockComponentId).get()).thenReturn(mockComponent); + when(collectorRepository.findById(mockItem2.getCollectorId()).get()).thenReturn(mockJiraCollector); when(featureRepository.findByActiveEndingSprints(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Arrays.asList(mockJiraFeature, mockJiraFeature2)); @@ -251,8 +251,8 @@ public void testGetFeatureEstimates_ManySameSuperFeatures_OneSuperFeatureRs_Hour @Test public void testGetCurrentSprintDetail_ValidKanbanTeam_ShowKanban() { - when(componentRepository.findOne(mockComponentId)).thenReturn(mockComponent); - when(collectorRepository.findOne(mockItem3.getCollectorId())).thenReturn(mockJiraCollector); + when(componentRepository.findById(mockComponentId).get()).thenReturn(mockComponent); + when(collectorRepository.findById(mockItem3.getCollectorId()).get()).thenReturn(mockJiraCollector); when(featureRepository.findByUnendingSprints(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyBoolean())) .thenReturn(Arrays.asList(mockJiraFeature3_oldkanban)); @@ -268,8 +268,8 @@ public void testGetCurrentSprintDetail_ValidKanbanTeam_ShowKanban() { @Test public void testGetRelevantStories_Kanban() { - when(componentRepository.findOne(mockComponentId)).thenReturn(mockComponent); - when(collectorRepository.findOne(mockItem3.getCollectorId())).thenReturn(mockJiraCollector); + when(componentRepository.findById(mockComponentId).get()).thenReturn(mockComponent); + when(collectorRepository.findById(mockItem3.getCollectorId()).get()).thenReturn(mockJiraCollector); when(featureRepository.findByUnendingSprints(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyBoolean())).thenReturn(Arrays.asList(mockJiraFeature3_oldkanban, mockJiraFeature4_sprintkanban)); when(featureRepository.findByNullSprints(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyBoolean())).thenReturn(Arrays.asList(mockJiraFeature5_nullkanban)); @@ -281,8 +281,8 @@ public void testGetRelevantStories_Kanban() { @Test public void testGetRelevantStories_Scrum() { - when(componentRepository.findOne(mockComponentId)).thenReturn(mockComponent); - when(collectorRepository.findOne(mockItem3.getCollectorId())).thenReturn(mockJiraCollector); + when(componentRepository.findById(mockComponentId).get()).thenReturn(mockComponent); + when(collectorRepository.findById(mockItem3.getCollectorId()).get()).thenReturn(mockJiraCollector); when(featureRepository.findByActiveEndingSprints(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(Arrays.asList(mockJiraFeature, mockJiraFeature2)); DataResponse> result = featureService.getRelevantStories(mockComponentId, @@ -293,8 +293,8 @@ public void testGetRelevantStories_Scrum() { @Test public void testGetAggregatedSprintEstimates_Scrum() { - when(componentRepository.findOne(mockComponentId)).thenReturn(mockComponent); - when(collectorRepository.findOne(mockItem3.getCollectorId())).thenReturn(mockJiraCollector); + when(componentRepository.findById(mockComponentId).get()).thenReturn(mockComponent); + when(collectorRepository.findById(mockItem3.getCollectorId()).get()).thenReturn(mockJiraCollector); when(featureRepository.findByActiveEndingSprints(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(Arrays.asList(mockJiraFeature, mockJiraFeature2)); DataResponse result = featureService.getAggregatedSprintEstimates(mockComponentId, mockJiraFeature3_oldkanban.getsTeamID(), mockJiraFeature3_oldkanban.getsProjectID(), Optional.of("scrum"), Optional.of("storypoints")); @@ -307,8 +307,8 @@ public void testGetAggregatedSprintEstimates_Scrum() { @Test public void testGetAggregatedSprintEstimates_Kanban() { - when(componentRepository.findOne(mockComponentId)).thenReturn(mockComponent); - when(collectorRepository.findOne(mockItem3.getCollectorId())).thenReturn(mockJiraCollector); + when(componentRepository.findById(mockComponentId).get()).thenReturn(mockComponent); + when(collectorRepository.findById(mockItem3.getCollectorId()).get()).thenReturn(mockJiraCollector); when(featureRepository.findByUnendingSprints(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyBoolean())).thenReturn(Arrays.asList(mockJiraFeature3_oldkanban, mockJiraFeature4_sprintkanban)); when(featureRepository.findByNullSprints(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyBoolean())).thenReturn(Arrays.asList(mockJiraFeature5_nullkanban)); diff --git a/src/test/java/com/capitalone/dashboard/service/GenericCollectorItemServiceImplTest.java b/src/test/java/com/capitalone/dashboard/service/GenericCollectorItemServiceImplTest.java index 5c76b1ae..b16c218c 100644 --- a/src/test/java/com/capitalone/dashboard/service/GenericCollectorItemServiceImplTest.java +++ b/src/test/java/com/capitalone/dashboard/service/GenericCollectorItemServiceImplTest.java @@ -145,6 +145,6 @@ public void loadCollector() throws IOException { String json = IOUtils.toString(BinaryArtifactServiceTest.class.getResourceAsStream("coll.json")); List collector = gson.fromJson(json, new TypeToken>() { }.getType()); - collectorRepository.save(collector); + collectorRepository.saveAll(collector); } } \ No newline at end of file diff --git a/src/test/java/com/capitalone/dashboard/service/GitRequestServiceTest.java b/src/test/java/com/capitalone/dashboard/service/GitRequestServiceTest.java index cc0fa35a..0e9f1118 100644 --- a/src/test/java/com/capitalone/dashboard/service/GitRequestServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/GitRequestServiceTest.java @@ -50,8 +50,8 @@ public void searchTest() { GitRequestRequest request = new GitRequestRequest(); request.setComponentId(componentId); - when(componentRepository.findOne(request.getComponentId())).thenReturn(makeComponent(collectorItemId, collectorId, true)); - when(collectorRepository.findOne(collectorId)).thenReturn(collector); + when(componentRepository.findById(request.getComponentId()).get()).thenReturn(makeComponent(collectorItemId, collectorId, true)); + when(collectorRepository.findById(collectorId).get()).thenReturn(collector); gitRequestService.search(request,"pull", "all"); @@ -67,8 +67,8 @@ public void search_Empty_Response_No_CollectorItems() { GitRequestRequest request = new GitRequestRequest(); request.setComponentId(componentId); - when(componentRepository.findOne(request.getComponentId())).thenReturn(makeComponent(collectorItemId, collectorId, false)); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(componentRepository.findById(request.getComponentId()).get()).thenReturn(makeComponent(collectorItemId, collectorId, false)); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); DataResponse> response = gitRequestService.search(request, "pull", "all"); @@ -82,8 +82,8 @@ public void search_Empty_Response_No_Component() { GitRequestRequest request = new GitRequestRequest(); - when(componentRepository.findOne(request.getComponentId())).thenReturn(null); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(componentRepository.findById(request.getComponentId()).get()).thenReturn(null); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); DataResponse> response = gitRequestService.search(request, "pull", "all"); diff --git a/src/test/java/com/capitalone/dashboard/service/LogAnalysisServiceImplTest.java b/src/test/java/com/capitalone/dashboard/service/LogAnalysisServiceImplTest.java index 2c58ad79..c7e1407e 100644 --- a/src/test/java/com/capitalone/dashboard/service/LogAnalysisServiceImplTest.java +++ b/src/test/java/com/capitalone/dashboard/service/LogAnalysisServiceImplTest.java @@ -71,7 +71,7 @@ public void collectorItemNotFoundReturnsEmptyResponse() { long startTime = System.currentTimeMillis()-1000; LogAnalysisSearchRequest request = new LogAnalysisSearchRequest(); request.setComponentId(ObjectId.get()); - when(mockComponentRepository.findOne(any(ObjectId.class))).thenReturn(null); + when(mockComponentRepository.findById(any(ObjectId.class)).get()).thenReturn(null); DataResponse> response =subject.search(request); @@ -86,7 +86,7 @@ public void collectorItemFoundButNotOfType(){ LogAnalysisSearchRequest request = new LogAnalysisSearchRequest(); request.setComponentId(ObjectId.get()); Component component = mock(Component.class); - when(mockComponentRepository.findOne(any(ObjectId.class))).thenReturn(component); + when(mockComponentRepository.findById(any(ObjectId.class)).get()).thenReturn(component); when(component.getFirstCollectorItemForType(eq(CollectorType.Log))).thenReturn(null); DataResponse> response =subject.search(request); @@ -102,7 +102,7 @@ public void collectorItemReturnsWhenFound() { LogAnalysisSearchRequest request = new LogAnalysisSearchRequest(); request.setComponentId(ObjectId.get()); Component component = mock(Component.class); - when(mockComponentRepository.findOne(any(ObjectId.class))).thenReturn(component); + when(mockComponentRepository.findById(any(ObjectId.class)).get()).thenReturn(component); CollectorItem item = mock(CollectorItem.class); when(component.getFirstCollectorItemForType(eq(CollectorType.Log))).thenReturn(item); ObjectId itemId = ObjectId.get(); @@ -114,7 +114,7 @@ public void collectorItemReturnsWhenFound() { when(mockLogAnalyzerRepository.findAll(any(Predicate.class),any(OrderSpecifier.class))).thenReturn(items); Collector mockCollector = mock(Collector.class); - when(mockCollectorRepository.findOne(any(ObjectId.class))).thenReturn(mockCollector); + when(mockCollectorRepository.findById(any(ObjectId.class)).get()).thenReturn(mockCollector); when(mockCollector.getLastExecuted()).thenReturn(23L); DataResponse> response =subject.search(request); @@ -141,7 +141,7 @@ public void supportsMaxResults() { request.setMax(100); request.setComponentId(ObjectId.get()); Component component = mock(Component.class); - when(mockComponentRepository.findOne(any(ObjectId.class))).thenReturn(component); + when(mockComponentRepository.findById(any(ObjectId.class)).get()).thenReturn(component); CollectorItem item = mock(CollectorItem.class); when(component.getFirstCollectorItemForType(eq(CollectorType.Log))).thenReturn(item); ObjectId itemId = ObjectId.get(); @@ -154,7 +154,7 @@ public void supportsMaxResults() { when(mockLogAnalyzerRepository.findAll(any(Predicate.class),any(PageRequest.class))).thenReturn(items); Collector mockCollector = mock(Collector.class); - when(mockCollectorRepository.findOne(any(ObjectId.class))).thenReturn(mockCollector); + when(mockCollectorRepository.findById(any(ObjectId.class)).get()).thenReturn(mockCollector); when(mockCollector.getLastExecuted()).thenReturn(23L); DataResponse> response =subject.search(request); diff --git a/src/test/java/com/capitalone/dashboard/service/PipelineServiceTest.java b/src/test/java/com/capitalone/dashboard/service/PipelineServiceTest.java index f1ec15f5..9871661b 100644 --- a/src/test/java/com/capitalone/dashboard/service/PipelineServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/PipelineServiceTest.java @@ -74,8 +74,8 @@ public void search() throws Exception { pipelines.add(pipeline); when(pipelineRepository.findByCollectorItemId(dashboardCollectorItemId)).thenReturn(pipeline); - when(collectorItemRepository.findOne(pipeline.getCollectorItemId())).thenReturn(dashboardCollectorItem); - when(dashboardRepository.findOne(new ObjectId((String)dashboardCollectorItem.getOptions().get("dashboardId")))).thenReturn(dashboard); + when(collectorItemRepository.findById(pipeline.getCollectorItemId()).get()).thenReturn(dashboardCollectorItem); + when(dashboardRepository.findById(new ObjectId((String)dashboardCollectorItem.getOptions().get("dashboardId"))).get()).thenReturn(dashboard); PipelineResponse expected = makePipelineResponse(pipeline, dashboard); diff --git a/src/test/java/com/capitalone/dashboard/service/ServiceServiceTest.java b/src/test/java/com/capitalone/dashboard/service/ServiceServiceTest.java index e684fdc9..ac9d902d 100644 --- a/src/test/java/com/capitalone/dashboard/service/ServiceServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/ServiceServiceTest.java @@ -59,7 +59,7 @@ public void dashboardDependentServices() { public void get() { ObjectId id = ObjectId.get(); serviceService.get(id); - verify(serviceRepository).findOne(id); + verify(serviceRepository).findById(id).get(); } @Test @@ -72,21 +72,29 @@ public void create() { List owners = new ArrayList<>(); owners.add(new Owner("amit", AuthType.STANDARD)); final Dashboard dashboard = new Dashboard("template", "title", new Application("app"), owners, DashboardType.Team, "ASVTEST","BAPTEST",activeWidgets, false, ScoreDisplayType.HEADER); - when(dashboardRepository.findOne(id)).thenReturn(dashboard); + when(dashboardRepository.findById(id).get()).thenReturn(dashboard); Service service=serviceService.create(id, name,url); verify(serviceRepository).save(argThat(new ArgumentMatcher() { - @Override - public boolean matches(Object o) { - - Service service = (Service) o; - //return true; - return service.getName().equals(name) && - service.getDashboardId().equals(id) && - service.getStatus().equals(ServiceStatus.Warning) && - service.getApplicationName().equals(dashboard.getApplication().getName()); - } +// @Override +// public boolean matches(Object o) { +// +// Service service = (Service) o; +// //return true; +// return service.getName().equals(name) && +// service.getDashboardId().equals(id) && +// service.getStatus().equals(ServiceStatus.Warning) && +// service.getApplicationName().equals(dashboard.getApplication().getName()); +// } + @Override + public boolean matches(Service argument) { + return argument.getName().equals(name) && + argument.getDashboardId().equals(id) && + argument.getStatus().equals(ServiceStatus.Warning) && + argument.getApplicationName().equals(dashboard.getApplication().getName()); + } + })); } @@ -111,8 +119,8 @@ public void update() throws IOException { verify(serviceRepository).save(argThat(new ArgumentMatcher() { @Override - public boolean matches(Object o) { - return ((Service) o).getLastUpdated() > 0; + public boolean matches(Service argument) { + return argument.getLastUpdated() > 0; } })); } @@ -123,7 +131,7 @@ public void delete() { ObjectId serviceId = ObjectId.get(); Service service = new Service(); service.setDashboardId(dashId); - when(serviceRepository.findOne(serviceId)).thenReturn(service); + when(serviceRepository.findById(serviceId).get()).thenReturn(service); serviceService.delete(dashId, serviceId); @@ -136,15 +144,14 @@ public void addDependentService() { ObjectId serviceId = ObjectId.get(); Service service = new Service(); service.setDashboardId(ObjectId.get()); - when(serviceRepository.findOne(serviceId)).thenReturn(service); + when(serviceRepository.findById(serviceId).get()).thenReturn(service); serviceService.addDependentService(dashId, serviceId); verify(serviceRepository).save(argThat(new ArgumentMatcher() { - @Override - public boolean matches(Object o) { - Service service = (Service) o; - return service.getDependedBy().contains(dashId); + @Override + public boolean matches(Service argument) { + return argument.getDependedBy().contains(dashId); } })); } @@ -155,16 +162,21 @@ public void deleteDependentService() { ObjectId serviceId = ObjectId.get(); Service service = new Service(); service.setDashboardId(dashId); - when(serviceRepository.findOne(serviceId)).thenReturn(service); + when(serviceRepository.findById(serviceId).get()).thenReturn(service); serviceService.deleteDependentService(dashId, serviceId); verify(serviceRepository).save(argThat(new ArgumentMatcher() { - @Override - public boolean matches(Object o) { - Service service = (Service) o; - return !service.getDependedBy().contains(dashId); - } +// @Override +// public boolean matches(Object o) { +// Service service = (Service) o; +// return !service.getDependedBy().contains(dashId); +// } + + @Override + public boolean matches(Service argument) { + return !argument.getDependedBy().contains(dashId); + } })); } diff --git a/src/test/java/com/capitalone/dashboard/service/TeamServiceImplTest.java b/src/test/java/com/capitalone/dashboard/service/TeamServiceImplTest.java index c7d43160..66ceb144 100644 --- a/src/test/java/com/capitalone/dashboard/service/TeamServiceImplTest.java +++ b/src/test/java/com/capitalone/dashboard/service/TeamServiceImplTest.java @@ -164,8 +164,8 @@ public void cleanup() { @Test public void testGetTeam() { - when(componentRepository.findOne(mockComponentId)).thenReturn(mockComponent); - when(collectorRepository.findOne(mockItem2.getCollectorId())).thenReturn(mockJiraCollector); + when(componentRepository.findById(mockComponentId).get()).thenReturn(mockComponent); + when(collectorRepository.findById(mockItem2.getCollectorId()).get()).thenReturn(mockJiraCollector); when(teamRepository.findByTeamId(Mockito.anyString())) .thenReturn(mockJiraTeam); diff --git a/src/test/java/com/capitalone/dashboard/service/TemplateServiceTest.java b/src/test/java/com/capitalone/dashboard/service/TemplateServiceTest.java index 807bb60c..671912c1 100644 --- a/src/test/java/com/capitalone/dashboard/service/TemplateServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/TemplateServiceTest.java @@ -54,7 +54,7 @@ public void test_update() throws Exception { public void test_find() throws Exception { ObjectId templateId = ObjectId.get(); Template template = new Template("template1", getWidgetsAndOrder(), getWidgetsAndOrder()); - when(templateRepository.findOne(templateId)).thenReturn(template); + when(templateRepository.findById(templateId).get()).thenReturn(template); Template actual = templateService.get(templateId); assertEquals(actual, template); } diff --git a/src/test/java/com/capitalone/dashboard/service/TestResultServiceTest.java b/src/test/java/com/capitalone/dashboard/service/TestResultServiceTest.java index 2c2d9223..657b9384 100644 --- a/src/test/java/com/capitalone/dashboard/service/TestResultServiceTest.java +++ b/src/test/java/com/capitalone/dashboard/service/TestResultServiceTest.java @@ -52,7 +52,7 @@ public void createWithGoodRequest() throws HygieiaException { TestDataCreateRequest request = makeTestDateCreateRequest(); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); @@ -70,7 +70,7 @@ public void createV2WithGoodRequest() throws HygieiaException { TestDataCreateRequest request = makeTestDateCreateRequest(); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); @@ -89,8 +89,8 @@ public void search_Empty_Response_No_CollectorItems() { TestResultRequest request = new TestResultRequest(); - when(componentRepository.findOne(request.getComponentId())).thenReturn(makeComponent(collectorItemId, collectorId, false)); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(componentRepository.findById(request.getComponentId()).get()).thenReturn(makeComponent(collectorItemId, collectorId, false)); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); DataResponse> response = testResultService.search(request); @@ -103,8 +103,8 @@ public void search_Empty_Response_No_Component() { ObjectId collectorId = ObjectId.get(); TestResultRequest request = new TestResultRequest(); - when(componentRepository.findOne(request.getComponentId())).thenReturn(null); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(componentRepository.findById(request.getComponentId()).get()).thenReturn(null); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); DataResponse> response = testResultService.search(request); @@ -301,7 +301,7 @@ public void createWithGoodCucumberRequest() throws HygieiaException { TestCreateRequest request = makePrefTestCreateRequest(); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); when(apiSettings.getFunctional()).thenReturn( new HashMap() {{ @@ -323,7 +323,7 @@ public void createWithGoodJunitTestRequest() throws HygieiaException { TestCreateRequest request = makeJunitTestCreateRequest("PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48dGVzdHN1aXRlIGVycm9ycz0iMCIgZmFpbHVyZXM9IjAiIGhvc3RuYW1lPSJzb21lSG9zdCIgbmFtZT0ic2FtcGxlVGVzdCIgc2tpcHBlZD0iMCIgdGVzdHM9IjEiIHRpbWU9IjAuNTU1IiB0aW1lc3RhbXA9IjIwMjAtMTEtMDVUMTI6MjQ6MDIuMjkzNTQyIj48dGVzdGNhc2UgY2xhc3NuYW1lPSJ0ZXN0cy5zYW1wbGVUZXN0Q2FzZSIgbmFtZT0idGVzdF9kdW1teSIgdGltZT0iMC4wMDEiIC8+PC90ZXN0c3VpdGU+"); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); when(apiSettings.getUnit()).thenReturn("junit"); @@ -342,7 +342,7 @@ public void createWithGoodJunitTestRequestV2() throws HygieiaException { TestCreateRequest request = makeJunitTestCreateRequest("PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48dGVzdHN1aXRlcz48dGVzdHN1aXRlIGVycm9ycz0iMCIgZmFpbHVyZXM9IjAiIGhvc3RuYW1lPSJzb21lSG9zdCIgbmFtZT0ic2FtcGxlVGVzdCIgc2tpcHBlZD0iMCIgdGVzdHM9IjEiIHRpbWU9IjAuNTU1IiB0aW1lc3RhbXA9IjIwMjAtMTEtMDVUMTI6MjQ6MDIuMjkzNTQyIj48dGVzdGNhc2UgY2xhc3NuYW1lPSJ0ZXN0cy5zYW1wbGVUZXN0Q2FzZSIgbmFtZT0idGVzdF9kdW1teSIgdGltZT0iMC4wMDEiIC8+PC90ZXN0c3VpdGU+PC90ZXN0c3VpdGVzPg=="); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); when(apiSettings.getUnit()).thenReturn("junit"); @@ -361,7 +361,7 @@ public void createWithGoodJunitTestRequestV2MultipleTestsuites() throws HygieiaE TestCreateRequest request = makeJunitTestCreateRequest("PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48dGVzdHN1aXRlcz48dGVzdHN1aXRlIGVycm9ycz0iMCIgZmFpbHVyZXM9IjAiIGhvc3RuYW1lPSJzb21lSG9zdDEiIG5hbWU9InNhbXBsZVRlc3QxIiBza2lwcGVkPSIwIiB0ZXN0cz0iMSIgdGltZT0iMC41NTUiIHRpbWVzdGFtcD0iMjAyMC0xMS0wNVQxMjoyNDowMi4yOTM1NDIiPjx0ZXN0Y2FzZSBjbGFzc25hbWU9InRlc3RzLnNhbXBsZVRlc3RDYXNlIiBuYW1lPSJ0ZXN0X2R1bW15IiB0aW1lPSIwLjAwMSIgLz48L3Rlc3RzdWl0ZT48dGVzdHN1aXRlIGVycm9ycz0iMCIgZmFpbHVyZXM9IjAiIGhvc3RuYW1lPSJzb21lSG9zdDIiIG5hbWU9InNhbXBsZVRlc3QyIiBza2lwcGVkPSIwIiB0ZXN0cz0iMiIgdGltZT0iMC41NTUiIHRpbWVzdGFtcD0iMjAyMC0xMS0wNVQxMjoyNDowMi4yOTM1NDIiPjx0ZXN0Y2FzZSBjbGFzc25hbWU9InRlc3RzLnNhbXBsZVRlc3RDYXNlMSIgbmFtZT0idGVzdF9kdW1teTEiIHRpbWU9IjAuMDAxIiAvPjx0ZXN0Y2FzZSBjbGFzc25hbWU9InRlc3RzLnNhbXBsZVRlc3RDYXNlMiIgbmFtZT0idGVzdF9kdW1teTIiIHRpbWU9IjAuMDAxIiAvPjwvdGVzdHN1aXRlPjwvdGVzdHN1aXRlcz4="); - when(collectorRepository.findOne(collectorId)).thenReturn(new Collector()); + when(collectorRepository.findById(collectorId).get()).thenReturn(new Collector()); when(collectorService.createCollector(any(Collector.class))).thenReturn(new Collector()); when(collectorService.createCollectorItem(any(CollectorItem.class))).thenReturn(new CollectorItem()); when(apiSettings.getUnit()).thenReturn("junit"); diff --git a/src/test/java/com/capitalone/dashboard/util/TestUtil.java b/src/test/java/com/capitalone/dashboard/util/TestUtil.java index 01bbcd48..2d917960 100644 --- a/src/test/java/com/capitalone/dashboard/util/TestUtil.java +++ b/src/test/java/com/capitalone/dashboard/util/TestUtil.java @@ -54,7 +54,7 @@ public static void loadCollector(CollectorRepository collectorRepository) throws String json = IOUtils.toString(Resources.getResource("./collectors/coll.json")); List collector = gson.fromJson(json, new TypeToken>() { }.getType()); - collectorRepository.save(collector); + collectorRepository.saveAll(collector); } public static void loadComponent(ComponentRepository componentRepository) throws IOException { Gson gson = GsonUtil.getGson(); @@ -66,6 +66,6 @@ public static void loadCollectorItems(CollectorItemRepository collectorItemRepos Gson gson = GsonUtil.getGson(); String json = IOUtils.toString(Resources.getResource("./collector_items/items.json")); List collectorItem = gson.fromJson(json, new TypeToken>(){}.getType()); - collectorItemRepository.save(collectorItem); + collectorItemRepository.saveAll(collectorItem); } } \ No newline at end of file