我得到的错误是
java.lang.IndexOutOfBoundsException:索引:0,大小:0
在第5行。因为响应只有一个空数组。阵列将在调试模式下完美填充。调试并不容易。不确定是否重要。谢谢您的时间。
请在下面找到Java测试和属性文件。
@Test
public void testApplication() throws Exception {
String ResourceUrl = "/mdh/v";
String values = "205,2019-12-31";
ResponseEntity<String> response = testRestTemplate.getForEntity(ResourceUrl, String.class);
@SuppressWarnings("unchecked")
List<Map<String, String>> list = objectMapper.readValue(response.getBody(), List.class);
Iterator<Map.Entry<String, String>> it = list.get(0).entrySet().iterator();
String expected_values[] = values.split(",", -1);
int i = 0;
while (it.hasNext()) {
Map.Entry<String, String> entry = it.next();
if (expected_values[i].isEmpty())
assertEquals(String.valueOf("null"), String.valueOf(entry.getValue()));
else if (isValidInteger(expected_values[i].trim(), 10)) {
assertEquals(Integer.valueOf(expected_values[i]), Integer.valueOf(String.valueOf(entry.getValue())));
} else if (isValidDouble(expected_values[i].trim())) {
assertEquals(Double.valueOf(expected_values[i]), Double.valueOf(String.valueOf(entry.getValue())));
} else if (isValidDate(expected_values[i].trim())
&& (expected_values[i].contentEquals(String.valueOf(entry.getValue())) == false)) {
Long ts = Long.valueOf(String.valueOf(entry.getValue()));
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dt = formatter.format(ts);
assertEquals(expected_values[i], dt);
} else {
assertEquals(expected_values[i], String.valueOf(entry.getValue()));
}
i++;
}
assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
HttpHeaders httpHeaders = testRestTemplate.headForHeaders(ResourceUrl);
assertTrue(httpHeaders.getContentType().includes(MediaType.APPLICATION_JSON));
}
```
application-test.properties:
spring.datasource.url=jdbc:h2:mem:testdb;MODE=MYSQL;
spring.datasource.username=sa
spring.datasource.password=password
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.platform=h2
m.t.tableName=MOCK_TF_m_t_RESULT
spring.datasource.hikari.connection-timeout=600000
spring.datasource.hikari.minimum-idle=80
spring.datasource.hikari.maximum-pool-size=80
spring.datasource.hikari.idle-timeout=60000
spring.datasource.hikari.max-lifetime=6000
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.maxLifetime=6000000
#m.t.marketData.where[1] = WHERE upper(${m.t.aClass.column}) = upper('%1$s') AND upper(${m.t.service.column}) = upper('%2$s') AND ${m.t.vDate.column} = DATE '%3$s'
#m.t.marketData.where[2] = WHERE upper(${m.t.aClass.column}) = upper('%1$s') AND upper(${m.t.service.column}) = upper('%2$s') AND ${m.t.vDate.column} = DATE '%3$s' AND upper(${m.t.vDate.subArea.column}) = upper('%4$s') AND upper(${m.t.vDate.serviceFrequency.column}) = upper('%5$s')
#m.t.marketData.sql[0]= SELECT ${m-t-result.columnList.cdities} FROM ${m.t.tableName} WHERE upper(${m.t.aClass.column}) = upper('%1$s') AND upper(${m.t.service.column}) = upper('%2$s') AND ${m.t.vDate.column} = '%3$s';
#m.t.marketData.sql[0]= SELECT ${m-t-result.columnList.cdities} FROM MOCK_TF_m_t_RESULT WHERE upper(${m.t.aClass.column}) = upper('%1$s') AND upper(${m.t.service.column}) = upper('%2$s') AND ${m.t.vDate.column} = PARSEDATETIME('%3$s','dd-MMMM-yy');
m.t.marketData.vDate.Condn = ${m.t.vDate.column} = PARSEDATETIME('%3$s','dd-MMMM-yy')
m-t-result.columnList.interestRates=ClientID,vDate,aClass,ServiceName,ServiceFrequency,SubArea
#spring.jpa.hibernate.ddl-auto=none
#disable spring.jpa.hibernate.ddl-auto if you use schema.sql.
#spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
```