/** * Is a leaf level endpoint active? For a group endpoint this means at least one is active * @return true if at least one is active in a group endpoint; for a leaf - if it is currently active * @throws Exception */ public boolean isActive() throws Exception { if (endpoint.getChildren() != null) { return getActiveChildren() > 0; } else if (endpoint.getContext() != null) { return endpoint.getContext().isState(EndpointContext.ST_ACTIVE); } return false; }
/** * Is a leaf level endpoint active? For a group endpoint this means at least one is active * @return true if at least one is active in a group endpoint; for a leaf - if it is currently active * @throws Exception */ public boolean isActive() throws Exception { if (endpoint.getChildren() != null) { return getActiveChildren() > 0; } else if (endpoint.getContext() != null) { return endpoint.getContext().isState(EndpointContext.ST_ACTIVE); } return false; }
/** * Switches on the endpoint view and tests if the active state of the endpoint view is updated. Additionally, * asserts for the active children count to make sure that all children are activated. * * @throws Exception if an exception occurs while activating endpoint view */ public void testSwitchOn() throws Exception { EndpointView endpointView = createEndPointView(2); endpointView.switchOn(); Assert.assertEquals("Switching on endpoint view has not activated all children", 2, endpointView.getActiveChildren()); Assert.assertTrue("Endpoint view is not active", endpointView.isActive()); endpointView = createEndPointView(0); endpointView.switchOn(); Assert.assertTrue("Endpoint view is not active", endpointView.isActive()); }
/** * Asserts if the the endpoint view correctly returns the number of active child endpoints included in the * endpoint associated with the view. * * @throws Exception if an error occurs while accessing child endpoints */ public void testGetActiveChildren() throws Exception { //Assert with children AbstractEndpoint endpoint = createMockEndPoint(5); Mockito.when(endpoint.getChildren().get(0).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(true); Mockito.when(endpoint.getChildren().get(1).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(false); Mockito.when(endpoint.getChildren().get(2).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(true); Mockito.when(endpoint.getChildren().get(3).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(false); Mockito.when(endpoint.getChildren().get(4).getContext().isState(EndpointContext.ST_ACTIVE)).thenReturn(true); EndpointView endpointView = new EndpointView("endpoint", endpoint); Assert.assertEquals("Incorrect active children count", 3, endpointView.getActiveChildren()); //Assert when endpoint has no children EndpointView endpointViewWithoutChildren = createMockEndPointView(0); Assert.assertEquals("Incorrect active children count", 0, endpointViewWithoutChildren.getActiveChildren()); }
/** * Switches off the endpoint view and tests if the active state of the endpoint view is updated. Additionally, * asserts for the active children count to make sure that all children are de-activated. * * @throws Exception if an exception occurs while switching off the endpoint view */ public void testSwitchOff() throws Exception { EndpointView endpointView = createEndPointView(2); endpointView.switchOn(); endpointView.switchOff(); Assert.assertEquals("Switching off endpoint view has not deactivated all children", 0, endpointView.getActiveChildren()); Assert.assertFalse("Endpoint view is active", endpointView.isActive()); endpointView = createEndPointView(0); endpointView.switchOn(); endpointView.switchOff(); Assert.assertFalse("Endpoint view is active", endpointView.isActive()); }