/*
 *  Copyright (C) 2011 The Animo Project
 *  http://animotron.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 3
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.animotron.graph;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

import org.animotron.ATest;
import org.animotron.graph.stax.StAXGraphSerializer;
import org.animotron.operator.THE;
import org.junit.Test;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.Transaction;


/**
 * @author <a href="mailto:shabanovd@gmail.com">Dmitriy Shabanov</a>
 *
 */
public class StoreBinaryTest extends ATest {
	
	private static final String TXT = 
		"Lorem ipsum dolor sit amet, consectetur adipiscing elit." +
		" Phasellus rutrum gravida ante nec consectetur. Sed maur" +
		"is libero, vulputate a viverra nec, porta at purus. Done" +
		"c sed consequat lorem. Donec lacinia metus euismod mi el" +
		"eifend mattis. Mauris porttitor risus sed risus tempor a" +
		"uctor. Curabitur quam augue, vestibulum ut aliquam eget," +
		" tincidunt vitae nisi. Donec libero purus, convallis non" +
		" semper non, molestie adipiscing sapien. Sed facilisis e" +
		"rat in ligula aliquet consectetur. Nulla luctus, velit a" +
		"c faucibus tincidunt, justo sem aliquam elit, eu mattis " +
		"arcu nunc eu diam. Fusce vulputate nunc imperdiet diam c" +
		"onvallis ultrices eu sit amet velit. Lorem ipsum dolor s" +
		"it amet, consectetur adipiscing elit. Curabitur eget sem" +
		" eu nisl luctus feugiat a eget enim. Nulla ut dui purus," +
		" sit amet cursus est. Suspendisse potenti.";

	private static final String PATH = "test.txt";
	
	@Test
	public void storeAndSerialize() throws XMLStreamException {
        System.out.println("Test processing flow interator ...");
        
        InputStream stream = new ByteArrayInputStream(TXT.getBytes());
        
        CommonGraphBuilder.build(stream, PATH);
        
        System.out.println("loaded ...");
        
//        Transaction tx = AnimoGraph.beginTx();
//        try { 
//	        Relationship r = THE.getInstance().relationship("B");
//	        assertNotNull(r);
//	        XMLStreamWriter writer = OUTPUT_FACTORY.createXMLStreamWriter(System.out);
//	        StAXGraphSerializer serializer = new StAXGraphSerializer(writer);
//	        serializer.serialize(r);
//	        tx.success();
//	        
//        } catch (Exception e) {
//        	e.printStackTrace();
//			fail(e.toString());
//        } finally {
//        	tx.finish();
//        }
            
        System.out.println("done.");
	}
}

@@ -2531,227 +2531,67 @@
 est 
-processing flow interator ...%22);%0A        %0A        InputStream stream = new ByteArrayInputStream(TXT.getBytes());%0A        %0A        CommonGraphBuilder.build(stream, PATH);%0A        %0A        System.out.println(%22loaded ...%22)
+binary stream ...%22);%0A        %0A        Relationship r = null
 ;%0A  
@@ -2589,34 +2589,32 @@
  null;%0A        %0A
-//
         Transact
@@ -2640,26 +2640,24 @@
 .beginTx();%0A
-//
         try 
@@ -2661,21 +2661,17 @@
 ry %7B
- %0A//%09
+%0A
         
 Rela
@@ -2670,301 +2670,106 @@
     
-Relationship r = THE.getInstance().relationship(%22B%22);%0A//%09        assertNotNull(r);%0A//%09        XMLStreamWriter writer = OUTPUT_FACTORY.createXMLStreamWriter(System.out);%0A//%09        StAXGraphSerializer serializer = new StAXGraphSerializer(writer);%0A//%09        serializer.serialize(r);%0A//%09
+%09%0A        %09r = CommonGraphBuilder.build(new ByteArrayInputStream(TXT.getBytes()), PATH);%0A%0A
         
 tx.s
@@ -2764,16 +2764,17 @@
         
+%09
 tx.succe
@@ -2783,22 +2783,9 @@
 ();%0A
-//%09        %0A//
+%0A
     
@@ -2812,18 +2812,16 @@
 on e) %7B%0A
-//
         
@@ -2842,18 +2842,16 @@
 race();%0A
-//
 %09%09%09fail(
@@ -2865,18 +2865,16 @@
 ing());%0A
-//
         
@@ -2885,18 +2885,16 @@
 nally %7B%0A
-//
         
@@ -2907,18 +2907,16 @@
 nish();%0A
-//
         
@@ -2917,16 +2917,51 @@
       %7D%0A
+        %0A        assertNotNull(r);%0A
         

update test