Search in sources :

Example 36 with Thing

use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.

the class FSInternetRadioHandlerJavaTest method muteChhannelUpdated.

/**
 * Verify the mute channel is updated.
 */
@Test
public void muteChhannelUpdated() {
    String muteChannelID = FSInternetRadioBindingConstants.CHANNEL_MUTE;
    String acceptedItemType = acceptedItemTypes.get(muteChannelID);
    createChannel(DEFAULT_THING_UID, muteChannelID, acceptedItemType);
    Thing radioThing = initializeRadioThing(DEFAULT_COMPLETE_CONFIGURATION);
    testRadioThingConsideringConfiguration(radioThing);
    turnTheRadioOn(radioThing);
    ChannelUID muteChannelUID = getChannelUID(radioThing, FSInternetRadioBindingConstants.CHANNEL_MUTE);
    initializeItem(muteChannelUID, DEFAULT_TEST_ITEM_NAME, acceptedItemType);
    radioHandler.handleCommand(muteChannelUID, OnOffType.ON);
    waitForAssert(() -> {
        assertTrue("We should be able to mute the radio", radioServiceDummy.containsRequestParameter(1, CHANNEL_MUTE));
        radioServiceDummy.clearRequestParameters();
    });
    radioHandler.handleCommand(muteChannelUID, OnOffType.OFF);
    waitForAssert(() -> {
        assertTrue("We should be able to unmute the radio", radioServiceDummy.containsRequestParameter(0, CHANNEL_MUTE));
        radioServiceDummy.clearRequestParameters();
    });
/*
         * Setting the needed boolean variable to true, so we can be sure
         * that an invalid value will be returned in the XML response
         */
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Thing(org.eclipse.smarthome.core.thing.Thing) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

Example 37 with Thing

use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.

the class FSInternetRadioHandlerJavaTest method volumechannelUpdatedAbsIncDec.

/**
 * Verify the volume is updated through the CHANNEL_VOLUME_ABSOLUTE using INCREASE and DECREASE commands.
 */
@Test
public void volumechannelUpdatedAbsIncDec() {
    String absoluteVolumeChannelID = FSInternetRadioBindingConstants.CHANNEL_VOLUME_ABSOLUTE;
    String absoluteAcceptedItemType = acceptedItemTypes.get(absoluteVolumeChannelID);
    createChannel(DEFAULT_THING_UID, absoluteVolumeChannelID, absoluteAcceptedItemType);
    Thing radioThing = initializeRadioThing(DEFAULT_COMPLETE_CONFIGURATION);
    testRadioThingConsideringConfiguration(radioThing);
    turnTheRadioOn(radioThing);
    ChannelUID absoluteVolumeChannelUID = getChannelUID(radioThing, absoluteVolumeChannelID);
    Item volumeTestItem = initializeItem(absoluteVolumeChannelUID, DEFAULT_TEST_ITEM_NAME, absoluteAcceptedItemType);
    testChannelWithINCREASEAndDECREASECommands(absoluteVolumeChannelUID, volumeTestItem);
}
Also used : SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Item(org.eclipse.smarthome.core.items.Item) StringItem(org.eclipse.smarthome.core.library.items.StringItem) DimmerItem(org.eclipse.smarthome.core.library.items.DimmerItem) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Thing(org.eclipse.smarthome.core.thing.Thing) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

Example 38 with Thing

use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.

the class FSInternetRadioHandlerJavaTest method invalidAbsVolumeValues.

/**
 * Verify the invalid values when updating CHANNEL_VOLUME_ABSOLUTE are handled correctly.
 */
@Test
public void invalidAbsVolumeValues() {
    String absoluteVolumeChannelID = FSInternetRadioBindingConstants.CHANNEL_VOLUME_ABSOLUTE;
    String absoluteAcceptedItemType = acceptedItemTypes.get(absoluteVolumeChannelID);
    createChannel(DEFAULT_THING_UID, absoluteVolumeChannelID, absoluteAcceptedItemType);
    Thing radioThing = initializeRadioThing(DEFAULT_COMPLETE_CONFIGURATION);
    testRadioThingConsideringConfiguration(radioThing);
    turnTheRadioOn(radioThing);
    ChannelUID absoluteVolumeChannelUID = getChannelUID(radioThing, absoluteVolumeChannelID);
    initializeItem(absoluteVolumeChannelUID, DEFAULT_TEST_ITEM_NAME, absoluteAcceptedItemType);
    // Trying to set a value that is greater than the maximum volume
    radioHandler.handleCommand(absoluteVolumeChannelUID, DecimalType.valueOf("36"));
    waitForAssert(() -> {
        assertTrue("The volume should not exceed the maximum value", radioServiceDummy.containsRequestParameter(32, VOLUME));
        radioServiceDummy.clearRequestParameters();
    });
    // Trying to increase the volume more than its maximum value using the INCREASE command
    radioHandler.handleCommand(absoluteVolumeChannelUID, IncreaseDecreaseType.INCREASE);
    waitForAssert(() -> {
        assertTrue("The volume should not be increased above the maximum value", radioServiceDummy.areRequestParametersEmpty());
        radioServiceDummy.clearRequestParameters();
    });
    // Trying to increase the volume more than its maximum value using the UP command
    radioHandler.handleCommand(absoluteVolumeChannelUID, UpDownType.UP);
    waitForAssert(() -> {
        assertTrue("The volume should not be increased above the maximum value", radioServiceDummy.areRequestParametersEmpty());
        radioServiceDummy.clearRequestParameters();
    });
    // Trying to set a value that is lower than the minimum volume value
    radioHandler.handleCommand(absoluteVolumeChannelUID, DecimalType.valueOf("-10"));
    waitForAssert(() -> {
        assertTrue("The volume should not be decreased below 0", radioServiceDummy.containsRequestParameter(0, VOLUME));
        radioServiceDummy.clearRequestParameters();
    });
    /*
         * Setting the needed boolean variable to true, so we can be sure
         * that an invalid value will be returned in the XML response
         */
    // trying to set the volume
    radioHandler.handleCommand(absoluteVolumeChannelUID, DecimalType.valueOf("15"));
    waitForAssert(() -> {
        assertTrue("We should be able to set the volume correctly", radioServiceDummy.containsRequestParameter(15, VOLUME));
        radioServiceDummy.clearRequestParameters();
    });
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Thing(org.eclipse.smarthome.core.thing.Thing) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

Example 39 with Thing

use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.

the class FSInternetRadioHandlerJavaTest method offlineIfEmptyPIN.

/**
 * Verify OFFLINE Thing status when the PIN is empty String.
 */
@Test
public void offlineIfEmptyPIN() {
    Configuration config = createConfiguration(DEFAULT_CONFIG_PROPERTY_IP, "", String.valueOf(DEFAULT_CONFIG_PROPERTY_PORT), DEFAULT_CONFIG_PROPERTY_REFRESH);
    Thing radioThingWithEmptyPIN = initializeRadioThing(config);
    testRadioThingConsideringConfiguration(radioThingWithEmptyPIN);
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) Thing(org.eclipse.smarthome.core.thing.Thing) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

Example 40 with Thing

use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.

the class FSInternetRadioHandlerJavaTest method volumeChannelUpdatedPercUpDown.

/**
 * Verify the volume is updated through the CHANNEL_VOLUME_PERCENT using UP and DOWN commands.
 */
@Test
public void volumeChannelUpdatedPercUpDown() {
    /*
         * The volume is set through the CHANNEL_VOLUME_PERCENT in order to check if
         * the absolute volume will be updated properly.
         */
    String absoluteVolumeChannelID = FSInternetRadioBindingConstants.CHANNEL_VOLUME_ABSOLUTE;
    String absoluteAcceptedItemType = acceptedItemTypes.get(absoluteVolumeChannelID);
    createChannel(DEFAULT_THING_UID, absoluteVolumeChannelID, absoluteAcceptedItemType);
    String percentVolumeChannelID = FSInternetRadioBindingConstants.CHANNEL_VOLUME_PERCENT;
    String percentAcceptedItemType = acceptedItemTypes.get(percentVolumeChannelID);
    createChannel(DEFAULT_THING_UID, percentVolumeChannelID, percentAcceptedItemType);
    Thing radioThing = initializeRadioThing(DEFAULT_COMPLETE_CONFIGURATION);
    testRadioThingConsideringConfiguration(radioThing);
    turnTheRadioOn(radioThing);
    ChannelUID absoluteVolumeChannelUID = getChannelUID(radioThing, absoluteVolumeChannelID);
    Item volumeTestItem = initializeItem(absoluteVolumeChannelUID, DEFAULT_TEST_ITEM_NAME, absoluteAcceptedItemType);
    ChannelUID percentVolumeChannelUID = getChannelUID(radioThing, percentVolumeChannelID);
    testChannelWithUPAndDOWNCommands(percentVolumeChannelUID, volumeTestItem);
}
Also used : SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Item(org.eclipse.smarthome.core.items.Item) StringItem(org.eclipse.smarthome.core.library.items.StringItem) DimmerItem(org.eclipse.smarthome.core.library.items.DimmerItem) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Thing(org.eclipse.smarthome.core.thing.Thing) Test(org.junit.Test) JavaTest(org.eclipse.smarthome.test.java.JavaTest)

Aggregations

Thing (org.eclipse.smarthome.core.thing.Thing)98 Test (org.junit.Test)43 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)28 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)24 Configuration (org.eclipse.smarthome.config.core.Configuration)19 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)19 JavaTest (org.eclipse.smarthome.test.java.JavaTest)18 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)14 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)13 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 Item (org.eclipse.smarthome.core.items.Item)9 Path (javax.ws.rs.Path)8 Nullable (org.eclipse.jdt.annotation.Nullable)8 Locale (java.util.Locale)7 RolesAllowed (javax.annotation.security.RolesAllowed)7 Channel (org.eclipse.smarthome.core.thing.Channel)7 ThingHandlerCallback (org.eclipse.smarthome.core.thing.binding.ThingHandlerCallback)7 Command (org.eclipse.smarthome.core.types.Command)7 List (java.util.List)6