use of org.junit.jupiter.params.provider.MethodSource in project OpenGrok by OpenGrok.
the class SCCSRepositoryTest method testGetHistoryGet.
/**
* Test of {@link SCCSRepository#getHistoryGet(OutputStream, String, String, String)}.
*/
@ParameterizedTest
@MethodSource("getHistoryGetParams")
void testGetHistoryGet(final GetHistoryTestParams testParams) throws Exception {
try (InputStream inputStream = sccsRepository.getHistoryGet(repositoryRoot.toString(), "main.c", testParams.revision)) {
assertNotNull(inputStream);
byte[] buffer = inputStream.readAllBytes();
String fileContents = new String(buffer);
final String castedPrintf = "(void)printf";
if (testParams.shouldContain) {
assertTrue(fileContents.contains(castedPrintf));
} else {
assertFalse(fileContents.contains(castedPrintf));
}
}
}
use of org.junit.jupiter.params.provider.MethodSource in project hono by eclipse.
the class CacheBasedDeviceConnectionInfoTest method testGetCommandHandlingAdapterInstancesWithTerminatedAdapterInstanceContainer.
/**
* Verifies that the <em>getCommandHandlingAdapterInstances</em> operation succeeds with a result containing
* the mapping of a gateway device if the also existing mapping belonging to the *the given device* is associated
* with an adapter instance identified as already terminated.
*
* @param extraUnusedViaGateways Test values.
* @param ctx The vert.x context.
*/
@ParameterizedTest(name = PARAMETERIZED_TEST_NAME_PATTERN)
@MethodSource("extraUnusedViaGateways")
public void testGetCommandHandlingAdapterInstancesWithTerminatedAdapterInstanceContainer(final Set<String> extraUnusedViaGateways, final VertxTestContext ctx) {
final AdapterInstanceStatusProvider statusProvider = mock(AdapterInstanceStatusProvider.class);
info = new CacheBasedDeviceConnectionInfo(cache, tracer, statusProvider);
final String deviceId = "testDevice";
final String adapterInstance = "adapterInstance";
final String otherAdapterInstance = "otherAdapterInstance";
final String gatewayId = "gw-1";
final Set<String> viaGateways = new HashSet<>(Set.of(gatewayId));
viaGateways.addAll(extraUnusedViaGateways);
// GIVEN testDevice has no last known gateway registered
when(cache.get(CacheBasedDeviceConnectionInfo.getGatewayEntryKey(Constants.DEFAULT_TENANT, deviceId))).thenReturn(Future.succeededFuture());
// and testDevice's and gw-1's command handling adapter instances are set to
// adapterInstance and otherAdapterInstance respectively
when(cache.getAll(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKeys(Constants.DEFAULT_TENANT, deviceId, viaGateways))).thenReturn(Future.succeededFuture(Map.of(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKey(Constants.DEFAULT_TENANT, deviceId), adapterInstance, CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKey(Constants.DEFAULT_TENANT, gatewayId), otherAdapterInstance)));
when(cache.remove(anyString(), anyString())).thenReturn(Future.succeededFuture(Boolean.TRUE));
when(statusProvider.getStatus(adapterInstance)).thenReturn(AdapterInstanceStatus.DEAD);
when(statusProvider.getStatus(otherAdapterInstance)).thenReturn(AdapterInstanceStatus.ALIVE);
info.getCommandHandlingAdapterInstances(Constants.DEFAULT_TENANT, deviceId, viaGateways, span).onComplete(ctx.succeeding(result -> {
ctx.verify(() -> {
assertNotNull(result);
assertGetInstancesResultMapping(result, gatewayId, otherAdapterInstance);
assertGetInstancesResultSize(result, 1);
// verify mapping entry for terminated adapter instance has been removed
verify(cache).remove(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKey(Constants.DEFAULT_TENANT, deviceId), adapterInstance);
});
ctx.completeNow();
}));
}
use of org.junit.jupiter.params.provider.MethodSource in project hono by eclipse.
the class CacheBasedDeviceConnectionInfoTest method testGetCommandHandlingAdapterInstancesFailsForOtherTenantDevice.
/**
* Verifies that the <em>getCommandHandlingAdapterInstances</em> operation fails if no matching instance
* has been registered. An adapter instance has been registered for another device of the same tenant though.
*
* @param extraUnusedViaGateways Test values.
* @param ctx The vert.x context.
*/
@ParameterizedTest(name = PARAMETERIZED_TEST_NAME_PATTERN)
@MethodSource("extraUnusedViaGateways")
public void testGetCommandHandlingAdapterInstancesFailsForOtherTenantDevice(final Set<String> extraUnusedViaGateways, final VertxTestContext ctx) {
final String deviceId = "testDevice";
final String gatewayId = "gw-1";
final Set<String> viaGateways = new HashSet<>(Set.of(gatewayId));
viaGateways.addAll(extraUnusedViaGateways);
// GIVEN testDevice has no last known gateway registered
when(cache.get(CacheBasedDeviceConnectionInfo.getGatewayEntryKey(Constants.DEFAULT_TENANT, deviceId))).thenReturn(Future.succeededFuture());
// and gw-2's command handling adapter instance is set to adapterInstance
when(cache.getAll(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKeys(Constants.DEFAULT_TENANT, deviceId, viaGateways))).thenReturn(Future.succeededFuture(Map.of()));
info.getCommandHandlingAdapterInstances(Constants.DEFAULT_TENANT, deviceId, viaGateways, span).onComplete(ctx.failing(t -> {
ctx.verify(() -> {
assertThat(t).isInstanceOf(ClientErrorException.class);
assertThat(((ClientErrorException) t).getErrorCode()).isEqualTo(HttpURLConnection.HTTP_NOT_FOUND);
});
ctx.completeNow();
}));
}
use of org.junit.jupiter.params.provider.MethodSource in project hono by eclipse.
the class CacheBasedDeviceConnectionInfoTest method testGetCommandHandlingAdapterInstancesForLastKnownGateway.
/**
* Verifies that the <em>getCommandHandlingAdapterInstances</em> operation succeeds if an adapter instance has
* been registered for the last known gateway associated with the given device.
*
* @param extraUnusedViaGateways Test values.
* @param ctx The vert.x context.
*/
@ParameterizedTest(name = PARAMETERIZED_TEST_NAME_PATTERN)
@MethodSource("extraUnusedViaGateways")
public void testGetCommandHandlingAdapterInstancesForLastKnownGateway(final Set<String> extraUnusedViaGateways, final VertxTestContext ctx) {
final String deviceId = "testDevice";
final String adapterInstance = "adapterInstance";
final String otherAdapterInstance = "otherAdapterInstance";
final String gatewayId = "gw-1";
final String otherGatewayId = "gw-2";
final Set<String> viaGateways = new HashSet<>(Set.of(gatewayId, otherGatewayId));
viaGateways.addAll(extraUnusedViaGateways);
// GIVEN testDevice's last known gateway is set to gw-1
when(cache.get(CacheBasedDeviceConnectionInfo.getGatewayEntryKey(Constants.DEFAULT_TENANT, deviceId))).thenReturn(Future.succeededFuture(gatewayId));
// and command handling adapter instances being set for both gateways
when(cache.getAll(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKeys(Constants.DEFAULT_TENANT, deviceId, viaGateways))).thenReturn(Future.succeededFuture(Map.of(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKey(Constants.DEFAULT_TENANT, gatewayId), adapterInstance, CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKey(Constants.DEFAULT_TENANT, otherGatewayId), otherAdapterInstance)));
// but no command handling adapter instance registered for testDevice
when(cache.getAll(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKeys(Constants.DEFAULT_TENANT, deviceId, gatewayId))).thenReturn(Future.succeededFuture(Map.of(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKey(Constants.DEFAULT_TENANT, gatewayId), adapterInstance)));
// WHEN retrieving the list of command handling adapter instances for the device
info.getCommandHandlingAdapterInstances(Constants.DEFAULT_TENANT, deviceId, viaGateways, span).onComplete(ctx.succeeding(result -> {
ctx.verify(() -> {
// THEN the result contains the adapter instance registered for the gateway that the device
// has been last seen on
assertThat(result).isNotNull();
assertGetInstancesResultMapping(result, gatewayId, adapterInstance);
// be sure that only the mapping for the last-known-gateway is returned, not the mappings for both via gateways
assertGetInstancesResultSize(result, 1);
});
ctx.completeNow();
}));
}
use of org.junit.jupiter.params.provider.MethodSource in project hono by eclipse.
the class CacheBasedDeviceConnectionInfoTest method testGetCommandHandlingAdapterInstancesFailsWithGivenGateways.
/**
* Verifies that the <em>getCommandHandlingAdapterInstances</em> operation fails for a device with a
* non-empty set of given viaGateways, if no matching instance has been registered.
*
* @param extraUnusedViaGateways Test values.
* @param ctx The vert.x context.
*/
@ParameterizedTest(name = PARAMETERIZED_TEST_NAME_PATTERN)
@MethodSource("extraUnusedViaGateways")
public void testGetCommandHandlingAdapterInstancesFailsWithGivenGateways(final Set<String> extraUnusedViaGateways, final VertxTestContext ctx) {
final String deviceId = "testDevice";
final String gatewayId = "gw-1";
final Set<String> viaGateways = new HashSet<>(Set.of(gatewayId));
viaGateways.addAll(extraUnusedViaGateways);
// GIVEN testDevice has no last known gateway registered
when(cache.get(CacheBasedDeviceConnectionInfo.getGatewayEntryKey(Constants.DEFAULT_TENANT, deviceId))).thenReturn(Future.succeededFuture());
// and gw-1 has no command handling adapter instance registered
when(cache.getAll(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKeys(Constants.DEFAULT_TENANT, deviceId, viaGateways))).thenReturn(Future.succeededFuture(Map.of()));
info.getCommandHandlingAdapterInstances(Constants.DEFAULT_TENANT, deviceId, viaGateways, span).onComplete(ctx.failing(t -> {
ctx.verify(() -> {
assertThat(t).isInstanceOf(ClientErrorException.class);
assertThat(((ClientErrorException) t).getErrorCode()).isEqualTo(HttpURLConnection.HTTP_NOT_FOUND);
});
ctx.completeNow();
}));
}
Aggregations