All Downloads are FREE. Search and download functionalities are using the official Maven repository.

osgi.enroute.base.dtos.test.DTOsTest Maven / Gradle / Ivy

package osgi.enroute.base.dtos.test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.osgi.dto.DTO;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;

import aQute.bnd.annotation.component.Reference;
import aQute.bnd.testing.DSTestWiring;
import junit.framework.TestCase;
import osgi.enroute.base.configurer.test.ConfigurerTest;
import osgi.enroute.dto.api.DTOs;
import osgi.enroute.dto.api.DTOs.Difference;
import osgi.enroute.dto.api.TypeReference;

public class DTOsTest extends TestCase {
	BundleContext context = FrameworkUtil.getBundle(ConfigurerTest.class)
			.getBundleContext();
	DSTestWiring ds = new DSTestWiring();
	private DTOs dtos;

	public void setUp() throws Exception {
		ds.setContext(context);
		ds.add(this);
		ds.wire();
	}

	/*
	 * Simple conversion
	 */

	public void testSimple() throws Exception {
		
		assertEquals( 100D, dtos.convert("100").to(double.class));
		assertEquals( 10D, dtos.convert(10f).to(double.class));
		assertEquals( 100D, dtos.convert(100L).to(double.class));
		
		assertEquals( Arrays.asList(100F), 
					dtos.convert(100L).to(new TypeReference>(){}));
	
		
		long[] expected = new long[]{0x40L,  0x41L, 0x42L};
		byte[] source = "@AB".getBytes();
		long[] result = dtos.convert(source).to(long[].class);
		
		assertTrue( Arrays.equals(expected,result ));
	}

	/*
	 * Show Map -> Interface
	 */
	enum Option {
		bar, don, zun
	};

	interface FooMap {
		short port();

		String host();

		Set




© 2015 - 2024 Weber Informatics LLC | Privacy Policy