/*
 *    Copyright (c) 2013, University of Toronto.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License"); you may
 *    not use this file except in compliance with the License. You may obtain
 *    a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 *    License for the specific language governing permissions and limitations
 *    under the License.
 */
package edu.toronto.cs.xcurator.discoverer;

import edu.toronto.cs.xcurator.mapping.Mapping;
import edu.toronto.cs.xcurator.mapping.XmlBasedMapping;
import edu.toronto.cs.xcurator.xml.XmlParser;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

/**
 *
 * @author zhuerkan
 */
public class BasicEntityDiscoveryTest {
  
  private BasicEntitiesDiscovery basicEntitiesDiscovery;
  
  private final String defaultUri = "http://cs.toronto.edu/xcurator/items";
  private final String idPattern = "http://edgar.sec.gov/Archives/edgar/data/1326801/000132680113000003/fb-20121231.xml#${UUID}";
  private final String exampleEntityTypeUri = "http://fasb.org/us-gaap/2012-01-31#NonoperatingIncomeExpense";
  private Document dataDoc;
  private XmlParser parser;
  private Mapping mapping;
  
  @Before
  public void setup() {
    try {
      parser = new XmlParser();
      basicEntitiesDiscovery = new BasicEntitiesDiscovery(parser,
              defaultUri, idPattern);
      dataDoc = parser.parse(BasicEntityDiscoveryTest.class.getResourceAsStream(
              "/secxbrls/data/fb-20121231.xml"), -1);
      mapping = new XmlBasedMapping("http://www.cs.toronto.edu/xcurator");
    } catch (SAXException | IOException | ParserConfigurationException ex) {
      Logger.getLogger(BasicEntityDiscoveryTest.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
  
  @Test
  public void test_process() {
    basicEntitiesDiscovery.process(dataDoc, mapping);
    
    Assert.assertTrue(mapping.isInitialized());
    Assert.assertNotNull(mapping.getEntity(exampleEntityTypeUri));
  }
}

@@ -776,32 +776,125 @@
 mlBasedMapping;%0A
+import edu.toronto.cs.xcurator.model.Attribute;%0Aimport edu.toronto.cs.xcurator.model.Entity;%0A
 import edu.toron
@@ -919,24 +919,24 @@
 .XmlParser;%0A
-
 import java.
@@ -943,32 +943,59 @@
 io.IOException;%0A
+import java.util.Iterator;%0A
 import java.util
@@ -1311,19 +1311,17 @@
 yTest %7B%0A
-  
 %0A
+
   privat
@@ -1369,19 +1369,17 @@
 covery;%0A
-  
 %0A
+
   privat
@@ -1769,19 +1769,17 @@
 apping;%0A
-  
 %0A
+
   @Befor
@@ -2341,19 +2341,17 @@
   %7D%0A  %7D%0A
-  
 %0A
+
   @Test%0A
@@ -2439,13 +2439,9 @@
 g);%0A
-    
 %0A
+
     
@@ -2488,74 +2488,571 @@
 ));%0A
-    Assert.assertNotNull(mapping.getEntity(exampleEntityTypeUri));
+%0A    Entity example = mapping.getEntity(exampleEntityTypeUri);%0A    Assert.assertNotNull(example);%0A    %0A    Iterator%3CEntity%3E entIterator = mapping.getEntityIterator();%0A    while (entIterator.hasNext()) %7B%0A      Entity e = entIterator.next();%0A      System.out.println(%22Entity: %22 + e.getTypeUri() + %22 path: %22 + e.getPath());%0A      Iterator%3CAttribute%3E attrIterator = e.getAttributeIterator();%0A      while (attrIterator.hasNext()) %7B%0A        Attribute attr = attrIterator.next();%0A        System.out.println(attr.getTypeUri() + %22 path: %22 + attr.getPath());%0A      %7D%0A    %7D%0A
 %0A  %7D

add some test output