### Question:
SendAction extends BaseStatefulAction { @Override public boolean isSatisfiable(ActionContext context) { Address toAddress =to.apply(context); Model model = context.getModelByAddress(toAddress); String group = toAddress.getGroup()!=null?toAddress.getGroup().toString():""; boolean isSatisfiable = false; if(toAddress.getId() == null || toAddress.getId().equals(Address.ZERO_UUID)){ isSatisfiable = true; } else{ switch(group){ case VideoService.NAMESPACE: isSatisfiable = true; break; default: isSatisfiable = model != null; } } return isSatisfiable; } SendAction(
         String type,
         @Nullable Function<? super ActionContext, Address> to,
         @Nullable Map<String, Object> staticAttributes
   );  SendAction(
         String type,
         @Nullable Function<? super ActionContext, Address> to,
         @Nullable Map<String, Object> staticAttributes,
         @Nullable Map<String, Function<ActionContext, Object>> dynamicAttributes
   ); String getType(); Address getTo(ActionContext context); Map<String, Object> mergeAttributes(); Map<String, Object> getAttributes(ActionContext context); @Override String getName(); @Override String getDescription(); @Override boolean isSatisfiable(ActionContext context); @Override ActionState execute(ActionContext context); @Override ActionState keepFiring(ActionContext context, RuleEvent event, boolean conditionMatches); @Override String toString(); static final String VAR_TO; static final String VAR_ATTRIBUTES; static final String NAME; }### Answer:
@Test public void testSendActionSatisfiablityDevice() throws Exception { Model device = createDeviceModel(); SendAction action = new SendAction.Builder("test:Action") .withDestination(device.getAddress()) .build(); assertFalse(action.isSatisfiable(context)); context.putModel(device); assertTrue(action.isSatisfiable(context)); }
@Test public void testSendActionSatisfiablityNotification() throws Exception { SendAction action = new SendAction.Builder("test:Action") .withDestination(Address.platformService(NotificationCapability.NAMESPACE)) .build(); assertTrue(action.isSatisfiable(context)); }
@Test @Ignore public void testSendActionSatisfiablitySubsystemAvailable() throws Exception { Model subsystem = createModel(SecuritySubsystemCapability.NAMESPACE,Address.platformService(UUID.randomUUID(),"subssecurity")); SendAction action = new SendAction.Builder("test:Action") .withDestination(subsystem.getAddress()) .build(); assertFalse(action.isSatisfiable(context)); context.putModel(subsystem); assertFalse(action.isSatisfiable(context)); subsystem.setAttribute(SubsystemCapability.ATTR_AVAILABLE, true); assertTrue(action.isSatisfiable(context)); }
@Test public void testSendActionSatisfiablitySceneEnabled() throws Exception { Model scene = createModel(SecuritySubsystemCapability.NAMESPACE,Address.platformService(UUID.randomUUID(),"scene")); SendAction action = new SendAction.Builder("test:Action") .withDestination(scene.getAddress()) .build(); assertFalse(action.isSatisfiable(context)); context.putModel(scene); assertTrue(action.isSatisfiable(context)); }
@Test public void testSendActionSatisfiablity() throws Exception { SendAction action = new SendAction.Builder("test:Action") .withDestination(destination) .withAttribute("test:value", "test") .build(); assertFalse(action.isSatisfiable(context)); context.putModel(new SimpleModel(ImmutableMap.<String,Object>of("base:address", destination.getRepresentation()))); assertTrue(action.isSatisfiable(context)); }
@Test public void testSendActionSatisfiablityVideo() throws Exception { SendAction action = new SendAction.Builder("test:Action") .withDestination("SERV:video:ce07c9ab-bc69-4433-b0ca-6c56ecb3c5be") .withAttribute("test:value", "test") .build(); assertTrue(action.isSatisfiable(context)); }