@Override
    public void apply(IntentOperationContext<ProtectionEndpointIntent> context) {
        Optional<IntentData> toUninstall = context.toUninstall();
        Optional<IntentData> toInstall = context.toInstall();

        List<ProtectionEndpointIntent> uninstallIntents = context.intentsToUninstall();
        List<ProtectionEndpointIntent> installIntents = context.intentsToInstall();

        if (!toInstall.isPresent() && !toUninstall.isPresent()) {
            intentInstallCoordinator.intentInstallSuccess(context);
            return;
        }

        if (toUninstall.isPresent()) {
            IntentData intentData = toUninstall.get();
            trackerService.removeTrackedResources(intentData.key(), intentData.intent().resources());
            uninstallIntents.forEach(installable ->
                                             trackerService.removeTrackedResources(intentData.intent().key(),
                                                                                   installable.resources()));
        }

        if (toInstall.isPresent()) {
            IntentData intentData = toInstall.get();
            trackerService.addTrackedResources(intentData.key(), intentData.intent().resources());
            installIntents.forEach(installable ->
                                           trackerService.addTrackedResources(intentData.key(),
                                                                              installable.resources()));
        }

        List<Stage> stages = new ArrayList<>();

        stages.add(new Stage(uninstallIntents.stream()
                                     .map(i -> Pair.of(i, REMOVE))
                                     .collect(Collectors.toList())));

        stages.add(new Stage(installIntents.stream()
                                     .map(i -> Pair.of(i, ADD))
                                     .collect(Collectors.toList())));
        for (Stage stage : stages) {
            log.debug("applying Stage {}", stage);
            try {
                // wait for stage completion
                stage.apply();
                stage.listeners().forEach(networkConfigService::removeListener);
            } catch (IntentException e) {
                log.error("Stage {} failed, reason: {}", stage, e.toString());
                intentInstallCoordinator.intentInstallFailed(context);
                return;
            }
        }
        // All stage success
        intentInstallCoordinator.intentInstallSuccess(context);
    }
@Test
    public void testNoAnyIntentToApply() {
        IntentData toInstall = null;
        IntentData toUninstall = null;
        IntentOperationContext<ProtectionEndpointIntent> operationContext;
        IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
        operationContext = new IntentOperationContext<>(ImmutableList.of(), ImmutableList.of(), context);
        installer.apply(operationContext);
        IntentOperationContext successContext = intentInstallCoordinator.successContext;
        assertEquals(successContext, operationContext);
    }