4bc3affc2816109b12a2b3b59e6e4dae7232c61d
[taxeditor.git] / eu.etaxonomy.taxeditor.test / src / test / java / eu / etaxonomy / taxeditor / operation / RemotingCdmUpdateOperationTest.java
1 /**
2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.operation;
10
11 import java.util.HashSet;
12 import java.util.Set;
13 import java.util.UUID;
14
15 import org.apache.log4j.Logger;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.junit.Assert;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.unitils.dbunit.annotation.DataSet;
21
22 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
23 import eu.etaxonomy.cdm.api.service.UpdateResult;
24 import eu.etaxonomy.cdm.api.service.UpdateResult.Status;
25 import eu.etaxonomy.cdm.api.service.dto.CdmEntityIdentifier;
26 import eu.etaxonomy.cdm.cache.ProxyUtils;
27 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
28 import eu.etaxonomy.taxeditor.store.operations.RemotingTestUpdateOperation;
29
30 /**
31 * @author cmathew
32 * @date 26 Jun 2015
33 *
34 */
35 @DataSet
36 public class RemotingCdmUpdateOperationTest extends BaseOperationTest {
37
38 @SuppressWarnings("unused")
39 private static final Logger logger = Logger.getLogger(RemotingCdmUpdateOperationTest.class);
40
41 private static ITaxonNodeService taxonNodeService = getRemoteApplicationController().getTaxonNodeService();
42
43 private static UUID taxonNodeUuid1;
44 private static UUID taxonNodeUuid2;
45 private static UUID taxonNodeUuid3;
46 private static UUID taxonNodeUuid4;
47 private static UUID taxonNodeUuid5;
48
49
50 private static Set<TaxonNode> taxonNodes;
51 private static Set<CdmEntityIdentifier> ceis;
52
53 @BeforeClass
54 public static void initializeUpdatedObjects() {
55 taxonNodeUuid1 = UUID.fromString("b85b5b78-6760-409f-ac91-bb89e95ff2a1");
56 taxonNodeUuid2 = UUID.fromString("6ad8e9e2-f5f6-41ad-aa30-f62a903650db");
57 taxonNodeUuid3 = UUID.fromString("91698cec-615f-4472-9002-feda1a6acded");
58 taxonNodeUuid4 = UUID.fromString("b8439f51-6b96-445a-b401-7a836ba1cf58");
59 taxonNodeUuid5 = UUID.fromString("629b3fd3f-29b4-4011-ab12-9c1ad1607dbd");
60
61 }
62
63 @Test
64 public void testUpdateResultWithCdmEntities() throws ExecutionException {
65 TaxonNode taxonNode1 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid1));
66 TaxonNode taxonNode2 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid2));
67 TaxonNode taxonNode3 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid3));
68 TaxonNode taxonNode4 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid4));
69 TaxonNode taxonNode5 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid5));
70
71 taxonNodes = new HashSet<>();
72 taxonNodes.add(taxonNode1);
73 taxonNodes.add(taxonNode2);
74 taxonNodes.add(taxonNode3);
75 taxonNodes.add(taxonNode4);
76 taxonNodes.add(taxonNode5);
77
78 UpdateResult result = new UpdateResult();
79 result.addUpdatedObjects(taxonNodes);
80 result.setStatus(Status.OK);
81
82 sessionOwner.setExpectedUpdatedObjects(taxonNodes);
83
84 operation = new RemotingTestUpdateOperation(result, sessionOwner, false);
85 operation.execute(monitor, info);
86
87 Assert.assertEquals(taxonNodes, sessionOwner.getEventUpdatedObjects());
88 }
89
90 @Test
91 public void testUpdateResultWithCdmIdentities() throws ExecutionException {
92 TaxonNode taxonNode1 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid1));
93 TaxonNode taxonNode2 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid2));
94 TaxonNode taxonNode3 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid3));
95 TaxonNode taxonNode4 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid4));
96 TaxonNode taxonNode5 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid5));
97
98 taxonNodes = new HashSet<>();
99 taxonNodes.add(taxonNode1);
100 taxonNodes.add(taxonNode2);
101 taxonNodes.add(taxonNode3);
102 taxonNodes.add(taxonNode4);
103 taxonNodes.add(taxonNode5);
104
105 ceis = new HashSet<>();
106 ceis.add(new CdmEntityIdentifier(taxonNode3.getId(),TaxonNode.class));
107 ceis.add(new CdmEntityIdentifier(taxonNode4.getId(),TaxonNode.class));
108 ceis.add(new CdmEntityIdentifier(taxonNode5.getId(),TaxonNode.class));
109
110 UpdateResult result = new UpdateResult();
111 result.addUpdatedObject(taxonNode1);
112 result.addUpdatedObject(taxonNode2);
113 result.addUpdatedCdmIds(ceis);
114
115 result.setStatus(Status.OK);
116 sessionOwner.setExpectedUpdatedObjects(taxonNodes);
117 operation = new RemotingTestUpdateOperation(result, sessionOwner, false);
118 operation.execute(monitor, info);
119
120 Assert.assertEquals(taxonNodes, sessionOwner.getEventUpdatedObjects());
121 }
122
123 @Test
124 public void testUpdateResultWithLoadedCdmIdentities() throws ExecutionException {
125 TaxonNode taxonNode1 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid1));
126 TaxonNode taxonNode2 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid2));
127 TaxonNode taxonNode3 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid3));
128 TaxonNode taxonNode4 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid4));
129 TaxonNode taxonNode5 = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid5));
130
131 taxonNodes = new HashSet<>();
132 taxonNodes.add(taxonNode1);
133 taxonNodes.add(taxonNode2);
134 taxonNodes.add(taxonNode3);
135 taxonNodes.add(taxonNode4);
136 taxonNodes.add(taxonNode5);
137
138 ceis = new HashSet<>();
139 ceis.add(new CdmEntityIdentifier(taxonNode3.getId(),TaxonNode.class));
140 ceis.add(new CdmEntityIdentifier(taxonNode4.getId(),TaxonNode.class));
141 ceis.add(new CdmEntityIdentifier(taxonNode5.getId(),TaxonNode.class));
142
143
144 UpdateResult result = new UpdateResult();
145 result.addUpdatedObject(taxonNode1);
146 result.addUpdatedObject(taxonNode2);
147 result.addUpdatedCdmIds(ceis);
148 result.addUpdatedCdmId(new CdmEntityIdentifier(46,TaxonNode.class));
149
150 result.setStatus(Status.OK);
151 sessionOwner.setExpectedUpdatedObjects(taxonNodes);
152 operation = new RemotingTestUpdateOperation(result, sessionOwner, false);
153 operation.execute(monitor, info);
154
155 Assert.assertEquals(taxonNodes, sessionOwner.getEventUpdatedObjects());
156 }
157
158 @Test
159 public void testDataChange() throws ExecutionException {
160 TaxonNode taxonNode = (TaxonNode) ProxyUtils.deproxy(taxonNodeService.load(taxonNodeUuid1));
161 CdmEntityIdentifier cei = new CdmEntityIdentifier(taxonNode.getId(), TaxonNode.class);
162
163 taxonNodes = new HashSet<>();
164 taxonNodes.add(taxonNode);
165
166 int taxonNodeCountChildren = taxonNode.getCountChildren();
167 sessionOwner.setExpectedUpdatedObjects(taxonNodes);
168
169 operation = new RemotingTestUpdateOperation(cei, sessionOwner, false);
170 operation.execute(monitor, info);
171
172 Set eventUpdatedObjects = sessionOwner.getEventUpdatedObjects();
173 Assert.assertEquals(taxonNodes, eventUpdatedObjects);
174 Assert.assertEquals(taxonNodeCountChildren + 1, ((TaxonNode)eventUpdatedObjects.iterator().next()).getCountChildren());
175 }
176
177 }