示例#1
0
  @Test
  public void getInitialEventRenderingControl() throws Exception {

    MockUpnpService upnpService = new MockUpnpService();

    final List<Boolean> testAssertions = new ArrayList();

    LocalDevice device = MediaRendererSampleData.createDevice();
    upnpService.getRegistry().addDevice(device);

    LocalService service = device.getServices()[1];

    SubscriptionCallback callback =
        new SubscriptionCallback(service, 600) {

          @Override
          public void established(GENASubscription sub) {}

          @Override
          protected void failed(
              GENASubscription subscription,
              UpnpResponse responseStatus,
              Exception exception,
              String defaultMsg) {
            throw new RuntimeException(defaultMsg, exception);
          }

          @Override
          public void ended(GENASubscription sub, CancelReason reason, UpnpResponse response) {}

          public void eventReceived(GENASubscription sub) {

            Map<String, StateVariableValue> values = sub.getCurrentValues();
            String lastChangeString = values.get("LastChange").toString();

            try {
              LastChange lastChange =
                  new LastChange(new RenderingControlLastChangeParser(), lastChangeString);
              assertEquals(lastChange.getInstanceIDs().length, 1);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.Mute.class)
                      .getValue()
                      .getChannel(),
                  Channel.Master);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.Mute.class)
                      .getValue()
                      .getMute(),
                  Boolean.FALSE);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.Loudness.class)
                      .getValue()
                      .getChannel(),
                  Channel.Master);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.Loudness.class)
                      .getValue()
                      .getLoudness(),
                  Boolean.FALSE);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.Volume.class)
                      .getValue()
                      .getChannel(),
                  Channel.Master);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.Volume.class)
                      .getValue()
                      .getVolume(),
                  new Integer(50));
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.VolumeDB.class)
                      .getValue()
                      .getChannel(),
                  Channel.Master);
              assertEquals(
                  lastChange
                      .getEventedValue(0, RenderingControlVariable.VolumeDB.class)
                      .getValue()
                      .getVolumeDB(),
                  new Integer(0));

              testAssertions.add(true);

            } catch (Exception ex) {
              throw new RuntimeException(ex);
            }
          }

          public void eventsMissed(GENASubscription sub, int numberOfMissedEvents) {}
        };

    upnpService.getControlPoint().execute(callback);

    assertEquals(testAssertions.size(), 1);
    for (Boolean testAssertion : testAssertions) {
      assert testAssertion;
    }
  }
示例#2
0
  @Test
  public void getInitialEventAVTransport() throws Exception {

    MockUpnpService upnpService = new MockUpnpService();

    final List<Boolean> testAssertions = new ArrayList();

    LocalDevice device = MediaRendererSampleData.createDevice();
    upnpService.getRegistry().addDevice(device);

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

    SubscriptionCallback callback =
        new SubscriptionCallback(service, 600) {

          @Override
          public void established(GENASubscription sub) {}

          @Override
          protected void failed(
              GENASubscription subscription,
              UpnpResponse responseStatus,
              Exception exception,
              String defaultMsg) {
            throw new RuntimeException(defaultMsg, exception);
          }

          @Override
          public void ended(GENASubscription sub, CancelReason reason, UpnpResponse response) {}

          public void eventReceived(GENASubscription sub) {

            Map<String, StateVariableValue> values = sub.getCurrentValues();
            String lastChangeString = values.get("LastChange").toString();

            try {
              LastChange lastChange =
                  new LastChange(new AVTransportLastChangeParser(), lastChangeString);
              assertEquals(lastChange.getInstanceIDs().length, 1);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.AVTransportURI.class)
                      .getValue(),
                  null);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.AVTransportURIMetaData.class)
                      .getValue(),
                  null);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentMediaDuration.class)
                      .getValue(),
                  "00:00:00");
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentPlayMode.class)
                      .getValue(),
                  PlayMode.NORMAL);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentRecordQualityMode.class)
                      .getValue(),
                  RecordQualityMode.NOT_IMPLEMENTED);
              assertEquals(
                  lastChange.getEventedValue(0, AVTransportVariable.CurrentTrack.class).getValue(),
                  new UnsignedIntegerFourBytes(0));
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentTrackDuration.class)
                      .getValue(),
                  "00:00:00");
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentTrackMetaData.class)
                      .getValue(),
                  "NOT_IMPLEMENTED");
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentTrackURI.class)
                      .getValue(),
                  null);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.CurrentTransportActions.class)
                      .getValue(),
                  new TransportAction[] {TransportAction.Stop});
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.NextAVTransportURI.class)
                      .getValue()
                      .toString(),
                  "NOT_IMPLEMENTED"); // TODO: That's weird
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.NumberOfTracks.class)
                      .getValue(),
                  new UnsignedIntegerFourBytes(0));
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.PossiblePlaybackStorageMedia.class)
                      .getValue(),
                  new StorageMedium[] {StorageMedium.NETWORK});
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.PossibleRecordQualityModes.class)
                      .getValue(),
                  new RecordQualityMode[] {RecordQualityMode.NOT_IMPLEMENTED});
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.PossibleRecordStorageMedia.class)
                      .getValue(),
                  new StorageMedium[] {StorageMedium.NOT_IMPLEMENTED});
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.RecordMediumWriteStatus.class)
                      .getValue(),
                  RecordMediumWriteStatus.NOT_IMPLEMENTED);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.RecordStorageMedium.class)
                      .getValue(),
                  StorageMedium.NOT_IMPLEMENTED);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.TransportPlaySpeed.class)
                      .getValue(),
                  "1");
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.TransportState.class)
                      .getValue(),
                  TransportState.NO_MEDIA_PRESENT);
              assertEquals(
                  lastChange
                      .getEventedValue(0, AVTransportVariable.TransportStatus.class)
                      .getValue(),
                  TransportStatus.OK);

              testAssertions.add(true);

            } catch (Exception ex) {
              throw new RuntimeException(ex);
            }
          }

          public void eventsMissed(GENASubscription sub, int numberOfMissedEvents) {}
        };

    upnpService.getControlPoint().execute(callback);

    assertEquals(testAssertions.size(), 1);
    for (Boolean testAssertion : testAssertions) {
      assert testAssertion;
    }
  }