IntentServiceManager { public void addIntent(String src, String dst, String intentAction, String failOverType) { Preconditions.checkNotNull(src); Preconditions.checkNotNull(dst); Preconditions.checkNotNull(intentAction); List<Intent> intentList = null; List<Subjects> subjects = createSubjects(dst, src); List<Actions> intentActions = createActions(intentAction); List<Constraints> intentConstraints = createConstraints(failOverType); Intent intent = new IntentBuilder().setId(new Uuid(UUID.randomUUID().toString())) .setSubjects(subjects).setActions(intentActions) .setConstraints(intentConstraints) .build(); Intents currentIntents = mdsal.read(LogicalDatastoreType.CONFIGURATION, INTENTS_IID); if (currentIntents == null) { intentList = new ArrayList<>(); } else { intentList = currentIntents.getIntent(); } intentList.add(intent); Intents intents = new IntentsBuilder().setIntent(intentList).build(); mdsal.put(LogicalDatastoreType.CONFIGURATION, INTENTS_IID, intents); LOG.info("AddIntent: config populated: {}", intents); } IntentServiceManager(DataBroker dataBroker); void addIntent(String src, String dst, String intentAction, String failOverType); void removeIntent(Uuid id); void removeIntentsByEndpoint(String endpointGroupName); static final String ACTION_ALLOW; static final String ACTION_BLOCK; static final String FAST_REROUTE; static final String SLOW_REROUTE; }
@SuppressWarnings("unchecked") @Test public void testAddIntent() throws Exception { IntentBuilder intentBldr = mock(IntentBuilder.class); PowerMockito.whenNew(IntentBuilder.class).withNoArguments().thenReturn(intentBldr); when(intentBldr.setId(any(Uuid.class))).thenReturn(intentBldr); when(intentBldr.setSubjects(any(List.class))).thenReturn(intentBldr); when(intentBldr.setActions(any(List.class))).thenReturn(intentBldr); when(intentBldr.setConstraints(any(List.class))).thenReturn(intentBldr); when(intentBldr.build()).thenReturn(mock(Intent.class)); Intents currentIntents = mock(Intents.class); PowerMockito.when(mdsal.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(currentIntents); IntentsBuilder intentsBldr = mock(IntentsBuilder.class); PowerMockito.whenNew(IntentsBuilder.class).withNoArguments().thenReturn(intentsBldr); when(intentsBldr.setIntent(any(List.class))).thenReturn(intentsBldr); PowerMockito.when(mdsal.put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Intents.class))).thenReturn(true); intentServiceManager.addIntent(SRC_SITE_NAME, DST_SITE_NAME, INTENT_ALLOW_ACTION, "fast-reroute"); verify(intentBldr).setId(any(Uuid.class)); verify(mdsal).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)); verify(mdsal).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Intents.class)); }