IntentUtils { public static List<String> extractEndPointGroup(final Intent intent) { final Uuid uuid = intent.getId(); final List<Subjects> listSubjects = intent.getSubjects(); final String[] endPointGroups = new String[listSubjects.size()]; for (Subjects subjects : listSubjects) { final Subject subject = subjects.getSubject(); int order = subjects.getOrder(); verifySubjectInstance(subject, uuid); final EndPointGroup endPointGroup = (EndPointGroup) subject; final org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intent.subjects.subject.end.point.group .EndPointGroup epg = endPointGroup.getEndPointGroup(); if (epg != null) { endPointGroups[order-1] = epg.getName(); } } return Arrays.asList(endPointGroups); } 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 testExtractEndPointGroup() { final String EPG_NAME_ONE = "First_EPG"; List<String> expected = new ArrayList<String>(); expected.add(EPG_NAME_ONE); Subjects subjectsMockOne = Mockito.mock(Subjects.class); List<Subjects> subjectMockList = new ArrayList<Subjects>(); subjectMockList.add(subjectsMockOne); Mockito.when(intentMock.getSubjects()).thenReturn(subjectMockList); EndPointGroup subjectMockOne = Mockito.mock(EndPointGroup.class); Mockito.when(subjectsMockOne.getOrder()).thenReturn((short) 1); Mockito.when(subjectsMockOne.getSubject()).thenReturn(subjectMockOne); Mockito.when(subjectMockOne.getEndPointGroup()).thenReturn(epgMock); Mockito.when(epgMock.getName()).thenReturn(EPG_NAME_ONE); List<String> result = IntentUtils.extractEndPointGroup(intentMock); Assert.assertEquals(expected, result); }
@Test public void testExtractNullEndPointGroup() { List<String> expected = new ArrayList<String>(); expected.add(null); Subjects subjectsMockOne = Mockito.mock(Subjects.class); List<Subjects> subjectMockList = new ArrayList<Subjects>(); subjectMockList.add(subjectsMockOne); Mockito.when(intentMock.getSubjects()).thenReturn(subjectMockList); EndPointGroup subjectMockOne = Mockito.mock(EndPointGroup.class); Mockito.when(subjectsMockOne.getOrder()).thenReturn((short) 1); Mockito.when(subjectsMockOne.getSubject()).thenReturn(subjectMockOne); Mockito.when(subjectMockOne.getEndPointGroup()).thenReturn(null); List<String> result = IntentUtils.extractEndPointGroup(intentMock); Assert.assertEquals(expected, result); }