我需要测试一个使用另一个接口作为与 lambda 使用者的依赖注入的类。
@Builder
public class Interactor {
private final Gateway gateway;
void process(String message, Consumer<String> response){
gateway.process(message, uuid -> {
response.accept(uuid.toString());
});
}
}
Run Code Online (Sandbox Code Playgroud)
依赖项定义如下:
public interface Gateway {
void process(String message, Consumer<UUID> uuid);
}
Run Code Online (Sandbox Code Playgroud)
我将如何模拟网关,以便为我的测试提供 UUID 值响应?
这是我迄今为止尝试过的:
@Test
void whillReturnTheInjectedUUIDValueTest() {
UUID uuid = UUID.randomUUID();
Gateway gateway = Mockito.mock(Gateway.class);
Mockito.when(gateway.process("ignored", uuid1 -> {return uuid;}));
Interactor.builder().gateway(gateway).build().process("ignored", s -> {
Assertions.assertEquals(uuid.toString(), s);
});
}
Run Code Online (Sandbox Code Playgroud)
我应该如何向消费者提供返回值?
我想将我的EE应用程序迁移到OSGi.我的应用程序包括业务库,数据库JPA/Entities和REST/WS接口.它还有一个Web客户端.
我首先对结构进行原型设计,并使所有接口和捆绑包以OSGi方式相互通信.我希望在没有任何特定供应商或框架的情况下尽可能使用干净的规范.
我正在使用bnd maven插件来生成清单和声明性服务.我想使用注入从我的其余资源调用OSGI服务(在另一个包上),如下所示:
@Path("some-resources")
@Component
public class SomeResources{
private SomeService service = null;
@Reference
public void setController(SomeService service) { // <- this is never called
this.service = service;
}
@GET
@Produces(javax.ws.rs.core.MediaType.APPLICATION_XML)
public Object getSomeService() { // <- called
try {
service.process("Hello World"); // <- Error null object
}
...
}
Run Code Online (Sandbox Code Playgroud)
我可以使用bnd注释资源@Component并且可以@Resource注入吗?一切正常,但服务始终为空.
为BND声明我的捆绑包以使其成为web/wab包的方法应该是什么?
我使用maven包:
<packaging>bundle</packaging>
...
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<dependencies>
<dependency>
<groupId>biz.aQute</groupId>
<artifactId>bndlib</artifactId>
<version>1.50.0</version>
</dependency>
</dependencies>
<configuration>
<supportedProjectTypes>
<supportedProjectType>ejb</supportedProjectType>
<supportedProjectType>war</supportedProjectType>
<supportedProjectType>wab</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
<supportedProjectType>jar</supportedProjectType>
</supportedProjectTypes> …Run Code Online (Sandbox Code Playgroud) 对于分页数据(分页)我需要返回符合我的条件和结果第一页的记录总数.这对于显示用户的信息并计算预期的总页数(在客户端上)非常有用.
目前我运行相同的查询两次,一次是总计数,一次是实际记录.我希望有一种更有效的方式.
可以将这两个查询合并为一次调用数据库吗?
伯爵:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<VersionJpa> r = cq.from(VersionJpa.class);
Predicate p = cb.conjunction();
p = // some filtering code define by caller
cq.where(p);
cq.select(cb.count(r));
TypedQuery<Long> tq = em.createQuery(cq);
return tq.getSingleResult().intValue();
Run Code Online (Sandbox Code Playgroud)
这页纸:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<VersionJpa> cq = cb.createQuery(VersionJpa.class);
Root<VersionJpa> root = cq.from(VersionJpa.class);
Predicate p = cb.conjunction();
p = // same filtering code as in the count above
cq.where(p);
TypedQuery<VersionJpa> tq = em.createQuery(cq);
// paginatong
tq.setFirstResults(first); // from caller
tq.setMaxResults(max); // from caller …Run Code Online (Sandbox Code Playgroud) 使用 gradle 4.7
我想为测试集成类添加新的源集。与主测试源集分开,它将有一些其他依赖项,并且将有单独的任务来运行测试。
可以使用自定义 java gradle 插件来完成吗?
这是代码和使用它的项目。
https://github.com/gadieichhorn/gradle-java-multimodule/tree/master/buildSrc
因为这些测试使用从构建生成的 docker 镜像,所以它应该只在构建之后运行,而不是像正常测试那样。
任何样本或贡献将不胜感激。
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
SourceSet main = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
SourceSet test = javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);
final Configuration integrationImplementation = project.getConfigurations().create("integrationImplementation")
.setExtendsFrom(Arrays.asList(project.getConfigurations().getByName("testImplementation")))
.setVisible(false)
.setDescription("Integration Implementation");
project.getDependencies().add(integrationImplementation.getName(), "org.testcontainers:testcontainers:1.7.1");
final Configuration integrationRuntimeOnly = project.getConfigurations().create("integrationRuntimeOnly")
.setExtendsFrom(Arrays.asList(project.getConfigurations().getByName("testRuntimeOnly")))
.setVisible(false)
.setDescription("Integration Runtime Only ");
// project.getDependencies().add(integrationRuntimeOnly.getName(), "org.testcontainers:testcontainers:1.7.1");
final SourceSet integration = javaConvention.getSourceSets().create("integration", sourceSet -> {
sourceSet.getJava().srcDir(Arrays.asList("src/integration/java"));
sourceSet.getResources().srcDir("src/integration/resources");
sourceSet.setCompileClasspath(project.files(main.getOutput(), test.getOutput()));
sourceSet.setRuntimeClasspath(project.files(main.getOutput(), test.getOutput()));
sourceSet.setRuntimeClasspath(sourceSet.getOutput());
});
project.getTasks().create("e2e", Test.class, e2e -> {
e2e.setTestClassesDirs(integration.getOutput().getClassesDirs());
e2e.setClasspath(integration.getRuntimeClasspath());
});
});
Run Code Online (Sandbox Code Playgroud) 我有一个J2EE应用程序,需要进行大量的集成测试。我正在使用Jmeter生成HTTP POST请求。到目前为止,我设法将它们正确发送到服务器,但是xml是静态的。
我正在寻找一种将动态/随机值插入XML,然后将其发送到服务器的方法。类似于预处理器,但我不确定如何完成。
任何人都可以提供:
1. JMeter教程?
2.如何为HTTP请求生成动态/随机xml内容
3. JMeter示例
非常感谢,
加迪。
我有这个服务器 API 用于帐户分页
{
accounts (offset: 2, limit: 1) {
key
name
}
}
Run Code Online (Sandbox Code Playgroud)
使用 Graphiql 一切正常
{
"data": {
"accounts": [
{
"key": "fde3d97d-6a44-4c36-bc59-149a3e8e51ac",
"name": "a0f353611567c83e"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我按照 Apollo 文档将我的 Web 客户端连接到后端。默认查询有效,但是当我尝试添加变量时,我在服务器端收到此错误。
WARN g.GraphQL - Query failed to validate : 'query Accounts($offset: Int, $limit: Int) {
accounts(offset: $offset, limit: $limit) {
key
name
__typename
}
}
Run Code Online (Sandbox Code Playgroud)
我的角度(7)代码如下所示:
import { Component, OnInit } from "@angular/core";
import { Apollo, QueryRef } from "apollo-angular";
import { DocumentNode } from …Run Code Online (Sandbox Code Playgroud) 我有一个java EE应用程序EE5 EJB3.我使用NetBeans 6.7和GlassFish 2.x开发我需要一个部署/客户端特定的配置文件(*.xsl,*.xml).
我的问题是:
1)我在哪里放置ear文件外部的文件?
2)如何将文件加载到会话bean中?我可以使用注射吗?
我设法使用ejb-jar.xml为文件名注入@Resource.
提前谢谢了.G.
我需要 JMX 和 Java EE 方面的指导。
我知道(经过几周的研究)就部署而言,JMX 规范是缺失的。我正在寻找的供应商特定实现很少,但没有一个是跨供应商的。我想自动部署 MBean 并在服务器上注册。我需要服务器在部署应用程序时加载和注册我的 MBeand,并在取消部署应用程序时删除它。
我使用以下软件进行开发:NetBean 6.7.1、GlassFish 2.1、Java EE 5、EJB 3
更具体地说,我需要一种管理计时器服务运行的方法。我的应用程序需要运行不同的归档代理和批量报告。我希望 JMX 能够让我远程访问以创建和管理计时器服务,并使用户能够创建自己的时间表。如果 JMX 在应用程序部署时自动注册,用户可以立即连接并管理计划。另一方面,EJB 如何连接/访问 MBean?
提前谢谢了。加迪。
我正在尝试使用@Embeddablewith根据嵌入的属性CriteriaBuilder过滤父项Entity的结果。我使用 Eclipse Link 来生成元数据类。
这是嵌入的类/实体:
@Embeddable
public class Stamp implements Serializable {
@Basic()
@Column(name = "stamp_year", nullable = false)
private int year;
Run Code Online (Sandbox Code Playgroud)
父类具有Stamp作为成员:
@Entity(name = "Message")
public class Message implements Serializable {
@Embedded
private Stamp stamp = new Stamp();
Run Code Online (Sandbox Code Playgroud)
现在这段代码应该使用Message基于嵌入类属性年份的类和过滤结果:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Message> cq = cb.createQuery(Message.class);
Root<Message> root = cq.from(Message.class);
Predicate p = cb.conjunction();
p = ??????
cq.where(p);
TypedQuery<Message> tq = em.createQuery(cq);
List<Message> messages = tq.getResultList();
Run Code Online (Sandbox Code Playgroud)
在第 5 …
java ×5
ejb-3.0 ×2
java-ee ×2
jpa ×2
angular ×1
angular7 ×1
bnd ×1
criteria ×1
docker ×1
eclipselink ×1
embeddable ×1
glassfish ×1
gradle ×1
graphql ×1
jakarta-ee ×1
jax-rs ×1
jmeter ×1
jmx ×1
junit ×1
lambda ×1
metamodel ×1
mockito ×1
osgi ×1
plugins ×1
rest ×1
typescript ×1
unit-testing ×1
xml ×1