小编Joh*_*eke的帖子

如何对Spring Boot MongoRepository进行单元测试?

在我的Spring Boot Web应用程序中,我使用MongoDB来存储数据.在应用程序中,我使用扩展的接口访问数据库MongoRepository.

如何为此类存储库类设置单元测试?我想要的是

  • 启动MongoDB的嵌入式/内存实例
  • 从JSON或XML插入testdata
  • 使用自动装配的存储库对testdata执行查询

我尝试过使用Embedded MongoDB,但我无法弄清楚如何从文件中插入testdata.我也尝试使用NoSQLUnit,但SpringApplicationConfiguration与单元测试配置冲突,导致不同的数据库进行读写.

mongodb spring-data-mongodb spring-boot

10
推荐指数
3
解决办法
6358
查看次数

在iOS上使用RNCryptor加密/解密大文件时出现内存问题

我正在尝试使用RNCryptor加密和解密iOS上的大文件(600 + MB).在github上,我找到了关于如何在流上异步使用库的示例代码.此代码类似于Rob Napier关于同一主题的问题的答案.

但是,虽然我认为我正确实现了代码,但该应用程序使用高达1.5 GB的内存(在iPad 6.1模拟器中).我认为代码应该阻止应用程序在内存中保留多个数据块?出了什么问题?

在我的控制器中,我创建了一个'CryptController',我用加密/解密请求发送消息.

  // Controller.m
  NSString *password = @"pw123";
  self.cryptor = [[CryptController alloc] initWithPassword:password];

  //start encrypting file
  [self.cryptor streamEncryptRequest:self.fileName andExtension:@"pdf" withURL:[self samplesURL]];

  //wait for encryption to finish
  NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:1];
  do {
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
                             beforeDate:timeout];
  } while (![self.cryptor isFinished]);
Run Code Online (Sandbox Code Playgroud)

在CryptController我有:

- (void)streamEncryptionDidFinish {
  if (self.cryptor.error) {
    NSLog(@"An error occurred. You cannot trust decryptedData at this point");
  }
  else {
    NSLog(@"%@ is complete. Use it as you like", [self.tempURL …
Run Code Online (Sandbox Code Playgroud)

memory objective-c ios rncryptor

9
推荐指数
1
解决办法
3175
查看次数

JPA/Hibernate双向多对一导致StackOverflowException

我有实体User和GrantedRole具有双向一对多关系.

当我尝试将GrantedRole添加到Set in User时,没有抛出异常,但是当我调试User和GrantedRole对象的变量时,会有一个读取的描述

com.sun.jdi.InvocationException发生了调用方法.

调试时可以读取变量的不同字段,但是当我选择User中的角色字段或GrantedRole中的用户字段时,我得到与上面相同的描述.当我进入用户的Set of GrantedRole时,我最终找到以下描述:

详细格式化程序错误:发生异常:java.lang.StackOverflowError

我的代码:

public class User {
    private Set<GrantedRole> roles = new HashSet<GrantedRole>();

    public User() {
        super();
    }
    public User(String name, String password) {
        this.name = name;
        this.password = password;
    }

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
    public Set<GrantedRole> getRoles() {
        return roles;
    }

    public void setRoles(Set<GrantedRole> roles) {
        this.roles = roles;
    }

    // equals and hashCode are based on username
    // toString is based on all fields
}

public class GrantedRole { …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa bidirectional one-to-many

8
推荐指数
1
解决办法
8648
查看次数

JPA加入多列

我有实体User,Organization和GrantedRole。它们之间的关系是,GrantedRole定义了用户在组织中的角色。这三个实体都从其超类继承字段“ id”(用@Id注释)。组织没有对GrantedRole或User的引用,这些关系是单向的。

@Entity
@Table(name = "role_assignments", uniqueConstraints = @UniqueConstraint(columnNames = {
    "user_id", "organization_id" }))
public class GrantedRole extends DomainEntity implements GrantedAuthority {

    public static enum Role {
        ROLE_MODM_USER, ROLE_MODM_ORGADMIN, ROLE_MODM_ADMIN
    }

    private User user;
    private Role role;
    private Organization organization;

    public static enum Role {
        ROLE_MODM_USER, ROLE_MODM_ORGADMIN, ROLE_MODM_ADMIN
    }

    @ManyToOne
    @NotNull
    public User getUser() {
        return user;
    }

    @NotNull
    @Enumerated(EnumType.STRING)
    public Role getRole() {
        return role;
    }

    @ManyToOne
    public Organization getOrganization() {
        return organization;
    }

    // Some setters
}

@Entity …
Run Code Online (Sandbox Code Playgroud)

java jpa inner-join

3
推荐指数
1
解决办法
9491
查看次数