use of org.bf2.cos.fleetshard.api.ManagedConnectorClusterSpecBuilder in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class ConnectorTestSupport method fleetShard.
public static FleetShardClient fleetShard(String clusterId, Collection<ManagedConnector> connectors, Collection<Secret> secrets) {
Map<String, ManagedConnector> allConnectors = connectors.stream().collect(Collectors.toMap(e -> e.getMetadata().getName(), Function.identity()));
Map<String, Secret> allSecrets = secrets.stream().collect(Collectors.toMap(e -> e.getMetadata().getName(), Function.identity()));
FleetShardClient answer = Mockito.mock(FleetShardClient.class);
when(answer.getClusterId()).thenAnswer(invocation -> clusterId);
when(answer.getConnector(any(ConnectorDeployment.class))).thenAnswer(invocation -> {
return lookupConnector(allConnectors.values(), clusterId, invocation.getArgument(0));
});
when(answer.getSecret(any(ConnectorDeployment.class))).thenAnswer(invocation -> {
return lookupSecret(allSecrets.values(), clusterId, invocation.getArgument(0));
});
when(answer.createConnector(any(ManagedConnector.class))).thenAnswer(invocation -> {
var arg = invocation.getArgument(0, ManagedConnector.class);
allConnectors.put(arg.getMetadata().getName(), arg);
return arg;
});
when(answer.createSecret(any(Secret.class))).thenAnswer(invocation -> {
var arg = invocation.getArgument(0, Secret.class);
allSecrets.put(arg.getMetadata().getName(), arg);
return arg;
});
when(answer.getOrCreateManagedConnectorCluster()).thenAnswer(invocation -> {
return new ManagedConnectorClusterBuilder().withMetadata(new ObjectMetaBuilder().withName(Clusters.CONNECTOR_CLUSTER_PREFIX + "-" + clusterId).addToLabels(Resources.LABEL_CLUSTER_ID, clusterId).build()).withSpec(new ManagedConnectorClusterSpecBuilder().withClusterId(clusterId).build()).build();
});
return answer;
}
Aggregations