OpenShiftUniqueNamesProvisioner extends UniqueNamesProvisioner<OpenShiftEnvironment> { @Override public void provision(OpenShiftEnvironment osEnv, RuntimeIdentity identity) throws InfrastructureException { super.provision(osEnv, identity); final Set<Route> routes = new HashSet<>(osEnv.getRoutes().values()); osEnv.getRoutes().clear(); for (Route route : routes) { final ObjectMeta routeMeta = route.getMetadata(); putLabel(route, Constants.CHE_ORIGINAL_NAME_LABEL, routeMeta.getName()); final String routeName = Names.generateName("route"); routeMeta.setName(routeName); osEnv.getRoutes().put(routeName, route); } }  @Override void provision(OpenShiftEnvironment osEnv, RuntimeIdentity identity);  }
@Test public void provideUniquePodsNames() throws Exception { when(runtimeIdentity.getWorkspaceId()).thenReturn(WORKSPACE_ID); Pod pod = newPod(); PodData podData = new PodData(pod.getSpec(), pod.getMetadata()); doReturn(ImmutableMap.of(POD_NAME, podData)).when(osEnv).getPodsData(); uniqueNamesProvisioner.provision(osEnv, runtimeIdentity); ObjectMeta podMetadata = pod.getMetadata(); assertNotEquals(podMetadata.getName(), POD_NAME); assertEquals(podMetadata.getLabels().get(CHE_ORIGINAL_NAME_LABEL), POD_NAME); }
@Test public void provideUniqueRoutesNames() throws Exception { final HashMap<String, Route> routes = new HashMap<>(); Route route = newRoute(); routes.put(POD_NAME, route); doReturn(routes).when(osEnv).getRoutes(); uniqueNamesProvisioner.provision(osEnv, runtimeIdentity); final ObjectMeta routeData = route.getMetadata(); assertNotEquals(routeData.getName(), ROUTE_NAME); assertEquals(routeData.getLabels().get(CHE_ORIGINAL_NAME_LABEL), ROUTE_NAME); }