我希望从返回类型的方法中轻松提取值Either<Exception, Object>。
我正在做一些测试,但无法轻松测试我的方法的返回。
例如:
final Either<ServerException, TokenModel> result = await repository.getToken(...);
Run Code Online (Sandbox Code Playgroud)
为了测试我能够做到这一点
expect(result, equals(Right(tokenModelExpected))); // => OK
Run Code Online (Sandbox Code Playgroud)
现在如何直接检索结果?
final TokenModel modelRetrieved = Left(result); ==> Not working..
Run Code Online (Sandbox Code Playgroud)
我发现我必须这样投:
final TokenModel modelRetrieved = (result as Left).value; ==> But I have some linter complain, that telling me that I shouldn't do as to cast on object...
Run Code Online (Sandbox Code Playgroud)
我也想测试异常但它不起作用,例如:
expect(result, equals(Left(ServerException()))); // => KO
Run Code Online (Sandbox Code Playgroud)
所以我试过这个
expect(Left(ServerException()), equals(Left(ServerException()))); // => KO as well, because it says that the instances are different.
Run Code Online (Sandbox Code Playgroud) 我有一个JHipster应用程序正在运行,我想知道日志文件在哪里.他们在哪里生成?(这是一个新手问题,但找不到任何东西)
我在默认配置的"Dev"配置文件中.(没有改变关于application-dev.yml的任何内容)
谢谢.
我正在使用apache POI用Java读取和写入Excels的文件,但是我无法在源代码中找到WorkbookFactory或XSSFWorkbook来读取xlsx文件.
pom.xml:
<poi.version>3.13</poi.version>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我在apache poi的更改日志中找不到任何可能导致此行为的信息.
编辑:这里是我的实现(暂时只是一个简单的方法)
public static HSSFSheet getXLSSheet(String fileName, int sheetIndex) throws IOException {
InputStream inputStream = new FileInputStream(fileName);
HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
return workbook.getSheetAt(sheetIndex);
}
Run Code Online (Sandbox Code Playgroud)
我试图打开一个XLSX文件,但由于我找不到其他两个类(WorkbookFactory或XSSFWorkbook),我应该有这样的错误:
org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of …Run Code Online (Sandbox Code Playgroud) 在特定方法上测试我的rest控制器时出现错误。我正在使用@Query注释来进行数据库查询。它使用“ principal.username”来完成。我没有关于如何在应用程序中获取并使用principal.username的全部图片。我目前正在查看有关它的spring-security文档。但是我的问题出在测试部分,当我执行下面的测试时,由于出现错误“ Faillure” @Query。
仓库:
public interface MeetingRepository extends JpaRepository<Meeting,Long> {
@Query("select m from Meeting m where m.visibility = 'PUBLIC' OR m.user.login = ?#{principal.username}")
List<Meeting> findOpenAndUserMeetings();
}
Run Code Online (Sandbox Code Playgroud)
休息控制器方法:
@RequestMapping(value = "/api/meetings", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Meeting>> getAll()
{
List<Meeting> meetings = MeetingRepository.findOpenAndUserMeetings();
return new ResponseEntity<List<Meeting>>(meetings, HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)
一个测试:
@Test
@Transactional
public void getAllMeetings() throws Exception {
// Initialize the database
MeetingRepository.saveAndFlush(Meeting);
// Get all the Meetinges
restMeetingMockMvc.perform(get("/api/meetings"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
Run Code Online (Sandbox Code Playgroud)
而这个错误:
getAllMeetings(com.ent.web.rest.MeetingResourceTest) Time elapsed: …Run Code Online (Sandbox Code Playgroud) 我正在使用Jackson CSV生成CSV文件,但我希望到处都有引用.我找不到关于ApiDoc的任何信息.
CSV编写器
CsvMapper mapper = new CsvMapper();
//objects is a list
CsvSchema schema = mapper.schemaFor(objects).withHeader();
schema = schema.withQuoteChar('\"');
Run Code Online (Sandbox Code Playgroud)
预期产出
"name","value"
"fieldName1","5"
"fieldName2","2"
"fieldName3","5"
Run Code Online (Sandbox Code Playgroud)
实际产出
name,value
fieldName1,5
fieldName2,2
fieldName3,5
Run Code Online (Sandbox Code Playgroud)
的pom.xml
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-csv</artifactId>
<version>2.6.3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
如果杰克逊不可能,我可以尝试另一个图书馆.谢谢.
我正在做一些C++测试,我不明白下面的代码:
class A
{
public:
A(int n = 0): m_n(n)
{
std::cout << 'd';
}
A(const A& a): m_n(a.m_n)
{
std::cout << 'c';
}
private:
int m_n;
};
void f(const A &a1)
{
}
int main()
{
//Call 'f' function and prints: d
f(3);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么在这里调用构造函数并打印'd'?
谢谢.
我无法创建枚举以在MySQL DB中保存为字符串.我有一个带有字段的MySQL表:
status varchar(50)
枚举
public enum Status {OPEN, CLOSED, CANCELLED, DONE}
Run Code Online (Sandbox Code Playgroud)
实体
@Column(name="status", nullable=false)
private Status status;
@Enumerated(EnumType.STRING)
public Status getStatus() {return status;}
Run Code Online (Sandbox Code Playgroud)
当我启动我的应用程序时,我在获取数据时出现以下错误: SQLException:getInt()'OPEN'的值无效
另外我无法创建实体,我有一个SQLGrammarError.它试图用status = OPEN而不是status ='OPEN'来保存对象.
我按照文档JavaDoc Persistence Enum 编写了 本教程Jpa和Enums
通过在属性状态上添加@Enumerated(EnumType.STRING).提取错误不存在,但我仍然有相同的错误来创建实体.
错误日志
[DEBUG] com.vallois.valcrm.web.rest.BusinessResource - REST request to save Business : Business{id=null, name='test', description='okokok', createUpdateInfo=CreateUpdateInfo{createdUsername='user', updatedUsername='null', createdDate=Thu May 21 16:04:54 CEST 2015, updatedDate=null}, status=CLOSED, lock=PUBLIC}
Hibernate: insert into BUSINESS (created_date, created_name, updated_date, u pdated_name, description, lock, name, status, user_id) values (?, ?, ?, …Run Code Online (Sandbox Code Playgroud)