IntentUtils { public static EndPointGroup extractSrcEndPointGroup(final Intent intent) throws IntentInvalidException { final EndPointGroup srcEndPointGroup; try { final List<EndPointGroup> endPointGroups = extractEndPointGroups(intent); srcEndPointGroup = extractEndPointGroup(endPointGroups, SRC_END_POINT_GROUP_INDEX); } catch (IntentElementNotFoundException | IntentInvalidException ie) { throw new IntentInvalidException(ie.getMessage()); } return srcEndPointGroup; } 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(expected = IntentElementNotFoundException.class) public void extractEndPointGroupWithIntentElementNotFoundException() throws Exception { PowerMockito.mockStatic(IntentUtils.class); EndPointGroup source = mock(EndPointGroup.class); List<Subjects> subjectses = spy(new ArrayList<>()); when(intent.getSubjects()).thenReturn(subjectses); List<EndPointGroup> endPointGroups = spy(new ArrayList<>()); endPointGroups.add(source); when(endPointGroups.get(0)).thenThrow(new IndexOutOfBoundsException()); PowerMockito.when(IntentUtils.class, "extractEndPointGroup", endPointGroups, 0).thenReturn(source); IntentUtils.extractSrcEndPointGroup(intent); }
@Test(expected = IntentInvalidException.class) public void extractEndPointGroupWithIntentInvalidException() throws Exception { PowerMockito.mockStatic(IntentUtils.class); EndPointGroup source = mock(EndPointGroup.class); List<Subjects> subjectses = spy(new ArrayList<>()); when(intent.getSubjects()).thenReturn(subjectses); List<EndPointGroup> endPointGroups = spy(new ArrayList<>()); endPointGroups.add(source); when(endPointGroups.get(0)).thenReturn(null); PowerMockito.when(IntentUtils.class, "extractEndPointGroup", endPointGroups, 0).thenReturn(source); IntentUtils.extractSrcEndPointGroup(intent); }
@Test public void extractSrcEndPointGroup() throws IntentInvalidException { org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intent.subjects.Subject endPointGroupSource = mock( org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intent.subjects.Subject.class, Mockito.withSettings().extraInterfaces(EndPointGroup.class)); Subjects subjectsSource = mock(Subjects.class); when(subjectsSource.getSubject()).thenReturn(endPointGroupSource); List<Subjects> subjectsList = spy(new ArrayList<>()); subjectsList.add(subjectsSource); when(intent.getSubjects()).thenReturn(subjectsList); when(intent.getId()).thenReturn(uuidMock); EndPointGroup endPointGroup = IntentUtils .extractSrcEndPointGroup(intent); Assert.assertEquals(endPointGroupSource, endPointGroup); }
@Test(expected = IntentInvalidException.class) public void extractSrcEndPointGroupWithIntentInvalidException() throws IntentInvalidException { subject = mock( org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intent.subjects.Subject.class); Subjects subjects = mock(Subjects.class); when(subjects.getSubject()).thenReturn(subject); List<Subjects> subjectsList = spy(new ArrayList<>()); subjectsList.add(subjects); when(intent.getSubjects()).thenReturn(subjectsList); when(intent.getId()).thenReturn(uuidMock); IntentUtils.extractSrcEndPointGroup(intent); }