| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.infogrid.services.tests; |
| |
| import static org.junit.Assert.assertEquals; |
| import static org.junit.Assert.assertFalse; |
| import static org.junit.Assert.assertNotNull; |
| import static org.junit.Assert.assertTrue; |
| import static org.junit.Assert.fail; |
| |
| import java.lang.reflect.Field; |
| import java.util.HashMap; |
| import java.util.Locale; |
| import java.util.Map; |
| |
| import org.junit.Before; |
| import org.junit.Test; |
| import org.knowhowlab.osgi.testing.utils.BundleUtils; |
| import org.knowhowlab.osgi.testing.utils.ServiceUtils; |
| import org.eclipse.osbp.ecview.core.common.context.IViewContext; |
| import org.eclipse.osbp.infogrid.api.IGridSourceDescriptor; |
| import org.eclipse.osbp.infogrid.api.IGridSourceFacade; |
| import org.eclipse.osbp.infogrid.ecview.ECViewGridSourceDescriptor; |
| import org.osgi.framework.BundleContext; |
| import org.osgi.framework.FrameworkUtil; |
| |
| import com.vaadin.ui.ComponentContainer; |
| |
| @SuppressWarnings("restriction") |
| public class ECViewGridSourceDescriptorTest { |
| |
| private BundleContext bc; |
| private IGridSourceFacade facade; |
| private IGridSourceDescriptor descriptor; |
| |
| @Before |
| public void setup() throws Exception { |
| bc = getBundleContext(); |
| BundleUtils.startBundleAsync(bc, "org.eclipse.osbp.infogrid.model"); |
| BundleUtils.startBundleAsync(bc, "org.eclipse.osbp.infogrid.services"); |
| BundleUtils.startBundleAsync(bc, "org.eclipse.osbp.infogrid.ecview"); |
| |
| facade = ServiceUtils.getService(getBundleContext(), |
| IGridSourceFacade.class); |
| assertNotNull(facade); |
| descriptor = facade.getDescriptor("org.my", |
| new IGridSourceDescriptor.ConfigCallback() { |
| @Override |
| public Map<String, Object> getProperties( |
| IGridSourceDescriptor descriptor) { |
| Map<String, Object> properties = new HashMap<String, Object>(); |
| properties.put("locale", Locale.GERMANY); |
| properties.put("userId", "Admin"); |
| return properties; |
| } |
| }); |
| } |
| |
| private BundleContext getBundleContext() { |
| return FrameworkUtil.getBundle(getClass()).getBundleContext(); |
| } |
| |
| @Test |
| public void test_general() { |
| assertEquals("org.my", descriptor.getId()); |
| assertNotNull(descriptor.getSource()); |
| } |
| |
| @Test |
| public void test_dispose() { |
| assertFalse(descriptor.isDisposed()); |
| |
| descriptor.dispose(); |
| |
| // check the access |
| descriptor.getId(); |
| |
| try { |
| descriptor.getComponent(); |
| fail(); |
| } catch (Exception ex) { |
| } |
| |
| try { |
| descriptor.getLabel(); |
| fail(); |
| } catch (Exception ex) { |
| } |
| |
| try { |
| descriptor.getSource(); |
| fail(); |
| } catch (Exception ex) { |
| } |
| } |
| |
| @Test |
| public void test_getComponent() throws IllegalArgumentException, |
| IllegalAccessException, NoSuchFieldException, SecurityException { |
| ComponentContainer component = (ComponentContainer) descriptor |
| .getComponent(); |
| assertNotNull(component); |
| assertEquals(1, component.getComponentCount()); |
| |
| Field field = ECViewGridSourceDescriptor.class |
| .getDeclaredField("viewContext"); |
| field.setAccessible(true); |
| IViewContext viewContext = (IViewContext) field.get(descriptor); |
| assertFalse(viewContext.isDisposed()); |
| |
| // dispose |
| descriptor.dispose(); |
| assertTrue(viewContext.isDisposed()); |
| assertEquals(0, component.getComponentCount()); |
| } |
| } |