1   package test.tuigwaa;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import junit.framework.TestCase;
7   
8   import org.seasar.framework.container.S2Container;
9   import org.seasar.framework.container.factory.S2ContainerFactory;
10  import org.seasar.tuigwaa.model.common.EntityResource;
11  import org.seasar.tuigwaa.model.common.EntityResourceEcoreImpl;
12  import org.seasar.tuigwaa.model.core.TgwAttribute;
13  import org.seasar.tuigwaa.model.core.TgwEntity;
14  import org.seasar.tuigwaa.model.core.impl.DateAttribute;
15  import org.seasar.tuigwaa.model.core.impl.FkAttribute;
16  import org.seasar.tuigwaa.model.core.impl.IntegerAttribute;
17  import org.seasar.tuigwaa.model.core.impl.StringAttribute;
18  import org.seasar.tuigwaa.model.core.impl.TgwDomainImpl;
19  import org.seasar.tuigwaa.model.core.impl.TgwEntityImpl;
20  
21  
22  public class ECoreTest extends TestCase {
23  
24  	private EntityResource resource;
25  
26  	private TgwEntity sampleEntity_;
27  
28  	private TgwEntity sampleEntity2_;
29  
30  	public void setUp() {
31  		S2Container container = S2ContainerFactory.create("dicon/service.dicon");
32  		resource = (EntityResource) container.getComponent(EntityResourceEcoreImpl.class);
33  
34  		sampleEntity_ = new TgwEntityImpl("junit", "sample");
35  		putField(sampleEntity_, "name3", new StringAttribute());
36  		putField(sampleEntity_, "intest", new IntegerAttribute());
37  		putField(sampleEntity_, "datetest", new DateAttribute());
38  		sampleEntity_.setDescription("sample ł");
39  		sampleEntity_.setDisplayName("sample \" }}} > \n * &displayname");
40  
41  		sampleEntity2_ = new TgwEntityImpl("junit", "sample2");
42  		putField(sampleEntity2_, "name2", new StringAttribute());
43  	
44  		FkAttribute fk = new FkAttribute();
45  		fk.setRefEntity(sampleEntity_);
46  		fk.setName("ref");
47  		sampleEntity2_.addField(fk);
48  	}
49  
50  	public void testSave() {
51  		TgwDomainImpl domain = new TgwDomainImpl("junit");
52  		Map map = new HashMap();
53  		map.put(sampleEntity_.getName(), sampleEntity_);
54  		map.put(sampleEntity2_.getName(), sampleEntity2_);
55  
56  		domain.addEntity(sampleEntity2_);
57  		domain.addEntity(sampleEntity_);
58  		resource.save(domain);
59  
60  		//Map entityMap = dao_.load("junit");
61  
62  		/*
63  		Iterator itr = entityMap.keySet().iterator();
64  
65  		while (itr.hasNext()) {
66  			String entityName = (String) itr.next();
67  			Entity entity = (Entity) entityMap.get(entityName);
68  			System.out.println("========================");
69  			System.out.println("Entity Name : " + entity.getName());
70  			System.out.println("Entity DisplayName : " + entity.getDisplayName());
71  			System.out.println("Entity DisplayName : " + entity.getDisplayName());
72  			System.out.println("========================");
73  		}
74  		*/
75  		//dao_.save("junit", entityMap);
76  	}
77  	
78  	private void putField(TgwEntity entity, String name, TgwAttribute attr){
79  		attr.setName(name);
80  		entity.addField(attr);
81  	}
82  }