Search in sources :

Example 31 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class NtpOSGiTest method testNullPropertyFormatting.

@Test
public void testNullPropertyFormatting() {
    Configuration configuration = new Configuration();
    Configuration channelConfig = new Configuration();
    channelConfig.put(NtpBindingConstants.PROPERTY_DATE_TIME_FORMAT, null);
    initialize(configuration, NtpBindingConstants.CHANNEL_STRING, ACCEPTED_ITEM_TYPE_STRING, channelConfig, null);
    String dateFromItemRegistry = getItemState(ACCEPTED_ITEM_TYPE_STRING).toString();
    assertFormat(dateFromItemRegistry, NtpHandler.DATE_PATTERN_WITH_TZ);
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 32 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class NtpOSGiTest method testStringChannelFormatting.

@Test
public void testStringChannelFormatting() {
    final String formatPattern = "EEE, d MMM yyyy HH:mm:ss z";
    Configuration configuration = new Configuration();
    Configuration channelConfig = new Configuration();
    channelConfig.put(NtpBindingConstants.PROPERTY_DATE_TIME_FORMAT, formatPattern);
    initialize(configuration, NtpBindingConstants.CHANNEL_STRING, ACCEPTED_ITEM_TYPE_STRING, channelConfig, null);
    String dateFromItemRegistry = getItemState(ACCEPTED_ITEM_TYPE_STRING).toString();
    assertFormat(dateFromItemRegistry, formatPattern);
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 33 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class NtpOSGiTest method assertCommunicationError.

private void assertCommunicationError(String acceptedItemType) {
    Configuration configuration = new Configuration();
    final String WRONG_HOSTNAME = "wrong.hostname";
    if (acceptedItemType.equals(ACCEPTED_ITEM_TYPE_DATE_TIME)) {
        initialize(configuration, NtpBindingConstants.CHANNEL_DATE_TIME, ACCEPTED_ITEM_TYPE_DATE_TIME, null, WRONG_HOSTNAME);
    } else if (acceptedItemType.equals(ACCEPTED_ITEM_TYPE_STRING)) {
        initialize(configuration, NtpBindingConstants.CHANNEL_STRING, ACCEPTED_ITEM_TYPE_STRING, null, WRONG_HOSTNAME);
    }
    waitForAssert(() -> {
        assertEquals(ThingStatusDetail.COMMUNICATION_ERROR, ntpThing.getStatusInfo().getStatusDetail());
    });
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration)

Example 34 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class NtpOSGiTest method testEmptyStringPropertyFormatting.

@Test
public void testEmptyStringPropertyFormatting() {
    Configuration configuration = new Configuration();
    Configuration channelConfig = new Configuration();
    // Empty string
    channelConfig.put(NtpBindingConstants.PROPERTY_DATE_TIME_FORMAT, "");
    initialize(configuration, NtpBindingConstants.CHANNEL_STRING, ACCEPTED_ITEM_TYPE_STRING, channelConfig, null);
    String dateFromItemRegistry = getItemState(ACCEPTED_ITEM_TYPE_STRING).toString();
    assertFormat(dateFromItemRegistry, NtpHandler.DATE_PATTERN_WITH_TZ);
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 35 with Configuration

use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.

the class NtpOSGiTest method assertEventIsReceived.

private void assertEventIsReceived(UpdateEventType updateEventType, String channelID, String acceptedItemType) {
    Configuration configuration = new Configuration();
    initialize(configuration, channelID, acceptedItemType, null, null);
    EventSubscriber eventSubscriberMock = mock(EventSubscriber.class);
    when(eventSubscriberMock.getSubscribedEventTypes()).thenReturn(Collections.singleton(ItemStateEvent.TYPE));
    registerService(eventSubscriberMock);
    if (updateEventType.equals(UpdateEventType.HANDLE_COMMAND)) {
        ntpHandler.handleCommand(new ChannelUID("ntp:test:chan:1"), new StringType("test"));
    } else if (updateEventType.equals(UpdateEventType.CHANNEL_LINKED)) {
        ntpHandler.channelLinked(new ChannelUID("ntp:test:chan:1"));
    }
    waitForAssert(() -> {
        verify(eventSubscriberMock, atLeastOnce()).receive(ArgumentMatchers.any(Event.class));
    });
}
Also used : EventSubscriber(org.eclipse.smarthome.core.events.EventSubscriber) Configuration(org.eclipse.smarthome.config.core.Configuration) StringType(org.eclipse.smarthome.core.library.types.StringType) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ItemStateEvent(org.eclipse.smarthome.core.items.events.ItemStateEvent) Event(org.eclipse.smarthome.core.events.Event)

Aggregations

Configuration (org.eclipse.smarthome.config.core.Configuration)119 Test (org.junit.Test)27 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)19 ArrayList (java.util.ArrayList)18 Thing (org.eclipse.smarthome.core.thing.Thing)18 Action (org.eclipse.smarthome.automation.Action)16 Trigger (org.eclipse.smarthome.automation.Trigger)16 Rule (org.eclipse.smarthome.automation.Rule)15 Before (org.junit.Before)14 Condition (org.eclipse.smarthome.automation.Condition)10 Bridge (org.eclipse.smarthome.core.thing.Bridge)9 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiResponses (io.swagger.annotations.ApiResponses)8 HashMap (java.util.HashMap)8 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)8 Path (javax.ws.rs.Path)7 IOException (java.io.IOException)6 BigDecimal (java.math.BigDecimal)6 Consumes (javax.ws.rs.Consumes)6 RuleRegistry (org.eclipse.smarthome.automation.RuleRegistry)6