IntentAddShellCommand extends OsgiCommandSupport { protected List<Constraints> createConstraints() throws InvalidObjectException { final List<Constraints> constraintsList = new ArrayList<Constraints>(); short order = 1; for (String intentConstraint : this.constraints) { org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intent.constraints.Constraints constraint = null; MappedObject mappedObject = null; if (this.profilename.isEmpty()) { this.profilename = null; } else if(!mappingService.get(intentConstraint).isEmpty()) { Map<String, String> mappedConstraint = mappingService.get(intentConstraint); if(mappedConstraint.isEmpty()) { throw new InvalidObjectException(buildConstraintNotFoundMessage(intentConstraint)); } try { if ((mappedObject = MappedObject.extractFirstMappedObject(mappedConstraint, MappedObject.class)) == null) { throw new InvalidObjectException(buildConstraintNotFoundMessage(intentConstraint)); } } catch (JsonSyntaxException exception) { LOG.error("JSON format unknown, unable to parse"); throw new InvalidObjectException("Unknown JSON format!"); } QualityOfServiceConstraint qos = QualityOfServiceConstraint.fromMappedObject(mappedObject); this.profilename = qos.getProfileName(); } if (intentConstraint.equalsIgnoreCase(NicProvider.CONSTRAINT_QOS)) { LOG.info("QoS Constraint match"); constraint = new org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intent.constraints.constraints .QosConstraintBuilder().setQosConstraint(new QosConstraintBuilder().setQosName(this.profilename).build()).build(); } else if (intentConstraint.equalsIgnoreCase(NicProvider.CONSTRAINT_CLASSIFIER)) { LOG.info("Classifier Constraint match"); if (mappedObject.type().equals(ClassifierConstraint.TYPE)) { ClassifierConstraint classifier = ClassifierConstraint.fromMappedObject(mappedObject); } constraint = new org.opendaylight.yang.gen.v1.urn.opendaylight.intent.rev150122.intent.constraints.constraints .ClassificationConstraintBuilder().setClassificationConstraint(new ClassificationConstraintBuilder().setClassifier(intentConstraint).build()).build(); } else { LOG.info("No Constraint match"); continue; } Constraints intentConstraints = new ConstraintsBuilder().setOrder(order).setConstraints(constraint).build(); constraintsList.add(intentConstraints); order++; } return constraintsList; } IntentAddShellCommand(NicConsoleProvider provider, IntentMappingService mappingService);   }
@Test public final void testCreateConstraints() throws InvalidObjectException { Gson gson = new Gson(); MappedObject qos = new QualityOfServiceConstraint("HTTP"); qos.setKey("HTTP"); String object = gson.toJson(qos, MappedObject.class); Map<String, String> resultMap = new HashMap<>(); resultMap.put("QOS", object); resultMap.put("type", "QoSConstraint"); mappingService.add("QOS", resultMap); when(mappingService.get("QOS")).thenReturn(resultMap); when(mappingService.get("QOS")).thenReturn(resultMap); List<Constraints> constraints = nicAddShellCmd.createConstraints(); assertNotNull(constraints); assertEquals("there are should be at least 1 constraints", true , constraints.size() > 0); }