1 |
|
/**
|
2 |
|
* Copyright (C) 2014 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.httpinvoker;
|
10 |
|
|
11 |
|
|
12 |
|
import java.util.Map;
|
13 |
|
|
14 |
|
import org.apache.log4j.Logger;
|
15 |
|
import org.junit.Assert;
|
16 |
|
import org.junit.BeforeClass;
|
17 |
|
import org.junit.Test;
|
18 |
|
|
19 |
|
import eu.etaxonomy.cdm.config.CdmPersistentSourceUtils;
|
20 |
|
import eu.etaxonomy.cdm.config.CdmSourceException;
|
21 |
|
import eu.etaxonomy.cdm.model.metadata.CdmMetaData.MetaDataPropertyName;
|
22 |
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
23 |
|
import eu.etaxonomy.taxeditor.remoting.source.CdmPersistentRemoteSource;
|
24 |
|
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
|
25 |
|
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSourceException;
|
26 |
|
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
|
27 |
|
|
28 |
|
/**
|
29 |
|
* Class to test the cdm persistent source functionality, including
|
30 |
|
* initialising / saving / updating and deleting
|
31 |
|
*
|
32 |
|
* Corresponding test sources settings can be found at
|
33 |
|
* /src/text/resources/eu.etaxonomy.cdm/cdm.datasources.xml
|
34 |
|
*
|
35 |
|
*/
|
36 |
|
public class CdmPersistentRemoteSourceTest extends BaseRemotingTest {
|
37 |
|
private static final Logger logger = Logger.getLogger(CdmPersistentRemoteSourceTest.class);
|
38 |
|
|
39 |
|
private CdmPersistentRemoteSource remotePersistentSource;
|
40 |
|
|
41 |
|
@BeforeClass
|
42 |
|
public static void initialize() {
|
43 |
|
}
|
44 |
|
|
45 |
|
@Test
|
46 |
|
public void whenLoadingExistingCompleteRemoteSourceThenLoadIsSuccessful() {
|
47 |
|
|
48 |
|
remotePersistentSource = getCdmPersistentRemoteSource();
|
49 |
|
|
50 |
|
String expectedServer = "127.0.0.1";
|
51 |
|
String expectedPort = "9090";
|
52 |
|
String expectedContextPath = "";
|
53 |
|
logger.info("Default remote source server : " + remotePersistentSource.getServer());
|
54 |
|
Assert.assertTrue("Default server should be " + expectedServer,
|
55 |
|
expectedServer.equals(remotePersistentSource.getServer()));
|
56 |
|
|
57 |
|
logger.info("Default remote source port : " + remotePersistentSource.getPort());
|
58 |
|
Assert.assertTrue("Default port should be 9090",
|
59 |
|
expectedPort.equals(String.valueOf(remotePersistentSource.getPort())));
|
60 |
|
|
61 |
|
logger.info("Default remote source context path : " + remotePersistentSource.getContextPath());
|
62 |
|
Assert.assertTrue("Default remote source context path should be " + expectedContextPath,
|
63 |
|
expectedContextPath.equals(remotePersistentSource.getContextPath()));
|
64 |
|
|
65 |
|
logger.info("Default remote source nomenclatural code : " + remotePersistentSource.getNomenclaturalCode().toString());
|
66 |
|
Assert.assertTrue("Default NomenclaturalCode should be ICNAFP",
|
67 |
|
NomenclaturalCode.ICNAFP.equals(remotePersistentSource.getNomenclaturalCode()));
|
68 |
|
}
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@Test
|
74 |
|
public void whenConnectingToAnActiveServerThenConnectSuccessfully() {
|
75 |
|
// check if active server throws the right exception
|
76 |
|
|
77 |
|
remotePersistentSource = getCdmPersistentRemoteSource();
|
78 |
|
|
79 |
|
String dbSchemaVersion = "";
|
80 |
|
try {
|
81 |
|
dbSchemaVersion = remotePersistentSource.getDbSchemaVersion();
|
82 |
|
} catch (CdmSourceException e) {
|
83 |
|
Assert.fail("getDbSchemaVersion() on active cdm server should not have thrown CdmSourceException");
|
84 |
|
}
|
85 |
|
logger.info("dbSchemaVersion is " + dbSchemaVersion);
|
86 |
|
|
87 |
|
|
88 |
|
boolean isDbEmpty = false;
|
89 |
|
try {
|
90 |
|
isDbEmpty = remotePersistentSource.isDbEmpty();
|
91 |
|
} catch (CdmSourceException e) {
|
92 |
|
Assert.fail("isDbEmpty() on active cdm server should not have thrown CdmSourceException");
|
93 |
|
}
|
94 |
|
Assert.assertFalse(isDbEmpty);
|
95 |
|
|
96 |
|
|
97 |
|
boolean check = false;
|
98 |
|
try {
|
99 |
|
check = remotePersistentSource.checkConnection();
|
100 |
|
} catch (CdmSourceException e) {
|
101 |
|
Assert.fail("checkConnection() on active cdm server should not have thrown CdmSourceException");
|
102 |
|
}
|
103 |
|
Assert.assertTrue(check);
|
104 |
|
|
105 |
|
|
106 |
|
}
|
107 |
|
|
108 |
|
@Test
|
109 |
|
public void whenRequestingMetadatFromRemoteSourceThenMetaDataIsRetrieved() {
|
110 |
|
try {
|
111 |
|
remotePersistentSource = getCdmPersistentRemoteSource();
|
112 |
|
Map<MetaDataPropertyName, String> cdmMetaDataMap = remotePersistentSource.getMetaDataMap();
|
113 |
|
for(MetaDataPropertyName mdpn : cdmMetaDataMap.keySet()) {
|
114 |
|
String value = cdmMetaDataMap.get(mdpn);
|
115 |
|
logger.info("MetaData Property " + mdpn.name() + " has value " + value);
|
116 |
|
Assert.assertNotNull("Meta Data Value for property for " + mdpn.name() + " should not be null", value);
|
117 |
|
}
|
118 |
|
} catch (CdmSourceException e) {
|
119 |
|
// TODO Auto-generated catch block
|
120 |
|
e.printStackTrace();
|
121 |
|
}
|
122 |
|
}
|
123 |
|
|
124 |
|
@Test
|
125 |
|
public void whenLoadingNonExistingRemoteSourceThenThrowException() {
|
126 |
|
try {
|
127 |
|
remotePersistentSource = CdmPersistentRemoteSource.NewInstance("nonExistingSource");
|
128 |
|
Assert.fail("Initialising a non-existing remote source should throw an exception");
|
129 |
|
} catch (CdmRemoteSourceException e) {
|
130 |
|
logger.info(e.getMessage());
|
131 |
|
}
|
132 |
|
}
|
133 |
|
|
134 |
|
@Test
|
135 |
|
public void whenLoadingExistingIncompleteRemoteSourceThenThrowException() {
|
136 |
|
try {
|
137 |
|
remotePersistentSource = CdmPersistentRemoteSource.NewInstance("incomplete");
|
138 |
|
Assert.fail("Initialising an incomplete remote source should throw an exception");
|
139 |
|
} catch (CdmRemoteSourceException e) {
|
140 |
|
//Assert.assertThat(e.getMessage(), containsString("Required property '" + CdmSourceProperties.SERVER.toString() + "' is missing"));
|
141 |
|
}
|
142 |
|
}
|
143 |
|
|
144 |
|
@Test
|
145 |
|
public void whenSavingUpdatingDeletingNewCompleteRemoteSourceThenSaveUpdateDeleteIsSuccessful() {
|
146 |
|
String strRemoteSource = "local";
|
147 |
|
Assert.assertFalse("New remote source '" + strRemoteSource + "' should not yet exist in source settings file",
|
148 |
|
CdmPersistentRemoteSource.exists(strRemoteSource));
|
149 |
|
try {
|
150 |
|
ICdmRemoteSource remoteSource =
|
151 |
|
CdmRemoteSource.NewInstance(strRemoteSource,
|
152 |
|
"127.0.0.1",
|
153 |
|
8080,
|
154 |
|
"col",
|
155 |
|
NomenclaturalCode.ICNAFP);
|
156 |
|
remotePersistentSource = CdmPersistentRemoteSource.save(strRemoteSource,remoteSource);
|
157 |
|
|
158 |
|
logger.info("Server : " + remotePersistentSource.getServer());
|
159 |
|
Assert.assertTrue("Server value should be equal",
|
160 |
|
remoteSource.getServer().equals(remotePersistentSource.getServer()));
|
161 |
|
|
162 |
|
logger.info("Port : " + remotePersistentSource.getPort());
|
163 |
|
Assert.assertTrue("Port value should be equal",
|
164 |
|
remoteSource.getPort() == remotePersistentSource.getPort());
|
165 |
|
|
166 |
|
logger.info("Context Path : " + remotePersistentSource.getContextPath());
|
167 |
|
Assert.assertTrue("Context Path value should be equal",
|
168 |
|
remoteSource.getContextPath().equals(remotePersistentSource.getContextPath()));
|
169 |
|
|
170 |
|
logger.info("Nomenclatural Code : " + remotePersistentSource.getNomenclaturalCode().name());
|
171 |
|
Assert.assertTrue("Nomenclatural Code value should be equal",
|
172 |
|
remoteSource.getNomenclaturalCode().name().equals(remotePersistentSource.getNomenclaturalCode().name()));
|
173 |
|
|
174 |
|
Assert.assertTrue("New remote source '" + strRemoteSource + "' should be saved in source settings file",
|
175 |
|
CdmPersistentRemoteSource.exists(strRemoteSource));
|
176 |
|
|
177 |
|
remoteSource = CdmRemoteSource.NewInstance(strRemoteSource,
|
178 |
|
"127.0.0.55",
|
179 |
|
9090,
|
180 |
|
"cyprus",
|
181 |
|
NomenclaturalCode.ICNB);
|
182 |
|
remotePersistentSource = CdmPersistentRemoteSource.update(strRemoteSource,remoteSource);
|
183 |
|
|
184 |
|
logger.info("Server : " + remotePersistentSource.getServer());
|
185 |
|
Assert.assertTrue("Server value should be equal",
|
186 |
|
remoteSource.getServer().equals(remotePersistentSource.getServer()));
|
187 |
|
|
188 |
|
logger.info("Port : " + remotePersistentSource.getPort());
|
189 |
|
Assert.assertTrue("Port value should be equal",
|
190 |
|
remoteSource.getPort() == remotePersistentSource.getPort());
|
191 |
|
|
192 |
|
logger.info("Context Path : " + remotePersistentSource.getContextPath());
|
193 |
|
Assert.assertTrue("Context Path value should be equal",
|
194 |
|
remoteSource.getContextPath().equals(remotePersistentSource.getContextPath()));
|
195 |
|
|
196 |
|
logger.info("Nomenclatural Code : " + remotePersistentSource.getNomenclaturalCode().name());
|
197 |
|
Assert.assertTrue("Nomenclatural Code value should be equal",
|
198 |
|
remoteSource.getNomenclaturalCode().name().equals(remotePersistentSource.getNomenclaturalCode().name()));
|
199 |
|
|
200 |
|
Assert.assertTrue("New remote source '" + strRemoteSource + "' should be saved in source settings file",
|
201 |
|
CdmPersistentRemoteSource.exists(strRemoteSource));
|
202 |
|
|
203 |
|
CdmPersistentSourceUtils.delete(remotePersistentSource);
|
204 |
|
|
205 |
|
Assert.assertFalse("New remote source '" + strRemoteSource + "' should no longer exist in source settings file",
|
206 |
|
CdmPersistentRemoteSource.exists(strRemoteSource));
|
207 |
|
|
208 |
|
} catch (CdmRemoteSourceException e) {
|
209 |
|
Assert.fail("Saving a new complete remote source should not throw an exception");
|
210 |
|
logger.info(e.getMessage());
|
211 |
|
}
|
212 |
|
}
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
}
|
Ignore cdmlib war file