IntentUtils { public static Action getAction(final Intent intent) throws IntentInvalidException { final Action result; try { result = intent.getActions().get(0).getAction(); } catch (IndexOutOfBoundsException ie) { throw new IntentElementNotFoundException(NO_ACTION_FOUND_MESSAGE + intent.getId()); } if(result == null) { throw new IntentInvalidException(ACTION_NULL_MESSAGE + intent.getId()); } return result; } private  IntentUtils(); static boolean validateMAC(final String mac); static boolean validateIP(String ip); static boolean verifyIntent(final Intent intent); static boolean verifyIntentActions(final Intent intent); static boolean verifyIntentSubjects(final Intent intent); static List<String> extractEndPointGroup(final Intent intent); static List<EndPointGroup> extractEndPointGroups(final Intent intent); static EndPointGroup extractSrcEndPointGroup(final Intent intent); static EndPointGroup extractDstEndPointGroup(final Intent intent); static void verifySubjectInstance(final Subject subject, final Uuid intentId); static Action getAction(final Intent intent); static final Integer SRC_END_POINT_GROUP_INDEX; static final Integer DST_END_POINT_GROUP_INDEX; static final InstanceIdentifier<Intents> INTENTS_IID; static final InstanceIdentifier<IntentsLimiter> INTENTS_LIMITER_IDD; static final InstanceIdentifier<IntentIspPrefixes> INTENT_ISP_PREFIX_IID; }
@Test public void testGetAction() throws IntentInvalidException { Action result; Mockito.when(actionsMock.get(0)).thenReturn(actions); Mockito.when(actions.getAction()).thenReturn(action); result = IntentUtils.getAction(intentMock); Assert.assertEquals(result, action); }
@Test(expected = IntentElementNotFoundException.class) public void testGetActionWithIndexOutOfBoundsException() throws IntentInvalidException { Mockito.when(actionsMock.get(0)) .thenThrow(new IndexOutOfBoundsException()); IntentUtils.getAction(intentMock); }
@Test(expected = IntentInvalidException.class) public void testGetActionWithIntentInvalidException() throws IntentInvalidException { Mockito.when(actionsMock.get(0)).thenReturn(actions); Mockito.when(actions.getAction()).thenReturn(null); IntentUtils.getAction(intentMock); }