OpenStackConfigUtilImpl implements OpenStackConfigUtil { public String getPublicRouter(PaasManagerUser user, String region, String publicNetworkId) throws OpenStackException { log.debug("Obtain public router for external netwrk " + publicNetworkId); if (publicNetworkId == null) { String errorMessage = "There is not an external network valid for the router"; log.warn(errorMessage); throw new OpenStackException(errorMessage); } String type = "router"; String routerId = regionCache.getUrl(region, type); if (routerId != null) { return routerId; } OpenStackAccess openStackAccess = openStackRegion.getTokenAdmin(); HttpUriRequest request = openOperationUtil.createQuantumGetRequest(RESOURCE_ROUTERS, APPLICATION_JSON, region, openStackAccess.getToken(), openStackAccess.getTenantId()); String response = null; try { response = openOperationUtil.executeNovaRequest(request); routerId = getPublicRouterId(response, openStackAccess.getTenantId(), publicNetworkId); if (routerId == null) { String errorMessage = "It is not possible to find a public router for network " + publicNetworkId + ": "; log.error(errorMessage); throw new OpenStackException(errorMessage); } regionCache.putUrl(region, type, routerId); return routerId; } catch (OpenStackException e) { String errorMessage = "Error getting router for obtaining the public router: " + e; log.error(errorMessage); throw new OpenStackException(errorMessage); } catch (Exception e) { String errorMessage = "Error getting router from OpenStack for obtaining the public router: " + e; log.error(errorMessage); throw new OpenStackException(errorMessage); } } OpenStackConfigUtilImpl(); HttpClientConnectionManager getHttpConnectionManager(); void setHttpConnectionManager(HttpClientConnectionManager httpConnectionManager); String getPublicAdminNetwork(PaasManagerUser user, String region); String getPublicFloatingPool(PaasManagerUser user, String region); NetworkInstance getPublicAdmin(PaasManagerUser user, String region); String getPublicRouter(PaasManagerUser user, String region, String publicNetworkId); String getPublicRouterId(String response, String vdc, String publicNetworkId); OpenStackRegion getOpenStackRegion(); void setOpenStackRegion(OpenStackRegion openStackRegion); void setOpenOperationUtil(OpenOperationUtil openOperationUtil);  }
@Test public void shouldObtainPublicRouter() throws OpenStackException, IOException { String region = "RegionOne3"; OpenStackAccess openStackAccess = new OpenStackAccess(); openStackAccess.setToken("1234567891234567989"); openStackAccess.setTenantId("08bed031f6c54c9d9b35b42aa06b51c0"); when(openStackRegion.getTokenAdmin()).thenReturn(openStackAccess); when(openOperationUtil.executeNovaRequest(any(HttpUriRequest.class))).thenReturn(ROUTERS); String router = openStackUtil.getPublicRouter(paasManagerUser, region, "080b5f2a-668f-45e0-be23-361c3a7d11d0"); assertNotNull(router); }
@Test public void testBugFindRouterNetworkNull() throws OpenStackException { String region = "RegionOne4"; OpenStackAccess openStackAccess = new OpenStackAccess(); openStackAccess.setToken("1234567891234567989"); openStackAccess.setTenantId("08bed031f6c54c9d9b35b42aa06b51c0"); when(openStackRegion.getTokenAdmin()).thenReturn(openStackAccess); when(openOperationUtil.executeNovaRequest(any(HttpUriRequest.class))).thenReturn(ROUTERS); try { openStackUtil.getPublicRouter(paasManagerUser, region, null); fail("The method should have lanch an exception"); } catch (Exception e) { } }