Example #1
0
  @Test(dataProvider = "devices")
  public void invokeActions(LocalDevice device) {
    // We mostly care about the binding without exceptions, but let's also test invocation
    LocalService svc = device.getServices()[0];

    ActionInvocation setTargetInvocation = new ActionInvocation(svc.getAction("SetTarget"));
    setTargetInvocation.setInput("NewTargetValue", true);
    svc.getExecutor(setTargetInvocation.getAction()).execute(setTargetInvocation);
    assertEquals(setTargetInvocation.getFailure(), null);
    assertEquals(setTargetInvocation.getOutput().length, 0);

    ActionInvocation getStatusInvocation = new ActionInvocation(svc.getAction("GetStatus"));
    svc.getExecutor(getStatusInvocation.getAction()).execute(getStatusInvocation);
    assertEquals(getStatusInvocation.getFailure(), null);
    assertEquals(getStatusInvocation.getOutput().length, 1);
    assertEquals(getStatusInvocation.getOutput()[0].toString(), "1");

    setTargetInvocation = new ActionInvocation(svc.getAction("SetTarget"));
    setTargetInvocation.setInput("NewTargetValue", false);
    svc.getExecutor(setTargetInvocation.getAction()).execute(setTargetInvocation);
    assertEquals(setTargetInvocation.getFailure(), null);
    assertEquals(setTargetInvocation.getOutput().length, 0);

    ActionInvocation queryStateVariableInvocation =
        new ActionInvocation(svc.getAction("QueryStateVariable"));
    queryStateVariableInvocation.setInput("varName", "Status");
    svc.getExecutor(queryStateVariableInvocation.getAction()).execute(queryStateVariableInvocation);
    assertEquals(queryStateVariableInvocation.getFailure(), null);
    assertEquals(queryStateVariableInvocation.getOutput().length, 1);
    assertEquals(queryStateVariableInvocation.getOutput()[0].toString(), "0");
  }
Example #2
0
  public LocalDevice createTestDevice(Class serviceClass) throws Exception {

    LocalServiceBinder binder = new AnnotationLocalServiceBinder();
    LocalService svc = binder.read(serviceClass);
    svc.setManager(new DefaultServiceManager(svc, serviceClass));

    return new LocalDevice(
        SampleData.createLocalDeviceIdentity(),
        new UDADeviceType("BinaryLight", 1),
        new DeviceDetails("Example Binary Light"),
        svc);
  }
Example #3
0
  @Test(dataProvider = "devices")
  public void validateBinding(LocalDevice device) {

    LocalService svc = device.getServices()[0];

    /*
            System.out.println("############################################################################");
            ServiceDescriptorBinder binder = new DefaultUpnpServiceConfiguration().getServiceDescriptorBinderUDA10();
            try {
                System.out.println(binder.generate(svc));
            } catch (DescriptorBindingException e) {
                throw new RuntimeException(e);
            }
            System.out.println("############################################################################");

    */
    assertEquals(
        svc.getServiceId().toString(),
        "urn:" + UDAServiceId.DEFAULT_NAMESPACE + ":serviceId:SwitchPower");
    assertEquals(
        svc.getServiceType().toString(),
        "urn:" + UDAServiceType.DEFAULT_NAMESPACE + ":service:SwitchPower:1");

    assertEquals(svc.getStateVariables().length, 2);
    assertEquals(
        svc.getStateVariable("Target").getTypeDetails().getDatatype().getBuiltin(),
        Datatype.Builtin.BOOLEAN);
    assertEquals(svc.getStateVariable("Target").getTypeDetails().getDefaultValue(), "0");
    assertEquals(svc.getStateVariable("Target").getEventDetails().isSendEvents(), false);

    assertEquals(
        svc.getStateVariable("Status").getTypeDetails().getDatatype().getBuiltin(),
        Datatype.Builtin.BOOLEAN);
    assertEquals(svc.getStateVariable("Status").getTypeDetails().getDefaultValue(), "0");
    assertEquals(svc.getStateVariable("Status").getEventDetails().isSendEvents(), true);

    assertEquals(svc.getActions().length, 4); // Has 3 actions plus QueryStateVariableAction!

    assertEquals(svc.getAction("SetTarget").getName(), "SetTarget");
    assertEquals(svc.getAction("SetTarget").getArguments().length, 1);
    assertEquals(svc.getAction("SetTarget").getArguments()[0].getName(), "NewTargetValue");
    assertEquals(
        svc.getAction("SetTarget").getArguments()[0].getDirection(), ActionArgument.Direction.IN);
    assertEquals(
        svc.getAction("SetTarget").getArguments()[0].getRelatedStateVariableName(), "Target");

    assertEquals(svc.getAction("GetTarget").getName(), "GetTarget");
    assertEquals(svc.getAction("GetTarget").getArguments().length, 1);
    assertEquals(svc.getAction("GetTarget").getArguments()[0].getName(), "RetTargetValue");
    assertEquals(
        svc.getAction("GetTarget").getArguments()[0].getDirection(), ActionArgument.Direction.OUT);
    assertEquals(
        svc.getAction("GetTarget").getArguments()[0].getRelatedStateVariableName(), "Target");
    assertEquals(svc.getAction("GetTarget").getArguments()[0].isReturnValue(), true);

    assertEquals(svc.getAction("GetStatus").getName(), "GetStatus");
    assertEquals(svc.getAction("GetStatus").getArguments().length, 1);
    assertEquals(svc.getAction("GetStatus").getArguments()[0].getName(), "ResultStatus");
    assertEquals(
        svc.getAction("GetStatus").getArguments()[0].getDirection(), ActionArgument.Direction.OUT);
    assertEquals(
        svc.getAction("GetStatus").getArguments()[0].getRelatedStateVariableName(), "Status");
    assertEquals(svc.getAction("GetStatus").getArguments()[0].isReturnValue(), true);
  }