use of org.junit.jupiter.params.provider.ValueSource in project dhis2-core by dhis2.
the class TeiUpdateTests method shouldReturnErrorWhenTeiDoesntExist.
@ParameterizedTest
@ValueSource(strings = { "UPDATE", "DELETE" })
public void shouldReturnErrorWhenTeiDoesntExist(String importStrategy) throws Exception {
JsonObject teiBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/teis/tei.json"));
ApiResponse response = trackerActions.postAndGetJobReport(teiBody, new QueryParamsBuilder().add(String.format("importStrategy=%s", importStrategy)));
response.validate().statusCode(200).body("status", equalTo("ERROR")).body("stats.ignored", equalTo(1)).body("validationReport.errorReports", notNullValue()).rootPath("validationReport.errorReports[0]").body("errorCode", equalTo("E1063")).body("message", containsStringIgnoringCase("does not exist"));
}
use of org.junit.jupiter.params.provider.ValueSource in project spring-framework by spring-projects.
the class DataSourceTransactionManagerTests method transactionWithTimeout.
@ParameterizedTest(name = "transaction with {0} second timeout")
@ValueSource(ints = { 1, 10 })
@EnabledForTestGroups(LONG_RUNNING)
public void transactionWithTimeout(int timeout) throws Exception {
PreparedStatement ps = mock(PreparedStatement.class);
given(con.getAutoCommit()).willReturn(true);
given(con.prepareStatement("some SQL statement")).willReturn(ps);
TransactionTemplate tt = new TransactionTemplate(tm);
tt.setTimeout(timeout);
boolean condition1 = !TransactionSynchronizationManager.hasResource(ds);
assertThat(condition1).as("Hasn't thread connection").isTrue();
try {
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
Thread.sleep(1500);
} catch (InterruptedException ex) {
}
try {
Connection con = DataSourceUtils.getConnection(ds);
PreparedStatement ps = con.prepareStatement("some SQL statement");
DataSourceUtils.applyTransactionTimeout(ps, ds);
} catch (SQLException ex) {
throw new DataAccessResourceFailureException("", ex);
}
}
});
if (timeout <= 1) {
fail("Should have thrown TransactionTimedOutException");
}
} catch (TransactionTimedOutException ex) {
if (timeout <= 1) {
// expected
} else {
throw ex;
}
}
boolean condition = !TransactionSynchronizationManager.hasResource(ds);
assertThat(condition).as("Hasn't thread connection").isTrue();
if (timeout > 1) {
verify(ps).setQueryTimeout(timeout - 1);
verify(con).commit();
} else {
verify(con).rollback();
}
InOrder ordered = inOrder(con);
ordered.verify(con).setAutoCommit(false);
ordered.verify(con).setAutoCommit(true);
verify(con).close();
}
use of org.junit.jupiter.params.provider.ValueSource in project spring-framework by spring-projects.
the class JdbcTransactionManagerTests method transactionWithTimeout.
@ParameterizedTest(name = "transaction with {0} second timeout")
@ValueSource(ints = { 1, 10 })
@EnabledForTestGroups(LONG_RUNNING)
public void transactionWithTimeout(int timeout) throws Exception {
PreparedStatement ps = mock(PreparedStatement.class);
given(con.getAutoCommit()).willReturn(true);
given(con.prepareStatement("some SQL statement")).willReturn(ps);
TransactionTemplate tt = new TransactionTemplate(tm);
tt.setTimeout(timeout);
boolean condition1 = !TransactionSynchronizationManager.hasResource(ds);
assertThat(condition1).as("Hasn't thread connection").isTrue();
try {
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {
Thread.sleep(1500);
} catch (InterruptedException ex) {
}
try {
Connection con = DataSourceUtils.getConnection(ds);
PreparedStatement ps = con.prepareStatement("some SQL statement");
DataSourceUtils.applyTransactionTimeout(ps, ds);
} catch (SQLException ex) {
throw new DataAccessResourceFailureException("", ex);
}
}
});
if (timeout <= 1) {
fail("Should have thrown TransactionTimedOutException");
}
} catch (TransactionTimedOutException ex) {
if (timeout <= 1) {
// expected
} else {
throw ex;
}
}
boolean condition = !TransactionSynchronizationManager.hasResource(ds);
assertThat(condition).as("Hasn't thread connection").isTrue();
if (timeout > 1) {
verify(ps).setQueryTimeout(timeout - 1);
verify(con).commit();
} else {
verify(con).rollback();
}
InOrder ordered = inOrder(con);
ordered.verify(con).setAutoCommit(false);
ordered.verify(con).setAutoCommit(true);
verify(con).close();
}
use of org.junit.jupiter.params.provider.ValueSource in project graphhopper by graphhopper.
the class GraphHopperWebTest method testGetClientForRequest.
@ParameterizedTest(name = "POST={0}")
@ValueSource(booleans = { true, false })
public void testGetClientForRequest(boolean usePost) {
GraphHopperWeb gh = new GraphHopperWeb(null).setPostRequest(usePost);
GHRequest req = new GHRequest().addPoint(new GHPoint(42.509225, 1.534728)).addPoint(new GHPoint(42.512602, 1.551558)).putHint("vehicle", "car");
req.putHint(GraphHopperWeb.TIMEOUT, 5);
assertEquals(5, gh.getClientForRequest(req).connectTimeoutMillis());
}
use of org.junit.jupiter.params.provider.ValueSource in project graphhopper by graphhopper.
the class CHTurnCostTest method test_issue_1593_simple.
@ParameterizedTest
@ValueSource(strings = { DIJKSTRA_BI, ASTAR_BI })
public void test_issue_1593_simple(String algo) {
// 1
// |
// 3-0-x-5-4
// |
// 2
NodeAccess na = graph.getNodeAccess();
na.setNode(1, 0.2, 0.0);
na.setNode(3, 0.1, 0.0);
na.setNode(2, 0.0, 0.0);
na.setNode(0, 0.1, 0.1);
na.setNode(5, 0.1, 0.2);
na.setNode(4, 0.1, 0.3);
EdgeIteratorState edge0 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 1).setDistance(10));
EdgeIteratorState edge1 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 3).setDistance(10));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 0).setDistance(10));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 5).setDistance(10));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(5, 4).setDistance(10));
// cannot go, 2-3-1
setRestriction(edge1, edge0, 3);
graph.freeze();
prepareCH(0, 1, 2, 3, 4, 5);
assertEquals(5, chGraph.getBaseGraph().getEdges());
assertEquals(7, chGraph.getEdges(), "expected two shortcuts: 3->5 and 5->3");
// there should be no path from 2 to 1, because of the turn restriction and because u-turns are not allowed
assertFalse(findPathUsingDijkstra(2, 1).isFound());
compareCHQueryWithDijkstra(2, 1);
// we have to pay attention when there are virtual nodes: turning from the shortcut 3-5 onto the
// virtual edge 5-x should be forbidden.
LocationIndexTree index = new LocationIndexTree(graph, new RAMDirectory());
index.prepareIndex();
Snap snap = index.findClosest(0.1, 0.15, EdgeFilter.ALL_EDGES);
QueryGraph queryGraph = QueryGraph.create(graph, snap);
assertEquals(1, queryGraph.getNodes() - chGraph.getNodes(), "expected one virtual node");
QueryRoutingCHGraph routingCHGraph = new QueryRoutingCHGraph(chGraph, queryGraph);
RoutingAlgorithm chAlgo = new CHRoutingAlgorithmFactory(routingCHGraph).createAlgo(new PMap().putObject(ALGORITHM, algo));
Path path = chAlgo.calcPath(2, 1);
assertFalse(path.isFound(), "no path should be found, but found " + path.calcNodes());
}
Aggregations