我正在寻找一个模拟StopWatch的java类(如Spring的StopWatch或Commons的StopWatch),但它会给出最小,最大和平均时间.也优选在最后n次运行中的平均值.
有这样的事情还是我自己建造它?
问候,
维姆
我正在使用Spring Boot 1.1.3 CommonsMultipartResolver来允许一次上传多个文件.
当我尝试上传大于1 MB的文件时,我得到了这个堆栈跟踪:
Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException:
The field files[] exceeds its maximum permitted size of 1048576 bytes.
at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:637)
at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76)
at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:135)
at java.io.FilterInputStream.read(FilterInputStream.java:107)
Run Code Online (Sandbox Code Playgroud)
我尝试设置这样的最大上传大小:
public MultipartResolver multipartResolver()
{
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setMaxUploadSize( 100 * MEGABYTE_IN_BYTES );
return resolver;
}
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.我已经找到了关于upoading文件的Spring指南,他们在那里使用了MultipartConfigFactory.但是,我现在需要使用MultipartFile该类而不是MultipartHttpServletRequest在我的控制器中.
随着MultipartHttpServletRequest我能做getFileMap()得到的所有文件,但上没有这样的方法MultipartFile.
有关如何使用MultipartConfigFactory和多个文件的任何想法?我在客户端上使用jquery-file-upload,如果这很重要的话.
我试图用Mockito取代JMock(1.10.17).我已经成功完成了一些单元测试,但现在我想使用超时功能
verify(publisher, timeout(5000)).notifySubscribers(any(BecameMasterMessage.class));
Run Code Online (Sandbox Code Playgroud)
我得到这个例外:
java.lang.VerifyError: (class: org/mockito/internal/verification/VerificationOverTimeImpl, method: verify signature: (Lorg/mockito/internal/verification/api/VerificationData;)V) Incompatible argument to function
at org.mockito.verification.Timeout.<init>(Timeout.java:32)
at org.mockito.verification.Timeout.<init>(Timeout.java:25)
at org.mockito.Mockito.timeout(Mockito.java:2164)
Run Code Online (Sandbox Code Playgroud)
问题发生在IntelliJ和Maven中.类路径上只有一个版本的Mockito.在类路径上还有JMock 2.5.1,我无法删除,因为此时99%的单元测试仍然使用JMock.我不知道这与它有什么关系.
更新:我尝试使用JMock 2.6.0和Hamcrest 1.3,但结果是一样的.
更新2:
这有效:
Thread.sleep( 5000 );
verify( m_publisher ).notifySubscribers( any( BecameMasterMessage.class ) );
Run Code Online (Sandbox Code Playgroud)
而这不是:
verify(publisher, timeout(5000)).notifySubscribers(any(BecameMasterMessage.class));
Run Code Online (Sandbox Code Playgroud)
更新3:我做了一个小测试项目,它有完全相同的问题:请参阅https://github.com/wimdeblauwe/mockito-verify-problem并从IntelliJ或Maven运行它.
很多地方都说明,如果要在MySQL中使用JDBC,并且支持UTF-8,则需要useUnicode=true在JDBC URL中添加。
例如:
但是,我在 Mac OS X 上使用 MySQL 5.7.19 和 mysql-connector-java 5.1.41(由 Spring Boot 1.5.3 引入)在本地尝试了这个。我添加了一个文件/etc/my.cnf:
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
Run Code Online (Sandbox Code Playgroud)
这确保 MySQL 设置为 UTF-8:
mysql> SHOW VARIABLES LIKE 'character_set%';
+--------------------------+-----------------------------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | …Run Code Online (Sandbox Code Playgroud) 我将 Spring Boot 2.2.1 与spring-security-oauth2-resource-server:5.2.0.RELEASE. 我想写一个集成测试来测试安全性是否可以。
我WebSecurityConfigurerAdapter在我的应用程序中定义了这个:
import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer;
import org.springframework.security.oauth2.core.DelegatingOAuth2TokenValidator;
import org.springframework.security.oauth2.core.OAuth2Error;
import org.springframework.security.oauth2.core.OAuth2TokenValidator;
import org.springframework.security.oauth2.core.OAuth2TokenValidatorResult;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.security.oauth2.jwt.JwtDecoder;
import org.springframework.security.oauth2.jwt.JwtValidators;
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
private final OAuth2ResourceServerProperties properties;
private final SecuritySettings securitySettings;
public WebSecurityConfiguration(OAuth2ResourceServerProperties properties, SecuritySettings securitySettings) {
this.properties = properties;
this.securitySettings = securitySettings;
}
@Override
protected void configure(HttpSecurity http) …Run Code Online (Sandbox Code Playgroud) IntelliJ社区版是否提供UML类图功能?我只有社区版,并且已经查看了菜单中的每个位置。
我在弹簧启动项目中使用H2作为内存数据库进行单元测试.但是我得到了以下错误
Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:196)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:160)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1885)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1862)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839)
at org.hibernate.loader.Loader.doQuery(Loader.java:910)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
at org.hibernate.loader.Loader.doList(Loader.java:2554)
at org.hibernate.loader.Loader.doList(Loader.java:2540)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
at org.hibernate.loader.Loader.list(Loader.java:2365)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:495)
at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getSingleResult(CriteriaQueryTypeQueryAdapter.java:71)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:202)
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:74)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:97)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:88)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:395)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:373)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$DefaultMethodInvokingMethodInterceptor.invoke(RepositoryFactorySupport.java:486)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) …Run Code Online (Sandbox Code Playgroud) 我有一个 Angular Web 应用程序,我想使用 Jenkins 声明式管道将其作为工件发布到 Artifactory。我该怎么做呢?
我刚刚将我的项目从 Spring Boot 2.1 迁移到 2.3,因此现在有 JUnit 5(带有 Vintage)(还包括版本 3.3.3 的 mockito-core 和 mockito-junit-jupiter)。虽然所有 JUnit 4 测试工作正常,但我的第一个 JUnit 5 测试工作不正常:
@ExtendWith(MockitoExtension.class)
public class SomeTest {
@InjectMocks
private Some to;
@Mock
private SomeProperties properties;
@Test
public void applied() {
....
//properties is null -> NPE
when(properties.getSome()).thenReturn("some");
....
}
Run Code Online (Sandbox Code Playgroud)
没有注入模拟(when 语句中的 NPE)。如果我切换到旧的 JUnit 4 样式,@RunWith(MockitoJUnitRunner.class)一切正常。
那么可能使用的是旧跑步者还是复古跑步者?
如何解决此问题并使用“@ExtendWith”进行测试?我以为我可以逐步迁移 - 让新测试使用 junit5 runner 运行。
我有一个类,它具有三个不应从某些类调用的方法。
我如何使用 Archunit 检查这一点?
例如
public class Foo {
public void method1() {
}
public void method2() {
}
public void method3() {
}
}
Run Code Online (Sandbox Code Playgroud)
method1 和 method2 只能由类 Bar1 和 Bar2 调用。