Java Code Examples for org.eclipse.emf.common.util.BasicEList#add()

The following examples show how to use org.eclipse.emf.common.util.BasicEList#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemUIRegistryImplTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void getLabelColor_labelWithDecimalValue() {
    String testLabel = "Label [%.3f]";

    when(widget.getLabel()).thenReturn(testLabel);

    ColorArray colorArray = mock(ColorArray.class);
    when(colorArray.getState()).thenReturn("21");
    when(colorArray.getCondition()).thenReturn("<");
    when(colorArray.getArg()).thenReturn("yellow");
    BasicEList<ColorArray> colorArrays = new BasicEList<ColorArray>();
    colorArrays.add(colorArray);
    when(widget.getLabelColor()).thenReturn(colorArrays);

    when(item.getState()).thenReturn(new DecimalType(10f / 3f));

    String color = uiRegistry.getLabelColor(widget);
    assertEquals("yellow", color);
}
 
Example 2
Source File: ItemUIRegistryImplTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testStateConversionForSwitchWidgetWithMappingThroughGetState() throws ItemNotFoundException {
    State colorState = new HSBType("23,42,50");

    ColorItem colorItem = new ColorItem("myItem");
    colorItem.setLabel("myItem");
    colorItem.setState(colorState);

    when(registry.getItem("myItem")).thenReturn(colorItem);

    Switch switchWidget = mock(Switch.class);
    when(switchWidget.getItem()).thenReturn("myItem");

    Mapping mapping = mock(Mapping.class);
    BasicEList<Mapping> mappings = new BasicEList<Mapping>();
    mappings.add(mapping);
    when(switchWidget.getMappings()).thenReturn(mappings);

    State stateForSwitch = uiRegistry.getState(switchWidget);

    assertEquals(colorState, stateForSwitch);
}
 
Example 3
Source File: ItemUIRegistryImplTest.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void getLabelColorLabelWithUnitValue() {
    String testLabel = "Label [%.3f " + UnitUtils.UNIT_PLACEHOLDER + "]";

    when(widget.getLabel()).thenReturn(testLabel);

    ColorArray colorArray = mock(ColorArray.class);
    when(colorArray.getState()).thenReturn("20");
    when(colorArray.getCondition()).thenReturn("==");
    when(colorArray.getArg()).thenReturn("yellow");
    BasicEList<ColorArray> colorArrays = new BasicEList<>();
    colorArrays.add(colorArray);
    when(widget.getLabelColor()).thenReturn(colorArrays);

    when(item.getState()).thenReturn(new QuantityType<>("20 °C"));

    String color = uiRegistry.getLabelColor(widget);
    assertEquals("yellow", color);
}
 
Example 4
Source File: ItemUIRegistryImplTest.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testStateConversionForSwitchWidgetWithMappingThroughGetState() throws ItemNotFoundException {
    State colorState = new HSBType("23,42,50");

    ColorItem colorItem = new ColorItem("myItem");
    colorItem.setLabel("myItem");
    colorItem.setState(colorState);

    when(registry.getItem("myItem")).thenReturn(colorItem);

    Switch switchWidget = mock(Switch.class);
    when(switchWidget.getItem()).thenReturn("myItem");

    Mapping mapping = mock(Mapping.class);
    BasicEList<Mapping> mappings = new BasicEList<>();
    mappings.add(mapping);
    when(switchWidget.getMappings()).thenReturn(mappings);

    State stateForSwitch = uiRegistry.getState(switchWidget);

    assertEquals(colorState, stateForSwitch);
}
 
Example 5
Source File: JvmAnnotationReferenceImplCustom.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public EList<JvmAnnotationValue> getValues() {
	EList<JvmAnnotationValue> explicitValues = getExplicitValues();
	List<JvmOperation> operations = Lists.newArrayList(getAnnotation().getDeclaredOperations());
	if (operations.size() <= explicitValues.size()) {
		return ECollections.unmodifiableEList(explicitValues);
	}
	Set<JvmOperation> seenOperations = Sets.newHashSetWithExpectedSize(operations.size());
	BasicEList<JvmAnnotationValue> result = new BasicEList<JvmAnnotationValue>(operations.size());
	for(JvmAnnotationValue value: explicitValues) {
		seenOperations.add(value.getOperation());
		result.add(value);
	}
	for(JvmOperation operation: operations) {
		if (seenOperations.add(operation)) {
			JvmAnnotationValue defaultValue = operation.getDefaultValue();
			if (defaultValue != null) {
				result.add(defaultValue);
			}
		}
	}
	return ECollections.unmodifiableEList(result);
}
 
Example 6
Source File: UpdateConnectorDefinitionMigrationTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private EList<Instance> connectorConfiguratiobInstanceList(final String... defIds) {
    final BasicEList<Instance> instances = new BasicEList<Instance>();
    for (final String defId : defIds) {
        instances.add(aConnectorConfigurationInstance(defId, "1.0"));
    }
    return instances;
}
 
Example 7
Source File: AverageModuleImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * 
 * @generated NOT
 */
@Override
public EList<InputSpecification> getKnownInputs ()
{
    if ( this.knownInputs == null )
    {
        final BasicEList<InputSpecification> inputs = ECollections.newBasicEList ();
        inputs.add ( Components.createInput ( "input" ) );
        this.knownInputs = ECollections.unmodifiableEList ( inputs );
    }
    return this.knownInputs;
}
 
Example 8
Source File: CreateContractCustomMigrationTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    customMigration = new CreateContractCustomMigration();
    final BasicEList<Instance> uniqueTaskEList = new BasicEList<Instance>();
    uniqueTaskEList.add(originalTaskInstance);
    when(model.getAllInstances("process.Task")).thenReturn(uniqueTaskEList);
    when(model.newInstance("process.Contract")).thenReturn(newContractInstance);
}
 
Example 9
Source File: GenericThingProviderMultipleBundlesTest.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
private EList<ModelThing> createModelBridge() {
    ModelBridge bridge = mock(ModelBridge.class);
    when(bridge.getId()).thenReturn(BRIDGE_UID.toString());
    when(bridge.getProperties()).thenReturn(new BasicEList<>(0));
    when(bridge.getChannels()).thenReturn(new BasicEList<>(0));

    EList<ModelThing> modelThings = createModelThing();
    when(bridge.getThings()).thenReturn(modelThings);

    BasicEList<ModelThing> result = new BasicEList<>();
    result.add(bridge);
    return result;
}
 
Example 10
Source File: ClassDiagramTests.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testArgument() {
	// given
	BasicEList<String> paramNames = new BasicEList<>(Arrays.asList("a", "b", "c", "d", "e", "f"));

	BasicEList<Type> paramTypes = new BasicEList<Type>();
	paramTypes.add(classA);
	paramTypes.addAll(primitives.getSecond());

	List<String> paramTypeNames = new ArrayList<String>();
	paramTypeNames.add("A");
	paramTypeNames.addAll(primitives.getFirst());

	Operation op = classA.createOwnedOperation("function", (EList<String>) paramNames, (EList<Type>) paramTypes);

	// when
	List<Argument> instances = new ArrayList<>();
	op.getOwnedParameters().forEach(parameter -> {
		instances.add(new Argument(parameter));
	});

	// then
	IntStream.range(0, instances.size()).forEach(i -> {
		Argument instanceArgument = instances.get(i);

		Assert.assertEquals(paramNames.get(i), instanceArgument.getName());
		Assert.assertEquals(paramTypeNames.get(i), instanceArgument.getType());
	});
}
 
Example 11
Source File: UpdateConnectorDefinitionMigrationTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private EList<Instance> connectorInstanceList(final String... defIds) {
    final BasicEList<Instance> instances = new BasicEList<Instance>();
    for (final String defId : defIds) {
        instances.add(aConnectorInstance(defId, "1.0"));
    }
    return instances;
}
 
Example 12
Source File: XMemberFeatureCallImplCustom.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public EList<XExpression> getExplicitArguments() {
	BasicEList<XExpression> result = new BasicEList<XExpression>();
	if (getMemberCallTarget()!=null)
		result.add(getMemberCallTarget());
	result.addAll(getMemberCallArguments());
	return result;
}
 
Example 13
Source File: XUnaryOperationImplCustom.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public EList<XExpression> getExplicitArguments() {
	BasicEList<XExpression> result = new BasicEList<XExpression>();
	if (getOperand()!=null)
		result.add(getOperand());
	return result;
}
 
Example 14
Source File: CustomUserInfoNameExpressionProviderTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void getExpressions_return_one_expression_for_each_customUserDefition() throws Exception {
    final BasicEList<CustomUserInfoDefinition> elements = new BasicEList<CustomUserInfoDefinition>();
    elements.add(getUserDefinition("Skills"));
    elements.add(getUserDefinition("Office location"));
    given(definitionsContainer.getCustomUserInfoDefinition()).willReturn(elements);

    //when
    final Expression[] expressions = provider.getExpressions(null);

    //then
    assertThat(expressions).hasSize(2);
    assertThat(expressions[0].getContent()).isEqualTo("Skills");
    assertThat(expressions[1].getContent()).isEqualTo("Office location");
}
 
Example 15
Source File: MovingAverageModuleImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
@Override
public EList<OutputSpecification> getKnownOutputs ()
{
    if ( this.knownOutputs == null )
    {
        final BasicEList<OutputSpecification> outputs = ECollections.newBasicEList ();
        for ( final MovingAverageReferenceType type : MovingAverageReferenceType.values () )
        {
            outputs.add ( Components.createOutput ( type.getLiteral (), DataType.FLOAT ) );
        }
        this.knownOutputs = ECollections.unmodifiableEList ( outputs );
    }
    return this.knownOutputs;
}
 
Example 16
Source File: MovingAverageModuleImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated NOT
 */
@Override
public EList<InputSpecification> getKnownInputs ()
{
    if ( this.knownInputs == null )
    {
        final BasicEList<InputSpecification> inputs = ECollections.newBasicEList ();
        inputs.add ( Components.createInput ( "input" ) );
        this.knownInputs = ECollections.unmodifiableEList ( inputs );
    }
    return this.knownInputs;
}
 
Example 17
Source File: FormulaModuleImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * 
 * @generated NOT
 */
@Override
public EList<OutputSpecification> getKnownOutputs ()
{
    if ( this.knownOutputs == null )
    {
        final BasicEList<OutputSpecification> outputs = ECollections.newBasicEList ();
        outputs.add ( Components.createOutput ( "output", null ) );
        this.knownOutputs = ECollections.unmodifiableEList ( outputs );
    }
    return this.knownOutputs;
}
 
Example 18
Source File: AverageModuleImpl.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * 
 * @generated NOT
 */
@Override
public EList<OutputSpecification> getKnownOutputs ()
{
    if ( this.knownOutputs == null )
    {
        final BasicEList<OutputSpecification> outputs = ECollections.newBasicEList ();
        for ( final AverageReferenceType type : AverageReferenceType.values () )
        {
            outputs.add ( Components.createOutput ( type.getLiteral (), DataType.FLOAT ) );
        }
        this.knownOutputs = ECollections.unmodifiableEList ( outputs );
    }
    return this.knownOutputs;
}
 
Example 19
Source File: SitemapResourceTest.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
private EList<Widget> initSitemapWidgets() {
    // Initialize a sitemap containing 2 widgets linked to the same number item,
    // one slider and one switch

    Widget w1 = mock(Widget.class);
    EClass sliderEClass = mock(EClass.class);
    when(sliderEClass.getName()).thenReturn("slider");
    when(sliderEClass.getInstanceTypeName()).thenReturn("org.eclipse.smarthome.model.sitemap.Slider");
    when(w1.eClass()).thenReturn(sliderEClass);
    when(w1.getLabel()).thenReturn(WIDGET1_LABEL);
    when(w1.getItem()).thenReturn(ITEM_NAME);

    // add visibility rules to the mock widget:
    VisibilityRule visibilityRule = mock(VisibilityRule.class);
    when(visibilityRule.getItem()).thenReturn(VISIBILITY_RULE_ITEM_NAME);
    BasicEList<VisibilityRule> visibilityRules = new BasicEList<>(1);
    visibilityRules.add(visibilityRule);
    when(w1.getVisibility()).thenReturn(visibilityRules);

    // add label color conditions to the item:
    ColorArray labelColor = mock(ColorArray.class);
    when(labelColor.getItem()).thenReturn(LABEL_COLOR_ITEM_NAME);
    EList<ColorArray> labelColors = new BasicEList<>();
    labelColors.add(labelColor);
    when(w1.getLabelColor()).thenReturn(labelColors);

    // add value color conditions to the item:
    ColorArray valueColor = mock(ColorArray.class);
    when(valueColor.getItem()).thenReturn(VALUE_COLOR_ITEM_NAME);
    EList<ColorArray> valueColors = new BasicEList<>();
    valueColors.add(valueColor);
    when(w1.getValueColor()).thenReturn(valueColors);

    visibilityRules = new BasicEList<>();
    labelColors = new BasicEList<>();
    valueColors = new BasicEList<>();

    Widget w2 = mock(Widget.class);
    EClass switchEClass = mock(EClass.class);
    when(switchEClass.getName()).thenReturn("switch");
    when(switchEClass.getInstanceTypeName()).thenReturn("org.eclipse.smarthome.model.sitemap.Switch");
    when(w2.eClass()).thenReturn(switchEClass);
    when(w2.getLabel()).thenReturn(WIDGET2_LABEL);
    when(w2.getItem()).thenReturn(ITEM_NAME);
    when(w2.getVisibility()).thenReturn(visibilityRules);
    when(w2.getLabelColor()).thenReturn(labelColors);
    when(w2.getValueColor()).thenReturn(valueColors);

    BasicEList<Widget> widgets = new BasicEList<>(2);
    widgets.add(w1);
    widgets.add(w2);
    return widgets;
}
 
Example 20
Source File: SitemapResourceTest.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
private EList<Widget> initSitemapWidgets() {
    // Initialize a sitemap containing 2 widgets linked to the same number item,
    // one slider and one switch

    Widget w1 = mock(Widget.class);
    EClass sliderEClass = mock(EClass.class);
    when(sliderEClass.getName()).thenReturn("slider");
    when(sliderEClass.getInstanceTypeName()).thenReturn("org.openhab.core.model.sitemap.Slider");
    when(w1.eClass()).thenReturn(sliderEClass);
    when(w1.getLabel()).thenReturn(WIDGET1_LABEL);
    when(w1.getItem()).thenReturn(ITEM_NAME);

    // add visibility rules to the mock widget:
    VisibilityRule visibilityRule = mock(VisibilityRule.class);
    when(visibilityRule.getItem()).thenReturn(VISIBILITY_RULE_ITEM_NAME);
    BasicEList<VisibilityRule> visibilityRules = new BasicEList<>(1);
    visibilityRules.add(visibilityRule);
    when(w1.getVisibility()).thenReturn(visibilityRules);

    // add label color conditions to the item:
    ColorArray labelColor = mock(ColorArray.class);
    when(labelColor.getItem()).thenReturn(LABEL_COLOR_ITEM_NAME);
    EList<ColorArray> labelColors = new BasicEList<>();
    labelColors.add(labelColor);
    when(w1.getLabelColor()).thenReturn(labelColors);

    // add value color conditions to the item:
    ColorArray valueColor = mock(ColorArray.class);
    when(valueColor.getItem()).thenReturn(VALUE_COLOR_ITEM_NAME);
    EList<ColorArray> valueColors = new BasicEList<>();
    valueColors.add(valueColor);
    when(w1.getValueColor()).thenReturn(valueColors);

    visibilityRules = new BasicEList<>();
    labelColors = new BasicEList<>();
    valueColors = new BasicEList<>();

    Widget w2 = mock(Widget.class);
    EClass switchEClass = mock(EClass.class);
    when(switchEClass.getName()).thenReturn("switch");
    when(switchEClass.getInstanceTypeName()).thenReturn("org.openhab.core.model.sitemap.Switch");
    when(w2.eClass()).thenReturn(switchEClass);
    when(w2.getLabel()).thenReturn(WIDGET2_LABEL);
    when(w2.getItem()).thenReturn(ITEM_NAME);
    when(w2.getVisibility()).thenReturn(visibilityRules);
    when(w2.getLabelColor()).thenReturn(labelColors);
    when(w2.getValueColor()).thenReturn(valueColors);

    BasicEList<Widget> widgets = new BasicEList<>(2);
    widgets.add(w1);
    widgets.add(w2);
    return widgets;
}