Skip to main content
summaryrefslogtreecommitdiffstats
blob: 84204bb76a8f6f141ec737bb5c67dcf5c3fec16d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
 * <copyright>
 *
 * Copyright (c) 2005, 2006 Springsite BV (The Netherlands) and others
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Martin Taal
 * </copyright>
 *
 * $Id: MindMapAction.java,v 1.1 2006/11/15 17:17:48 mtaal Exp $
 */

package org.eclipse.emf.teneo.test.emf.sample;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.eclipse.emf.ecore.xml.type.internal.XMLCalendar;
import org.eclipse.emf.teneo.samples.emf.sample.mindmap.Map;
import org.eclipse.emf.teneo.samples.emf.sample.mindmap.MindmapFactory;
import org.eclipse.emf.teneo.samples.emf.sample.mindmap.MindmapPackage;
import org.eclipse.emf.teneo.samples.emf.sample.mindmap.Priority;
import org.eclipse.emf.teneo.samples.emf.sample.mindmap.Relationship;
import org.eclipse.emf.teneo.samples.emf.sample.mindmap.RelationshipType;
import org.eclipse.emf.teneo.samples.emf.sample.mindmap.Resource;
import org.eclipse.emf.teneo.samples.emf.sample.mindmap.Topic;
import org.eclipse.emf.teneo.test.AbstractTestAction;
import org.eclipse.emf.teneo.test.stores.TestStore;

/**
 * Tests the gmf mindmap example
 * 
 * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
 * @version $Revision: 1.1 $
 */
public class MindMapAction extends AbstractTestAction {
	
	/**
	 * Constructor for ClassHierarchyParsing.
	 * 
	 * @param arg0
	 */
	public MindMapAction() {
		super(MindmapPackage.eINSTANCE);
	}

	/** Creates an item, an address and links them to a po. */
	public void doAction(TestStore store) {
		final MindmapFactory factory = MindmapFactory.eINSTANCE;
		{
			final Map map = factory.createMap();
			map.setTitle("Persistency Discussions");
			
			final Resource res1 = factory.createResource();
			res1.setEmail("mtaal@elver.org");
			res1.setName("Martin Taal");
			
			final Resource res2 = factory.createResource();
			res2.setEmail("test@elver.org");
			res2.setName("Test Me");
			
			map.getResources().add(res1);
			map.getResources().add(res2);
			
			map.getRootTopics().add(createTopic(map.getResources(), factory, "Teneo JPOX", 5));
			map.getRootTopics().add(createTopic(new ArrayList(), factory, "Teneo Hibernate", 3));
			
			final Relationship rel = factory.createRelationship();
			rel.setSource((Topic)map.getRootTopics().get(0));
			rel.setTarget((Topic)map.getRootTopics().get(1));
			rel.setType(RelationshipType.EXTENDS_LITERAL);
			
			map.getRelations().add(rel);
			
			store.beginTransaction();
			store.store(map);
			store.commitTransaction();
		}
		
		{ 
			store.beginTransaction();
			Map map = (Map)store.getObject(Map.class);
			assertEquals(2, map.getRootTopics().size());
			checkTopic(map, (Topic)map.getRootTopics().get(0), "Teneo JPOX", 5);
			checkTopic(map, (Topic)map.getRootTopics().get(1), "Teneo Hibernate", 3);
			Relationship rs = (Relationship)map.getRelations().get(0);
			assertEquals(rs.getSource(), map.getRootTopics().get(0));
			assertEquals(rs.getTarget(), map.getRootTopics().get(1));
			map.getRelations().remove(0);
			map.getRootTopics().remove(1);
			store.commitTransaction();
		}
		{
			store.beginTransaction();
			Map map = (Map)store.getObject(Map.class);
			assertEquals(1, map.getRootTopics().size());
			checkTopic(map, (Topic)map.getRootTopics().get(0), "Teneo JPOX", 5);
			store.commitTransaction();
		}
	}

	/** Create a default topic */
	private Topic createTopic(List resources, MindmapFactory factory, String name, int level) {
		final Topic topic = factory.createTopic();
		topic.setEndDate(new XMLCalendar(new Date(), XMLCalendar.DATETIME));
		topic.setStartDate(new Date());
		topic.setName(name + level);
		topic.setPriority(Priority.get(level));
		topic.setPercentComplete((float)(level * 10.0 / 100.0));
		topic.getResources().addAll(resources);
		for (int i = 0; i < level; i++) {
			topic.getSubtopics().add(createTopic(resources, factory, name + "_", level - 1));
		}
		return topic;
	}

	private void checkTopic(Map map, Topic topic, String name, int level) {
		assertEquals(name + level, topic.getName());
		assertEquals(level, topic.getSubtopics().size());
		assertEquals(Priority.get(level), topic.getPriority());
		assertEquals((float)(level * 10.0 / 100.0), topic.getPercentComplete(), 0.1f);
		for (int i = 0; i < topic.getResources().size(); i++) {
			assertEquals(topic.getResources().get(i), map.getResources().get(i));
		}
		for (int i = 0; i < level; i++) {
			checkTopic(map, (Topic)topic.getSubtopics().get(i), name + "_", level - 1);
		}
	}
}

Back to the top