Ejemplo n.º 1
0
  @Before
  public void setUp() {
    mgr = new GroupManager();
    groupService = mgr;
    // mgr.deviceService = new DeviceManager();
    mgr.deviceService = new TestDeviceService();
    mgr.cfgService = new ComponentConfigAdapter();
    mgr.store = new SimpleGroupStore();
    injectEventDispatcher(mgr, new TestEventDispatcher());
    providerRegistry = mgr;

    mgr.activate(null);
    mgr.addListener(listener);

    driverService = new TestDriverManager();
    driverService.addDriver(
        new DefaultDriver(
            "foo",
            ImmutableList.of(),
            "",
            "",
            "",
            ImmutableMap.of(GroupProgrammable.class, TestGroupProgrammable.class),
            ImmutableMap.of()));

    internalProvider = new TestGroupProvider(PID);
    provider = internalProvider;
    providerService = providerRegistry.register(provider);
    appId = new DefaultApplicationId(2, "org.groupmanager.test");
    assertTrue(
        "provider should be registered", providerRegistry.getProviders().contains(provider.id()));
  }
Ejemplo n.º 2
0
    @Override
    public void notify(GroupEvent event) {
      final Group group = event.subject();
      GroupProvider groupProvider = getProvider(group.deviceId());
      GroupOperations groupOps = null;
      switch (event.type()) {
        case GROUP_ADD_REQUESTED:
          log.debug("GROUP_ADD_REQUESTED for Group {} on device {}", group.id(), group.deviceId());
          GroupOperation groupAddOp =
              GroupOperation.createAddGroupOperation(group.id(), group.type(), group.buckets());
          groupOps = new GroupOperations(Collections.singletonList(groupAddOp));
          groupProvider.performGroupOperation(group.deviceId(), groupOps);
          break;

        case GROUP_UPDATE_REQUESTED:
          log.debug(
              "GROUP_UPDATE_REQUESTED for Group {} on device {}", group.id(), group.deviceId());
          GroupOperation groupModifyOp =
              GroupOperation.createModifyGroupOperation(group.id(), group.type(), group.buckets());
          groupOps = new GroupOperations(Collections.singletonList(groupModifyOp));
          groupProvider.performGroupOperation(group.deviceId(), groupOps);
          break;

        case GROUP_REMOVE_REQUESTED:
          log.debug(
              "GROUP_REMOVE_REQUESTED for Group {} on device {}", group.id(), group.deviceId());
          GroupOperation groupDeleteOp =
              GroupOperation.createDeleteGroupOperation(group.id(), group.type());
          groupOps = new GroupOperations(Collections.singletonList(groupDeleteOp));
          groupProvider.performGroupOperation(group.deviceId(), groupOps);
          break;

        case GROUP_ADDED:
        case GROUP_UPDATED:
        case GROUP_REMOVED:
        case GROUP_ADD_FAILED:
        case GROUP_UPDATE_FAILED:
        case GROUP_REMOVE_FAILED:
          post(event);
          break;

        default:
          break;
      }
    }
Ejemplo n.º 3
0
 @After
 public void tearDown() {
   providerRegistry.unregister(provider);
   assertFalse(
       "provider should not be registered",
       providerRegistry.getProviders().contains(provider.id()));
   mgr.removeListener(listener);
   mgr.deactivate();
   injectEventDispatcher(mgr, null);
 }