我有一个简单的插件,其 greet任务是执行一些“Hello World”打印。
plugins {
id 'java-gradle-plugin'
id 'groovy'
id 'maven-publish'
}
group = 'standalone.plugin2.greeting'
version = '1.0'
gradlePlugin {
plugins {
greeting {
id = 'standalone.plugin2.greeting'
implementationClass = 'standalone.plugin2.StandalonePlugin2Plugin'
}
}
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'standalone.plugin2.greeting'
version = '1.0'
from components.java
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我有跑步者应用程序来运行greet task
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath 'standalone.plugin2.greeting:standalone-plugin2:1.0'
}
}
apply plugin: 'standalone.plugin2.greeting'
Run Code Online (Sandbox Code Playgroud)
使用apply plugin符号它可以正常工作,但是当我使用插件符号时,如下所示:
plugins {
id 'standalone.plugin2.greeting' version '1.0'
} …Run Code Online (Sandbox Code Playgroud) 有这个简单的片段。
@Component
public class SomeDependency {
public Optional<Integer> getSomeInt(String string) {
return Optional.of(1);
}
}
@Component
public class SomeService {
@Autowired
private SomeDependency someDependency;
public String someMethod(String string) {
return String.valueOf(someDependency.getSomeInt(string).get());
}
}
@RunWith(MockitoJUnitRunner.class)
public class SomeServiceTest {
@Mock
private SomeDependency someDependency;
@InjectMocks
private SomeService someService;
@Test
public void test() {
when(someDependency.getSomeInt(anyString()))
.thenReturn(Optional.of(111));
String value = someService.someMethod("test");
assertThat(value, is("111"));
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我运行测试时,一切正常,但是当我在调试模式下运行它,同时在 when...thenReturn... mock 和 use 上设置断点时step over,会引发以下错误。
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
Optional cannot be returned by toString()
toString() should return …Run Code Online (Sandbox Code Playgroud) 我有以下代码段:
List<O> os = new ArrayList<>();
os.add(new O("A", 3, "x"));
os.add(new O("A", 2, "y"));
os.add(new O("B", 1, "z"));
Comparator<O> byA = Comparator.comparing(O::getA);
Comparator<O> byB = Comparator.comparing(O::getB);
// I want to use rather this...
List<Comparator<O>> comparators = new ArrayList<>();
comparators.add(byA);
comparators.add(byB);
os.stream()
.sorted(byB.thenComparing(byA))
.forEach(o -> System.out.println(o.getC()));
Run Code Online (Sandbox Code Playgroud)
如您所见,我使用显式两个比较器进行排序.但是如果我在某个列表中有未知数量的比较器并且我想按它们排序呢?有什么办法吗?或者应该使用旧时尚方式比较器与多个ifs?
我有非常简单的 SpringBoot 项目,具有简单的配置和简单的集成测试来测试 WebSockets。
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sandbox.websocket</groupId>
<artifactId>websocket</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
SpringBoot应用:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
消息代理配置
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/topic");
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 我有一个接口的两个实现 - default 和 dev。我使用@ConditionalOnProperty了默认的实施和组合@Profile,并@ConditionalOnMissingBean为开发实施。
@Service
@ConditionalOnProperty(prefix = "keystore", value = "file")
public class DefaultKeyStoreService implements KeyStoreService {
@Service
@Profile("dev")
@ConditionalOnMissingBean(KeyStoreService.class)
public class DevKeyStoreService implements KeyStoreService {
Run Code Online (Sandbox Code Playgroud)
现在,问题正在测试DevKeyStoreServiceTest中DevKeyStoreService。我有这样的配置:
@SpringBootTest(
classes = {DevKeyStoreService.class},
properties = {"keystore.file="}
)
@RunWith(SpringRunner.class)
@ActiveProfiles("dev")
public class DevKeyStoreServiceTest {
@Autowired
private DevKeyStoreService tested;
@Test
public void testPrivateKey() {
} //... etc.
Run Code Online (Sandbox Code Playgroud)
结果是:
Negative matches:
-----------------
DevKeyStoreService:
Did not match:
- @ConditionalOnMissingBean (types: service.crypto.KeyStoreService; SearchStrategy: all) found bean …Run Code Online (Sandbox Code Playgroud) 我正在玩Azure asp.net开发.我使用Visual Studio 2010,Azure SDK,我是Azure云的新手.
我创建了几个应用程序并将它们部署到我的测试Azure网站.一切正常 - ASP.NET Web Page,ASP.NET MVC3,甚至是我之前创建的Azure SQL数据库的简单GridView绑定,我使用ADO.NET管理Microsoft SQL Management Studio.这很简单.
现在,我从一些教程中了解到,我需要使用Windows Azure云服务项目来确保我的应用程序能够正常运行.但它也没有这个项目.那么我在解决方案中究竟需要这样一个项目呢?
我的页面中有一个组合,我希望在配置中填充一些关键字.我想使用托管bean来完成它.
假设我有一个名为Config的bean,其中有一个List categories字段...
public class Configuration implements Serializable {
private static final long serialVersionUID = 1L;
private List<String> categories;
public List<String> getCategories() {
if (categories == null)
categories = getCats();
return categories;
}
//... etc.
}
Run Code Online (Sandbox Code Playgroud)
当我将这个字段用于我的组合时,它运作良好......
<xp:comboBox>
<xp:selectItems>
<xp:this.value><![CDATA[#{config.categories}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
Run Code Online (Sandbox Code Playgroud)
但是,它只是一个标签列表.我也需要价值观.如何用两个字符串填充我的组合的selectItems - 标签和值?
编辑:
我尝试使用标签和值字段创建一个对象组合,并在我的comboBox中使用重复.
<xp:comboBox>
<xp:repeat id="repeat1" value="#{config.combo}" var="c" rows="30">
<xp:selectItem itemLabel="#{c.label}" itemValue="#{c.value}" />
</xp:repeat>
</xp:comboBox>
Run Code Online (Sandbox Code Playgroud)
还是行不通... :-(
我有一些事件发布:
@Autowired private final ApplicationEventPublisher publisher;
...
publisher.publishEvent(new MyApplicationEvent(mySource));
Run Code Online (Sandbox Code Playgroud)
我有这个事件监听器:
class MyApplicationEventHandler {
@Autowired SomeDependency someDependency;
@EventListener public void processEvent(final MyApplicationEvent event) {
// handle event...
}
}
Run Code Online (Sandbox Code Playgroud)
我需要使用EasyMock进行测试。有没有一种简单的方法可以在测试中发布某些内容并断言我的事件侦听器做了什么?
编辑:
我试图创建这样的模拟测试:
// testing class
SomeDependency someDependency = mock(SomeDependency.class);
MyApplicationEventHandler tested = new MyApplicationEventHandler(someDependency);
@Autowired private final ApplicationEventPublisher publisher;
@Test
public void test() {
someDependency.doSomething(anyObject(SomeClass.class));
replay();
publisher.publishEvent(new MyApplicationEvent(createMySource()));
}
Run Code Online (Sandbox Code Playgroud)
没用
java.lang.AssertionError:
Expectation failure on verify:
SomeDependency.doSomething(<any>): expected: 1, actual: 0
Run Code Online (Sandbox Code Playgroud) 我是 docker 的新手。我想用我的 Web 应用程序创建一个图像。我需要一些应用程序服务器,例如 wlp,然后我需要一些数据库,例如 postgres。
wlp 有一个 Docker 映像,postgres 有一个 Docker 映像。
所以我创建了以下简单的 Dockerfile。
FROM websphere-liberty:javaee7
FROM postgres:latest
Run Code Online (Sandbox Code Playgroud)
现在,也许它很蹩脚,但是当我构建这个图像时
docker build -t wlp-db .
Run Code Online (Sandbox Code Playgroud)
运行容器
docker run -it --name wlp-db-test wlp-db
Run Code Online (Sandbox Code Playgroud)
并检查它
docker exec -it wlp-db-test /bin/bash
Run Code Online (Sandbox Code Playgroud)
只有 postgres 正在运行,而 wlp 甚至不在那里。目录/opt为空。
我错过了什么?
函数 TO_NUMBER 在1.4.x的H2 路线图中作为优先级 2。但在最新版本 1.4.196 中它仍然不受支持。谁能告诉我,我可以期望在哪个版本中支持此功能?
java ×3
spring ×3
asp.net ×1
asp.net-mvc ×1
azure ×1
docker ×1
gradle ×1
h2 ×1
java-8 ×1
java-stream ×1
mockito ×1
sorting ×1
spring-boot ×1
unit-testing ×1
xpages ×1