IntentAddShellCommand extends OsgiCommandSupport { protected List<Subjects> createSubjects() throws InvalidObjectException { List<Subjects> subjectList = new ArrayList<Subjects>(); if (!IntentUtils.validateIP(this.from) && !IntentUtils.validateIP(this.to) && !IntentUtils.validateMAC(this.to) && !IntentUtils.validateMAC(this.from)) { LOG.info("The subjects are not IP or MAC addresses"); Map<String, String> subjectFromMap = mappingService.get(this.from); Map<String, String> subjectToMap = mappingService.get(this.to); if(subjectFromMap.isEmpty()) { throw new InvalidObjectException(buildSubjectNotFoundMessage(this.from)); } if(subjectToMap.isEmpty()) { throw new InvalidObjectException(buildSubjectNotFoundMessage(this.to)); } if (IntentUtils.validateIP(subjectFromMap.get(IP))) { this.from = subjectFromMap.get(IP); } else if (IntentUtils.validateMAC(subjectFromMap.get(MAC))) { this.from = subjectFromMap.get(MAC); } if (IntentUtils.validateIP(subjectToMap.get(IP))) { this.to = subjectToMap.get(IP); } else if (IntentUtils.validateMAC(subjectToMap.get(MAC))) { this.to = subjectToMap.get(MAC); } } EndPointGroup endpointGroupFrom = new EndPointGroupBuilder().setName(this.from).build(); org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intent.subjects.subject.EndPointGroup fromEPG = new org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intent.subjects.subject .EndPointGroupBuilder().setEndPointGroup(endpointGroupFrom).build(); Subjects subjects1 = new SubjectsBuilder().setOrder((short) FIRST_SUBJECT).setSubject(fromEPG).build(); EndPointGroup endpointGroupTo = new EndPointGroupBuilder().setName(this.to).build(); org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intent.subjects.subject.EndPointGroup toEPG = new org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intent.subjects.subject .EndPointGroupBuilder().setEndPointGroup(endpointGroupTo).build(); Subjects subjects2 = new SubjectsBuilder().setOrder((short) SECOND_SUBJECT).setSubject(toEPG).build(); subjectList.add(subjects1); subjectList.add(subjects2); return subjectList; } IntentAddShellCommand(NicConsoleProvider provider, IntentMappingService mappingService);   }
@Test public final void testCreateSubjects() throws InvalidObjectException { Map<String, String> resultMap = new HashMap<>(); resultMap.put("any","0.0.0.0"); when(mappingService.get("any")).thenReturn(resultMap); when(mappingService.get("any")).thenReturn(resultMap); List<Subjects> subjects = nicAddShellCmd.createSubjects(); assertNotNull(subjects); assertEquals("there are should be at least 2 subjects", true , subjects.size() > 1); }