| /** |
| * |
| * 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.assertNotNull; |
| import static org.junit.Assert.assertNotSame; |
| import static org.junit.Assert.assertNull; |
| import static org.junit.Assert.assertTrue; |
| |
| import java.util.List; |
| 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.infogrid.api.IGridSourceDescriptor; |
| import org.eclipse.osbp.infogrid.api.IGridSourceFacade; |
| import org.eclipse.osbp.infogrid.ecview.ECViewGridSourceDescriptor; |
| import org.eclipse.osbp.infogrid.model.gridsource.CxGridSource; |
| import org.eclipse.osbp.infogrid.services.tests.data.MyDto; |
| import org.osgi.framework.BundleContext; |
| import org.osgi.framework.FrameworkUtil; |
| |
| public class GridSourceFacadeTest { |
| |
| private BundleContext bc; |
| private IGridSourceFacade facade; |
| |
| @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); |
| } |
| |
| private BundleContext getBundleContext() { |
| return FrameworkUtil.getBundle(getClass()).getBundleContext(); |
| } |
| |
| @Test |
| public void test_getById() { |
| CxGridSource result = facade.getSource("org.my"); |
| assertNotNull(result); |
| assertEquals("org.my", result.getId()); |
| |
| CxGridSource result2 = facade.getSource("org.my"); |
| assertNotSame(result, result2); |
| } |
| |
| @Test |
| public void test_getByClass() { |
| List<CxGridSource> result = facade.getSources(MyDto.class); |
| assertEquals(1, result.size()); |
| assertEquals("org.my", result.get(0).getId()); |
| |
| List<CxGridSource> result2 = facade.getSources(MyDto.class); |
| assertNotSame(result.get(0), result2.get(0)); |
| } |
| |
| @SuppressWarnings("restriction") |
| @Test |
| public void test_getDescriptorById() { |
| IGridSourceDescriptor result = facade.getDescriptor("org.my", null); |
| assertNotNull(result); |
| assertTrue(result instanceof ECViewGridSourceDescriptor); |
| } |
| |
| @SuppressWarnings("restriction") |
| @Test |
| public void test_getDescriptorBySource() { |
| CxGridSource source = facade.getSource("org.my"); |
| source.setKind(IGridSourceDescriptor.KIND_ECVIEW); |
| IGridSourceDescriptor result = facade.getDescriptor(source, |
| new IGridSourceDescriptor.ConfigCallback() { |
| @Override |
| public Map<String, Object> getProperties( |
| IGridSourceDescriptor descriptor) { |
| return null; |
| } |
| }); |
| assertNotNull(result); |
| assertTrue(result instanceof ECViewGridSourceDescriptor); |
| |
| // try different kind |
| source.setKind("NoKind"); |
| result = facade.getDescriptor(source, null); |
| assertNull(result); |
| } |
| |
| @SuppressWarnings("restriction") |
| @Test |
| public void test_getDescriptorsByClass() { |
| List<IGridSourceDescriptor> result = facade.getDescriptors(MyDto.class, |
| new IGridSourceDescriptor.ConfigCallback() { |
| @Override |
| public Map<String, Object> getProperties( |
| IGridSourceDescriptor descriptor) { |
| return null; |
| } |
| }); |
| assertEquals(1, result.size()); |
| assertTrue(result.get(0) instanceof ECViewGridSourceDescriptor); |
| |
| result = facade.getDescriptors(List.class, null); |
| assertEquals(0, result.size()); |
| } |
| |
| } |