package jp.langedge.FreeXAdES;

import static org.junit.Assert.*;

import org.junit.Test;

public class IFreeXAdESTest {

    //////////////////////////////////////////////////////////////////////////////
    // Ώ

	private static String testXml_ = "<MyData xmlns=\"\"><Data Id=\"D1\">book</Data><Data Id=\"D2\">note</Data></MyData>";
	private static String testData_ = "aaa";
	private static String testXmlFile_ = "MyData.xml";
	private static String testDataFile_ = "aaa.txt";

    //////////////////////////////////////////////////////////////////////////////
	// pPKCS#12ݒ

    private static String pkcs12File_ = "LeTest.p12";				// t@C
    private static String pkcs12Pswd_ = "test";						// pX[h

    //////////////////////////////////////////////////////////////////////////////

	@Test
	public void testDetachedOut() {
		System.out.println("testDetachedOut call");
		
		// CX^XE
		System.out.println(" - create.");
		int rc = IFreeXAdES.FXERR_NO_ERROR;
		FreeXAdES xades = new FreeXAdES();

		// IE
		System.out.println(" - finalize.");
		xades.finalize();
	}

    @Test
	public void testDetachedIn() {
		System.out.println("testDetachedIn call");
		
		// CX^XE
		System.out.println(" - create.");
		int rc = IFreeXAdES.FXERR_NO_ERROR;
		FreeXAdES xades = new FreeXAdES();

		// IE
		System.out.println(" - finalize.");
		xades.finalize();
	}

	@Test
	public void testEnvelopingXml() {
		System.out.println("testEnvelopingXml call");
		
		// CX^XE
		System.out.println(" - create.");
		int rc = IFreeXAdES.FXERR_NO_ERROR;
		FreeXAdES xades = new FreeXAdES();

		// IE
		System.out.println(" - finalize.");
		xades.finalize();
	}

	@Test
	public void testEnvelopingFile() {
		System.out.println("testEnvelopingFile call");
		
		// CX^XE
		System.out.println(" - create.");
		int rc = IFreeXAdES.FXERR_NO_ERROR;
		FreeXAdES xades = new FreeXAdES();

		// IE
		System.out.println(" - finalize.");
		xades.finalize();
	}

	@Test
	public void testEnvelopingBase64() {
		System.out.println("testEnvelopingBase64 call");
		
		// CX^XE
		System.out.println(" - create.");
		int rc = IFreeXAdES.FXERR_NO_ERROR;
		FreeXAdES xades = new FreeXAdES();

		// Envelopingǉ
		System.out.println(" - addEnveloping.");
		rc = xades.addEnveloping(testData_, IFreeXAdES.FXAT_DATA_STRING, IFreeXAdES.FXRF_TRANS_BASE64);
		assertEquals(rc, IFreeXAdES.FXERR_NO_ERROR);

		// s
		System.out.println(" - execSign.");
		String id = "Signature1";
		int fxsFlag = IFreeXAdES.FXSF_NONE;
		rc = xades.execSign(pkcs12File_, pkcs12Pswd_, fxsFlag, id);
		assertEquals(rc, IFreeXAdES.FXERR_NO_ERROR);

		// IE
		System.out.println(" - finalize.");
		xades.finalize();
	}

	@Test
	public void testEnveloped() {
		System.out.println("testEnveloped call");
		
		// CX^XE
		System.out.println(" - create.");
		int rc = IFreeXAdES.FXERR_NO_ERROR;
		FreeXAdES xades = new FreeXAdES();

		// IE
		System.out.println(" - finalize.");
		xades.finalize();
	}

}

@@ -273,16 +273,27 @@
 ns=%5C%22%5C%22%3E
+%22%0D%0A%09%09%09+ %22  
 %3CData Id
@@ -303,25 +303,60 @@
 D1%5C%22
-%3Ebook%3C/Data%3E%3CData
+ price=%5C%22680%5C%22%3E%3C/Data%3E%22%0D%0A%09%09%09+ %22  %3CData price=%5C%22100%5C%22
  Id=
@@ -366,19 +366,29 @@
 2%5C%22%3E
-note
+(m%5Bg)
 %3C/Data%3E
+%22%0D%0A%09%09%09+ %22
 %3C/My

edit test data.