@Test public void testReadConfigEndpointsDown() throws Exception { EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse("")).anyTimes(); replay(); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); verify(); assertEquals(configuredServices, services); }
@Test public void testReadConfigNoEndpoints() throws Exception { JSONObject config = createConfig(); config.getJSONObject("default"). getJSONObject(DefaultServiceFetcher.GADGETS_FEATURES_CONFIG) .remove(DefaultServiceFetcher.OSAPI_FEATURE_CONFIG); JsonContainerConfig containerConfig = new JsonContainerConfig(config, Expressions.forTesting(new Functions())); fetcher = new DefaultServiceFetcher(containerConfig, mockFetcher); EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse("")).anyTimes(); replay(); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); verify(); assertEquals(configuredServices, services); }
@Test public void testReadConfigRequestMarkedInternal() throws Exception { JSONObject config = createConfig(); config.getJSONObject("default"). getJSONObject(DefaultServiceFetcher.GADGETS_FEATURES_CONFIG) .getJSONObject(DefaultServiceFetcher.OSAPI_FEATURE_CONFIG) .put(DefaultServiceFetcher.OSAPI_BASE_ENDPOINTS, new JSONArray(ImmutableList.of(endPoint1))); JsonContainerConfig containerConfig = new JsonContainerConfig(config, Expressions.forTesting(new Functions())); CapturingHttpFetcher httpFetcher = new CapturingHttpFetcher(); fetcher = new DefaultServiceFetcher(containerConfig, httpFetcher); fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() ); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); assertEquals(configuredServices, services); assertNotNull( httpFetcher.request ); assertTrue( httpFetcher.request.isInternalRequest() ); }
@Before public void setUp() throws Exception { JSONObject config = createConfig(); JsonContainerConfig containerConfig = new JsonContainerConfig(config, Expressions.forTesting(new Functions())); mockFetcher = mock(HttpFetcher.class); fetcher = new DefaultServiceFetcher(containerConfig, mockFetcher); }
@Test public void testReadConfigBadContainer() throws Exception { Multimap<String, String> multimap = fetcher.getServicesForContainer("badcontainer", "dontcare"); assertEquals(0, multimap.size()); }
@Test public void testReadConfigNoEndpoints() throws Exception { JSONObject config = createConfig(); config.getJSONObject("default"). getJSONObject(DefaultServiceFetcher.GADGETS_FEATURES_CONFIG) .remove(DefaultServiceFetcher.OSAPI_FEATURE_CONFIG); JsonContainerConfig containerConfig = new JsonContainerConfig(config, Expressions.forTesting(new Functions())); fetcher = new DefaultServiceFetcher(containerConfig, mockFetcher); EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse("")).anyTimes(); replay(); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); verify(); assertEquals(configuredServices, services); }
@Test public void testReadConfigRequestMarkedInternal() throws Exception { JSONObject config = createConfig(); config.getJSONObject("default"). getJSONObject(DefaultServiceFetcher.GADGETS_FEATURES_CONFIG) .getJSONObject(DefaultServiceFetcher.OSAPI_FEATURE_CONFIG) .put(DefaultServiceFetcher.OSAPI_BASE_ENDPOINTS, new JSONArray(ImmutableList.of(endPoint1))); JsonContainerConfig containerConfig = new JsonContainerConfig(config, Expressions.forTesting(new Functions())); CapturingHttpFetcher httpFetcher = new CapturingHttpFetcher(); fetcher = new DefaultServiceFetcher(containerConfig, httpFetcher); fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() ); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); assertEquals(configuredServices, services); assertNotNull( httpFetcher.request ); assertTrue( httpFetcher.request.isInternalRequest() ); }
@Before public void setUp() throws Exception { JSONObject config = createConfig(); JsonContainerConfig containerConfig = new JsonContainerConfig(config, Expressions.forTesting(new Functions())); mockFetcher = mock(HttpFetcher.class); fetcher = new DefaultServiceFetcher(containerConfig, mockFetcher); }
@Test public void testReadConfigBadContainer() throws Exception { Multimap<String, String> multimap = fetcher.getServicesForContainer("badcontainer", "dontcare"); assertEquals(0, multimap.size()); } }
@Test public void testReadConfigWithValidEndpoints() throws Exception { List<String> endPoint1Services = ImmutableList.of("do.something", "delete.someting"); JSONObject service1 = new JSONObject(); service1.put("result", endPoint1Services); List<String> endPoint2Services = ImmutableList.of("weather.get"); JSONObject service2 = new JSONObject(); service2.put("result", endPoint2Services); EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse(service1.toString())); EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse(service2.toString())); replay(); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); verify(); Multimap<String, String> mergedServices = LinkedHashMultimap.create(configuredServices); mergedServices.putAll(endPoint1, endPoint1Services); mergedServices.putAll(endPoint2, endPoint2Services); assertEquals(mergedServices, LinkedHashMultimap.create(services)); }
@Test public void testReadConfigNoEndpoints() throws Exception { JSONObject config = createConfig(); config.getJSONObject("default"). getJSONObject(DefaultServiceFetcher.GADGETS_FEATURES_CONFIG) .remove(DefaultServiceFetcher.OSAPI_FEATURE_CONFIG); JsonContainerConfig containerConfig = new JsonContainerConfig(config, Expressions.forTesting(new Functions())); fetcher = new DefaultServiceFetcher(containerConfig, mockFetcher); EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse("")).anyTimes(); replay(); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); verify(); assertEquals(configuredServices, services); }
@Before public void setUp() throws Exception { JSONObject config = createConfig(); JsonContainerConfig containerConfig = new JsonContainerConfig(config, Expressions.forTesting(new Functions())); mockFetcher = mock(HttpFetcher.class); fetcher = new DefaultServiceFetcher(containerConfig, mockFetcher); }
@Test public void testReadConfigBadContainer() throws Exception { Multimap<String, String> multimap = fetcher.getServicesForContainer("badcontainer", "dontcare"); assertEquals(0, multimap.size()); }
@Test public void testReadConfigEndpointsDown() throws Exception { EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse("")).anyTimes(); replay(); fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() ); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); verify(); assertEquals(configuredServices, services); }
@Test public void testReadConfigEndpointsDown() throws Exception { EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse("")).anyTimes(); replay(); fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() ); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); verify(); assertEquals(configuredServices, services); }
@Test public void testReadConfigWithValidEndpoints() throws Exception { List<String> endPoint1Services = ImmutableList.of("do.something", "delete.someting"); JSONObject service1 = new JSONObject(); service1.put("result", endPoint1Services); List<String> endPoint2Services = ImmutableList.of("weather.get"); JSONObject service2 = new JSONObject(); service2.put("result", endPoint2Services); EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse(service1.toString())); EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse(service2.toString())); replay(); fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() ); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); verify(); Multimap<String, String> mergedServices = LinkedHashMultimap.create(configuredServices); mergedServices.putAll(endPoint1, endPoint1Services); mergedServices.putAll(endPoint2, endPoint2Services); assertEquals(mergedServices, LinkedHashMultimap.create(services)); }
@Test public void testReadConfigWithValidEndpoints() throws Exception { List<String> endPoint1Services = ImmutableList.of("do.something", "delete.someting"); JSONObject service1 = new JSONObject(); service1.put("result", endPoint1Services); List<String> endPoint2Services = ImmutableList.of("weather.get"); JSONObject service2 = new JSONObject(); service2.put("result", endPoint2Services); EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse(service1.toString())); EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn( new HttpResponse(service2.toString())); replay(); fetcher.setSecurityTokenCodec( new BasicSecurityTokenCodec() ); Multimap<String, String> services = fetcher.getServicesForContainer("default", "dontcare"); verify(); Multimap<String, String> mergedServices = LinkedHashMultimap.create(configuredServices); mergedServices.putAll(endPoint1, endPoint1Services); mergedServices.putAll(endPoint2, endPoint2Services); assertEquals(mergedServices, LinkedHashMultimap.create(services)); }