HostedServersInstanceRuntimeInfo extends DockerInstanceRuntimeInfo { @Override public Map<String, ServerImpl> getServers() { if (servers == null) { final HashMap<String, ServerImpl> servers = new HashMap<>(super.getServers()); for (Map.Entry<String, ServerImpl> serverEntry : servers.entrySet()) { if (transformers.containsKey(serverEntry.getValue().getRef())) { serverEntry.setValue( transformers.get(serverEntry.getValue().getRef()).transform(serverEntry.getValue())); } } this.servers = servers; } return servers; } @Inject  HostedServersInstanceRuntimeInfo(
      @Assisted ContainerInfo containerInfo,
      @Assisted String containerInternalHostname,
      @Assisted MachineConfig machineConfig,
      @Named("machine.docker.dev_machine.machine_servers") Set<ServerConf> devMachineServers,
      @Named("machine.docker.machine_servers") Set<ServerConf> allMachinesServers,
      Map<String, MachineServerProxyTransformer> transformers,
      ServerEvaluationStrategyProvider serverEvaluationStrategyProvider); @Override Map<String, ServerImpl> getServers();  }
@Test public void shouldReturnUnchangedServersOfDockerInstanceRuntimeInfoIfNoModifiersIsProvided() throws Exception { HashMap<String, ServerImpl> originServers = new HashMap<>(); originServers.put( "8080/tcp", new ServerImpl( "ref1", "http", DEFAULT_HOST + ":32000", "http: new ServerPropertiesImpl( "/some/path", DEFAULT_HOST + ":32000", "http: originServers.put( "1000/tcp", new ServerImpl( "ref2", "wss", DEFAULT_HOST + ":32001", "wss: new ServerPropertiesImpl( "/some/path", DEFAULT_HOST + ":32001", "wss: HostedServersInstanceRuntimeInfo runtimeInfo = prepareHostedServersInstanceRuntimeInfo( originServers, singletonMap( "otherreference", new UriTemplateServerProxyTransformer("http: Map<String, ServerImpl> modifiedServers = runtimeInfo.getServers(); assertEquals(modifiedServers, originServers); }
@Test public void shouldModifyOnlyServersThatHasCorrespondingModifier() throws Exception { HashMap<String, ServerImpl> originServers = new HashMap<>(); originServers.put( "8080/tcp", new ServerImpl( "ref1", "http", DEFAULT_HOST + ":32000", "http: new ServerPropertiesImpl( "/some/path", DEFAULT_HOST + ":32000", "http: originServers.put( "1000/tcp", new ServerImpl( "ref2", "wss", DEFAULT_HOST + ":30001", "wss: new ServerPropertiesImpl( "/some/path", DEFAULT_HOST + ":30001", "wss: HashMap<String, ServerImpl> expectedServers = new HashMap<>(); expectedServers.put("8080/tcp", originServers.get("8080/tcp")); expectedServers.put( "1000/tcp", new ServerImpl( "ref2", "http", "host:9090", "http: new ServerPropertiesImpl("/path", "host:9090", "http: HostedServersInstanceRuntimeInfo runtimeInfo = prepareHostedServersInstanceRuntimeInfo( originServers, singletonMap( "ref2", new UriTemplateServerProxyTransformer("http: Map<String, ServerImpl> modifiedServers = runtimeInfo.getServers(); assertEquals(modifiedServers, expectedServers); }