下面我只是尝试模拟一个名为 TestWrapper 的类并对其设置“允许”期望。然而,在设定期望时我遇到了错误。当使用 easymock 并只是设置期望时,这似乎不会发生
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.Before;
import org.junit.Test;
import java.math.BigDecimal;
public class CustomerPaymentProgramConverterTest {
TestWrapper paymentType;
Mockery mockery = new JUnit4Mockery() {{
setImposteriser(ClassImposteriser.INSTANCE);
}};
@Before
public void setupMethod() {
paymentType = mockery.mock(TestWrapper.class);
}
@Test
public void testFromWebService() {
mockery.checking(new Expectations() {{
//debugger throws error on the line below.
allowing(paymentType.getScheduledPaymentAmount());
will(returnValue(new BigDecimal(123)));
allowing(paymentType.getScheduledPaymentConfirmationNumber());
will(returnValue(121212L));
}});
}
}
Run Code Online (Sandbox Code Playgroud)
TestWrapper.class
//Class I am mocking using JMock
public class TestWrapper {
public java.math.BigDecimal getScheduledPaymentAmount() { …Run Code Online (Sandbox Code Playgroud) Amazon Athena 使用提交查询的用户的 IAM 凭证从输入 Amazon S3 存储桶读取数据;查询结果存储在单独的S3存储桶中。
这是 Hashicorp 网站https://www.terraform.io/docs/providers/aws/r/athena_database.html中的脚本
resource "aws_s3_bucket" "hoge" {
bucket = "hoge"
}
resource "aws_athena_database" "hoge" {
name = "database_name"
bucket = "${aws_s3_bucket.hoge.bucket}"
}
Run Code Online (Sandbox Code Playgroud)
哪里说的
bucket - (Required) Name of s3 bucket to save the results of the query execution.
Run Code Online (Sandbox Code Playgroud)
如何在 terraform 脚本中指定输入 S3 存储桶?
我正在寻找一个解决方案来模拟子类ButtonClicker中的超级调用.
Class Click {
public void buttonClick() throws java.lang.Exception { /* compiled code */ } }
Class ButtonClicker extends Click {
@Override
public void buttonClick() throws Exception {
super.buttonClick();
} }
Run Code Online (Sandbox Code Playgroud) 我正在使用Jasypt 1.9,当我尝试用感叹号加密密码时,它失败了.没有感叹号,它工作正常
对于前:
./encrypt.sh input="abc!abc"
-sh: !abc": event not found
Run Code Online (Sandbox Code Playgroud)
Jasypt声称它已在此修复.. http://www.jasypt.org/changelogs/jasypt/ChangeLog.txt
注意:
./encrypt.sh input="abc\!abc" works, but decrypting produces the "abc\!abc"
Run Code Online (Sandbox Code Playgroud) 我需要编写一个select查询从Spring Data Repository层中的多个表中获取数据.我知道我们可以使用@Query编写自定义查询,但只返回单个表中的值?
SELECT s.service_id, s.name, us.rating_id
FROM services s,
ratings r,
user_services us
where
us.service_id = s.service_id and
us.rating_id = r.rating_id and
us.user_id= ?;
Run Code Online (Sandbox Code Playgroud) 我在项目中实现了非对称加密,使用"公钥"来"加密"消息,使用"私钥"来"解密"消息.
我们是否曾使用"私钥"来"加密"消息,并使用"公钥"来"解密".如果是,有人可以给我一个用例,这种密码术也称为"非对称加密"
java encryption cryptography public-key-encryption private-key
我有Java Web服务,并使用Java Keytool创建的jks文件实现了X.509.
keytool -genkey -keyalg RSA -sigalg SHA1withRSA -validity 730 -alias myservicekey -keypass skpass -storepass sspass -keystore serviceKeystore.jks -dname "cn=localhost"
keytool -genkey -keyalg RSA -sigalg SHA1withRSA -validity 730 -alias myclientkey -keypass ckpass -storepass cspass -keystore clientKeystore.jks -dname "cn=clientuser"
Run Code Online (Sandbox Code Playgroud)
要在客户端和服务器之间建立信任,我将服务器证书导入客户端和客户端证书到服务器.
将服务器公钥(证书)导入客户端.
keytool -export -rfc -keystore clientKeystore.jks -storepass cspass -alias myclientkey -file MyClient.cer
keytool -import -trustcacerts -keystore serviceKeystore.jks -storepass sspass -alias myclientkey -file MyClient.cer -noprompt
Run Code Online (Sandbox Code Playgroud)
将客户端公钥(certs)导入服务器
keytool -export -rfc -keystore serviceKeystore.jks -storepass sspass -alias myservicekey -file MyService.cer
keytool -import -trustcacerts -keystore …Run Code Online (Sandbox Code Playgroud) 问题: Spring切入点表达式可以在非托管Spring组件(例如域对象)上运行吗?从我的实验来看,它似乎没有,那么在常规对象上运行切入点表达式的最佳方法是什么?
我创建了自定义批注名称@Encrypt,以便在域对象中的字段顶部使用它时,该字段将发送到Web服务并自动加密。
我首先从方法级注释开始,发现切入点表达式不适用于不受Spring管理的对象,它必须是Spring bean。
1. Spring Aspect:检查自定义注释@Encrypt并打印出来。
@Aspect
public class EncryptAspect {
@Around("@annotation(encrypt)")
public Object logAction(ProceedingJoinPoint pjp, Encrypt encrypt)
throws Throwable {
System.out.println("Only encrypt annotation is running!");
return pjp.proceed();
}
}
Run Code Online (Sandbox Code Playgroud)
2.自定义注释:
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Encrypt
{
// Handled by EncryptFieldAspect
}
Run Code Online (Sandbox Code Playgroud)
3.使用注释的域对象
public interface CustomerBo {
void addCustomerAround(String name);
}
public class CustomerBoImpl implements CustomerBo {
@Encrypt
public void addCustomerAround(String name){
System.out.println("addCustomerAround() is running, args : " + name);
}
}
Run Code Online (Sandbox Code Playgroud)
4.调用
ApplicationContext appContext = …Run Code Online (Sandbox Code Playgroud) 要将ec2实例连接到S3或RDS,通常需要给ec2实例一个具有适当权限的角色,对吗?
如果我将ec2-instance放在一个SecurityGroup中,而将s3 / RD3放在另一个Security Group中,那么是否仅赋予S3 / RDS角色和对ec2的权限就足够了?
试图了解我何时应该使用角色组与安全组来允许各种AWS资源相互通信。
amazon-s3 amazon-ec2 amazon-web-services amazon-rds amazon-iam
为了实现Kafka消费者对消息的一次性处理,我一次只提交一条消息,如下所示
public void commitOneRecordConsumer(long seconds) {
KafkaConsumer<String, String> consumer = consumerConfigFactory.getConsumerConfig();
try {
while (running) {
ConsumerRecords<String, String> records = consumer.poll(1000);
try {
for (ConsumerRecord<String, String> record : records) {
processingService.process(record);
consumer.commitSync(Collections.singletonMap(new TopicPartition(record.topic(),record.partition()), new OffsetAndMetadata(record.offset() + 1)));
System.out.println("Committed Offset" + ": " + record.offset());
}
} catch (CommitFailedException e) {
// application specific failure handling
}
}
} finally {
consumer.close();
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码将消息的处理异步委托给下面的另一个类.
@Service
public class ProcessingService {
@Async
public void process(ConsumerRecord<String, String> record) throws InterruptedException {
Thread.sleep(5000L);
Map<String, …Run Code Online (Sandbox Code Playgroud) java ×6
amazon-s3 ×2
jmock ×2
spring ×2
amazon-ec2 ×1
amazon-iam ×1
amazon-rds ×1
annotations ×1
apache-kafka ×1
assertion ×1
cryptography ×1
easymock ×1
encryption ×1
hql ×1
jasypt ×1
jks ×1
junit ×1
keytool ×1
mockito ×1
pfx ×1
private-key ×1
seam ×1
spring-aop ×1
spring-data ×1
terraform ×1
unit-testing ×1
x509 ×1