@Before public void setUp() { RegionCache regionCache = new RegionCache(); regionCache.clear(); openStackRegion = new OpenStackRegionImpl(); Client client = mock(Client.class); WebTarget webResource = mock(WebTarget.class); builder = mock(Invocation.Builder.class); clientResponse = mock(Response.class); Response clientResponseAdmin = mock(Response.class); // when when(webResource.request(MediaType.APPLICATION_JSON)).thenReturn(builder); when(builder.accept(MediaType.APPLICATION_JSON)).thenReturn(builder); when(client.target(anyString())).thenReturn(webResource); openStackRegion.setClient(client); systemPropertiesProvider = mock(SystemPropertiesProvider.class); openStackRegion.setSystemPropertiesProvider(systemPropertiesProvider); String responseJSON = "{\"access\": {\"token\": {\"issued_at\": \"2014-01-13T14:00:10.103025\", \"expires\": \"2014-01-14T14:00:09Z\"," + "\"id\": \"ec3ecab46f0c4830ad2a5837fd0ad0d7\", \"tenant\": { \"description\": null, \"enabled\": true, \"id\": \"08bed031f6c54c9d9b35b42aa06b51c0\"," + "\"name\": \"admin\" } }, \"serviceCatalog\": []}}}"; when(builder.post(Entity.entity(anyString(), MediaType.APPLICATION_JSON))) .thenReturn(clientResponseAdmin); when(clientResponseAdmin.getStatus()).thenReturn(200); when(clientResponseAdmin.readEntity(String.class)).thenReturn(responseJSON); }
@Test public void testShouldGetEndPointsForNovaAndARegionNameUsingCache() throws OpenStackException { // given String regionName = "RegionOne"; String token = "123123232"; RegionCache regionCache = new RegionCache(); regionCache.putUrl("RegionOne", "compute", "http://130.206.80.58:8774/v2/12321312312312321"); // when String resultURL = openStackRegion.getNovaEndPoint(regionName, token); // then assertNotNull(resultURL); assertEquals("http://130.206.80.58:8774/v2/", resultURL); }
@Test public void testShouldGetEndPointsForFederatedNetwork() throws OpenStackException { // given String token = "123123232"; when(builder.get()).thenReturn(clientResponse); when(clientResponse.getStatus()).thenReturn(200); when(clientResponse.readEntity(String.class)).thenReturn(RESPONSE_JSON_GRIZZLY_TWO_REGIONS); RegionCache regionCache = new RegionCache(); regionCache.putUrl( "regionOne", "federatednetwork", "http://130.206.80.58:8774/v2/12321312312312321"); // when String resultURL = openStackRegion.getFederatedQuantumEndPoint(token); // then assertNotNull(resultURL); assertEquals("http://130.206.80.58:8774/v2/12321312312312321", resultURL); }