ConsulRepository implements EntryPointRepository, PortRepository, HaproxyRepository { @Override public void init() { try { putIfAbsent("ports", "{}"); putIfAbsent("haproxyversions", "[]"); putIfAbsent("haproxy/", ""); putIfAbsent("admin/", ""); } catch (Exception e) { LOGGER.warn("Can't request consul server. Initialization of data has failed.", e); } } ConsulRepository(String host, int port, int minGeneratedPort, int maxGeneratedPort);   ConsulRepository(String host, int port, int minGeneratedPort, int maxGeneratedPort, ObjectMapper mapper, ConsulReader consulReader, CloseableHttpClient client); @Override boolean lock(EntryPointKey entryPointKey); @Override boolean isAutoreloaded(EntryPointKey entryPointKey); @Override void release(EntryPointKey key); @Override Optional<EntryPoint> getCurrentConfiguration(EntryPointKey key); @Override Set<String> getEntryPointsId(); @Override Optional<EntryPoint> getPendingConfiguration(EntryPointKey key); @Override Optional<EntryPoint> getCommittingConfiguration(EntryPointKey key); @Override void setPendingConfiguration(EntryPointKey key, EntryPoint configuration); @Override void removePendingConfiguration(EntryPointKey key); @Override boolean setCommittingConfiguration(String correlationId, EntryPointKey entryPointKey, EntryPoint configuration, int ttl); @Override void removeCommittingConfiguration(EntryPointKey key); @Override Optional<Boolean> removeEntrypoint(EntryPointKey entryPointKey); @Override void setCurrentConfiguration(EntryPointKey key, EntryPoint configuration); @Override void init(); @Override Optional<Map<String, Integer>> getPorts(); @Override Optional<Integer> getPort(String key); @Override Integer newPort(String key); @Override Optional<Map<String, String>> getHaproxyProperties(String haproxyId); @Override Optional<Map<String, String>> getHaproxyPropertiesAndAccepting404(String haproxyId); @Override Set<String> getHaproxyVersions(); @Override void addVersion(String haproxyVersion); @Override List<Map<String, String>> getHaproxyProperties(); @Override boolean isAutoreload(String haproxyId); @Override Set<String> getHaproxyIds(); @Override void setHaproxyProperty(String haproxyId, String key, String value); @Override Optional<String> getHaproxyProperty(String haproxyId, String key); @Override Optional<String> getCommitCorrelationId(EntryPointKey key); @Override void setAutoreload(EntryPointKey entryPointKey, Boolean autoreload); void shutdown();  }
@Test public void should_init_ports_if_absent() throws IOException { ConsulReader consulReader = mock(ConsulReader.class); CloseableHttpClient closeableHttpClient = mock(CloseableHttpClient.class); ConsulRepository consulRepository = new ConsulRepository("localhost", 50080, 32_000, 64_000, null, consulReader, closeableHttpClient); HttpMatcher httpPutPorts = new HttpMatcher("http: HttpMatcher httpPutHaproxyversions = new HttpMatcher("http: HttpMatcher httpPutHaproxy = new HttpMatcher("http: HttpMatcher httpPutAdmin = new HttpMatcher("http: when(closeableHttpClient.execute(any(HttpRequestBase.class), any(ResponseHandler.class))).thenReturn(Optional.empty(), Optional.empty(), Optional.empty()); consulRepository.init(); verify(closeableHttpClient, times(1)).execute(argThat(httpPutPorts), any(ResponseHandler.class)); verify(closeableHttpClient, times(1)).execute(argThat(httpPutHaproxyversions), any(ResponseHandler.class)); verify(closeableHttpClient, times(1)).execute(argThat(httpPutHaproxy), any(ResponseHandler.class)); verify(closeableHttpClient, times(1)).execute(argThat(httpPutAdmin), any(ResponseHandler.class)); }