package eu.dnetlib.enabling.aas.utils;

import static org.junit.Assert.assertEquals;

import org.bouncycastle.util.encoders.Base64;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import eu.dnetlib.enabling.aas.rmi.TypedString;
import eu.dnetlib.enabling.aas.utils.CommonUtils;


public class CommonUtilsTest {
	
	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testJoinTypedStringTables() {
		TypedString[] tab1 = new TypedString[2];
		tab1[0] = new TypedString("text0","type0");
		tab1[1] = new TypedString("text1","type1");
		TypedString[] tab2 = new TypedString[2];
		tab2[0] = new TypedString("text2","type2");
		tab2[1] = new TypedString("text3","type3");
		TypedString[] result = CommonUtils.joinTypedStringTables(tab1, tab2);
		assertEquals(result.length, tab1.length + tab2.length);
		
	}

	@Test
	public void testBase64() {
		String someText = "some text";
		System.out.println("source: " + someText.getBytes());
		byte[] encoded = Base64.encode(someText.getBytes());
		System.out.println("encoded: " + encoded);
		byte[] decoded = Base64.decode(encoded);
		System.out.println("decoded: " + decoded);
		assertEquals(someText, new String(decoded));
	}
}
